From ec3d656bebb9ee7c38724500779b7ad322ba0377 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Thu, 1 Jun 2017 21:31:30 +0200 Subject: Inital implementation of trie --- src/config.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/config.go') diff --git a/src/config.go b/src/config.go index f6f1378..62af67a 100644 --- a/src/config.go +++ b/src/config.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "net" ) /* todo : use real error code @@ -18,6 +19,7 @@ const ( ipcErrorInvalidPrivateKey = 3 ipcErrorInvalidPublicKey = 4 ipcErrorInvalidPort = 5 + ipcErrorInvalidIPAddress = 6 ) type IPCError struct { @@ -104,6 +106,10 @@ func ipcSetOperation(dev *Device, socket *bufio.ReadWriter) *IPCError { } case "replace_peers": + if key == "true" { + dev.RemoveAllPeers() + } + // todo: else fail default: /* Peer configuration */ @@ -116,20 +122,27 @@ func ipcSetOperation(dev *Device, socket *bufio.ReadWriter) *IPCError { case "remove": peer.mutex.Lock() - + dev.RemovePeer(peer.publicKey) peer = nil case "preshared_key": - func() { + err := func() error { peer.mutex.Lock() defer peer.mutex.Unlock() + return peer.presharedKey.FromHex(value) }() + if err != nil { + return &IPCError{Code: ipcErrorInvalidPublicKey} + } case "endpoint": - func() { - peer.mutex.Lock() - defer peer.mutex.Unlock() - }() + ip := net.ParseIP(value) + if ip == nil { + return &IPCError{Code: ipcErrorInvalidIPAddress} + } + peer.mutex.Lock() + peer.endpoint = ip + peer.mutex.Unlock() case "persistent_keepalive_interval": func() { -- cgit v1.2.3