mirror of https://github.com/status-im/go-waku.git
refactor: connect to discovered peers linearly
This commit is contained in:
parent
dbd94ebb81
commit
6d9018cb11
|
@ -250,13 +250,6 @@ func (c *PeerConnectionStrategy) workPublisher(ctx context.Context) {
|
|||
|
||||
func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) {
|
||||
defer c.wg.Done()
|
||||
|
||||
maxGoRoutines := c.minPeers
|
||||
if maxGoRoutines > 15 {
|
||||
maxGoRoutines = 15
|
||||
}
|
||||
|
||||
sem := make(chan struct{}, maxGoRoutines)
|
||||
for {
|
||||
select {
|
||||
case pi, ok := <-c.dialCh:
|
||||
|
@ -291,20 +284,14 @@ func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) {
|
|||
continue
|
||||
}
|
||||
|
||||
sem <- struct{}{}
|
||||
c.wg.Add(1)
|
||||
go func(pi peer.AddrInfo) {
|
||||
defer c.wg.Done()
|
||||
|
||||
ctx, cancel := context.WithTimeout(c.workerCtx, c.dialTimeout)
|
||||
defer cancel()
|
||||
err := c.host.Connect(ctx, pi)
|
||||
dialCtx, dialCtxCancel := context.WithTimeout(c.workerCtx, c.dialTimeout)
|
||||
err := c.host.Connect(dialCtx, pi)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
c.host.Peerstore().(peers.WakuPeerstore).AddConnFailure(pi)
|
||||
c.logger.Info("connecting to peer", logging.HostID("peerID", pi.ID), zap.Error(err))
|
||||
}
|
||||
<-sem
|
||||
}(pi)
|
||||
dialCtxCancel()
|
||||
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue