5
5
"fmt"
6
6
"io"
7
7
8
+ "github.com/libp2p/go-libp2p-core/network"
9
+
8
10
"github.com/libp2p/go-libp2p-core/host"
9
11
"github.com/libp2p/go-libp2p-core/peer"
10
12
"github.com/libp2p/go-libp2p-core/transport"
@@ -49,14 +51,25 @@ var _ transport.Transport = (*Client)(nil)
49
51
var _ io.Closer = (* Client )(nil )
50
52
51
53
func (c * Client ) Dial (ctx context.Context , a ma.Multiaddr , p peer.ID ) (transport.CapableConn , error ) {
54
+ var connScope network.ConnectionManagementScope
55
+ if rcmgr := c .host .Network ().ResourceManager (); rcmgr != nil {
56
+ var err error
57
+ // TODO: what's the best way to tell if we'll be using a fd here?
58
+ connScope , err = rcmgr .OpenConnection (network .DirOutbound , true )
59
+ if err != nil {
60
+ return nil , err
61
+ }
62
+ }
52
63
conn , err := c .dial (ctx , a , p )
53
64
if err != nil {
65
+ if connScope != nil {
66
+ connScope .Done ()
67
+ }
54
68
return nil , err
55
69
}
56
70
57
71
conn .tagHop ()
58
-
59
- return c .upgrader .UpgradeOutbound (ctx , c , conn , p )
72
+ return c .upgrader .Upgrade (ctx , c , conn , network .DirOutbound , p , connScope )
60
73
}
61
74
62
75
func (c * Client ) CanDial (addr ma.Multiaddr ) bool {
@@ -70,7 +83,7 @@ func (c *Client) Listen(addr ma.Multiaddr) (transport.Listener, error) {
70
83
return nil , err
71
84
}
72
85
73
- return c .upgrader .UpgradeListener (c , c .Listener (), nil ), nil
86
+ return c .upgrader .UpgradeListener (c , c .Listener (), c . host . Network (). ResourceManager () ), nil
74
87
}
75
88
76
89
func (c * Client ) Protocols () []int {
0 commit comments