From 5e81a0c42167f4ff882e89fb2d0f5b17433c3d3f Mon Sep 17 00:00:00 2001 From: Arceliar Date: Wed, 7 Aug 2019 18:08:31 -0500 Subject: [PATCH] Use a separate buffer per session for incoming packets, so 1 session that floods won't block other sessions --- src/yggdrasil/session.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index d8b7e9b3..da66ad59 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -508,6 +508,32 @@ func (sinfo *sessionInfo) recvWorker() { util.WorkerGo(poolFunc) callbacks = append(callbacks, ch) } + fromHelper := make(chan wire_trafficPacket, 1) + go func() { + var buf []wire_trafficPacket + for { + for len(buf) > 0 { + select { + case <-sinfo.cancel.Finished(): + return + case p := <-sinfo.fromRouter: + buf = append(buf, p) + for len(buf) > 64 { // Based on nonce window size + util.PutBytes(buf[0].Payload) + buf = buf[1:] + } + case fromHelper <- buf[0]: + buf = buf[1:] + } + } + select { + case <-sinfo.cancel.Finished(): + return + case p := <-sinfo.fromRouter: + buf = append(buf, p) + } + } + }() for { for len(callbacks) > 0 { select { @@ -516,14 +542,14 @@ func (sinfo *sessionInfo) recvWorker() { f() case <-sinfo.cancel.Finished(): return - case p := <-sinfo.fromRouter: + case p := <-fromHelper: doRecv(p) } } select { case <-sinfo.cancel.Finished(): return - case p := <-sinfo.fromRouter: + case p := <-fromHelper: doRecv(p) } }