mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 11:51:37 +00:00
Merge pull request #494 from Arceliar/bufpersession
Per-session front-dropping buffers for incoming traffic
This commit is contained in:
commit
ae05683c73
@ -508,6 +508,32 @@ func (sinfo *sessionInfo) recvWorker() {
|
|||||||
util.WorkerGo(poolFunc)
|
util.WorkerGo(poolFunc)
|
||||||
callbacks = append(callbacks, ch)
|
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 {
|
||||||
for len(callbacks) > 0 {
|
for len(callbacks) > 0 {
|
||||||
select {
|
select {
|
||||||
@ -516,14 +542,14 @@ func (sinfo *sessionInfo) recvWorker() {
|
|||||||
f()
|
f()
|
||||||
case <-sinfo.cancel.Finished():
|
case <-sinfo.cancel.Finished():
|
||||||
return
|
return
|
||||||
case p := <-sinfo.fromRouter:
|
case p := <-fromHelper:
|
||||||
doRecv(p)
|
doRecv(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-sinfo.cancel.Finished():
|
case <-sinfo.cancel.Finished():
|
||||||
return
|
return
|
||||||
case p := <-sinfo.fromRouter:
|
case p := <-fromHelper:
|
||||||
doRecv(p)
|
doRecv(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user