pub struct ChanMgr<R: Runtime> {
pub(crate) mgr: AbstractChanMgr<CompoundFactory<ChanBuilder<R, DefaultTransport<R>>>>,
pub(crate) bootstrap_status: ConnStatusEvents,
pub(crate) runtime: R,
}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.
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.)
Fields§
§mgr: AbstractChanMgr<CompoundFactory<ChanBuilder<R, DefaultTransport<R>>>>Internal channel manager object that does the actual work.
§How this is built
This internal manager is parameterized over an
mgr::AbstractChannelFactory, which here is instantiated with a factory::CompoundFactory.
The CompoundFactory itself holds:
- A
dynfactory::AbstractPtMgrthat can provide adynfactory::ChannelFactoryfor each supported pluggable transport. This starts out asNone, but can be replaced withChanMgr::set_pt_mgr. TheTorClientcode currently sets this usingtor_ptmgr::PtMgr.PtMgrcurrently returnsChannelFactoryimplementations that are built usingtransport::proxied::ExternalProxyPlugin, which implementstransport::TransportImplHelper, which in turn is wrapped into aChanBuilderto implementChannelFactory. - A generic
factory::ChannelFactorythat it uses for everything else We instantiate this with abuilder::ChanBuilderusing atransport::default::DefaultTransport.
bootstrap_status: ConnStatusEventsStream of ConnStatus events.
runtime: RThe runtime. Needed to possibly spawn tasks.
Implementations§
Source§impl<R: Runtime> ChanMgr<R>
impl<R: Runtime> ChanMgr<R>
Sourcepub fn new(
runtime: R,
config: ChanMgrConfig,
dormancy: Dormancy,
netparams: &NetParameters,
memquota: ToplevelAccount,
) -> Result<Self>where
R: 'static,
pub fn new(
runtime: R,
config: ChanMgrConfig,
dormancy: Dormancy,
netparams: &NetParameters,
memquota: ToplevelAccount,
) -> Result<Self>where
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.
The keymgr is only needed for a relay which is used for authenticating its channel to
other relays. Pass None for a client.
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: Sensitive<SocketAddr>,
stream: <R as NetStreamProvider>::Stream,
) -> Result<Arc<Channel>>
pub async fn handle_incoming( &self, src: Sensitive<SocketAddr>, stream: <R as NetStreamProvider>::Stream, ) -> Result<Arc<Channel>>
Build a channel for an incoming stream.
The my_addrs are the IP address(es) that are advertised by the relay in the consensus. We
need to pass them so they can be sent in the NETINFO cell.
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.
This function does not guarantee that the returned channel
satisfies all of the properties of target. For example if an
existing channel is returned, it might not be connected to any
of the addresses specified in target.
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>)
pub fn set_pt_mgr(&self, ptmgr: Arc<dyn AbstractPtMgr + 'static>)
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 fn set_relay_auth_material(
&self,
auth_material: Arc<RelayChannelAuthMaterial>,
) -> Result<()>
pub fn set_relay_auth_material( &self, auth_material: Arc<RelayChannelAuthMaterial>, ) -> Result<()>
Replace the relay auth material used for building new channels.
This rebuilds the internal channel builder with the provided auth_material, which includes a
new TLS cert and key. Existing channels are not affected, only newly created channels will
use the new keys.
Sourcepub fn set_create_request_handler(
&self,
handler: Arc<CreateRequestHandler>,
) -> Result<()>
pub fn set_create_request_handler( &self, handler: Arc<CreateRequestHandler>, ) -> Result<()>
This will be used to handle CREATE* requests on channels.
This handler will only be used for new channels, not existing channels.
This will not be updated in any way by the channel manager, for example by a netdir update or when any keys change. The caller must handle this. The idea is that the channel manager shouldn’t need to deal with circuit-specific stuff.
It’s expected to only ever call this once.
Ideally it would be an Option in the constructor,
but we don’t want conditionally-compiled constructor arguments,
and the CreateRequestHandler requires a [dyn ChannelProvider]
which is typically this ChanMgr itself.
Sourcepub async fn build_unmanaged_channel(
&self,
target: impl IntoOwnedChanTarget,
memquota: ChannelAccount,
) -> Result<Arc<Channel>>
pub async fn build_unmanaged_channel( &self, target: impl IntoOwnedChanTarget, memquota: ChannelAccount, ) -> Result<Arc<Channel>>
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.
Sourcepub(crate) async fn continually_update_channels_config(
self_: Weak<Self>,
netdir: Arc<dyn NetDirProvider>,
)
pub(crate) async fn continually_update_channels_config( self_: Weak<Self>, netdir: Arc<dyn NetDirProvider>, )
Watch for things that ought to change the configuration of all channels in the client
Currently this handles enabling and disabling channel padding.
This is a daemon task that runs indefinitely in the background,
and exits when we find that chanmgr is dropped.
Sourcepub(crate) async fn continually_expire_channels(
sched: TaskSchedule<R>,
chanmgr: Weak<Self>,
)
pub(crate) async fn continually_expire_channels( sched: TaskSchedule<R>, chanmgr: Weak<Self>, )
Periodically expire any channels that have been unused beyond the maximum duration allowed.
Exist when we find that chanmgr is dropped
This is a daemon task that runs indefinitely in the background
Trait Implementations§
Source§impl<R: Runtime> ChannelProvider for ChanMgr<R>
impl<R: Runtime> ChannelProvider for ChanMgr<R>
Source§type BuildSpec = OwnedChanTarget
type BuildSpec = OwnedChanTarget
Source§fn get_or_launch(
self: Arc<Self>,
reactor_id: UniqId,
target: Self::BuildSpec,
tx: OutboundChanSender,
) -> Result<()>
fn get_or_launch( self: Arc<Self>, reactor_id: UniqId, target: Self::BuildSpec, tx: OutboundChanSender, ) -> Result<()>
target, for the circuit reactor with the
specified reactor_id which should only be used for logging purposes. Read moreAuto 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>where
R: Unpin,
impl<R> UnsafeUnpin for ChanMgr<R>where
R: UnsafeUnpin,
impl<R> !UnwindSafe for ChanMgr<R>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§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
Source§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
Source§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.Source§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.Source§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
Source§impl<T> Tap for T
impl<T> Tap for T
Source§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.