diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-11-18 23:34:02 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-11-18 23:34:02 +0100 |
commit | d10126f883ad39567248540347b5469956ab8b2e (patch) | |
tree | a83329093198bd5dd2c7770835a3851e6d23d880 /src/uapi.go | |
parent | fa399a91d5da9874cbf248e00db8dbd87b587e91 (diff) |
Moved endpoint into interface and simplified peer
Diffstat (limited to 'src/uapi.go')
-rw-r--r-- | src/uapi.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/uapi.go b/src/uapi.go index e1d0929..670ecc4 100644 --- a/src/uapi.go +++ b/src/uapi.go @@ -53,8 +53,8 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError { defer peer.mutex.RUnlock() send("public_key=" + peer.handshake.remoteStatic.ToHex()) send("preshared_key=" + peer.handshake.presharedKey.ToHex()) - if peer.endpoint.set { - send("endpoint=" + peer.endpoint.value.DstToString()) + if peer.endpoint != nil { + send("endpoint=" + peer.endpoint.DstToString()) } nano := atomic.LoadInt64(&peer.stats.lastHandshakeNano) @@ -255,17 +255,25 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError { case "endpoint": - // set endpoint destination and reset handshake timer + // set endpoint destination + + err := func() error { + peer.mutex.Lock() + defer peer.mutex.Unlock() + + endpoint := NewEndpoint() + if err := endpoint.SetDst(value); err != nil { + return err + } + peer.endpoint = endpoint + signalSend(peer.signal.handshakeReset) + return nil + }() - peer.mutex.Lock() - err := peer.endpoint.value.SetDst(value) - peer.endpoint.set = (err == nil) - peer.mutex.Unlock() if err != nil { logError.Println("Failed to set endpoint:", value) return &IPCError{Code: ipcErrorInvalid} } - signalSend(peer.signal.handshakeReset) case "persistent_keepalive_interval": |