@cryptotaxi247 / kubo / commits / d21bb1eed

feat(coreapi): tag all explicit connect requests in the connection manager

This doesn't _stop_ us from cutting these connections but indicates that there's some hidden usefulness to them. fixes #6164 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Apr 3, 2019 at 09:56 UTC d21bb1eed85401412ad0e8749f60de75ee27051a
1 file changed +10 -1
core/coreapi/swarm.go
+10 -1
@@ -27,6 +27,10 @@ type connInfo struct {
27 peer peer.ID
28 }
29
30 +// tag used in the connection manager when explicitly connecting to a peer.
31 +const connectionManagerTag = "user-connect"
32 +const connectionManagerWeight = 100
33 +
34 func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
35 if api.peerHost == nil {
36 return coreiface.ErrOffline
@@ -36,7 +40,12 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
40 swrm.Backoff().Clear(pi.ID)
41 }
42
39 - return api.peerHost.Connect(ctx, pi)
43 + if err := api.peerHost.Connect(ctx, pi); err == nil {
44 + return err
45 + }
46 +
47 + api.peerHost.ConnManager().TagPeer(pi.ID, connectionManagerTag, connectionManagerWeight)
48 + return nil
49 }
50
51 func (api *SwarmAPI) Disconnect(ctx context.Context, addr ma.Multiaddr) error {