diff --git a/p2p/protocol/circuitv2/client/conn.go b/p2p/protocol/circuitv2/client/conn.go index 23bde93d5e..ed01be3b33 100644 --- a/p2p/protocol/circuitv2/client/conn.go +++ b/p2p/protocol/circuitv2/client/conn.go @@ -7,6 +7,7 @@ import ( "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" + tpt "github.com/libp2p/go-libp2p/core/transport" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" @@ -79,7 +80,7 @@ func (c *Conn) RemoteMultiaddr() ma.Multiaddr { // TODO: We should be able to do this directly without converting to/from a string. relayAddr, err := ma.NewComponent( ma.ProtocolWithCode(ma.P_P2P).Name, - c.stream.Conn().RemotePeer().Pretty(), + c.stream.Conn().RemotePeer().String(), ) if err != nil { panic(err) @@ -102,8 +103,8 @@ func (c *Conn) LocalAddr() net.Addr { func (c *Conn) RemoteAddr() net.Addr { return &NetAddr{ - Relay: c.stream.Conn().RemotePeer().Pretty(), - Remote: c.remote.ID.Pretty(), + Relay: c.stream.Conn().RemotePeer().String(), + Remote: c.remote.ID.String(), } } @@ -143,3 +144,20 @@ func (c *Conn) untagHop() { delete(c.client.hopCount, p) } } + +type capableConnWithStat interface { + tpt.CapableConn + network.ConnStat +} + +type capableConn struct { + capableConnWithStat +} + +var transportName = ma.ProtocolWithCode(ma.P_CIRCUIT).Name + +func (c capableConn) ConnState() network.ConnectionState { + return network.ConnectionState{ + Transport: transportName, + } +} diff --git a/p2p/protocol/circuitv2/client/transport.go b/p2p/protocol/circuitv2/client/transport.go index 97fc1ce1a2..5c94fa7ebd 100644 --- a/p2p/protocol/circuitv2/client/transport.go +++ b/p2p/protocol/circuitv2/client/transport.go @@ -63,7 +63,11 @@ func (c *Client) Dial(ctx context.Context, a ma.Multiaddr, p peer.ID) (transport return nil, err } conn.tagHop() - return c.upgrader.Upgrade(ctx, c, conn, network.DirOutbound, p, connScope) + cc, err := c.upgrader.Upgrade(ctx, c, conn, network.DirOutbound, p, connScope) + if err != nil { + return nil, err + } + return capableConn{cc.(capableConnWithStat)}, nil } func (c *Client) CanDial(addr ma.Multiaddr) bool {