diff options
author | Josh Bleecher Snyder <josh@tailscale.com> | 2021-02-08 10:01:35 -0800 |
---|---|---|
committer | Josh Bleecher Snyder <josh@tailscale.com> | 2021-02-08 10:32:07 -0800 |
commit | 15810daa2283e3cfe0c811c3632f053274f31950 (patch) | |
tree | 917b946fbd80604c7a2bd0b214db7ecf80ea9786 /device | |
parent | d840445e9bdd4f4db3538c9caf93d797cc987fbc (diff) |
device: separate timersInit from timersStart
timersInit sets up the timers.
It need only be done once per peer.
timersStart does the work to prepare the timers
for a newly running peer. It needs to be done
every time a peer starts.
Separate the two and call them in the appropriate places.
This prevents data races on the peer's timers fields
when starting and stopping peers.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device')
-rw-r--r-- | device/peer.go | 3 | ||||
-rw-r--r-- | device/timers.go | 9 |
2 files changed, 7 insertions, 5 deletions
diff --git a/device/peer.go b/device/peer.go index abe8a08..3e4f4ec 100644 --- a/device/peer.go +++ b/device/peer.go @@ -107,6 +107,7 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) { device.peers.empty.Set(false) // start peer + peer.timersInit() if peer.device.isUp() { peer.Start() } @@ -183,7 +184,7 @@ func (peer *Peer) Start() { } peer.device.queue.encryption.wg.Add(1) // keep encryption queue open for our writes - peer.timersInit() + peer.timersStart() go peer.RoutineSequentialSender() go peer.RoutineSequentialReceiver() diff --git a/device/timers.go b/device/timers.go index f740cf0..fa44874 100644 --- a/device/timers.go +++ b/device/timers.go @@ -14,10 +14,8 @@ import ( "time" ) -/* This Timer structure and related functions should roughly copy the interface of - * the Linux kernel's struct timer_list. - */ - +// A Timer manages time-based aspects of the WireGuard protocol. +// Timer roughly copies the interface of the Linux kernel's struct timer_list. type Timer struct { *time.Timer modifyingLock sync.RWMutex @@ -213,6 +211,9 @@ func (peer *Peer) timersInit() { peer.timers.newHandshake = peer.NewTimer(expiredNewHandshake) peer.timers.zeroKeyMaterial = peer.NewTimer(expiredZeroKeyMaterial) peer.timers.persistentKeepalive = peer.NewTimer(expiredPersistentKeepalive) +} + +func (peer *Peer) timersStart() { atomic.StoreUint32(&peer.timers.handshakeAttempts, 0) peer.timers.sentLastMinuteHandshake.Set(false) peer.timers.needAnotherKeepalive.Set(false) |