Skip to content

Commit 9c80669

Browse files
committed
tcpreuse: fix rcmgr accounting when tcp metrics are enabled
Yet another interface embedding bug. Running all transport integration tests is a bit overkill, but the rcmgr transport integration test is the only one that tests for this behavior.
1 parent 613f5a7 commit 9c80669

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

p2p/test/transport/transport_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
3232
"github.com/libp2p/go-libp2p/p2p/security/noise"
3333
tls "github.com/libp2p/go-libp2p/p2p/security/tls"
34+
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
3435
libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"
3536
"go.uber.org/mock/gomock"
3637

@@ -116,6 +117,41 @@ var transportsToTest = []TransportTestCase{
116117
return h
117118
},
118119
},
120+
{
121+
Name: "TCP-Shared-WithMetrics / TLS / Yamux",
122+
HostGenerator: func(t *testing.T, opts TransportTestCaseOpts) host.Host {
123+
libp2pOpts := transformOpts(opts)
124+
libp2pOpts = append(libp2pOpts, libp2p.ShareTCPListener())
125+
libp2pOpts = append(libp2pOpts, libp2p.Security(tls.ID, tls.New))
126+
libp2pOpts = append(libp2pOpts, libp2p.Muxer(yamux.ID, yamux.DefaultTransport))
127+
libp2pOpts = append(libp2pOpts, libp2p.Transport(tcp.NewTCPTransport, tcp.WithMetrics()))
128+
if opts.NoListen {
129+
libp2pOpts = append(libp2pOpts, libp2p.NoListenAddrs)
130+
} else {
131+
libp2pOpts = append(libp2pOpts, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"))
132+
}
133+
h, err := libp2p.New(libp2pOpts...)
134+
require.NoError(t, err)
135+
return h
136+
},
137+
},
138+
{
139+
Name: "TCP-WithMetrics / TLS / Yamux",
140+
HostGenerator: func(t *testing.T, opts TransportTestCaseOpts) host.Host {
141+
libp2pOpts := transformOpts(opts)
142+
libp2pOpts = append(libp2pOpts, libp2p.Security(tls.ID, tls.New))
143+
libp2pOpts = append(libp2pOpts, libp2p.Muxer(yamux.ID, yamux.DefaultTransport))
144+
libp2pOpts = append(libp2pOpts, libp2p.Transport(tcp.NewTCPTransport, tcp.WithMetrics()))
145+
if opts.NoListen {
146+
libp2pOpts = append(libp2pOpts, libp2p.NoListenAddrs)
147+
} else {
148+
libp2pOpts = append(libp2pOpts, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"))
149+
}
150+
h, err := libp2p.New(libp2pOpts...)
151+
require.NoError(t, err)
152+
return h
153+
},
154+
},
119155
{
120156
Name: "WebSocket-Shared",
121157
HostGenerator: func(t *testing.T, opts TransportTestCaseOpts) host.Host {

p2p/transport/tcp/metrics.go

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sync"
88
"time"
99

10+
"github.com/libp2p/go-libp2p/core/network"
1011
"github.com/marten-seemann/tcp"
1112
"github.com/mikioh/tcpinfo"
1213
manet "github.com/multiformats/go-multiaddr/net"
@@ -252,6 +253,16 @@ func (c *tracingConn) Close() error {
252253
return c.closeErr
253254
}
254255

256+
func (c *tracingConn) Scope() network.ConnManagementScope {
257+
if cs, ok := c.Conn.(interface {
258+
Scope() network.ConnManagementScope
259+
}); ok {
260+
return cs.Scope()
261+
}
262+
// upgrader is expected to handle this
263+
return nil
264+
}
265+
255266
func (c *tracingConn) getTCPInfo() (*tcpinfo.Info, error) {
256267
var o tcpinfo.Info
257268
var b [256]byte

0 commit comments

Comments
 (0)