fix(hs): probe onion reachability instead of waiting on Bootstrapping
All checks were successful
ci / test (push) Successful in 2m59s
All checks were successful
ci / test (push) Successful in 2m59s
Arti combined status stays Bootstrapping through a 5 min HsDir upload round. Treat a successful connect as published, floor cbtinitialtimeout with cbtmintimeout at 20s, and skip preemptive 80/443 circuits so IPT and HsDir builds are not starved. PUBLISH_WAIT stays 360s fail-closed.
This commit is contained in:
parent
e63203ff56
commit
e902a9041d
5 changed files with 130 additions and 24 deletions
75
src/hs.rs
75
src/hs.rs
|
|
@ -15,7 +15,16 @@ pub const HS_PORT: u16 = 80;
|
|||
/// HsDir descriptor upload often stays Bootstrapping past 3 minutes.
|
||||
pub const PUBLISH_WAIT: Duration = Duration::from_secs(360);
|
||||
/// Consensus default `cbtmintimeout` is 10ms; learned CBT can drop to ~1s.
|
||||
pub const CBT_MIN_TIMEOUT_MS: i32 = 10_000;
|
||||
/// 4-hop vanguard HS circuits need more than 10s on a slow net.
|
||||
pub const CBT_MIN_TIMEOUT_MS: i32 = 20_000;
|
||||
/// Consensus `cbtinitialtimeout` can be ~2s; match the min floor.
|
||||
pub const CBT_INITIAL_TIMEOUT_MS: i32 = CBT_MIN_TIMEOUT_MS;
|
||||
/// OnionWire never uses exit ports. Default 80/443 preemptive circuits
|
||||
/// compete with IPT + HsDir builds during publish.
|
||||
pub const PREEMPTIVE_PREDICTED_PORTS: &[u16] = &[];
|
||||
|
||||
const PROBE_EVERY: Duration = Duration::from_secs(15);
|
||||
const PROBE_TIMEOUT: Duration = Duration::from_secs(12);
|
||||
|
||||
pub type Client = Arc<TorClient<PreferredRuntime>>;
|
||||
|
||||
|
|
@ -27,6 +36,12 @@ pub fn client_config(state_dir: &std::path::Path, cache_dir: &std::path::Path) -
|
|||
builder
|
||||
.override_net_params()
|
||||
.insert("cbtmintimeout".to_string(), CBT_MIN_TIMEOUT_MS);
|
||||
builder
|
||||
.override_net_params()
|
||||
.insert("cbtinitialtimeout".to_string(), CBT_INITIAL_TIMEOUT_MS);
|
||||
builder
|
||||
.preemptive_circuits()
|
||||
.set_initial_predicted_ports(PREEMPTIVE_PREDICTED_PORTS.to_vec());
|
||||
builder.build().expect("TorClientConfig")
|
||||
}
|
||||
|
||||
|
|
@ -55,29 +70,61 @@ pub fn onion_string(svc: &RunningOnionService) -> Result<String, String> {
|
|||
Ok(id.display_unredacted().to_string())
|
||||
}
|
||||
|
||||
pub async fn wait_until_published(svc: &RunningOnionService, label: &str) -> Result<(), String> {
|
||||
/// Combined Arti status stays Bootstrapping through a 5 min HsDir upload
|
||||
/// round. A successful connect means some HsDir already has the descriptor.
|
||||
pub fn hs_is_ready(state: State, probe_ok: bool) -> bool {
|
||||
match state {
|
||||
State::Broken | State::Shutdown => false,
|
||||
State::Running | State::DegradedReachable => true,
|
||||
_ => probe_ok,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn wait_until_published(
|
||||
client: &Client,
|
||||
svc: &RunningOnionService,
|
||||
onion: &str,
|
||||
label: &str,
|
||||
) -> Result<(), String> {
|
||||
let deadline = Instant::now() + PUBLISH_WAIT;
|
||||
let mut events = svc.status_events();
|
||||
let mut next_probe = Instant::now() + PROBE_EVERY;
|
||||
loop {
|
||||
let st = svc.status();
|
||||
eprintln!("{label} hs status: {:?}", st.state());
|
||||
match st.state() {
|
||||
State::Running | State::DegradedReachable => return Ok(()),
|
||||
State::Broken => {
|
||||
return Err(format!(
|
||||
"{label}: onion service broken: {:?}",
|
||||
st.current_problem()
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
let state = st.state();
|
||||
eprintln!("{label} hs status: {state:?}");
|
||||
if hs_is_ready(state, false) {
|
||||
return Ok(());
|
||||
}
|
||||
if matches!(state, State::Broken) {
|
||||
return Err(format!(
|
||||
"{label}: onion service broken: {:?}",
|
||||
st.current_problem()
|
||||
));
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
return Err(format!(
|
||||
"{label}: onion service did not publish within {}s: {:?}",
|
||||
"{label}: onion service did not publish within {}s: {state:?}",
|
||||
PUBLISH_WAIT.as_secs(),
|
||||
st.state()
|
||||
));
|
||||
}
|
||||
let now = Instant::now();
|
||||
if now >= next_probe {
|
||||
eprintln!("{label} probing reachability");
|
||||
let probe_ok = tokio::time::timeout(PROBE_TIMEOUT, client.connect((onion, HS_PORT)))
|
||||
.await
|
||||
.ok()
|
||||
.and_then(Result::ok)
|
||||
.is_some();
|
||||
if probe_ok {
|
||||
eprintln!("{label} hs reachable while status {state:?}");
|
||||
}
|
||||
if hs_is_ready(state, probe_ok) {
|
||||
return Ok(());
|
||||
}
|
||||
next_probe = Instant::now() + PROBE_EVERY;
|
||||
continue;
|
||||
}
|
||||
tokio::select! {
|
||||
_ = events.next() => {}
|
||||
_ = tokio::time::sleep(Duration::from_secs(2)) => {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue