Add rustfmt formatting policy and reformat codebase

Add rustfmt.toml with stable defaults and apply cargo fmt to all
source files. This establishes a consistent formatting baseline
for CI enforcement.
This commit is contained in:
Johnathan Corgan
2026-04-10 08:27:07 +00:00
parent a859da7748
commit 13c0b70dc3
101 changed files with 3451 additions and 2227 deletions
+10 -10
View File
@@ -5,9 +5,9 @@
//! (not PeerConnection) because each retry creates a fresh connection.
use super::Node;
use crate::PeerIdentity;
use crate::config::PeerConfig;
use crate::identity::NodeAddr;
use crate::PeerIdentity;
use tracing::{debug, info, warn};
// MAX_BACKOFF_MS is now derived from config: node.retry.max_backoff_secs * 1000
@@ -44,7 +44,9 @@ impl RetryState {
/// capped at `MAX_BACKOFF_MS`.
pub fn backoff_ms(&self, base_interval_ms: u64, max_backoff_ms: u64) -> u64 {
let multiplier = 1u64.checked_shl(self.retry_count).unwrap_or(u64::MAX);
base_interval_ms.saturating_mul(multiplier).min(max_backoff_ms)
base_interval_ms
.saturating_mul(multiplier)
.min(max_backoff_ms)
}
}
@@ -55,11 +57,7 @@ impl Node {
/// have not been exhausted (unless `reconnect` is true, which retries
/// indefinitely). Does nothing if the peer is already connected or has
/// a connection in progress.
pub(super) fn schedule_retry(
&mut self,
node_addr: NodeAddr,
now_ms: u64,
) {
pub(super) fn schedule_retry(&mut self, node_addr: NodeAddr, now_ms: u64) {
let retry_cfg = &self.config.node.retry;
let max_retries = retry_cfg.max_retries;
if max_retries == 0 {
@@ -240,8 +238,7 @@ impl Node {
// succeeds, promote_connection() clears retry_pending. If
// it times out, check_timeouts() calls schedule_retry()
// which bumps the counter and applies proper backoff.
let hs_timeout_ms =
self.config.node.rate_limit.handshake_timeout_secs * 1000;
let hs_timeout_ms = self.config.node.rate_limit.handshake_timeout_secs * 1000;
if let Some(state) = self.retry_pending.get_mut(&node_addr) {
state.retry_after_ms = now_ms + hs_timeout_ms;
}
@@ -317,7 +314,10 @@ mod tests {
retry_after_ms: 0,
reconnect: false,
};
assert_eq!(state.backoff_ms(5000, TEST_MAX_BACKOFF_MS), TEST_MAX_BACKOFF_MS);
assert_eq!(
state.backoff_ms(5000, TEST_MAX_BACKOFF_MS),
TEST_MAX_BACKOFF_MS
);
}
#[test]