Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(p2p/peerTracker): fix bootstraping #169

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading