mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 18:15:24 +00:00
remove peer.linkIn channel and related logic
This commit is contained in:
parent
ecf37cae8a
commit
deb755e3e9
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user