diff options
Diffstat (limited to 'device/receive.go')
-rw-r--r-- | device/receive.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/device/receive.go b/device/receive.go index 0bd22bf..fa31a1a 100644 --- a/device/receive.go +++ b/device/receive.go @@ -8,6 +8,7 @@ package device import ( "bytes" "encoding/binary" + "errors" "net" "strconv" "sync" @@ -17,6 +18,7 @@ import ( "golang.org/x/crypto/chacha20poly1305" "golang.org/x/net/ipv4" "golang.org/x/net/ipv6" + "golang.zx2c4.com/wireguard/conn" ) @@ -117,15 +119,13 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind conn.Bind) { buffer := device.GetMessageBuffer() var ( - err error - size int - endpoint conn.Endpoint + err error + size int + endpoint conn.Endpoint + deathSpiral int ) for { - - // read next datagram - switch IP { case ipv4.Version: size, endpoint, err = bind.ReceiveIPv4(buffer[:]) @@ -137,8 +137,18 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind conn.Bind) { if err != nil { device.PutMessageBuffer(buffer) + if errors.Is(err, net.ErrClosed) { + return + } + device.log.Error.Printf("Failed to receive packet: %v", err) + if deathSpiral < 10 { + deathSpiral++ + time.Sleep(time.Second / 3) + continue + } return } + deathSpiral = 0 if size < MinMessageSize { continue |