Enforce min 4MB switch queue total size

This commit is contained in:
Neil Alexander 2018-12-02 23:20:11 +00:00
parent 319457ae27
commit b5f4637b5c
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 13 additions and 7 deletions

View file

@ -169,9 +169,12 @@ type switchTable struct {
idleIn chan switchPort // Incoming idle notifications from peer links
admin chan func() // Pass a lambda for the admin socket to query stuff
queues switch_buffers // Queues - not atomic so ONLY use through admin chan
queuetotalmaxsize uint64 // Maximum combined size of queues
queueTotalMaxSize uint64 // Maximum combined size of queues
}
// Minimum allowed total size of switch queues.
const SwitchQueueTotalMinSize = 4 * 1024 * 1024
// Initializes the switchTable struct.
func (t *switchTable) init(core *Core, key sigPubKey) {
now := time.Now()
@ -186,6 +189,7 @@ func (t *switchTable) init(core *Core, key sigPubKey) {
t.packetIn = make(chan []byte, 1024)
t.idleIn = make(chan switchPort, 1024)
t.admin = make(chan func())
t.queueTotalMaxSize = SwitchQueueTotalMinSize
}
// Safely gets a copy of this node's locator.
@ -649,7 +653,7 @@ func (b *switch_buffers) cleanup(t *switchTable) {
}
}
for b.size > b.switchTable.queuetotalmaxsize {
for b.size > b.switchTable.queueTotalMaxSize {
// Drop a random queue
target := rand.Uint64() % b.size
var size uint64 // running total