summaryrefslogtreecommitdiffhomepage
path: root/src/device.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-01 21:31:30 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-01 21:31:30 +0200
commitec3d656bebb9ee7c38724500779b7ad322ba0377 (patch)
tree766c47aa8bcd69e6d6db1383dfdf62fc861723c1 /src/device.go
parent8ce921987fbc91064cf4a14839ef792fecbb0d80 (diff)
Inital implementation of trie
Diffstat (limited to 'src/device.go')
-rw-r--r--src/device.go41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/device.go b/src/device.go
index cd0835c..d03057d 100644
--- a/src/device.go
+++ b/src/device.go
@@ -5,10 +5,39 @@ import (
)
type Device struct {
- mutex sync.RWMutex
- peers map[NoisePublicKey]*Peer
- privateKey NoisePrivateKey
- publicKey NoisePublicKey
- fwMark uint32
- listenPort uint16
+ mutex sync.RWMutex
+ peers map[NoisePublicKey]*Peer
+ privateKey NoisePrivateKey
+ publicKey NoisePublicKey
+ fwMark uint32
+ listenPort uint16
+ routingTable RoutingTable
+}
+
+func (dev *Device) RemovePeer(key NoisePublicKey) {
+ dev.mutex.Lock()
+ defer dev.mutex.Unlock()
+ peer, ok := dev.peers[key]
+ if !ok {
+ return
+ }
+ peer.mutex.Lock()
+ dev.routingTable.RemovePeer(peer)
+ delete(dev.peers, key)
+}
+
+func (dev *Device) RemoveAllAllowedIps(peer *Peer) {
+
+}
+
+func (dev *Device) RemoveAllPeers() {
+ dev.mutex.Lock()
+ defer dev.mutex.Unlock()
+
+ for key, peer := range dev.peers {
+ peer.mutex.Lock()
+ dev.routingTable.RemovePeer(peer)
+ delete(dev.peers, key)
+ peer.mutex.Unlock()
+ }
}