mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
server: standardize use of connmanager's Disconnect and Remove methods
The Disconnect method would still attempt to reconnect to the same peer, which could cause us to reconnect to bad/unstable peers if we came across them. Instead, we'll now use Remove whenever we intend to remove a peer that is not persistent.
This commit is contained in:
parent
ab6f3089f6
commit
45d66d46f9
1 changed files with 18 additions and 11 deletions
29
server.go
29
server.go
|
@ -1671,24 +1671,26 @@ func (s *server) handleDonePeerMsg(state *peerState, sp *serverPeer) {
|
||||||
} else {
|
} else {
|
||||||
list = state.outboundPeers
|
list = state.outboundPeers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regardless of whether the peer was found in our list, we'll inform
|
||||||
|
// our connection manager about the disconnection. This can happen if we
|
||||||
|
// process a peer's `done` message before its `add`.
|
||||||
|
if !sp.Inbound() {
|
||||||
|
if sp.persistent {
|
||||||
|
s.connManager.Disconnect(sp.connReq.ID())
|
||||||
|
} else {
|
||||||
|
s.connManager.Remove(sp.connReq.ID())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := list[sp.ID()]; ok {
|
if _, ok := list[sp.ID()]; ok {
|
||||||
if !sp.Inbound() && sp.VersionKnown() {
|
if !sp.Inbound() && sp.VersionKnown() {
|
||||||
state.outboundGroups[addrmgr.GroupKey(sp.NA())]--
|
state.outboundGroups[addrmgr.GroupKey(sp.NA())]--
|
||||||
}
|
}
|
||||||
if !sp.Inbound() && sp.connReq != nil {
|
|
||||||
s.connManager.Disconnect(sp.connReq.ID())
|
|
||||||
}
|
|
||||||
delete(list, sp.ID())
|
delete(list, sp.ID())
|
||||||
srvrLog.Debugf("Removed peer %s", sp)
|
srvrLog.Debugf("Removed peer %s", sp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if sp.connReq != nil {
|
|
||||||
s.connManager.Disconnect(sp.connReq.ID())
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we get here it means that either we didn't know about the peer
|
|
||||||
// or we purposefully deleted it.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleBanPeerMsg deals with banning peers. It is invoked from the
|
// handleBanPeerMsg deals with banning peers. It is invoked from the
|
||||||
|
@ -2025,7 +2027,12 @@ func (s *server) outboundPeerConnected(c *connmgr.ConnReq, conn net.Conn) {
|
||||||
p, err := peer.NewOutboundPeer(newPeerConfig(sp), c.Addr.String())
|
p, err := peer.NewOutboundPeer(newPeerConfig(sp), c.Addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
srvrLog.Debugf("Cannot create outbound peer %s: %v", c.Addr, err)
|
srvrLog.Debugf("Cannot create outbound peer %s: %v", c.Addr, err)
|
||||||
s.connManager.Disconnect(c.ID())
|
if c.Permanent {
|
||||||
|
s.connManager.Disconnect(c.ID())
|
||||||
|
} else {
|
||||||
|
s.connManager.Remove(c.ID())
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
sp.Peer = p
|
sp.Peer = p
|
||||||
sp.connReq = c
|
sp.connReq = c
|
||||||
|
|
Loading…
Add table
Reference in a new issue