()
| 947 | } |
| 948 | |
| 949 | func (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. |
no test coverage detected