remove peer.linkIn channel and related logic

This commit is contained in:
Arceliar 2018-06-07 00:49:06 -05:00
parent ecf37cae8a
commit deb755e3e9
3 changed files with 16 additions and 28 deletions

View File

@ -449,8 +449,17 @@ func (c *Core) DEBUG_addAllowedEncryptionPublicKey(boxStr string) {
func DEBUG_simLinkPeers(p, q *peer) { func DEBUG_simLinkPeers(p, q *peer) {
// Sets q.out() to point to p and starts p.linkLoop() // 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 = make(chan []byte, 1), make(chan []byte, 1)
p.linkOut, q.linkOut = q.linkIn, p.linkIn 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) { p.out = func(bs []byte) {
go q.handlePacket(bs) go q.handlePacket(bs)
} }

View File

@ -106,7 +106,6 @@ type peer struct {
// To allow the peer to call close if idle for too long // To allow the peer to call close if idle for too long
lastAnc time.Time // TODO? rename and use this lastAnc time.Time // TODO? rename and use this
// used for protocol traffic (to bypass queues) // used for protocol traffic (to bypass queues)
linkIn (chan []byte) // handlePacket sends, linkLoop recvs
linkOut (chan []byte) linkOut (chan []byte)
lastMsg []byte // last switchMsg accepted lastMsg []byte // last switchMsg accepted
doSend (chan struct{}) // tell the linkLoop to send a switchMsg doSend (chan struct{}) // tell the linkLoop to send a switchMsg
@ -170,7 +169,7 @@ func (ps *peers) removePeer(port switchPort) {
if p.close != nil { if p.close != nil {
p.close() p.close()
} }
close(p.linkIn) close(p.doSend)
} }
} }
@ -200,27 +199,8 @@ func (ps *peers) fixSwitchAfterPeerDisconnect() {
func (p *peer) linkLoop() { func (p *peer) linkLoop() {
go func() { p.doSend <- struct{}{} }() go func() { p.doSend <- struct{}{} }()
ticker := time.NewTicker(10 * time.Second) for range p.doSend {
defer ticker.Stop() p.sendSwitchMsg()
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()
}
} }
} }
@ -237,8 +217,8 @@ func (p *peer) handlePacket(packet []byte) {
case wire_ProtocolTraffic: case wire_ProtocolTraffic:
p.handleTraffic(packet, pTypeLen) p.handleTraffic(packet, pTypeLen)
case wire_LinkProtocolTraffic: case wire_LinkProtocolTraffic:
p.linkIn <- packet p.handleLinkTraffic(packet)
default: /*panic(pType) ;*/ default:
return return
} }
} }

View File

@ -209,7 +209,6 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
// Note that multiple connections to the same node are allowed // Note that multiple connections to the same node are allowed
// E.g. over different interfaces // E.g. over different interfaces
p := iface.core.peers.newPeer(&info.box, &info.sig) p := iface.core.peers.newPeer(&info.box, &info.sig)
p.linkIn = make(chan []byte, 1)
p.linkOut = make(chan []byte, 1) p.linkOut = make(chan []byte, 1)
in := func(bs []byte) { in := func(bs []byte) {
p.handlePacket(bs) p.handlePacket(bs)