5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 21:10:29 +00:00

Drop 1 packet instead of a whole queue when overflowing

This commit is contained in:
Arceliar 2018-07-06 00:55:00 -05:00
parent e6a47f705d
commit ad5dc9ea87

View File

@ -605,21 +605,16 @@ type switch_buffers struct {
} }
func (b *switch_buffers) cleanup(t *switchTable) { 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 { for streamID, buf := range b.bufs {
// Remove queues for which we have no next hop // Remove queues for which we have no next hop
packet := buf.packets[0] packet := buf.packets[0]
coords := switch_getPacketCoords(packet.bytes) coords := switch_getPacketCoords(packet.bytes)
if t.selfIsClosest(coords) { 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 const maxSize = 4 * 1048576 // Maximum 4 MB
@ -632,7 +627,13 @@ func (b *switch_buffers) cleanup(t *switchTable) {
if size < target { if size < target {
continue 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 break
} }
} }