pub struct ChanMgr<R: Runtime> { /* private fields */ }
Expand description
An object that remembers a set of live channels, and launches new ones on request.
Use the ChanMgr::get_or_launch
function to create a new Channel
, or
get one if it exists. (For a slightly lower-level API that does no caching,
see ChannelFactory
and its implementors. For a
much lower-level API, see tor_proto::channel::ChannelBuilder
.)
Each channel is kept open as long as there is a reference to it, or something else (such as the relay or a network error) kills the channel.
After a ChanMgr
launches a channel, it keeps a reference to it until that
channel has been unused (that is, had no circuits attached to it) for a
certain amount of time. (Currently this interval is chosen randomly from
between 180-270 seconds, but this is an implementation detail that may change
in the future.)
Implementations§
Source§impl<R: Runtime> ChanMgr<R>
impl<R: Runtime> ChanMgr<R>
Sourcepub fn new(
runtime: R,
config: &ChannelConfig,
dormancy: Dormancy,
netparams: &NetParameters,
memquota: ToplevelAccount,
) -> Selfwhere
R: 'static,
pub fn new(
runtime: R,
config: &ChannelConfig,
dormancy: Dormancy,
netparams: &NetParameters,
memquota: ToplevelAccount,
) -> Selfwhere
R: 'static,
Construct a new channel manager.
A new ChannelAccount
will be made from memquota
, for each Channel.
The ChannelAccount
is used for data associated with this channel.
This does not (currently) include downstream outbound data (ie, data processed by the channel implementation here, awaiting TLS processing and actual transmission). In any case we try to keep those buffers small.
The ChannelAccount does track upstream outbound data
(ie, data processed by a circuit, but not yet by the channel),
even though that data relates to a specific circuit.
TODO #1652 use CircuitAccount
for circuit->channel queue.
§Usage note
For the manager to work properly, you will need to call ChanMgr::launch_background_tasks
.
Sourcepub fn launch_background_tasks(
self: &Arc<Self>,
runtime: &R,
netdir: Arc<dyn NetDirProvider>,
) -> Result<Vec<TaskHandle>>
pub fn launch_background_tasks( self: &Arc<Self>, runtime: &R, netdir: Arc<dyn NetDirProvider>, ) -> Result<Vec<TaskHandle>>
Launch the periodic daemon tasks required by the manager to function properly.
Returns a TaskHandle
that can be used to manage
those daemon tasks that poll periodically.
Sourcepub async fn handle_incoming(
&self,
src: SocketAddr,
stream: <R as NetStreamProvider>::Stream,
) -> Result<Arc<Channel>>
Available on crate feature relay
only.
pub async fn handle_incoming( &self, src: SocketAddr, stream: <R as NetStreamProvider>::Stream, ) -> Result<Arc<Channel>>
relay
only.Build a channel for an incoming stream.
The channel may or may not be authenticated. This method will wait until the channel is usable, and may return an error if we already have an existing channel to this peer, or if there are already too many open connections with this peer or subnet (as a dos defence).
Sourcepub async fn get_or_launch<T: ChanTarget + ?Sized>(
&self,
target: &T,
usage: ChannelUsage,
) -> Result<(Arc<Channel>, ChanProvenance)>
pub async fn get_or_launch<T: ChanTarget + ?Sized>( &self, target: &T, usage: ChannelUsage, ) -> Result<(Arc<Channel>, ChanProvenance)>
Try to get a suitable channel to the provided target
,
launching one if one does not exist.
If there is already a channel launch attempt in progress, this function will wait until that launch is complete, and succeed or fail depending on its outcome.
Sourcepub fn bootstrap_events(&self) -> ConnStatusEvents
pub fn bootstrap_events(&self) -> ConnStatusEvents
Return a stream of ConnStatus
events to tell us about changes
in our ability to connect to the internet.
Note that this stream can be lossy: the caller will not necessarily observe every event on the stream
Sourcepub fn expire_channels(&self) -> Duration
pub fn expire_channels(&self) -> Duration
Expire all channels that have been unused for too long.
Return the duration from now until next channel expires.
Sourcepub fn set_dormancy(
&self,
dormancy: Dormancy,
netparams: Arc<dyn AsRef<NetParameters>>,
) -> StdResult<(), Bug>
pub fn set_dormancy( &self, dormancy: Dormancy, netparams: Arc<dyn AsRef<NetParameters>>, ) -> StdResult<(), Bug>
Notifies the chanmgr to be dormant like dormancy
Sourcepub fn reconfigure(
&self,
config: &ChannelConfig,
how: Reconfigure,
netparams: Arc<dyn AsRef<NetParameters>>,
) -> StdResult<(), ReconfigureError>
pub fn reconfigure( &self, config: &ChannelConfig, how: Reconfigure, netparams: Arc<dyn AsRef<NetParameters>>, ) -> StdResult<(), ReconfigureError>
Reconfigure all channels
Sourcepub fn set_pt_mgr(&self, ptmgr: Arc<dyn AbstractPtMgr + 'static>)
Available on crate feature pt-client
only.
pub fn set_pt_mgr(&self, ptmgr: Arc<dyn AbstractPtMgr + 'static>)
pt-client
only.Replace the transport registry with one that may know about more transports.
Note that the ChannelFactory
instances returned by ptmgr
are
required to time-out channels that take too long to build. You’ll get
this behavior by default if the factories implement ChannelFactory
using
transport::proxied::ExternalProxyPlugin
, which tor-ptmgr
does.
Sourcepub async fn build_unmanaged_channel(
&self,
target: impl IntoOwnedChanTarget,
memquota: ChannelAccount,
) -> Result<Arc<Channel>>
Available on crate feature experimental-api
only.
pub async fn build_unmanaged_channel( &self, target: impl IntoOwnedChanTarget, memquota: ChannelAccount, ) -> Result<Arc<Channel>>
experimental-api
only.Try to create a new, unmanaged channel to target
.
Unlike get_or_launch
, this function always
creates a new channel, never retries transient failure, and does not
register this channel with the ChanMgr
.
Generally you should not use this function; get_or_launch
is usually a
better choice. This function is the right choice if, for whatever
reason, you need to manage the lifetime of the channel you create, and
make sure that no other code with access to this ChanMgr
will be able
to use the channel.
Auto Trait Implementations§
impl<R> !Freeze for ChanMgr<R>
impl<R> !RefUnwindSafe for ChanMgr<R>
impl<R> Send for ChanMgr<R>
impl<R> Sync for ChanMgr<R>
impl<R> Unpin for ChanMgr<R>
impl<R> !UnwindSafe for ChanMgr<R>
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> 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.