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

Method peerStatsRoutine

consensus/reactor.go:949–987  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

947}
948
949func (conR *Reactor) peerStatsRoutine() {
950 for {
951 if !conR.IsRunning() {
952 conR.Logger.Info("Stopping peerStatsRoutine")
953 return
954 }
955
956 select {
957 case msg := <-conR.conS.statsMsgQueue:
958 // Get peer
959 peer := conR.Switch.Peers().Get(msg.PeerID)
960 if peer == nil {
961 conR.Logger.Debug("Attempt to update stats for non-existent peer",
962 "peer", msg.PeerID)
963 continue
964 }
965 // Get peer state
966 ps, ok := peer.Get(types.PeerStateKey).(*PeerState)
967 if !ok {
968 panic(fmt.Sprintf("Peer %v has no state", peer))
969 }
970 switch msg.Msg.(type) {
971 case *VoteMessage:
972 if numVotes := ps.RecordVote(); numVotes%votesToContributeToBecomeGoodPeer == 0 {
973 conR.Switch.MarkPeerAsGood(peer)
974 }
975 case *BlockPartMessage:
976 if numParts := ps.RecordBlockPart(); numParts%blocksToContributeToBecomeGoodPeer == 0 {
977 conR.Switch.MarkPeerAsGood(peer)
978 }
979 }
980 case <-conR.conS.Quit():
981 return
982
983 case <-conR.Quit():
984 return
985 }
986 }
987}
988
989// String returns a string representation of the Reactor.
990// NOTE: For now, it is just a hard-coded string to avoid accessing unprotected shared variables.

Callers 1

OnStartMethod · 0.95

Calls 9

MarkPeerAsGoodMethod · 0.80
IsRunningMethod · 0.65
InfoMethod · 0.65
GetMethod · 0.65
PeersMethod · 0.65
DebugMethod · 0.65
QuitMethod · 0.65
RecordVoteMethod · 0.45
RecordBlockPartMethod · 0.45

Tested by

no test coverage detected