summaryrefslogtreecommitdiff
path: root/src/conn.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2018-02-02 16:40:14 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2018-02-02 16:40:14 +0100
commit029410b118f079d77fa448cf56a97b949faee126 (patch)
tree5c9ecf509601b3abffe36094b3b228b87b7d8b92 /src/conn.go
parent1e42b1402261d15b87b1b5871f7bc51342b46e34 (diff)
downloadwireguard-go-029410b118f079d77fa448cf56a97b949faee126.tar.gz
wireguard-go-029410b118f079d77fa448cf56a97b949faee126.zip
Rework of entire locking system
Locking on the Device instance is now much more fined-grained, seperating out the fields into "resources" st. most common interactions only require a small number.
Diffstat (limited to '')
-rw-r--r--src/conn.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/conn.go b/src/conn.go
index c2f5dee..fb30ec2 100644
--- a/src/conn.go
+++ b/src/conn.go
@@ -65,12 +65,12 @@ func unsafeCloseBind(device *Device) error {
}
func (device *Device) BindUpdate() error {
- device.mutex.Lock()
- defer device.mutex.Unlock()
- netc := &device.net
- netc.mutex.Lock()
- defer netc.mutex.Unlock()
+ device.net.mutex.Lock()
+ defer device.net.mutex.Unlock()
+
+ device.peers.mutex.Lock()
+ defer device.peers.mutex.Unlock()
// close existing sockets
@@ -85,6 +85,7 @@ func (device *Device) BindUpdate() error {
// bind to new port
var err error
+ netc := &device.net
netc.bind, netc.port, err = CreateBind(netc.port)
if err != nil {
netc.bind = nil
@@ -100,12 +101,12 @@ func (device *Device) BindUpdate() error {
// clear cached source addresses
- for _, peer := range device.peers {
+ for _, peer := range device.peers.keyMap {
peer.mutex.Lock()
+ defer peer.mutex.Unlock()
if peer.endpoint != nil {
peer.endpoint.ClearSrc()
}
- peer.mutex.Unlock()
}
// start receiving routines
@@ -120,10 +121,8 @@ func (device *Device) BindUpdate() error {
}
func (device *Device) BindClose() error {
- device.mutex.Lock()
device.net.mutex.Lock()
err := unsafeCloseBind(device)
device.net.mutex.Unlock()
- device.mutex.Unlock()
return err
}