From d9f995209c3cc7bda242e8752680d78684fd62e4 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 30 May 2019 15:15:54 +0200 Subject: device: add SendKeepalivesToPeersWithCurrentKeypair for handover --- device/device.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'device') diff --git a/device/device.go b/device/device.go index fa7ed88..7775844 100644 --- a/device/device.go +++ b/device/device.go @@ -396,3 +396,20 @@ func (device *Device) Close() { func (device *Device) Wait() chan struct{} { return device.signals.stop } + +func (device *Device) SendKeepalivesToPeersWithCurrentKeypair() { + if device.isClosed.Get() { + return + } + + device.peers.RLock() + for _, peer := range device.peers.keyMap { + peer.keypairs.RLock() + sendKeepalive := peer.keypairs.current != nil && !peer.keypairs.current.created.Add(RejectAfterTime).Before(time.Now()) + peer.keypairs.RUnlock() + if sendKeepalive { + peer.SendKeepalive() + } + } + device.peers.RUnlock() +} -- cgit v1.2.3