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

Method AddPeer

ethstorage/p2p/protocol/syncclient.go:513–542  ·  view source on GitHub ↗
(id peer.ID, shards map[common.Address][]uint64, direction network.Direction)

Source from the content-addressed store, hash-verified

511}
512
513func (s *SyncClient) AddPeer(id peer.ID, shards map[common.Address][]uint64, direction network.Direction) bool {
514 s.lock.Lock()
515 if _, ok := s.peers[id]; ok {
516 s.lg.Debug("Peer was already registered", "peer", id)
517 s.lock.Unlock()
518 return true
519 }
520 if s.closingPeers {
521 s.lock.Unlock()
522 return false
523 }
524 if !s.needThisPeer(shards) {
525 s.lg.Debug("No need this peer, the connection would be closed later", "maxPeers", s.maxPeers,
526 "Peer count", len(s.peers), "peer", id.String(), "shards", shards)
527 s.metrics.IncDropPeerCount()
528 s.lock.Unlock()
529 return false
530 }
531 // add new peer routine
532 pr := NewPeer(0, s.chainID, id, s.newStreamFn, direction, s.syncerParams.InitRequestSize, s.storageManager.MaxKvSize(), shards)
533 s.peers[id] = pr
534
535 s.idlerPeers[id] = struct{}{}
536 s.addPeerToTask(shards)
537 s.metrics.IncPeerCount()
538 s.lock.Unlock()
539
540 s.notifyPeerJoin(id)
541 return true
542}
543
544func (s *SyncClient) RemovePeer(id peer.ID) bool {
545 s.lock.Lock()

Callers 2

initMethod · 0.80

Calls 8

needThisPeerMethod · 0.95
addPeerToTaskMethod · 0.95
notifyPeerJoinMethod · 0.95
NewPeerFunction · 0.85
IncDropPeerCountMethod · 0.65
MaxKvSizeMethod · 0.65
IncPeerCountMethod · 0.65
StringMethod · 0.45

Tested by 1