mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 06:01:37 +00:00
more work on backpressure, but still needs more testing
This commit is contained in:
parent
4b83efa218
commit
0ad801bcfe
@ -588,18 +588,32 @@ func (t *switchTable) handleIn(packet []byte, idle map[switchPort]struct{}) bool
|
||||
ports[0].sendPacket(packet)
|
||||
return true
|
||||
}
|
||||
table := t.getTable()
|
||||
myDist := table.self.dist(coords)
|
||||
var best *peer
|
||||
bestDist := myDist
|
||||
for port := range idle {
|
||||
if to := ports[port]; to != nil {
|
||||
if t.portIsCloser(coords, port) {
|
||||
delete(idle, port)
|
||||
to.sendPacket(packet)
|
||||
if info, isIn := table.elems[to.port]; isIn {
|
||||
dist := info.locator.dist(coords)
|
||||
if !(dist < bestDist) {
|
||||
continue
|
||||
}
|
||||
best = to
|
||||
bestDist = dist
|
||||
}
|
||||
}
|
||||
}
|
||||
if best != nil {
|
||||
// Send to the best idle next hop
|
||||
delete(idle, best.port)
|
||||
best.sendPacket(packet)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Didn't find anyone idle to send it to
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Handles incoming idle notifications
|
||||
// Loops over packets and sends the newest one that's OK for this peer to send
|
||||
|
Loading…
Reference in New Issue
Block a user