network: count only handshaked peers as connected
This commit is contained in:
parent
65332f5e7f
commit
7c900edd2d
1 changed files with 18 additions and 1 deletions
|
@ -253,7 +253,7 @@ func (s *Server) tryStartConsensus() {
|
|||
return
|
||||
}
|
||||
|
||||
if s.PeerCount() >= s.MinPeers {
|
||||
if s.HandshakedPeersCount() >= s.MinPeers {
|
||||
log.Info("minimum amount of peers were connected to")
|
||||
if s.connected.CAS(false, true) {
|
||||
s.consensus.Start()
|
||||
|
@ -282,6 +282,23 @@ func (s *Server) PeerCount() int {
|
|||
return len(s.peers)
|
||||
}
|
||||
|
||||
// HandshakedPeersCount returns the number of connected peers
|
||||
// which have already performed handshake.
|
||||
func (s *Server) HandshakedPeersCount() int {
|
||||
s.lock.RLock()
|
||||
defer s.lock.RUnlock()
|
||||
|
||||
var count int
|
||||
|
||||
for p := range s.peers {
|
||||
if p.Handshaked() {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
// startProtocol starts a long running background loop that interacts
|
||||
// every ProtoTickInterval with the peer.
|
||||
func (s *Server) startProtocol(p Peer) {
|
||||
|
|
Loading…
Reference in a new issue