Skip to content

Commit

Permalink
Add hostname constraint to ExitConstraint and update get_dialer to su…
Browse files Browse the repository at this point in the history
…pport hostname filtering
  • Loading branch information
nullchinchilla committed Sep 2, 2024
1 parent cb6139e commit 473a5b8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion binaries/geph5-client/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn deprioritize_route(addr: SocketAddr) {
pub enum ExitConstraint {
Auto,
Direct(String),
Hostname(String),
Country(CountryCode),
CountryCity(CountryCode, String),
}
Expand All @@ -44,6 +45,7 @@ pub async fn get_dialer(
) -> anyhow::Result<(VerifyingKey, ExitDescriptor, DynDialer)> {
let mut country_constraint = None;
let mut city_constraint = None;
let mut hostname_constraint = None;
match &ctx.init().exit_constraint {
ExitConstraint::Direct(dir) => {
let (dir, pubkey) = dir
Expand Down Expand Up @@ -79,6 +81,9 @@ pub async fn get_dialer(
country_constraint = Some(*country);
city_constraint = Some(city.clone())
}
ExitConstraint::Hostname(hostname) => {
hostname_constraint = Some(hostname.clone());
}
ExitConstraint::Auto => {}
}
tracing::debug!(
Expand Down Expand Up @@ -111,7 +116,12 @@ pub async fn get_dialer(
} else {
true
};
country_pass && city_pass
let hostname_pass = if let Some(hostname) = &hostname_constraint {
&exit.b2e_listen.ip().to_string() == hostname
} else {
true
};
country_pass && city_pass && hostname_pass
})
.min_by_key(|e| (e.1.load * 1000.0) as u64)
.context("no exits that fit the criterion")?;
Expand Down

0 comments on commit 473a5b8

Please sign in to comment.