mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Asynchronous Dials To Peers (#5021)
* make dial non-blocking * add sleep Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
acb15a1f04
commit
069f2c5fb6
@ -161,6 +161,7 @@ func TestStaticPeering_PeersAreAdded(t *testing.T) {
|
||||
s.Start()
|
||||
s.dv5Listener = &mockListener{}
|
||||
defer s.Stop()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
peers := s.host.Network().Peers()
|
||||
if len(peers) != 5 {
|
||||
|
@ -311,19 +311,19 @@ func (s *Service) connectWithAllPeers(multiAddrs []ma.Multiaddr) {
|
||||
return
|
||||
}
|
||||
for _, info := range addrInfos {
|
||||
if info.ID == s.host.ID() {
|
||||
continue
|
||||
}
|
||||
if _, ok := s.exclusionList.Get(info.ID.String()); ok {
|
||||
continue
|
||||
}
|
||||
if s.Peers().IsBad(info.ID) {
|
||||
continue
|
||||
}
|
||||
if err := s.host.Connect(s.ctx, info); err != nil {
|
||||
log.Errorf("Could not connect with peer %s: %v", info.String(), err)
|
||||
s.exclusionList.Set(info.ID.String(), true, 1)
|
||||
}
|
||||
// make each dial non-blocking
|
||||
go func(info peer.AddrInfo) {
|
||||
if info.ID == s.host.ID() {
|
||||
return
|
||||
}
|
||||
if s.Peers().IsBad(info.ID) {
|
||||
return
|
||||
}
|
||||
if err := s.host.Connect(s.ctx, info); err != nil {
|
||||
log.Errorf("Could not connect with peer %s: %v", info.String(), err)
|
||||
s.Peers().IncrementBadResponses(info.ID)
|
||||
}
|
||||
}(info)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user