pub struct Channel {
channel_type: ChannelType,
control: UnboundedSender<CtrlMsg>,
cell_tx: CountingSink<Sender<(AnyChanCell, Option<QueuedCellPaddingInfo>), MpscSpec>>,
reactor_closed_rx: Receiver<Result<CloseInfo>>,
padding_ctrl: PaddingController,
unique_id: UniqId,
peer_id: OwnedChanTarget,
clock_skew: ClockSkew,
opened_at: Instant,
mutable: Mutex<MutableDetails>,
details: Arc<ChannelDetails>,
}Expand description
An open client channel, ready to send and receive Tor cells.
A channel is a direct connection to a Tor relay, implemented using TLS.
This struct is a frontend that can be used to send cells and otherwise control the channel. The main state is in the Reactor object.
(Users need a mutable reference because of the types in Sink, and
ultimately because cell_tx: mpsc::Sender doesn’t work without mut.
§Channel life cycle
Channels can be created directly here through the ChannelBuilder API.
For a higher-level API (with better support for TLS, pluggable transports,
and channel reuse) see the tor-chanmgr crate.
After a channel is created, it will persist until it is closed in one of four ways:
- A remote error occurs.
- The other side of the channel closes the channel.
- Someone calls
Channel::terminateon the channel. - The last reference to the
Channelis dropped. (Note that every circuit on aChannelkeeps a reference to it, which will in turn keep the channel from closing until all those circuits have gone away.)
Note that in cases 1-3, the Channel object itself will still exist: it
will just be unusable for most purposes. Most operations on it will fail
with an error.
Fields§
§channel_type: ChannelTypeThe channel type.
control: UnboundedSender<CtrlMsg>A channel used to send control messages to the Reactor.
cell_tx: CountingSink<Sender<(AnyChanCell, Option<QueuedCellPaddingInfo>), MpscSpec>>A channel used to send cells to the Reactor.
reactor_closed_rx: Receiver<Result<CloseInfo>>A receiver that indicates whether the channel is closed.
Awaiting will return a CancelledError event when the reactor is dropped.
Read to decide if operations may succeed, and is returned by wait_for_close.
padding_ctrl: PaddingControllerPadding controller, used to report when data is queued for this channel.
unique_id: UniqIdA unique identifier for this channel.
peer_id: OwnedChanTargetValidated identity and address information for this peer.
clock_skew: ClockSkewThe declared clock skew on this channel, at the time when this channel was created.
opened_at: InstantThe time when this channel was successfully completed
mutable: Mutex<MutableDetails>Mutable state used by the `Channel.
details: Arc<ChannelDetails>Information shared with the reactor
Implementations§
Source§impl Channel
impl Channel
Sourcefn new<S>(
channel_type: ChannelType,
link_protocol: u16,
sink: Box<dyn Sink<AnyChanCell, Error = Error> + Send + Unpin + 'static>,
stream: Box<dyn Stream<Item = Result<AnyChanCell, Error>> + Send + Unpin + 'static>,
streamops: Box<dyn StreamOps + Send + Unpin + 'static>,
unique_id: UniqId,
peer_id: OwnedChanTarget,
clock_skew: ClockSkew,
sleep_prov: S,
memquota: ChannelAccount,
) -> Result<(Arc<Self>, Reactor<S>)>where
S: CoarseTimeProvider + SleepProvider,
fn new<S>(
channel_type: ChannelType,
link_protocol: u16,
sink: Box<dyn Sink<AnyChanCell, Error = Error> + Send + Unpin + 'static>,
stream: Box<dyn Stream<Item = Result<AnyChanCell, Error>> + Send + Unpin + 'static>,
streamops: Box<dyn StreamOps + Send + Unpin + 'static>,
unique_id: UniqId,
peer_id: OwnedChanTarget,
clock_skew: ClockSkew,
sleep_prov: S,
memquota: ChannelAccount,
) -> Result<(Arc<Self>, Reactor<S>)>where
S: CoarseTimeProvider + SleepProvider,
Construct a channel and reactor.
Internal method, called to finalize the channel when we’ve sent our netinfo cell, received the peer’s netinfo cell, and we’re finally ready to create circuits.
Quick note on the allow clippy. This is has one call site so for now, it is fine that we bust the mighty 7 arguments.
Sourcepub fn mq_account(&self) -> &ChannelAccount
pub fn mq_account(&self) -> &ChannelAccount
Return a reference to the memory tracking account for this Channel
Sourcepub fn time_provider(&self) -> &DynTimeProvider
pub fn time_provider(&self) -> &DynTimeProvider
Obtain a reference to the Channel’s DynTimeProvider
(This can sometimes be used to avoid having to keep a separate clone of the time provider.)
Sourcepub fn target(&self) -> &OwnedChanTarget
pub fn target(&self) -> &OwnedChanTarget
Return an OwnedChanTarget representing the actual handshake used to create this channel.
Sourcepub fn age(&self) -> Duration
pub fn age(&self) -> Duration
Return the amount of time that has passed since this channel became open.
Sourcepub fn clock_skew(&self) -> ClockSkew
pub fn clock_skew(&self) -> ClockSkew
Return a ClockSkew declaring how much clock skew the other side of this channel claimed that we had when we negotiated the connection.
Sourcefn send_control(&self, msg: CtrlMsg) -> StdResult<(), ChannelClosed>
fn send_control(&self, msg: CtrlMsg) -> StdResult<(), ChannelClosed>
Send a control message
Sourcefn mutable(&self) -> MutexGuard<'_, MutableDetails>
fn mutable(&self) -> MutexGuard<'_, MutableDetails>
Acquire the lock on mutable (and handle any poison error)
Sourcepub fn engage_padding_activities(&self)
pub fn engage_padding_activities(&self)
Specify that this channel should do activities related to channel padding
Initially, the channel does nothing related to channel padding: it neither sends any padding, nor sends any PADDING_NEGOTIATE cells.
After this function has been called, it will do both,
according to the parameters specified through reparameterize.
Note that this might include disabling padding
(for example, by sending a PADDING_NEGOTIATE).
Idempotent.
There is no way to undo the effect of this call.
Sourcepub fn reparameterize(
&self,
params: Arc<ChannelPaddingInstructionsUpdates>,
) -> Result<()>
pub fn reparameterize( &self, params: Arc<ChannelPaddingInstructionsUpdates>, ) -> Result<()>
Reparameterise (update parameters; reconfigure)
Returns Err if the channel was closed earlier
Sourcepub fn reparameterize_kist(&self, kist_params: KistParams) -> Result<()>
pub fn reparameterize_kist(&self, kist_params: KistParams) -> Result<()>
Update the KIST parameters.
Returns Err if the channel is closed.
Sourcepub fn check_match<T: HasRelayIds + ?Sized>(&self, target: &T) -> Result<()>
pub fn check_match<T: HasRelayIds + ?Sized>(&self, target: &T) -> Result<()>
Return an error if this channel is somehow mismatched with the given target.
Sourcepub fn is_closing(&self) -> bool
pub fn is_closing(&self) -> bool
Return true if this channel is closed and therefore unusable.
Sourcepub fn duration_unused(&self) -> Option<Duration>
pub fn duration_unused(&self) -> Option<Duration>
If the channel is not in use, return the amount of time it has had with no circuits.
Return None if the channel is currently in use.
Sourcepub(crate) fn sender(&self) -> ChannelSender
pub(crate) fn sender(&self) -> ChannelSender
Return a new ChannelSender to transmit cells on this channel.
Sourcepub async fn new_tunnel(
self: &Arc<Self>,
timeouts: Arc<dyn TimeoutEstimator>,
) -> Result<(PendingClientTunnel, Reactor)>
pub async fn new_tunnel( self: &Arc<Self>, timeouts: Arc<dyn TimeoutEstimator>, ) -> Result<(PendingClientTunnel, Reactor)>
Return a newly allocated PendingClientTunnel object with a corresponding tunnel reactor. A circuit ID is allocated, but no messages are sent, and no cryptography is done.
To use the results of this method, call Reactor::run() in a new task, then use the methods of crate::client::circuit::PendingClientTunnel to build the circuit.
Sourcepub fn terminate(&self)
pub fn terminate(&self)
Shut down this channel immediately, along with all circuits that are using it.
Note that other references to this channel may exist. If they do, they will stop working after you call this function.
It’s not necessary to call this method if you’re just done with a channel: the channel should close on its own once nothing is using it any more.
Sourcepub fn close_circuit(&self, circid: CircId) -> Result<()>
pub fn close_circuit(&self, circid: CircId) -> Result<()>
Tell the reactor that the circuit with the given ID has gone away.
Sourcepub fn wait_for_close(
&self,
) -> impl Future<Output = StdResult<CloseInfo, ClosedUnexpectedly>> + Send + Sync + 'static + use<>
pub fn wait_for_close( &self, ) -> impl Future<Output = StdResult<CloseInfo, ClosedUnexpectedly>> + Send + Sync + 'static + use<>
Return a future that will resolve once this channel has closed.
Note that this method does not cause the channel to shut down on its own.
Sourcepub async fn start_padding(
self: &Arc<Self>,
padder: CircuitPadder,
) -> Result<()>
Available on crate feature circ-padding-manual only.
pub async fn start_padding( self: &Arc<Self>, padder: CircuitPadder, ) -> Result<()>
circ-padding-manual only.Install a CircuitPadder for this channel.
Replaces any previous padder installed.
Sourcepub async fn stop_padding(self: &Arc<Self>) -> Result<()>
Available on crate feature circ-padding-manual only.
pub async fn stop_padding(self: &Arc<Self>) -> Result<()>
circ-padding-manual only.Remove any CircuitPadder installed for this channel.
Does nothing if there was not a padder installed there.
Sourceasync fn set_padder_impl(
self: &Arc<Self>,
padder: Option<CircuitPadder>,
) -> Result<()>
Available on crate feature circ-padding-manual only.
async fn set_padder_impl( self: &Arc<Self>, padder: Option<CircuitPadder>, ) -> Result<()>
circ-padding-manual only.Replace the CircuitPadder installed for this channel with padder.
Sourcepub fn new_fake(
rt: impl SleepProvider + CoarseTimeProvider,
channel_type: ChannelType,
) -> (Channel, UnboundedReceiver<CtrlMsg>)
Available on crate feature testing only.
pub fn new_fake( rt: impl SleepProvider + CoarseTimeProvider, channel_type: ChannelType, ) -> (Channel, UnboundedReceiver<CtrlMsg>)
testing only.Make a new fake reactor-less channel. For testing only, obviously.
Returns the receiver end of the control message mpsc.
Suitable for external callers who want to test behaviour
of layers including the logic in the channel frontend
(Channel object methods).
Trait Implementations§
Source§impl HasRelayIds for Channel
impl HasRelayIds for Channel
Source§fn identity(&self, key_type: RelayIdType) -> Option<RelayIdRef<'_>>
fn identity(&self, key_type: RelayIdType) -> Option<RelayIdRef<'_>>
key_type, or None if
the relay has no such identity. Read more§fn identities(&self) -> RelayIdIter<'_, Self>
fn identities(&self) -> RelayIdIter<'_, Self>
§fn ed_identity(&self) -> Option<&Ed25519Identity>
fn ed_identity(&self) -> Option<&Ed25519Identity>
§fn rsa_identity(&self) -> Option<&RsaIdentity>
fn rsa_identity(&self) -> Option<&RsaIdentity>
§fn has_identity(&self, id: RelayIdRef<'_>) -> bool
fn has_identity(&self, id: RelayIdRef<'_>) -> bool
§fn has_any_identity(&self) -> bool
fn has_any_identity(&self) -> bool
§fn same_relay_ids<T>(&self, other: &T) -> boolwhere
T: HasRelayIds + ?Sized,
fn same_relay_ids<T>(&self, other: &T) -> boolwhere
T: HasRelayIds + ?Sized,
other.§fn has_all_relay_ids_from<T>(&self, other: &T) -> boolwhere
T: HasRelayIds + ?Sized,
fn has_all_relay_ids_from<T>(&self, other: &T) -> boolwhere
T: HasRelayIds + ?Sized,
other does. Read more§fn has_any_relay_id_from<T>(&self, other: &T) -> boolwhere
T: HasRelayIds + ?Sized,
fn has_any_relay_id_from<T>(&self, other: &T) -> boolwhere
T: HasRelayIds + ?Sized,
other has. Read more§fn cmp_by_relay_ids<T>(&self, other: &T) -> Orderingwhere
T: HasRelayIds + ?Sized,
fn cmp_by_relay_ids<T>(&self, other: &T) -> Orderingwhere
T: HasRelayIds + ?Sized,
§fn display_relay_ids(&self) -> DisplayRelayIds<'_, Self>
fn display_relay_ids(&self) -> DisplayRelayIds<'_, Self>
HasRelayIds] members.Auto Trait Implementations§
impl !Freeze for Channel
impl !RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl !UnwindSafe for Channel
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PossiblyOption<T> for T
impl<T> PossiblyOption<T> for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.