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§
Sourcetype Tunnel: AbstractTunnel + Send + Sync
type Tunnel: AbstractTunnel + Send + Sync
The tunnel type that this builder knows how to build.
Sourcetype Plan: Send + Debug + MockablePlan
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§
Sourcefn plan_tunnel(
&self,
usage: &TargetTunnelUsage,
dir: DirInfo<'_>,
) -> Result<(Self::Plan, SupportedTunnelUsage)>
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.
Sourcefn 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 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.
Sourcefn learning_timeouts(&self) -> bool
fn learning_timeouts(&self) -> bool
Return true if we are currently attempting to learn tunnel timeouts by building testing tunnels.
Sourcefn save_state(&self) -> Result<bool>
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.
Sourcefn path_config(&self) -> Arc<PathConfig>
fn path_config(&self) -> Arc<PathConfig>
Return this builder’s PathConfig.
Sourcefn set_path_config(&self, new_config: PathConfig)
fn set_path_config(&self, new_config: PathConfig)
Replace this builder’s PathConfig.
Sourcefn vanguardmgr(&self) -> &Arc<VanguardMgr<R>>
fn vanguardmgr(&self) -> &Arc<VanguardMgr<R>>
Return a reference to this builder’s VanguardMgr.
Sourcefn upgrade_to_owned_state(&self) -> Result<()>
fn upgrade_to_owned_state(&self) -> Result<()>
Replace our state with a new owning state, assuming we have storage permission.
Sourcefn reload_state(&self) -> Result<()>
fn reload_state(&self) -> Result<()>
Reload persistent state from disk, if we don’t have storage permission.
Sourcefn update_network_parameters(&self, p: &NetParameters)
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§
Sourcefn launch_parallelism(&self, usage: &TargetTunnelUsage) -> usize
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.
Sourcefn select_parallelism(&self, usage: &TargetTunnelUsage) -> usize
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.