Skip to content

Commit

Permalink
circuitv2: correctly set the transport in the ConnectionState
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jan 7, 2023
1 parent 8231591 commit 52034ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 21 additions & 3 deletions p2p/protocol/circuitv2/client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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(),
}
}

Expand Down Expand Up @@ -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,
}
}
6 changes: 5 additions & 1 deletion p2p/protocol/circuitv2/client/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 52034ff

Please sign in to comment.