diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-10-17 15:43:06 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-10-17 15:43:06 +0200 |
commit | ae492d1b359918d20fda817e31675f126c7a7837 (patch) | |
tree | 07875355d8c6404d84d4d3aa0e4a60dc88cee562 | |
parent | 95fbfccf60b7d8528e5f89bcf01d132516af5817 (diff) |
device: recheck counters while holding write lock
-rw-r--r-- | device/noise-protocol.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/device/noise-protocol.go b/device/noise-protocol.go index dd75cc3..88c6aae 100644 --- a/device/noise-protocol.go +++ b/device/noise-protocol.go @@ -315,8 +315,13 @@ func (device *Device) ConsumeMessageInitiation(msg *MessageInitiation) *Peer { handshake.chainKey = chainKey handshake.remoteIndex = msg.Sender handshake.remoteEphemeral = msg.Ephemeral - handshake.lastTimestamp = timestamp - handshake.lastInitiationConsumption = time.Now() + if timestamp.After(handshake.lastTimestamp) { + handshake.lastTimestamp = timestamp + } + now := time.Now() + if now.After(handshake.lastInitiationConsumption) { + handshake.lastInitiationConsumption = now + } handshake.state = HandshakeInitiationConsumed handshake.mutex.Unlock() |