From c1dfc848c48978603fe801737a07b16cb0a9c1a3 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sun, 14 Jun 2020 21:57:35 +0200 Subject: Added architecture illustration. --- src/wireguard/router/peer.rs | 55 ++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'src/wireguard/router/peer.rs') diff --git a/src/wireguard/router/peer.rs b/src/wireguard/router/peer.rs index 8248a55..d960da0 100644 --- a/src/wireguard/router/peer.rs +++ b/src/wireguard/router/peer.rs @@ -37,16 +37,22 @@ pub struct KeyWheel { } pub struct PeerInner> { - pub device: Device, - pub opaque: C::Opaque, - pub outbound: Queue>, - pub inbound: Queue>, - pub staged_packets: Mutex; MAX_QUEUED_PACKETS], Wrapping>>, - pub keys: Mutex, - pub enc_key: Mutex>, - pub endpoint: Mutex>, + pub(super) device: Device, + pub(super) opaque: C::Opaque, + pub(super) outbound: Queue>, + pub(super) inbound: Queue>, + pub(super) staged_packets: Mutex; MAX_QUEUED_PACKETS], Wrapping>>, + pub(super) keys: Mutex, + pub(super) enc_key: Mutex>, + pub(super) endpoint: Mutex>, } +/// A Peer dereferences to its opaque type: +/// This allows the router code to take ownership of the opaque type +/// used for callback events, while still enabling the rest of the code to access the opaque type +/// (which might expose other functionality in their scope) from a Peer pointer. +/// +/// e.g. it can take ownership of the timer state of a peer. impl> Deref for PeerInner { type Target = C::Opaque; @@ -55,10 +61,20 @@ impl> Deref for Pee } } +/// A Peer represents a reference to the router state associated with a peer pub struct Peer> { inner: Arc>, } +/// A PeerHandle is a specially designated reference to the peer +/// which removes the peer from the device when dropped. +/// +/// A PeerHandle cannot be cloned (unlike the wrapped type). +/// A PeerHandle dereferences to a Peer (meaning you can use it like a Peer struct) +pub struct PeerHandle> { + peer: Peer, +} + impl> Clone for Peer { fn clone(&self) -> Self { Peer { @@ -67,7 +83,7 @@ impl> Clone for Pee } } -/* Equality of peers is defined as pointer equality +/* Equality of peers is defined as pointer equality of * the atomic reference counted pointer. */ impl> PartialEq for Peer { @@ -89,25 +105,6 @@ impl> Deref for Pee } } -/* A peer handle is a specially designated peer pointer - * which removes the peer from the device when dropped. - */ -pub struct PeerHandle> { - peer: Peer, -} - -/* -impl> Clone - for PeerHandle -{ - fn clone(&self) -> Self { - PeerHandle { - peer: self.peer.clone(), - } - } -} -*/ - impl> Deref for PeerHandle { @@ -130,7 +127,6 @@ impl EncryptionState { EncryptionState { nonce: 0, keypair: keypair.clone(), - death: keypair.birth + REJECT_AFTER_TIME, } } } @@ -141,7 +137,6 @@ impl> DecryptionSta confirmed: AtomicBool::new(keypair.initiator), keypair: keypair.clone(), protector: spin::Mutex::new(AntiReplay::new()), - death: keypair.birth + REJECT_AFTER_TIME, peer, } } -- cgit v1.2.3-59-g8ed1b