From deb755e3e99768de613cb441bd18053378783b30 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 7 Jun 2018 00:49:06 -0500 Subject: [PATCH] remove peer.linkIn channel and related logic --- src/yggdrasil/debug.go | 13 +++++++++++-- src/yggdrasil/peer.go | 30 +++++------------------------- src/yggdrasil/tcp.go | 1 - 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index 940db79..f080882 100644 --- a/src/yggdrasil/debug.go +++ b/src/yggdrasil/debug.go @@ -449,8 +449,17 @@ func (c *Core) DEBUG_addAllowedEncryptionPublicKey(boxStr string) { func DEBUG_simLinkPeers(p, q *peer) { // Sets q.out() to point to p and starts p.linkLoop() - p.linkIn, q.linkIn = make(chan []byte, 32), make(chan []byte, 32) - p.linkOut, q.linkOut = q.linkIn, p.linkIn + p.linkOut, q.linkOut = make(chan []byte, 1), make(chan []byte, 1) + go func() { + for bs := range p.linkOut { + q.handlePacket(bs) + } + }() + go func() { + for bs := range q.linkOut { + p.handlePacket(bs) + } + }() p.out = func(bs []byte) { go q.handlePacket(bs) } diff --git a/src/yggdrasil/peer.go b/src/yggdrasil/peer.go index 0efcbe3..ce5cd0c 100644 --- a/src/yggdrasil/peer.go +++ b/src/yggdrasil/peer.go @@ -106,7 +106,6 @@ type peer struct { // To allow the peer to call close if idle for too long lastAnc time.Time // TODO? rename and use this // used for protocol traffic (to bypass queues) - linkIn (chan []byte) // handlePacket sends, linkLoop recvs linkOut (chan []byte) lastMsg []byte // last switchMsg accepted doSend (chan struct{}) // tell the linkLoop to send a switchMsg @@ -170,7 +169,7 @@ func (ps *peers) removePeer(port switchPort) { if p.close != nil { p.close() } - close(p.linkIn) + close(p.doSend) } } @@ -200,27 +199,8 @@ func (ps *peers) fixSwitchAfterPeerDisconnect() { func (p *peer) linkLoop() { go func() { p.doSend <- struct{}{} }() - ticker := time.NewTicker(10 * time.Second) - defer ticker.Stop() - for { - select { - case packet, ok := <-p.linkIn: - if !ok { - return - } - p.handleLinkTraffic(packet) - case <-ticker.C: - p.throttle = 0 - if p.lastMsg != nil { - // TODO? remove ticker completely - // p.throttle isn't useful anymore (if they send a wrong message, remove peer instead) - // the handleMessage below is just for debugging, but it *shouldn't* be needed now that things react to state changes instantly - // The one case where it's maybe useful is if you get messages faster than the switch throttle, but that should fix itself after the next periodic update or timeout - p.handleSwitchMsg(p.lastMsg) - } - case <-p.doSend: - p.sendSwitchMsg() - } + for range p.doSend { + p.sendSwitchMsg() } } @@ -237,8 +217,8 @@ func (p *peer) handlePacket(packet []byte) { case wire_ProtocolTraffic: p.handleTraffic(packet, pTypeLen) case wire_LinkProtocolTraffic: - p.linkIn <- packet - default: /*panic(pType) ;*/ + p.handleLinkTraffic(packet) + default: return } } diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 75be31b..90fb80b 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -209,7 +209,6 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) { // Note that multiple connections to the same node are allowed // E.g. over different interfaces p := iface.core.peers.newPeer(&info.box, &info.sig) - p.linkIn = make(chan []byte, 1) p.linkOut = make(chan []byte, 1) in := func(bs []byte) { p.handlePacket(bs)