summaryrefslogtreecommitdiffhomepage
path: root/src/peer.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-28 23:45:45 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-28 23:45:45 +0200
commit1f0976a26c1d0a6b5eb2c0aa993f12d89f96eed2 (patch)
tree36771e8468214583a5c3f3441b36662c4108a58c /src/peer.go
parent8236f3afa2eca0aae6c5da9560301c04d882c81b (diff)
Work on UAPI
Cross-platform API (get operation) Handshake initiation creation process Outbound packet flow Fixes from code-review
Diffstat (limited to 'src/peer.go')
-rw-r--r--src/peer.go46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/peer.go b/src/peer.go
index e192b12..21cad9d 100644
--- a/src/peer.go
+++ b/src/peer.go
@@ -7,9 +7,7 @@ import (
"time"
)
-const (
- OutboundQueueSize = 64
-)
+const ()
type Peer struct {
mutex sync.RWMutex
@@ -18,10 +16,26 @@ type Peer struct {
keyPairs KeyPairs
handshake Handshake
device *Device
- queueInbound chan []byte
- queueOutbound chan *OutboundWorkQueueElement
- queueOutboundRouting chan []byte
- mac MacStatePeer
+ tx_bytes uint64
+ rx_bytes uint64
+ time struct {
+ lastSend time.Time // last send message
+ }
+ signal struct {
+ newHandshake chan bool
+ flushNonceQueue chan bool // empty queued packets
+ stopSending chan bool // stop sending pipeline
+ stopInitiator chan bool // stop initiator timer
+ }
+ timer struct {
+ sendKeepalive time.Timer
+ handshakeTimeout time.Timer
+ }
+ queue struct {
+ nonce chan []byte // nonce / pre-handshake queue
+ outbound chan *QueueOutboundElement // sequential ordering of work
+ }
+ mac MacStatePeer
}
func (device *Device) NewPeer(pk NoisePublicKey) *Peer {
@@ -33,7 +47,8 @@ func (device *Device) NewPeer(pk NoisePublicKey) *Peer {
peer.device = device
peer.keyPairs.Init()
peer.mac.Init(pk)
- peer.queueOutbound = make(chan *OutboundWorkQueueElement, OutboundQueueSize)
+ peer.queue.outbound = make(chan *QueueOutboundElement, QueueOutboundSize)
+ peer.queue.nonce = make(chan []byte, QueueOutboundSize)
// map public key
@@ -54,5 +69,20 @@ func (device *Device) NewPeer(pk NoisePublicKey) *Peer {
handshake.mutex.Unlock()
peer.mutex.Unlock()
+ // start workers
+
+ peer.signal.stopSending = make(chan bool, 1)
+ peer.signal.stopInitiator = make(chan bool, 1)
+ peer.signal.newHandshake = make(chan bool, 1)
+ peer.signal.flushNonceQueue = make(chan bool, 1)
+
+ go peer.RoutineNonce()
+ go peer.RoutineHandshakeInitiator()
+
return &peer
}
+
+func (peer *Peer) Close() {
+ peer.signal.stopSending <- true
+ peer.signal.stopInitiator <- true
+}