aboutsummaryrefslogtreecommitdiffstats
path: root/src/peer.rs
diff options
context:
space:
mode:
authorJake McGinty <me@jake.su>2018-05-03 18:01:57 -0700
committerJake McGinty <me@jake.su>2018-05-03 18:01:57 -0700
commitdb6bc2e8118b5f8d46a983e7d4bf3f0075cab356 (patch)
treeb9fa5e3998ef547fa5ee5d9c60dc04889f650ab5 /src/peer.rs
parenttimers: create Timers struct to store more detailed timer info (diff)
downloadwireguard-rs-db6bc2e8118b5f8d46a983e7d4bf3f0075cab356.tar.xz
wireguard-rs-db6bc2e8118b5f8d46a983e7d4bf3f0075cab356.zip
timers: refactor out timers from Session struct
Diffstat (limited to 'src/peer.rs')
-rw-r--r--src/peer.rs54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/peer.rs b/src/peer.rs
index 752253a..37285c5 100644
--- a/src/peer.rs
+++ b/src/peer.rs
@@ -55,17 +55,15 @@ pub struct Timers {
pub egress_queued : Timestamp,
pub handshake_completed : Timestamp,
pub handshake_initialized : Timestamp,
+ pub keepalive_sent : bool
}
pub struct Session {
- pub noise : snow::Session,
- pub our_index : u32,
- pub their_index : u32,
- pub anti_replay : AntiReplay,
- pub birthday : Timestamp,
- pub last_sent : Timestamp,
- pub last_received : Timestamp,
- pub keepalive_sent : bool,
+ pub noise : snow::Session,
+ pub our_index : u32,
+ pub their_index : u32,
+ pub anti_replay : AntiReplay,
+ pub birthday : Timestamp,
}
impl Session {
@@ -73,12 +71,9 @@ impl Session {
Session {
noise,
our_index,
- their_index : 0,
- anti_replay : AntiReplay::default(),
- last_sent : Timestamp::default(),
- last_received : Timestamp::default(),
- birthday : Timestamp::default(),
- keepalive_sent : false,
+ their_index : 0,
+ anti_replay : AntiReplay::default(),
+ birthday : Timestamp ::default(),
}
}
@@ -87,24 +82,18 @@ impl Session {
noise,
our_index,
their_index,
- anti_replay : AntiReplay::default(),
- last_sent : Timestamp::default(),
- last_received : Timestamp::default(),
- birthday : Timestamp::default(),
- keepalive_sent : false,
+ anti_replay : AntiReplay::default(),
+ birthday : Timestamp ::default(),
}
}
pub fn into_transport_mode(self) -> Result<Session, Error> {
Ok(Session {
- noise : self.noise.into_transport_mode()?,
- our_index : self.our_index,
- their_index : self.their_index,
- anti_replay : self.anti_replay,
- last_sent : self.last_sent,
- last_received : self.last_received,
- keepalive_sent : self.keepalive_sent,
- birthday : self.birthday,
+ noise : self.noise.into_transport_mode()?,
+ our_index : self.our_index,
+ their_index : self.their_index,
+ anti_replay : self.anti_replay,
+ birthday : self.birthday,
})
}
}
@@ -359,12 +348,15 @@ impl Peer {
raw_packet.truncate(0);
}
- session.last_received = Timestamp::now();
- session.keepalive_sent = false; // reset passive keepalive token since received a valid ingress transport
-
session_type
};
+ if raw_packet.len() > 0 {
+ self.timers.data_received = Timestamp::now();
+ }
+
+ self.timers.keepalive_sent = false; // reset passive keepalive token since received a valid ingress transport
+
let transition = if session_type == SessionType::Next {
debug!("moving 'next' session to current after receiving first transport packet");
let next = std::mem::replace(&mut self.sessions.next, None);
@@ -401,7 +393,7 @@ impl Peer {
let padded_packet = &[packet, &vec![0u8; padding]].concat();
let len = session.noise.write_message(padded_packet, &mut out_packet[16..])?;
self.tx_bytes += len as u64;
- session.last_sent = Timestamp::now();
+ self.timers.data_sent = Timestamp::now(); // TODO: only set this timer if not a keepalive
out_packet.truncate(TRANSPORT_HEADER_SIZE + len);
Ok((endpoint, out_packet))
}