Skip to content

Commit

Permalink
refactor: fix clippy lints and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
max-niederman committed Apr 22, 2024
1 parent 99b04ce commit 989bf3b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
11 changes: 3 additions & 8 deletions packages/centipede_control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketAddr>,

Expand Down Expand Up @@ -107,7 +104,7 @@ impl<R: Rng + CryptoRng> Controller<R> {
/// * `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) {
Expand Down Expand Up @@ -187,7 +184,7 @@ impl<R: Rng + CryptoRng> Controller<R> {
..
}) => {
// 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);
}
Expand Down Expand Up @@ -309,7 +306,7 @@ impl<R: Rng + CryptoRng> Controller<R> {
///
/// * `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.
Expand Down Expand Up @@ -481,7 +478,6 @@ impl<R: Rng + CryptoRng> Controller<R> {

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,
Expand Down Expand Up @@ -574,7 +570,6 @@ impl<R: Rng + CryptoRng> Controller<R> {

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,
Expand Down
3 changes: 2 additions & 1 deletion packages/centipede_control/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
3 changes: 1 addition & 2 deletions packages/centipede_proto/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<auth::Unknown>,
})
Expand Down
13 changes: 7 additions & 6 deletions packages/centipede_worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub struct Worker<'r> {
router_handle: WorkerHandle<'r>,

/// A callback for received control messages.
control_message_sink:
Box<dyn FnMut(SocketAddr, ControlMessage<Vec<u8>, auth::Unknown>) + Send + 'r>,
control_message_sink: Box<ControlMessageSink<'r>>,

/// The TUN queue.
tun_queue: hypertube::Queue<'r, false>,
Expand All @@ -39,13 +38,14 @@ pub struct Worker<'r> {
poll: mio::Poll,
}

pub type ControlMessageSink<'r> =
dyn FnMut(SocketAddr, ControlMessage<Vec<u8>, 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<Vec<u8>, auth::Unknown>) + Send + 'r,
>,
control_message_sink: Box<ControlMessageSink<'r>>,
tun_queue: hypertube::Queue<'r, false>,
) -> Result<Self, Error> {
let poll = mio::Poll::new()?;
Expand Down Expand Up @@ -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)?;
}
Expand Down
1 change: 1 addition & 0 deletions packages/centipede_worker/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub struct UpdateStats {
}

impl UpdateResults {
#[cfg(test)]
pub fn stats(&self) -> UpdateStats {
UpdateStats {
closed: self.closed_count,
Expand Down

0 comments on commit 989bf3b

Please sign in to comment.