WIP
This commit is contained in:
parent
73669fa05e
commit
ad851c43c6
|
@ -54,7 +54,7 @@ impl<R: Runtime> crate::mgr::AbstractCircBuilder for crate::build::CircuitBuilde
|
|||
) -> Result<(Plan, SupportedCircUsage)> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let (path, final_spec, guard_status, guard_usable) =
|
||||
usage.build_path(&mut rng, dir, self.path_config())?;
|
||||
usage.build_path(&mut rng, dir, Some(self.guardmgr()), self.path_config())?;
|
||||
|
||||
let plan = Plan {
|
||||
final_spec: final_spec.clone(),
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
use super::TorPath;
|
||||
use crate::{DirInfo, Error, Result};
|
||||
use tor_netdir::{Relay, WeightRole};
|
||||
use tor_guardmgr::GuardMgr;
|
||||
use tor_rtcompat::Runtime;
|
||||
|
||||
use rand::{seq::SliceRandom, Rng};
|
||||
|
||||
|
@ -23,8 +25,8 @@ impl DirPathBuilder {
|
|||
|
||||
/// Try to create and return a path corresponding to the requirements of
|
||||
/// this builder.
|
||||
pub fn pick_path<'a, R: Rng>(&self, rng: &mut R, netdir: DirInfo<'a>) -> Result<TorPath<'a>> {
|
||||
// TODO: this will need to learn about directory guards.
|
||||
pub fn pick_path<'a, R: Rng, RT: Runtime>(&self, rng: &mut R, netdir: DirInfo<'a>, guards: Option<&GuardMgr<RT>>) -> Result<TorPath<'a>> {
|
||||
let _ = guards; // XXXXX Implement me.
|
||||
match netdir {
|
||||
DirInfo::Fallbacks(f) => {
|
||||
let relay = f.choose(rng);
|
||||
|
@ -63,7 +65,7 @@ mod test {
|
|||
let dirinfo = (&netdir).into();
|
||||
|
||||
for _ in 0..1000 {
|
||||
let p = DirPathBuilder::default().pick_path(&mut rng, dirinfo);
|
||||
let p = DirPathBuilder::default().pick_path(&mut rng, dirinfo, None);
|
||||
let p = p.unwrap();
|
||||
assert!(p.exit_relay().is_none());
|
||||
assert_eq!(p.len(), 1);
|
||||
|
@ -96,7 +98,7 @@ mod test {
|
|||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _ in 0..10 {
|
||||
let p = DirPathBuilder::default().pick_path(&mut rng, dirinfo);
|
||||
let p = DirPathBuilder::default().pick_path(&mut rng, dirinfo, None);
|
||||
let p = p.unwrap();
|
||||
assert!(p.exit_relay().is_none());
|
||||
assert_eq!(p.len(), 1);
|
||||
|
@ -116,7 +118,7 @@ mod test {
|
|||
let dirinfo = DirInfo::Fallbacks(&fb[..]);
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let err = DirPathBuilder::default().pick_path(&mut rng, dirinfo);
|
||||
let err = DirPathBuilder::default().pick_path(&mut rng, dirinfo, None);
|
||||
assert!(matches!(err, Err(Error::NoRelays(_))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use super::TorPath;
|
|||
use crate::{DirInfo, Error, PathConfig, Result, TargetPort};
|
||||
use rand::Rng;
|
||||
use tor_netdir::{NetDir, Relay, SubnetConfig, WeightRole};
|
||||
use tor_guardmgr::GuardMgr;
|
||||
|
||||
/// Internal representation of PathBuilder.
|
||||
enum ExitPathBuilderInner<'a> {
|
||||
|
@ -97,13 +98,14 @@ impl<'a> ExitPathBuilder<'a> {
|
|||
|
||||
/// Try to create and return a path corresponding to the requirements of
|
||||
/// this builder.
|
||||
pub fn pick_path<R: Rng>(
|
||||
pub fn pick_path<R: Rng, RT: Runtime>(
|
||||
&self,
|
||||
rng: &mut R,
|
||||
netdir: DirInfo<'a>,
|
||||
guards: Option<&GuardMgr<RT>>,
|
||||
config: &PathConfig,
|
||||
) -> Result<TorPath<'a>> {
|
||||
// TODO: implement guards
|
||||
let _ = guards; // XXXXXX Implement me.
|
||||
let netdir = match netdir {
|
||||
DirInfo::Fallbacks(_) => return Err(Error::NeedConsensus),
|
||||
DirInfo::Directory(d) => d,
|
||||
|
|
|
@ -5,9 +5,10 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::path::{dirpath::DirPathBuilder, exitpath::ExitPathBuilder, TorPath};
|
||||
use tor_guardmgr::{GuardMonitor, GuardUsable};
|
||||
use tor_guardmgr::{GuardMgr, GuardMonitor, GuardUsable};
|
||||
use tor_netdir::Relay;
|
||||
use tor_netdoc::types::policy::PortPolicy;
|
||||
use tor_rtcompat::Runtime;
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
|
@ -168,10 +169,11 @@ pub(crate) enum SupportedCircUsage {
|
|||
impl TargetCircUsage {
|
||||
/// Construct path for a given circuit purpose; return it and the
|
||||
/// usage that it _actually_ supports.
|
||||
pub(crate) fn build_path<'a, R: Rng>(
|
||||
pub(crate) fn build_path<'a, R: Rng, RT: Runtime>(
|
||||
&self,
|
||||
rng: &mut R,
|
||||
netdir: crate::DirInfo<'a>,
|
||||
guards: Option<&GuardMgr<RT>>,
|
||||
config: &crate::PathConfig,
|
||||
) -> Result<(
|
||||
TorPath<'a>,
|
||||
|
@ -181,7 +183,7 @@ impl TargetCircUsage {
|
|||
)> {
|
||||
match self {
|
||||
TargetCircUsage::Dir => {
|
||||
let path = DirPathBuilder::new().pick_path(rng, netdir)?;
|
||||
let path = DirPathBuilder::new().pick_path(rng, netdir, guards)?;
|
||||
Ok((path, SupportedCircUsage::Dir, None, None))
|
||||
}
|
||||
TargetCircUsage::Exit {
|
||||
|
@ -189,7 +191,7 @@ impl TargetCircUsage {
|
|||
isolation_group,
|
||||
} => {
|
||||
let path =
|
||||
ExitPathBuilder::from_target_ports(p.clone()).pick_path(rng, netdir, config)?;
|
||||
ExitPathBuilder::from_target_ports(p.clone()).pick_path(rng, netdir, guards, config)?;
|
||||
let policy = path
|
||||
.exit_policy()
|
||||
.expect("ExitPathBuilder gave us a one-hop circuit?");
|
||||
|
@ -204,7 +206,7 @@ impl TargetCircUsage {
|
|||
))
|
||||
}
|
||||
TargetCircUsage::TimeoutTesting => {
|
||||
let path = ExitPathBuilder::for_timeout_testing().pick_path(rng, netdir, config)?;
|
||||
let path = ExitPathBuilder::for_timeout_testing().pick_path(rng, netdir, guards, config)?;
|
||||
let policy = path.exit_policy();
|
||||
let usage = match policy {
|
||||
Some(policy) if policy.allows_some_port() => SupportedCircUsage::Exit {
|
||||
|
|
Loading…
Reference in New Issue