2017-06-24 15:34:17 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/cipher"
|
2017-06-26 13:14:02 +02:00
|
|
|
"sync"
|
2017-06-27 17:33:06 +02:00
|
|
|
"time"
|
2017-06-24 15:34:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type KeyPair struct {
|
2017-06-27 17:33:06 +02:00
|
|
|
recv cipher.AEAD
|
|
|
|
recvNonce uint64
|
|
|
|
send cipher.AEAD
|
|
|
|
sendNonce uint64
|
|
|
|
isInitiator bool
|
|
|
|
created time.Time
|
2017-06-26 13:14:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type KeyPairs struct {
|
|
|
|
mutex sync.RWMutex
|
|
|
|
current *KeyPair
|
|
|
|
previous *KeyPair
|
2017-06-26 22:07:29 +02:00
|
|
|
next *KeyPair // not yet "confirmed by transport"
|
|
|
|
newKeyPair chan bool // signals when "current" has been updated
|
|
|
|
}
|
|
|
|
|
|
|
|
func (kp *KeyPairs) Init() {
|
|
|
|
kp.mutex.Lock()
|
|
|
|
kp.newKeyPair = make(chan bool, 5)
|
|
|
|
kp.mutex.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (kp *KeyPairs) Current() *KeyPair {
|
|
|
|
kp.mutex.RLock()
|
|
|
|
defer kp.mutex.RUnlock()
|
|
|
|
return kp.current
|
2017-06-24 15:34:17 +02:00
|
|
|
}
|