Browse Source

circuitv2: correctly set the transport in the ConnectionState (#1972)

run-go-generate-on-ci
Marten Seemann 2 years ago
committed by GitHub
parent
commit
4ad3734091
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      p2p/protocol/circuitv2/client/conn.go
  2. 6
      p2p/protocol/circuitv2/client/transport.go

24
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,
}
}

6
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 {

Loading…
Cancel
Save