Skip to content

Commit

Permalink
fix(p2p/peerTracker): fix bootstraping (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs authored Apr 2, 2024
1 parent 3b63466 commit dbcee58
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions p2p/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ func (p *peerTracker) bootstrap(ctx context.Context, trusted []libpeer.ID) error
connectCtx, cancel := context.WithTimeout(context.Background(), time.Second*60)
defer cancel()

wg := sync.WaitGroup{}
wg.Add(len(trusted))
for _, trust := range trusted {
go p.connectToPeer(connectCtx, trust)
trust := trust
go func() {
defer wg.Done()
p.connectToPeer(connectCtx, trust)
}()
}

// short-circuit if pidstore was not provided
Expand All @@ -96,9 +102,15 @@ func (p *peerTracker) bootstrap(ctx context.Context, trusted []libpeer.ID) error
return err
}

wg.Add(len(prevSeen))
for _, peer := range prevSeen {
go p.connectToPeer(connectCtx, peer)
peer := peer
go func() {
defer wg.Done()
p.connectToPeer(connectCtx, peer)
}()
}
wg.Wait()
return nil
}

Expand Down

0 comments on commit dbcee58

Please sign in to comment.