Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Expose underlying transport connection stat where available #71

Merged
merged 2 commits into from Feb 17, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions conn.go
Expand Up @@ -13,6 +13,7 @@ type transportConn struct {
network.ConnMultiaddrs
network.ConnSecurity
transport transport.Transport
stat network.Stat
}

func (t *transportConn) Transport() transport.Transport {
Expand All @@ -33,3 +34,7 @@ func (t *transportConn) String() string {
t.RemotePeer(),
)
}

func (t *transportConn) Stat() network.Stat {
return t.stat
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -5,7 +5,7 @@ go 1.12
require (
github.com/ipfs/go-log v1.0.4
github.com/jbenet/go-temp-err-catcher v0.1.0
github.com/libp2p/go-libp2p-core v0.8.1
github.com/libp2p/go-libp2p-core v0.8.2
github.com/libp2p/go-libp2p-mplex v0.4.1
github.com/libp2p/go-libp2p-pnet v0.2.0
github.com/multiformats/go-multiaddr v0.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -76,8 +76,8 @@ github.com/libp2p/go-libp2p-core v0.3.0/go.mod h1:ACp3DmS3/N64c2jDzcV429ukDpicbL
github.com/libp2p/go-libp2p-core v0.5.0/go.mod h1:49XGI+kc38oGVwqSBhDEwytaAxgZasHhFfQKibzTls0=
github.com/libp2p/go-libp2p-core v0.8.0 h1:5K3mT+64qDTKbV3yTdbMCzJ7O6wbNsavAEb8iqBvBcI=
github.com/libp2p/go-libp2p-core v0.8.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8=
github.com/libp2p/go-libp2p-core v0.8.1 h1:+hvGysqSZ1AAWFHU8vNXX05vMSwI/6BSukuyn4DEBPE=
github.com/libp2p/go-libp2p-core v0.8.1/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8=
github.com/libp2p/go-libp2p-core v0.8.2 h1:/eaSZACWftJZYm07S0nRxdI84v1hSmgnCXrGOvJdpNQ=
github.com/libp2p/go-libp2p-core v0.8.2/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8=
github.com/libp2p/go-libp2p-mplex v0.4.1 h1:/pyhkP1nLwjG3OM+VuaNJkQT/Pqq73WzB3aDN3Fx1sc=
github.com/libp2p/go-libp2p-mplex v0.4.1/go.mod h1:cmy+3GfqfM1PceHTLL7zQzAAYaryDu6iPSC+CIb094g=
github.com/libp2p/go-libp2p-pnet v0.2.0 h1:J6htxttBipJujEjz1y0a5+eYoiPcFHhSYHH6na5f0/k=
Expand Down
6 changes: 6 additions & 0 deletions upgrader.go
Expand Up @@ -66,6 +66,11 @@ func (u *Upgrader) UpgradeInbound(ctx context.Context, t transport.Transport, ma
}

func (u *Upgrader) upgrade(ctx context.Context, t transport.Transport, maconn manet.Conn, p peer.ID, dir network.Direction) (transport.CapableConn, error) {
var stat network.Stat
if cs, ok := maconn.(network.ConnStat); ok {
stat = cs.Stat()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could just call this on-demand. Not critical but the results from Stat may not always be constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice indeed, but right now it wouldn't buy us much the way the swarm treats the stat object. That could change too of course if we want to expose dynamic stat information.

}

var conn net.Conn = maconn
if u.PSK != nil {
pconn, err := pnet.NewProtectedConn(u.PSK, conn)
Expand Down Expand Up @@ -107,6 +112,7 @@ func (u *Upgrader) upgrade(ctx context.Context, t transport.Transport, maconn ma
ConnMultiaddrs: maconn,
ConnSecurity: sconn,
transport: t,
stat: stat,
}
return tc, nil
}
Expand Down