aboutsummaryrefslogtreecommitdiffstats
path: root/src/peer.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-26 13:14:02 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-26 13:14:02 +0200
commit9d806d3853c926df75e83966d2c4f832708a1b08 (patch)
tree97dd50a56751d5cb48b60353697aa9ccad9a3e14 /src/peer.go
parentCompleted noise handshake (diff)
downloadwireguard-go-9d806d3853c926df75e83966d2c4f832708a1b08.tar.xz
wireguard-go-9d806d3853c926df75e83966d2c4f832708a1b08.zip
Begin work on outbound packet flow
Diffstat (limited to 'src/peer.go')
-rw-r--r--src/peer.go43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/peer.go b/src/peer.go
index f6eb555..42b9e8d 100644
--- a/src/peer.go
+++ b/src/peer.go
@@ -1,39 +1,64 @@
package main
import (
+ "errors"
+ "golang.org/x/crypto/blake2s"
"net"
"sync"
"time"
)
+const (
+ OutboundQueueSize = 64
+)
+
type Peer struct {
mutex sync.RWMutex
endpointIP net.IP //
endpointPort uint16 //
persistentKeepaliveInterval time.Duration // 0 = disabled
+ keyPairs KeyPairs
handshake Handshake
device *Device
+ macKey [blake2s.Size]byte // Hash(Label-Mac1 || publicKey)
+ cookie []byte // cookie
+ cookieExpire time.Time
+ queueInbound chan []byte
+ queueOutbound chan *OutboundWorkQueueElement
+ queueOutboundRouting chan []byte
}
func (device *Device) NewPeer(pk NoisePublicKey) *Peer {
var peer Peer
+ // create peer
+
+ peer.mutex.Lock()
+ peer.device = device
+ peer.queueOutbound = make(chan *OutboundWorkQueueElement, OutboundQueueSize)
+
// map public key
device.mutex.Lock()
+ _, ok := device.peers[pk]
+ if ok {
+ panic(errors.New("bug: adding existing peer"))
+ }
device.peers[pk] = &peer
device.mutex.Unlock()
- // precompute
+ // precompute DH
- 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)
+ handshake := &peer.handshake
+ handshake.mutex.Lock()
+ handshake.remoteStatic = pk
+ handshake.precomputedStaticStatic = device.privateKey.sharedSecret(handshake.remoteStatic)
+
+ // compute mac key
+
+ peer.macKey = blake2s.Sum256(append([]byte(WGLabelMAC1[:]), handshake.remoteStatic[:]...))
+
+ handshake.mutex.Unlock()
peer.mutex.Unlock()
return &peer