MCPcopy Create free account
hub / github.com/ethstorage/es-node / needThisPeer

Method needThisPeer

ethstorage/p2p/protocol/syncclient.go:1339–1362  ·  view source on GitHub ↗
(contractShards map[common.Address][]uint64)

Source from the content-addressed store, hash-verified

1337}
1338
1339func (s *SyncClient) needThisPeer(contractShards map[common.Address][]uint64) bool {
1340 if contractShards == nil {
1341 return false
1342 }
1343 for contract, shards := range contractShards {
1344 for _, shard := range shards {
1345 for _, t := range s.tasks {
1346 if t.Contract != contract || shard != t.ShardId {
1347 continue
1348 }
1349
1350 // when the peer and local node has overlap, the peer will be added to the sync client when
1351 // - SyncClient peer count smaller than maxPeers; or
1352 // - task peer count smaller than minPeersPerShard
1353 // otherwise, the peer will be disconnected.
1354 if len(s.peers) < s.maxPeers || t.state.PeerCount < s.minPeersPerShard {
1355 return true
1356 }
1357 }
1358 }
1359 }
1360
1361 return false
1362}
1363
1364func (s *SyncClient) addPeerToTask(contractShards map[common.Address][]uint64) {
1365 for contract, shards := range contractShards {

Callers 1

AddPeerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected