|
@ -472,8 +472,6 @@ func (r *Router) dialSleep(ctx context.Context) { |
|
|
// acceptPeers accepts inbound connections from peers on the given transport,
|
|
|
// acceptPeers accepts inbound connections from peers on the given transport,
|
|
|
// and spawns goroutines that route messages to/from them.
|
|
|
// and spawns goroutines that route messages to/from them.
|
|
|
func (r *Router) acceptPeers(ctx context.Context, transport Transport) { |
|
|
func (r *Router) acceptPeers(ctx context.Context, transport Transport) { |
|
|
r.logger.Debug("starting accept routine", "transport", transport) |
|
|
|
|
|
|
|
|
|
|
|
for { |
|
|
for { |
|
|
conn, err := transport.Accept(ctx) |
|
|
conn, err := transport.Accept(ctx) |
|
|
switch err { |
|
|
switch err { |
|
@ -555,8 +553,6 @@ func (r *Router) openConnection(ctx context.Context, conn Connection) { |
|
|
|
|
|
|
|
|
// dialPeers maintains outbound connections to peers by dialing them.
|
|
|
// dialPeers maintains outbound connections to peers by dialing them.
|
|
|
func (r *Router) dialPeers(ctx context.Context) { |
|
|
func (r *Router) dialPeers(ctx context.Context) { |
|
|
r.logger.Debug("starting dial routine") |
|
|
|
|
|
|
|
|
|
|
|
addresses := make(chan NodeAddress) |
|
|
addresses := make(chan NodeAddress) |
|
|
wg := &sync.WaitGroup{} |
|
|
wg := &sync.WaitGroup{} |
|
|
|
|
|
|
|
@ -587,7 +583,6 @@ LOOP: |
|
|
address, err := r.peerManager.DialNext(ctx) |
|
|
address, err := r.peerManager.DialNext(ctx) |
|
|
switch { |
|
|
switch { |
|
|
case errors.Is(err, context.Canceled): |
|
|
case errors.Is(err, context.Canceled): |
|
|
r.logger.Debug("stopping dial routine") |
|
|
|
|
|
break LOOP |
|
|
break LOOP |
|
|
case err != nil: |
|
|
case err != nil: |
|
|
r.logger.Error("failed to find next peer to dial", "err", err) |
|
|
r.logger.Error("failed to find next peer to dial", "err", err) |
|
@ -917,16 +912,12 @@ func (r *Router) sendPeer(ctx context.Context, peerID types.NodeID, conn Connect |
|
|
|
|
|
|
|
|
// evictPeers evicts connected peers as requested by the peer manager.
|
|
|
// evictPeers evicts connected peers as requested by the peer manager.
|
|
|
func (r *Router) evictPeers(ctx context.Context) { |
|
|
func (r *Router) evictPeers(ctx context.Context) { |
|
|
r.logger.Debug("starting evict routine") |
|
|
|
|
|
|
|
|
|
|
|
for { |
|
|
for { |
|
|
peerID, err := r.peerManager.EvictNext(ctx) |
|
|
peerID, err := r.peerManager.EvictNext(ctx) |
|
|
|
|
|
|
|
|
switch { |
|
|
switch { |
|
|
case errors.Is(err, context.Canceled): |
|
|
case errors.Is(err, context.Canceled): |
|
|
r.logger.Debug("stopping evict routine") |
|
|
|
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
case err != nil: |
|
|
case err != nil: |
|
|
r.logger.Error("failed to find next peer to evict", "err", err) |
|
|
r.logger.Error("failed to find next peer to evict", "err", err) |
|
|
return |
|
|
return |
|
|