summaryrefslogtreecommitdiff
path: root/src/peer.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-24 15:34:17 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-24 15:34:44 +0200
commit25190e43369a79dc77a740dc8cd28b8a9fcb235e (patch)
treeb7057627e0710fe9ef40c077a204904c78bed9cc /src/peer.go
parent521e77fd54fba275405affd790ac91f7998e4559 (diff)
downloadwireguard-go-25190e43369a79dc77a740dc8cd28b8a9fcb235e.tar.gz
wireguard-go-25190e43369a79dc77a740dc8cd28b8a9fcb235e.zip
Restructuring of noise impl.
Diffstat (limited to 'src/peer.go')
-rw-r--r--src/peer.go40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/peer.go b/src/peer.go
index db5e99f..f6eb555 100644
--- a/src/peer.go
+++ b/src/peer.go
@@ -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
}