summaryrefslogtreecommitdiffhomepage
path: root/src/device.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-23 13:41:59 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-23 13:41:59 +0200
commit50aeefcb5198d99777e19f9a0100fe74af630dfb (patch)
tree5e8924cde01e586fcb1f7168946bee46528d70c9 /src/device.go
parent1868d15914d6cd7cd57b90b7644b008ec16361b9 (diff)
Beginning work noise handshake
Diffstat (limited to 'src/device.go')
-rw-r--r--src/device.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/device.go b/src/device.go
index d03057d..9f1daa6 100644
--- a/src/device.go
+++ b/src/device.go
@@ -1,12 +1,17 @@
package main
import (
+ "math/rand"
"sync"
)
+/* TODO: Locking may be a little broad here
+ */
+
type Device struct {
mutex sync.RWMutex
peers map[NoisePublicKey]*Peer
+ sessions map[uint32]*Handshake
privateKey NoisePrivateKey
publicKey NoisePublicKey
fwMark uint32
@@ -14,6 +19,19 @@ type Device struct {
routingTable RoutingTable
}
+func (dev *Device) NewID(h *Handshake) uint32 {
+ dev.mutex.Lock()
+ defer dev.mutex.Unlock()
+ for {
+ id := rand.Uint32()
+ _, ok := dev.sessions[id]
+ if !ok {
+ dev.sessions[id] = h
+ return id
+ }
+ }
+}
+
func (dev *Device) RemovePeer(key NoisePublicKey) {
dev.mutex.Lock()
defer dev.mutex.Unlock()