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:
Nishant Das 2020-03-06 22:57:47 +08:00 committed by GitHub
parent acb15a1f04
commit 069f2c5fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -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 {

View File

@ -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)
}
}