Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circuitv2: correctly set the transport in the ConnectionState #1972

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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