Skip to content

Commit

Permalink
Merge pull request #6171 from ipfs/fix/6164
Browse files Browse the repository at this point in the history
feat(coreapi): tag all explicit connect requests in the connection manager
  • Loading branch information
Stebalien authored Apr 3, 2019
2 parents c126cd3 + d21bb1e commit 81b1cfe
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/coreapi/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type connInfo struct {
peer peer.ID
}

// tag used in the connection manager when explicitly connecting to a peer.
const connectionManagerTag = "user-connect"
const connectionManagerWeight = 100

func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
if api.peerHost == nil {
return coreiface.ErrOffline
Expand All @@ -36,7 +40,12 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
swrm.Backoff().Clear(pi.ID)
}

return api.peerHost.Connect(ctx, pi)
if err := api.peerHost.Connect(ctx, pi); err == nil {
return err
}

api.peerHost.ConnManager().TagPeer(pi.ID, connectionManagerTag, connectionManagerWeight)
return nil
}

func (api *SwarmAPI) Disconnect(ctx context.Context, addr ma.Multiaddr) error {
Expand Down

0 comments on commit 81b1cfe

Please sign in to comment.