Unverified 提交 81b1cfea 作者: Steven Allen 提交者: GitHub

Merge pull request #6171 from ipfs/fix/6164

feat(coreapi): tag all explicit connect requests in the connection manager
...@@ -27,6 +27,10 @@ type connInfo struct { ...@@ -27,6 +27,10 @@ type connInfo struct {
peer peer.ID 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 { func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
if api.peerHost == nil { if api.peerHost == nil {
return coreiface.ErrOffline return coreiface.ErrOffline
...@@ -36,7 +40,12 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error { ...@@ -36,7 +40,12 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
swrm.Backoff().Clear(pi.ID) 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 { func (api *SwarmAPI) Disconnect(ctx context.Context, addr ma.Multiaddr) error {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论