| 1337 | } |
| 1338 | |
| 1339 | func (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 | |
| 1364 | func (s *SyncClient) addPeerToTask(contractShards map[common.Address][]uint64) { |
| 1365 | for contract, shards := range contractShards { |