pub struct Channel { /* private fields */ }
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::terminate
on the channel. - The last reference to the
Channel
is dropped. (Note that every circuit on aChannel
keeps 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.
Implementations§
Source§impl Channel
impl Channel
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.
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 async fn new_circ(self: &Arc<Self>) -> Result<(PendingClientCirc, Reactor)>
pub async fn new_circ(self: &Arc<Self>) -> Result<(PendingClientCirc, Reactor)>
Return a newly allocated PendingClientCirc object with a corresponding circuit 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::circuit::PendingClientCirc 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
pub fn wait_for_close( &self, ) -> impl Future<Output = StdResult<CloseInfo, ClosedUnexpectedly>> + Send + Sync + 'static
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 fn new_fake() -> (Channel, UnboundedReceiver<CtrlMsg>)
Available on crate feature testing
only.
pub fn new_fake() -> (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 moreSource§fn identities(&self) -> RelayIdIter<'_, Self>
fn identities(&self) -> RelayIdIter<'_, Self>
Source§fn ed_identity(&self) -> Option<&Ed25519Identity>
fn ed_identity(&self) -> Option<&Ed25519Identity>
Source§fn rsa_identity(&self) -> Option<&RsaIdentity>
fn rsa_identity(&self) -> Option<&RsaIdentity>
Source§fn has_identity(&self, id: RelayIdRef<'_>) -> bool
fn has_identity(&self, id: RelayIdRef<'_>) -> bool
Source§fn has_any_identity(&self) -> bool
fn has_any_identity(&self) -> bool
Source§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
.Source§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 moreSource§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 moreSource§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,
Source§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>
. Box<dyn Any>
can
then be further downcast
into Box<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>
. Rc<Any>
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> 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.§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.