[PATCH 04/12] device: move removePeerUnsafe() into Device

Simon Ruderich simon at ruderich.org
Mon Jan 1 11:52:54 CET 2018


Feels more natural as it operates on a Device's state and is just one
more private helper function.
---
 src/device.go | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/device.go b/src/device.go
index f4a087c..537af67 100644
--- a/src/device.go
+++ b/src/device.go
@@ -70,7 +70,7 @@ func (device *Device) Down() {
 /* Warning:
  * The caller must hold the device mutex (write lock)
  */
-func removePeerUnsafe(device *Device, key NoisePublicKey) {
+func (device *Device) removePeerUnsafe(key NoisePublicKey) {
 	peer, ok := device.peers[key]
 	if !ok {
 		return
@@ -109,7 +109,7 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error {
 		h := &peer.handshake
 		h.mutex.RLock()
 		if h.remoteStatic.Equals(publicKey) {
-			removePeerUnsafe(device, key)
+			device.removePeerUnsafe(key)
 		}
 		h.mutex.RUnlock()
 	}
@@ -132,7 +132,7 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error {
 		} else {
 			h.precomputedStaticStatic = device.privateKey.sharedSecret(h.remoteStatic)
 			if isZero(h.precomputedStaticStatic[:]) {
-				removePeerUnsafe(device, key)
+				device.removePeerUnsafe(key)
 			}
 		}
 		h.mutex.Unlock()
@@ -214,14 +214,14 @@ func (device *Device) LookupPeer(pk NoisePublicKey) *Peer {
 func (device *Device) RemovePeer(key NoisePublicKey) {
 	device.mutex.Lock()
 	defer device.mutex.Unlock()
-	removePeerUnsafe(device, key)
+	device.removePeerUnsafe(key)
 }
 
 func (device *Device) RemoveAllPeers() {
 	device.mutex.Lock()
 	defer device.mutex.Unlock()
 	for key := range device.peers {
-		removePeerUnsafe(device, key)
+		device.removePeerUnsafe(key)
 	}
 }
 
-- 
2.15.1



More information about the WireGuard mailing list