Restructuring of noise impl.

This commit is contained in:
Mathias Hall-Andersen
2017-06-24 15:34:17 +02:00
parent 521e77fd54
commit 25190e4336
10 changed files with 420 additions and 128 deletions

View File

@@ -6,17 +6,35 @@ import (
"time"
)
type KeyPair struct {
recieveKey NoiseSymmetricKey
recieveNonce NoiseNonce
sendKey NoiseSymmetricKey
sendNonce NoiseNonce
}
type Peer struct {
mutex sync.RWMutex
publicKey NoisePublicKey
presharedKey NoiseSymmetricKey
endpoint net.IP
persistentKeepaliveInterval time.Duration
endpointIP net.IP //
endpointPort uint16 //
persistentKeepaliveInterval time.Duration // 0 = disabled
handshake Handshake
device *Device
}
func (device *Device) NewPeer(pk NoisePublicKey) *Peer {
var peer Peer
// map public key
device.mutex.Lock()
device.peers[pk] = &peer
device.mutex.Unlock()
// precompute
peer.mutex.Lock()
peer.device = device
func(h *Handshake) {
h.mutex.Lock()
h.remoteStatic = pk
h.precomputedStaticStatic = device.privateKey.sharedSecret(h.remoteStatic)
h.mutex.Unlock()
}(&peer.handshake)
peer.mutex.Unlock()
return &peer
}