5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 06:20:26 +00:00

Merge pull request #375 from Arceliar/fixes

More switch/link fixes
This commit is contained in:
Arceliar 2019-03-09 18:43:09 -06:00 committed by GitHub
commit 7017c6d102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -234,6 +234,9 @@ func (intf *linkInterface) handler() error {
signalReady := make(chan struct{}, 1) signalReady := make(chan struct{}, 1)
signalSent := make(chan bool, 1) signalSent := make(chan bool, 1)
sendAck := make(chan struct{}, 1) sendAck := make(chan struct{}, 1)
sendBlocked := time.NewTimer(time.Second)
defer util.TimerStop(sendBlocked)
util.TimerStop(sendBlocked)
go func() { go func() {
defer close(signalReady) defer close(signalReady)
defer close(signalSent) defer close(signalSent)
@ -241,7 +244,9 @@ func (intf *linkInterface) handler() error {
tcpTimer := time.NewTimer(interval) // used for backwards compat with old tcp tcpTimer := time.NewTimer(interval) // used for backwards compat with old tcp
defer util.TimerStop(tcpTimer) defer util.TimerStop(tcpTimer)
send := func(bs []byte) { send := func(bs []byte) {
sendBlocked.Reset(time.Second)
intf.msgIO.writeMsg(bs) intf.msgIO.writeMsg(bs)
util.TimerStop(sendBlocked)
select { select {
case signalSent <- len(bs) > 0: case signalSent <- len(bs) > 0:
default: default:
@ -269,7 +274,7 @@ func (intf *linkInterface) handler() error {
strings.ToUpper(intf.info.linkType), themString, intf.info.local) strings.ToUpper(intf.info.linkType), themString, intf.info.local)
send(nil) send(nil)
case msg := <-intf.peer.linkOut: case msg := <-intf.peer.linkOut:
intf.msgIO.writeMsg(msg) send(msg)
case msg, ok := <-out: case msg, ok := <-out:
if !ok { if !ok {
return return
@ -360,6 +365,10 @@ func (intf *linkInterface) handler() error {
intf.link.core.switchTable.idleIn <- intf.peer.port intf.link.core.switchTable.idleIn <- intf.peer.port
isReady = true 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: case <-sendTimer.C:
// We haven't sent anything, so signal a send of a 0 packet to let them know we're alive // We haven't sent anything, so signal a send of a 0 packet to let them know we're alive
select { select {