5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-09 23:20:28 +00:00

fix handling of keepAliveTimer and blocked state in link.go

This commit is contained in:
Arceliar 2020-05-30 10:32:15 -05:00
parent 1df305d31c
commit 3dc2242712

View File

@ -387,19 +387,14 @@ func (intf *link) notifySending(size int) {
intf.Act(&intf.writer, func() { intf.Act(&intf.writer, func() {
intf.isSending = true intf.isSending = true
intf.sendTimer = time.AfterFunc(sendTime, intf.notifyBlockedSend) intf.sendTimer = time.AfterFunc(sendTime, intf.notifyBlockedSend)
intf._cancelStallTimer() if intf.keepAliveTimer != nil {
intf.keepAliveTimer.Stop()
intf.keepAliveTimer = nil
}
intf.peer.notifyBlocked(intf) 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 // 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 // to have gotten blocked on a write, so the switch should start routing traffic
// through other links, if alternatives exist // 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 // Set the peer as stalled, to prevent them from returning to the switch until a read succeeds
func (intf *link) notifyStalled() { func (intf *link) notifyStalled() {
intf.Act(nil, func() { // Sent from a time.AfterFunc intf.Act(nil, func() { // Sent from a time.AfterFunc
if intf.stallTimer != nil && !intf.blocked { if intf.stallTimer != nil {
intf.stallTimer.Stop() intf.stallTimer.Stop()
intf.stallTimer = nil intf.stallTimer = nil
intf.blocked = true if !intf.blocked {
intf.links.core.switchTable.blockPeer(intf, intf.peer.port) 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 // We need to send keep-alive traffic now
func (intf *link) notifyDoKeepAlive() { func (intf *link) notifyDoKeepAlive() {
intf.Act(nil, func() { // Sent from a time.AfterFunc intf.Act(nil, func() { // Sent from a time.AfterFunc
if intf.stallTimer != nil { if intf.keepAliveTimer != nil {
intf.stallTimer.Stop() intf.keepAliveTimer.Stop()
intf.stallTimer = nil intf.keepAliveTimer = nil
intf.writer.sendFrom(nil, [][]byte{nil}) // Empty keep-alive traffic intf.writer.sendFrom(nil, [][]byte{nil}) // Empty keep-alive traffic
} }
}) })