From ba3e486667987f16290ac85dc35b53cb9702d662 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Fri, 30 Jun 2017 14:41:08 +0200 Subject: Completed initial version of outbound flow --- src/keypair.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/keypair.go') diff --git a/src/keypair.go b/src/keypair.go index 0b029ce..0e845f7 100644 --- a/src/keypair.go +++ b/src/keypair.go @@ -13,20 +13,27 @@ type KeyPair struct { sendNonce uint64 isInitiator bool created time.Time + id uint32 } type KeyPairs struct { - mutex sync.RWMutex - current *KeyPair - previous *KeyPair - next *KeyPair // not yet "confirmed by transport" - newKeyPair chan bool // signals when "current" has been updated + mutex sync.RWMutex + current *KeyPair + previous *KeyPair + next *KeyPair // not yet "confirmed by transport" } -func (kp *KeyPairs) Init() { - kp.mutex.Lock() - kp.newKeyPair = make(chan bool, 5) - kp.mutex.Unlock() +/* Called during recieving to confirm the handshake + * was completed correctly + */ +func (kp *KeyPairs) Used(key *KeyPair) { + if key == kp.next { + kp.mutex.Lock() + kp.previous = kp.current + kp.current = key + kp.next = nil + kp.mutex.Unlock() + } } func (kp *KeyPairs) Current() *KeyPair { -- cgit v1.2.3