Skip to main content

AbstractTunnelBuilder

Trait AbstractTunnelBuilder 

Source
pub(crate) trait AbstractTunnelBuilder<R: Runtime>: Send + Sync {
    type Tunnel: AbstractTunnel + Send + Sync;
    type Plan: Send + Debug + MockablePlan;

Show 14 methods // Required methods fn plan_tunnel( &self, usage: &TargetTunnelUsage, dir: DirInfo<'_>, ) -> Result<(Self::Plan, SupportedTunnelUsage)>; fn build_tunnel<'life0, 'async_trait>( &'life0 self, plan: Self::Plan, ) -> Pin<Box<dyn Future<Output = Result<(SupportedTunnelUsage, Self::Tunnel)>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn learning_timeouts(&self) -> bool; fn save_state(&self) -> Result<bool>; fn path_config(&self) -> Arc<PathConfig>; fn set_path_config(&self, new_config: PathConfig); fn estimator(&self) -> &Estimator; fn vanguardmgr(&self) -> &Arc<VanguardMgr<R>>; fn upgrade_to_owned_state(&self) -> Result<()>; fn reload_state(&self) -> Result<()>; fn guardmgr(&self) -> &GuardMgr<R>; fn update_network_parameters(&self, p: &NetParameters); // Provided methods fn launch_parallelism(&self, usage: &TargetTunnelUsage) -> usize { ... } fn select_parallelism(&self, usage: &TargetTunnelUsage) -> usize { ... }
}
Expand description

An object that knows how to build tunnels.

This creates tunnels in two phases. First, a plan is made for how to build the tunnel. This planning phase should be relatively fast, and must not suspend or block. Its purpose is to get an early estimate of which operations the tunnel will be able to support when it’s done.

Second, the tunnel is actually built, using the plan as input.

Required Associated Types§

Source

type Tunnel: AbstractTunnel + Send + Sync

The tunnel type that this builder knows how to build.

Source

type Plan: Send + Debug + MockablePlan

An opaque type describing how a given tunnel will be built. It may represent some or all of a path-or it may not.

Required Methods§

Source

fn plan_tunnel( &self, usage: &TargetTunnelUsage, dir: DirInfo<'_>, ) -> Result<(Self::Plan, SupportedTunnelUsage)>

Form a plan for how to build a new tunnel that supports usage.

Return an opaque Plan object, and a new spec describing what the tunnel will actually support when it’s built. (For example, if the input spec requests a tunnel that connect to port 80, then “planning” the tunnel might involve picking an exit that supports port 80, and the resulting spec might be the exit’s complete list of supported ports.)

§Requirements

The resulting Spec must support usage.

Source

fn build_tunnel<'life0, 'async_trait>( &'life0 self, plan: Self::Plan, ) -> Pin<Box<dyn Future<Output = Result<(SupportedTunnelUsage, Self::Tunnel)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Construct a tunnel according to a given plan.

On success, return a spec describing what the tunnel can be used for, and the tunnel that was just constructed.

This function should implement some kind of a timeout for tunnel that are taking too long.

§Requirements

The spec that this function returns must support the usage that was originally passed to plan_tunnel. It must also contain the spec that was originally returned by plan_tunnel.

Source

fn learning_timeouts(&self) -> bool

Return true if we are currently attempting to learn tunnel timeouts by building testing tunnels.

Source

fn save_state(&self) -> Result<bool>

Flush state to the state manager if we own the lock.

Return Ok(true) if we saved, and Ok(false) if we didn’t hold the lock.

Source

fn path_config(&self) -> Arc<PathConfig>

Return this builder’s PathConfig.

Source

fn set_path_config(&self, new_config: PathConfig)

Replace this builder’s PathConfig.

Source

fn estimator(&self) -> &Estimator

Return a reference to this builder’s timeout estimator.

Source

fn vanguardmgr(&self) -> &Arc<VanguardMgr<R>>

Return a reference to this builder’s VanguardMgr.

Source

fn upgrade_to_owned_state(&self) -> Result<()>

Replace our state with a new owning state, assuming we have storage permission.

Source

fn reload_state(&self) -> Result<()>

Reload persistent state from disk, if we don’t have storage permission.

Source

fn guardmgr(&self) -> &GuardMgr<R>

Return a reference to this builder’s GuardMgr.

Source

fn update_network_parameters(&self, p: &NetParameters)

Reconfigure this builder using the latest set of network parameters.

(NOTE: for now, this only affects tunnel timeout estimation.)

Provided Methods§

Source

fn launch_parallelism(&self, usage: &TargetTunnelUsage) -> usize

Return a “parallelism factor” with which tunnels should be constructed for a given purpose.

If this function returns N, then whenever we launch tunnels for this purpose, then we launch N in parallel.

The default implementation returns 1. The value of 0 is treated as if it were 1.

Source

fn select_parallelism(&self, usage: &TargetTunnelUsage) -> usize

Return a “parallelism factor” for which tunnels should be used for a given purpose.

If this function returns N, then whenever we select among open tunnels for this purpose, we choose at random from the best N.

The default implementation returns 1. The value of 0 is treated as if it were 1.

Implementors§