diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-17 16:16:18 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-17 16:16:18 +0200 |
commit | c5d7efc2467abb6cd8365c83fae68da6924c17f2 (patch) | |
tree | 0324219cf4979a87fc45fc575e26f7058b0a196f /src/device.go | |
parent | dd4da93749fd9a8a231942a6b75ad137cc308e02 (diff) |
Fixed deadlock in index.go
Diffstat (limited to 'src/device.go')
-rw-r--r-- | src/device.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/device.go b/src/device.go index 4981f51..d32d648 100644 --- a/src/device.go +++ b/src/device.go @@ -78,7 +78,6 @@ func NewDevice(tun TUNDevice, logLevel int) *Device { defer device.mutex.Unlock() device.log = NewLogger(logLevel) - // device.mtu = tun.MTU() device.peers = make(map[NoisePublicKey]*Peer) device.indices.Init() device.ratelimiter.Init() @@ -131,12 +130,21 @@ func NewDevice(tun TUNDevice, logLevel int) *Device { func (device *Device) RoutineMTUUpdater(tun TUNDevice) { logError := device.log.Error - for ; ; time.Sleep(time.Second) { + for ; ; time.Sleep(5 * time.Second) { + + // load updated MTU + mtu, err := tun.MTU() if err != nil { logError.Println("Failed to load updated MTU of device:", err) continue } + + // upper bound of mtu + + if mtu+MessageTransportSize > MaxMessageSize { + mtu = MaxMessageSize - MessageTransportSize + } atomic.StoreInt32(&device.mtu, int32(mtu)) } } |