mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 18:15:24 +00:00
Drop 1 packet instead of a whole queue when overflowing
This commit is contained in:
parent
e6a47f705d
commit
ad5dc9ea87
@ -605,21 +605,16 @@ type switch_buffers struct {
|
||||
}
|
||||
|
||||
func (b *switch_buffers) cleanup(t *switchTable) {
|
||||
remove := func(streamID string) {
|
||||
// Helper function to drop a queue
|
||||
buf := b.bufs[streamID]
|
||||
for _, packet := range buf.packets {
|
||||
util_putBytes(packet.bytes)
|
||||
}
|
||||
b.size -= buf.size
|
||||
delete(b.bufs, streamID)
|
||||
}
|
||||
for streamID, buf := range b.bufs {
|
||||
// Remove queues for which we have no next hop
|
||||
packet := buf.packets[0]
|
||||
coords := switch_getPacketCoords(packet.bytes)
|
||||
if t.selfIsClosest(coords) {
|
||||
remove(streamID)
|
||||
for _, packet := range buf.packets {
|
||||
util_putBytes(packet.bytes)
|
||||
}
|
||||
b.size -= buf.size
|
||||
delete(b.bufs, streamID)
|
||||
}
|
||||
}
|
||||
const maxSize = 4 * 1048576 // Maximum 4 MB
|
||||
@ -632,7 +627,13 @@ func (b *switch_buffers) cleanup(t *switchTable) {
|
||||
if size < target {
|
||||
continue
|
||||
}
|
||||
remove(streamID)
|
||||
var packet switch_packetInfo
|
||||
packet, buf.packets = buf.packets[0], buf.packets[1:]
|
||||
buf.size -= uint64(len(packet.bytes))
|
||||
b.size -= uint64(len(packet.bytes))
|
||||
if len(buf.packets) == 0 {
|
||||
delete(b.bufs, streamID)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user