From 3dc22427125103f2ac3e1dbe3664bf38c7a8b167 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 30 May 2020 10:32:15 -0500 Subject: [PATCH] fix handling of keepAliveTimer and blocked state in link.go --- src/yggdrasil/link.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/yggdrasil/link.go b/src/yggdrasil/link.go index 0dd97ec5..7a843b68 100644 --- a/src/yggdrasil/link.go +++ b/src/yggdrasil/link.go @@ -387,19 +387,14 @@ func (intf *link) notifySending(size int) { intf.Act(&intf.writer, func() { intf.isSending = true intf.sendTimer = time.AfterFunc(sendTime, intf.notifyBlockedSend) - intf._cancelStallTimer() + if intf.keepAliveTimer != nil { + intf.keepAliveTimer.Stop() + intf.keepAliveTimer = nil + } intf.peer.notifyBlocked(intf) }) } -// we just sent something, so cancel any pending timer to send keep-alive traffic -func (intf *link) _cancelStallTimer() { - if intf.stallTimer != nil { - intf.stallTimer.Stop() - intf.stallTimer = nil - } -} - // This gets called from a time.AfterFunc, and notifies the switch that we appear // to have gotten blocked on a write, so the switch should start routing traffic // through other links, if alternatives exist @@ -441,11 +436,13 @@ func (intf *link) _notifyIdle() { // Set the peer as stalled, to prevent them from returning to the switch until a read succeeds func (intf *link) notifyStalled() { intf.Act(nil, func() { // Sent from a time.AfterFunc - if intf.stallTimer != nil && !intf.blocked { + if intf.stallTimer != nil { intf.stallTimer.Stop() intf.stallTimer = nil - intf.blocked = true - intf.links.core.switchTable.blockPeer(intf, intf.peer.port) + if !intf.blocked { + intf.blocked = true + intf.links.core.switchTable.blockPeer(intf, intf.peer.port) + } } }) } @@ -480,9 +477,9 @@ func (intf *link) notifyRead(size int) { // We need to send keep-alive traffic now func (intf *link) notifyDoKeepAlive() { intf.Act(nil, func() { // Sent from a time.AfterFunc - if intf.stallTimer != nil { - intf.stallTimer.Stop() - intf.stallTimer = nil + if intf.keepAliveTimer != nil { + intf.keepAliveTimer.Stop() + intf.keepAliveTimer = nil intf.writer.sendFrom(nil, [][]byte{nil}) // Empty keep-alive traffic } })