Work on UAPI
Cross-platform API (get operation) Handshake initiation creation process Outbound packet flow Fixes from code-review
This commit is contained in:
46
src/peer.go
46
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user