summaryrefslogtreecommitdiffhomepage
path: root/src/device.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-01 23:29:22 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-01 23:29:22 +0200
commit1e620427bd01b1e897c57752359f7dbb28e34bff (patch)
treef525ee38fec7826b07060271dcc06601f992612d /src/device.go
parenta4cc0a30faa64c2c293c589d98e4ba7390e56fda (diff)
Handshake negotiation functioning
Diffstat (limited to 'src/device.go')
-rw-r--r--src/device.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/device.go b/src/device.go
index a33e923..ff10e32 100644
--- a/src/device.go
+++ b/src/device.go
@@ -23,7 +23,13 @@ type Device struct {
routingTable RoutingTable
indices IndexTable
queue struct {
- encryption chan *QueueOutboundElement // parallel work queue
+ encryption chan *QueueOutboundElement
+ decryption chan *QueueInboundElement
+ handshake chan QueueHandshakeElement
+ inbound chan []byte // inbound queue for TUN
+ }
+ signal struct {
+ stop chan struct{}
}
peers map[NoisePublicKey]*Peer
mac MacStateDevice
@@ -56,6 +62,7 @@ func NewDevice(tun TUNDevice, logLevel int) *Device {
defer device.mutex.Unlock()
device.log = NewLogger(logLevel)
+ device.mtu = tun.MTU()
device.peers = make(map[NoisePublicKey]*Peer)
device.indices.Init()
device.routingTable.Reset()
@@ -71,13 +78,22 @@ func NewDevice(tun TUNDevice, logLevel int) *Device {
// create queues
device.queue.encryption = make(chan *QueueOutboundElement, QueueOutboundSize)
+ device.queue.handshake = make(chan QueueHandshakeElement, QueueHandshakeSize)
+ device.queue.decryption = make(chan *QueueInboundElement, QueueInboundSize)
+
+ // prepare signals
+
+ device.signal.stop = make(chan struct{})
// start workers
for i := 0; i < runtime.NumCPU(); i += 1 {
go device.RoutineEncryption()
+ go device.RoutineDecryption()
+ go device.RoutineHandshake()
}
go device.RoutineReadFromTUN(tun)
+ go device.RoutineReceiveIncomming()
return device
}
@@ -115,5 +131,6 @@ func (device *Device) RemoveAllPeers() {
func (device *Device) Close() {
device.RemoveAllPeers()
+ close(device.signal.stop)
close(device.queue.encryption)
}