Use larger UDP chunks for link-local IP and let the OS fragment it. Switch to UDP for link-local peers. Minor code cleanup for TCP.

This commit is contained in:
Arceliar 2018-02-19 19:34:51 -06:00
parent 8c7d514032
commit 4045597516
4 changed files with 53 additions and 47 deletions

View file

@ -158,6 +158,23 @@ func (iface *tcpInterface) handler(sock *net.TCPConn) {
}
out := make(chan []byte, 32) // TODO? what size makes sense
defer close(out)
send := func(msg []byte) {
buf := net.Buffers{tcp_msg[:],
wire_encode_uint64(uint64(len(msg))),
msg}
size := 0
for _, bs := range buf {
size += len(bs)
}
start := time.Now()
buf.WriteTo(sock)
timed := time.Since(start)
pType, _ := wire_decode_uint64(msg)
if pType == wire_LinkProtocolTraffic {
p.updateBandwidth(size, timed)
}
util_putBytes(msg)
}
go func() {
var stack [][]byte
put := func(msg []byte) {
@ -167,25 +184,6 @@ func (iface *tcpInterface) handler(sock *net.TCPConn) {
stack = stack[1:]
}
}
send := func() {
msg := stack[len(stack)-1]
stack = stack[:len(stack)-1]
buf := net.Buffers{tcp_msg[:],
wire_encode_uint64(uint64(len(msg))),
msg}
size := 0
for _, bs := range buf {
size += len(bs)
}
start := time.Now()
buf.WriteTo(sock)
timed := time.Since(start)
pType, _ := wire_decode_uint64(msg)
if pType == wire_LinkProtocolTraffic {
p.updateBandwidth(size, timed)
}
util_putBytes(msg)
}
for msg := range out {
put(msg)
for len(stack) > 0 {
@ -197,7 +195,9 @@ func (iface *tcpInterface) handler(sock *net.TCPConn) {
}
put(msg)
default:
send()
msg := stack[len(stack)-1]
stack = stack[:len(stack)-1]
send(msg)
}
}
}