mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
possibly fix memory leak (if this works, i don't yet understand how the leak was happening originally)
This commit is contained in:
parent
d160eccab0
commit
8075a60900
@ -800,7 +800,7 @@ func (t *switchTable) _handleIdle(port switchPort) bool {
|
|||||||
t.queues._cleanup(t)
|
t.queues._cleanup(t)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for psize < 65535 {
|
for psize < 65535 {
|
||||||
var best string
|
var best *string
|
||||||
var bestPriority float64
|
var bestPriority float64
|
||||||
for streamID, buf := range t.queues.bufs {
|
for streamID, buf := range t.queues.bufs {
|
||||||
// Filter over the streams that this node is closer to
|
// Filter over the streams that this node is closer to
|
||||||
@ -809,22 +809,23 @@ func (t *switchTable) _handleIdle(port switchPort) bool {
|
|||||||
coords := switch_getPacketCoords(packet.bytes)
|
coords := switch_getPacketCoords(packet.bytes)
|
||||||
priority := float64(now.Sub(packet.time)) / float64(buf.size)
|
priority := float64(now.Sub(packet.time)) / float64(buf.size)
|
||||||
if priority >= bestPriority && t.portIsCloser(coords, port) {
|
if priority >= bestPriority && t.portIsCloser(coords, port) {
|
||||||
best = streamID
|
b := streamID // copy since streamID is mutated in the loop
|
||||||
|
best = &b
|
||||||
bestPriority = priority
|
bestPriority = priority
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if best != "" {
|
if best != nil {
|
||||||
buf := t.queues.bufs[best]
|
buf := t.queues.bufs[*best]
|
||||||
var packet switch_packetInfo
|
var packet switch_packetInfo
|
||||||
// TODO decide if this should be LIFO or FIFO
|
// TODO decide if this should be LIFO or FIFO
|
||||||
packet, buf.packets = buf.packets[0], buf.packets[1:]
|
packet, buf.packets = buf.packets[0], buf.packets[1:]
|
||||||
buf.size -= uint64(len(packet.bytes))
|
buf.size -= uint64(len(packet.bytes))
|
||||||
t.queues.size -= uint64(len(packet.bytes))
|
t.queues.size -= uint64(len(packet.bytes))
|
||||||
if len(buf.packets) == 0 {
|
if len(buf.packets) == 0 {
|
||||||
delete(t.queues.bufs, best)
|
delete(t.queues.bufs, *best)
|
||||||
} else {
|
} else {
|
||||||
// Need to update the map, since buf was retrieved by value
|
// Need to update the map, since buf was retrieved by value
|
||||||
t.queues.bufs[best] = buf
|
t.queues.bufs[*best] = buf
|
||||||
}
|
}
|
||||||
packets = append(packets, packet.bytes)
|
packets = append(packets, packet.bytes)
|
||||||
psize += len(packet.bytes)
|
psize += len(packet.bytes)
|
||||||
|
Loading…
Reference in New Issue
Block a user