From 63aadf6e88beb61935875a29b05cbba45c535ac4 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 3 Feb 2018 18:44:28 -0600 Subject: [PATCH] use smaller buffer sizes for buffered channels --- src/yggdrasil/router.go | 6 +++--- src/yggdrasil/session.go | 4 ++-- src/yggdrasil/tcp.go | 4 ++-- src/yggdrasil/udp.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/yggdrasil/router.go b/src/yggdrasil/router.go index b5b687f9..5c02943c 100644 --- a/src/yggdrasil/router.go +++ b/src/yggdrasil/router.go @@ -41,7 +41,7 @@ type router struct { func (r *router) init(core *Core) { r.core = core r.addr = *address_addrForNodeID(&r.core.dht.nodeID) - in := make(chan []byte, 1024) // TODO something better than this... + in := make(chan []byte, 32) // TODO something better than this... p := r.core.peers.newPeer(&r.core.boxPub, &r.core.sigPub) //, out, in) p.out = func(packet []byte) { // This is to make very sure it never blocks @@ -56,8 +56,8 @@ func (r *router) init(core *Core) { } r.in = in r.out = func(packet []byte) { p.handlePacket(packet, nil) } // The caller is responsible for go-ing if it needs to not block - recv := make(chan []byte, 1024) - send := make(chan []byte, 1024) + recv := make(chan []byte, 32) + send := make(chan []byte, 32) r.recv = recv r.send = send r.core.tun.recv = recv diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 3fbf4c6a..06061bc2 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -163,8 +163,8 @@ func (ss *sessions) createSession(theirPermKey *boxPubKey) *sessionInfo { sinfo.myHandle = *newHandle() sinfo.theirAddr = *address_addrForNodeID(getNodeID(&sinfo.theirPermPub)) sinfo.theirSubnet = *address_subnetForNodeID(getNodeID(&sinfo.theirPermPub)) - sinfo.send = make(chan []byte, 1024) - sinfo.recv = make(chan *wire_trafficPacket, 1024) + sinfo.send = make(chan []byte, 32) + sinfo.recv = make(chan *wire_trafficPacket, 32) go sinfo.doWorker() sinfo.time = time.Now() // Do some cleanup diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index e8d1d386..ad9139a6 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -128,13 +128,13 @@ func (iface *tcpInterface) handler(sock *net.TCPConn) { in := func(bs []byte) { p.handlePacket(bs, linkIn) } - out := make(chan []byte, 1024) // TODO? what size makes sense + out := make(chan []byte, 32) // TODO? what size makes sense defer close(out) go func() { var stack [][]byte put := func(msg []byte) { stack = append(stack, msg) - for len(stack) > 1024 { + for len(stack) > 32 { util_putBytes(stack[0]) stack = stack[1:] } diff --git a/src/yggdrasil/udp.go b/src/yggdrasil/udp.go index d41593b6..8d88df1d 100644 --- a/src/yggdrasil/udp.go +++ b/src/yggdrasil/udp.go @@ -167,7 +167,7 @@ func (iface *udpInterface) handleKeys(msg []byte, addr connAddr) { peer: iface.core.peers.newPeer(&ks.box, &ks.sig), linkIn: make(chan []byte, 1), keysIn: make(chan *udpKeys, 1), - out: make(chan []byte, 1024), + out: make(chan []byte, 32), } /* conn.in = func (msg []byte) { conn.peer.handlePacket(msg, conn.linkIn) }