MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / stopAndRemovePeer

Method stopAndRemovePeer

p2p/switch.go:399–420  ·  view source on GitHub ↗
(peer Peer, reason interface{})

Source from the content-addressed store, hash-verified

397}
398
399func (sw *Switch) stopAndRemovePeer(peer Peer, reason interface{}) {
400 sw.transport.Cleanup(peer)
401 if err := peer.Stop(); err != nil {
402 sw.Logger.Error("error while stopping peer", "error", err) // TODO: should return error to be handled accordingly
403 }
404
405 for _, reactor := range sw.reactors {
406 reactor.RemovePeer(peer, reason)
407 }
408
409 // Removing a peer should go last to avoid a situation where a peer
410 // reconnect to our node and the switch calls InitPeer before
411 // RemovePeer is finished.
412 // https://github.com/DeAI-Artist/Linkis/issues/3338
413 if sw.peers.Remove(peer) {
414 sw.metrics.Peers.Add(float64(-1))
415 } else {
416 // Removal of the peer has failed. The function above sets a flag within the peer to mark this.
417 // We keep this message here as information to the developer.
418 sw.Logger.Debug("error on peer removal", ",", "peer", peer.ID())
419 }
420}
421
422// reconnectToPeer tries to reconnect to the addr, first repeatedly
423// with a fixed interval, then with exponential backoff.

Callers 3

OnStopMethod · 0.95
StopPeerForErrorMethod · 0.95
StopPeerGracefullyMethod · 0.95

Calls 8

CleanupMethod · 0.65
StopMethod · 0.65
ErrorMethod · 0.65
RemovePeerMethod · 0.65
RemoveMethod · 0.65
DebugMethod · 0.65
IDMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected