Skip to content

Commit e12c2ad

Browse files
use the resource manager in cicuitv2
1 parent a435803 commit e12c2ad

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

p2p/host/basic/basic_host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ func (h *BasicHost) SetAutoNat(a autonat.AutoNAT) {
10101010
}
10111011
}
10121012

1013-
// Return the host's AutoNAT service, if AutoNAT is enabled.
1013+
// GetAutoNat returns the host's AutoNAT service, if AutoNAT is enabled.
10141014
func (h *BasicHost) GetAutoNat() autonat.AutoNAT {
10151015
h.addrMu.Lock()
10161016
defer h.addrMu.Unlock()

p2p/protocol/circuitv2/client/transport.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"io"
77

8+
"github.com/libp2p/go-libp2p-core/network"
9+
810
"github.com/libp2p/go-libp2p-core/host"
911
"github.com/libp2p/go-libp2p-core/peer"
1012
"github.com/libp2p/go-libp2p-core/transport"
@@ -49,14 +51,25 @@ var _ transport.Transport = (*Client)(nil)
4951
var _ io.Closer = (*Client)(nil)
5052

5153
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+
}
5263
conn, err := c.dial(ctx, a, p)
5364
if err != nil {
65+
if connScope != nil {
66+
connScope.Done()
67+
}
5468
return nil, err
5569
}
5670

5771
conn.tagHop()
58-
59-
return c.upgrader.UpgradeOutbound(ctx, c, conn, p)
72+
return c.upgrader.Upgrade(ctx, c, conn, network.DirOutbound, p, connScope)
6073
}
6174

6275
func (c *Client) CanDial(addr ma.Multiaddr) bool {
@@ -70,7 +83,7 @@ func (c *Client) Listen(addr ma.Multiaddr) (transport.Listener, error) {
7083
return nil, err
7184
}
7285

73-
return c.upgrader.UpgradeListener(c, c.Listener(), nil), nil
86+
return c.upgrader.UpgradeListener(c, c.Listener(), c.host.Network().ResourceManager()), nil
7487
}
7588

7689
func (c *Client) Protocols() []int {

0 commit comments

Comments
 (0)