From 989bf3bfd7ce02e268f7c83436fd2c8ef62072be Mon Sep 17 00:00:00 2001 From: Max Niederman Date: Mon, 22 Apr 2024 00:09:41 -0700 Subject: [PATCH] refactor: fix clippy lints and reformat --- packages/centipede_control/src/lib.rs | 11 +++-------- packages/centipede_control/tests/simple.rs | 3 ++- packages/centipede_proto/src/control.rs | 3 +-- packages/centipede_worker/src/lib.rs | 13 +++++++------ packages/centipede_worker/src/sockets.rs | 1 + 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/centipede_control/src/lib.rs b/packages/centipede_control/src/lib.rs index 7dc158a..a722bf3 100644 --- a/packages/centipede_control/src/lib.rs +++ b/packages/centipede_control/src/lib.rs @@ -75,9 +75,6 @@ enum PeerState { /// The timestamp of the handshake that established the connection, **on the initiator's clock**. handshake_timestamp: SystemTime, - /// The shared cipher. - cipher: ChaCha20Poly1305, - /// Addreses on which we're listening for incoming packets, and are sending heartbeats from. local_addrs: HashSet, @@ -107,7 +104,7 @@ impl Controller { /// * `private_key` - the private key of the local peer. /// * `rng` - a cryptographic random number generator to use for generating ephemeral keys. pub fn new( - now: SystemTime, + _now: SystemTime, private_key: ed25519_dalek::SigningKey, rng: R, ) -> (Self, centipede_router::Config) { @@ -187,7 +184,7 @@ impl Controller { .. }) => { // Iterate over all the new addresses. - for &addr in local_addrs.difference(&state_local_addrs) { + for &addr in local_addrs.difference(state_local_addrs) { // Queue a heartbeat for each new address. queued_heartbeats.entry(now).or_default().insert(addr); } @@ -309,7 +306,7 @@ impl Controller { /// /// * `now` - the current time. /// * `public_key` - the public key of the peer. - pub fn disconnect(&mut self, now: SystemTime, public_key: ed25519_dalek::VerifyingKey) { + pub fn disconnect(&mut self, _now: SystemTime, public_key: ed25519_dalek::VerifyingKey) { log::debug!("disconnecting from {public_key:?}"); // Right now, we just clean up all references to the peer. @@ -481,7 +478,6 @@ impl Controller { PeerState::Connected { handshake_timestamp: *handshake_timestamp, - cipher, // Create the heartbeat queue, with the initial heartbeats queued. queued_heartbeats: [(now, local_addrs.clone())].into_iter().collect(), local_addrs, @@ -574,7 +570,6 @@ impl Controller { PeerState::Connected { handshake_timestamp, - cipher, // Create the heartbeat queue, with the initial heartbeats queued. queued_heartbeats: [(now, local_addrs.clone())].into_iter().collect(), local_addrs, diff --git a/packages/centipede_control/tests/simple.rs b/packages/centipede_control/tests/simple.rs index 429a456..45a0907 100644 --- a/packages/centipede_control/tests/simple.rs +++ b/packages/centipede_control/tests/simple.rs @@ -216,7 +216,8 @@ fn initiate() { for wait_to_initiate in [false, true] { println!("testing initiate with clock = {clock:?}, pk = {private_key:?}, and wait_to_initiate = {wait_to_initiate}"); - let (mut controller, _) = Controller::new(clock.now(), private_key.clone(), rng.clone()); + let (mut controller, _) = + Controller::new(clock.now(), private_key.clone(), rng.clone()); clock.increment(Duration::from_millis(1)); diff --git a/packages/centipede_proto/src/control.rs b/packages/centipede_proto/src/control.rs index 05a93ab..aeec01b 100644 --- a/packages/centipede_proto/src/control.rs +++ b/packages/centipede_proto/src/control.rs @@ -155,8 +155,7 @@ where signature: ed25519_dalek::Signature::from_bytes( &buffer[SIGNATURE_RANGE].try_into().unwrap(), ), - content: serde_json::from_slice(&buffer[CONTENT_RANGE]) - .map_err(ParseError::Content)?, + content: serde_json::from_slice(&buffer[CONTENT_RANGE]).map_err(ParseError::Content)?, buffer, _auth: PhantomData::, }) diff --git a/packages/centipede_worker/src/lib.rs b/packages/centipede_worker/src/lib.rs index c76c09f..5dc1247 100644 --- a/packages/centipede_worker/src/lib.rs +++ b/packages/centipede_worker/src/lib.rs @@ -26,8 +26,7 @@ pub struct Worker<'r> { router_handle: WorkerHandle<'r>, /// A callback for received control messages. - control_message_sink: - Box, auth::Unknown>) + Send + 'r>, + control_message_sink: Box>, /// The TUN queue. tun_queue: hypertube::Queue<'r, false>, @@ -39,13 +38,14 @@ pub struct Worker<'r> { poll: mio::Poll, } +pub type ControlMessageSink<'r> = + dyn FnMut(SocketAddr, ControlMessage, auth::Unknown>) + Send + 'r; + impl<'r> Worker<'r> { /// Create a new worker. pub fn new( router_handle: WorkerHandle<'r>, - control_message_sink: Box< - dyn FnMut(SocketAddr, ControlMessage, auth::Unknown>) + Send + 'r, - >, + control_message_sink: Box>, tun_queue: hypertube::Queue<'r, false>, ) -> Result { let poll = mio::Poll::new()?; @@ -205,7 +205,8 @@ impl<'r> Worker<'r> { if let Some(obligation) = self.router_handle.handle_incoming(packet) { // TODO: ensure writes complete - self.tun_queue + let _ = self + .tun_queue .write(obligation.packet()) .map_err(Error::WriteTun)?; } diff --git a/packages/centipede_worker/src/sockets.rs b/packages/centipede_worker/src/sockets.rs index 9559dbd..caa4c98 100644 --- a/packages/centipede_worker/src/sockets.rs +++ b/packages/centipede_worker/src/sockets.rs @@ -150,6 +150,7 @@ pub struct UpdateStats { } impl UpdateResults { + #[cfg(test)] pub fn stats(&self) -> UpdateStats { UpdateStats { closed: self.closed_count,