diff --git a/src/yggdrasil/link.go b/src/yggdrasil/link.go index b24c4cc6..9c9223b7 100644 --- a/src/yggdrasil/link.go +++ b/src/yggdrasil/link.go @@ -234,6 +234,9 @@ func (intf *linkInterface) handler() error { signalReady := make(chan struct{}, 1) signalSent := make(chan bool, 1) sendAck := make(chan struct{}, 1) + sendBlocked := time.NewTimer(time.Second) + defer util.TimerStop(sendBlocked) + util.TimerStop(sendBlocked) go func() { defer close(signalReady) defer close(signalSent) @@ -241,7 +244,9 @@ func (intf *linkInterface) handler() error { tcpTimer := time.NewTimer(interval) // used for backwards compat with old tcp defer util.TimerStop(tcpTimer) send := func(bs []byte) { + sendBlocked.Reset(time.Second) intf.msgIO.writeMsg(bs) + util.TimerStop(sendBlocked) select { case signalSent <- len(bs) > 0: default: @@ -269,7 +274,7 @@ func (intf *linkInterface) handler() error { strings.ToUpper(intf.info.linkType), themString, intf.info.local) send(nil) case msg := <-intf.peer.linkOut: - intf.msgIO.writeMsg(msg) + send(msg) case msg, ok := <-out: if !ok { return @@ -360,6 +365,10 @@ func (intf *linkInterface) handler() error { intf.link.core.switchTable.idleIn <- intf.peer.port isReady = true } + case <-sendBlocked.C: + // We blocked while trying to send something + isReady = false + intf.link.core.switchTable.blockPeer(intf.peer.port) case <-sendTimer.C: // We haven't sent anything, so signal a send of a 0 packet to let them know we're alive select { diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 1576ef53..bff2ae39 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -677,12 +677,12 @@ func (t *switchTable) handleIn(packet []byte, idle map[switchPort]struct{}) bool //nothing case coordLen < bestCoordLen: update = true - /* - case coordLen > bestCoordLen: - //nothing - case port < best.port: - update = true - */ + /* + case coordLen > bestCoordLen: + //nothing + case port < best.port: + update = true + */ default: //nothing }