MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / backoff_for

Method backoff_for

nodedb-cluster/src/bootstrap/config.rs:48–60  ·  view source on GitHub ↗

Backoff delay before `attempt` (1-indexed). Attempt 0 is the initial try and never sleeps. Returns `Duration::ZERO` for out-of-range attempts.

(&self, attempt: u32)

Source from the content-addressed store, hash-verified

46 /// initial try and never sleeps. Returns `Duration::ZERO` for
47 /// out-of-range attempts.
48 pub fn backoff_for(&self, attempt: u32) -> Duration {
49 if attempt == 0 || attempt > self.max_attempts {
50 return Duration::ZERO;
51 }
52 // Schedule grows exponentially toward `max_backoff_secs`. We
53 // compute in millis so small `max_backoff_secs` values (test
54 // configs) still produce non-zero delays for the early
55 // attempts instead of being floored to zero seconds.
56 let exp = self.max_attempts - attempt;
57 let max_ms = self.max_backoff_secs.saturating_mul(1_000);
58 let ms = max_ms >> exp;
59 Duration::from_millis(ms.max(1))
60 }
61}
62
63/// Configuration for cluster formation.

Callers 2

joinFunction · 0.80

Calls

no outgoing calls