5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 07:11:40 +00:00

adjust tcp timeout and add shadow queues to track dropped packets

This commit is contained in:
Arceliar 2018-06-07 15:04:17 -05:00
parent c1f8baf9b5
commit 63feed8dc3

View File

@ -225,16 +225,20 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
} }
go func() { go func() {
defer buf.Flush() defer buf.Flush()
var shadow uint64
var stack [][]byte var stack [][]byte
put := func(msg []byte) { put := func(msg []byte) {
stack = append(stack, msg) stack = append(stack, msg)
for len(stack) > 32 { for len(stack) > 32 {
util_putBytes(stack[0]) util_putBytes(stack[0])
stack = stack[1:] stack = stack[1:]
p.updateQueueSize(-1) shadow++
} }
} }
for { for {
for ; shadow > 0; shadow-- {
p.updateQueueSize(-1)
}
select { select {
case msg := <-p.linkOut: case msg := <-p.linkOut:
send(msg) send(msg)
@ -294,7 +298,7 @@ func (iface *tcpInterface) reader(sock net.Conn, in func([]byte)) {
bs := make([]byte, 2*tcp_msgSize) bs := make([]byte, 2*tcp_msgSize)
frag := bs[:0] frag := bs[:0]
for { for {
timeout := time.Now().Add(6 * time.Second) timeout := time.Now().Add(2 * time.Minute)
sock.SetReadDeadline(timeout) sock.SetReadDeadline(timeout)
n, err := sock.Read(bs[len(frag):]) n, err := sock.Read(bs[len(frag):])
if err != nil || n == 0 { if err != nil || n == 0 {