Skip to content
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
11 changes: 1 addition & 10 deletions network/wsNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -1842,16 +1842,7 @@ func (wn *WebsocketNetwork) getPeerConnectionTelemetryDetails(now time.Time, pee
AVCount: atomic.LoadUint64(&peer.avMessageCount),
PPCount: atomic.LoadUint64(&peer.ppMessageCount),
}
// unwrap websocket.Conn, requestTrackedConnection, rejectingLimitListenerConn
var uconn net.Conn = peer.conn.UnderlyingConn()
for i := 0; i < 10; i++ {
wconn, ok := uconn.(wrappedConn)
if !ok {
break
}
uconn = wconn.UnderlyingConn()
}
if tcpInfo, err := util.GetConnTCPInfo(uconn); err == nil && tcpInfo != nil {
if tcpInfo, err := peer.GetUnderlyingConnTCPInfo(); err == nil && tcpInfo != nil {
connDetail.TCP = *tcpInfo
}
if peer.outgoing {
Expand Down
23 changes: 23 additions & 0 deletions network/wsPeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/util"
"github.com/algorand/go-algorand/util/metrics"
)

Expand Down Expand Up @@ -299,6 +300,12 @@ type UnicastPeer interface {
Respond(ctx context.Context, reqMsg IncomingMessage, topics Topics) (e error)
}

// TCPInfoUnicastPeer exposes information about the underlying connection if available on the platform
type TCPInfoUnicastPeer interface {
UnicastPeer
GetUnderlyingConnTCPInfo() (*util.TCPInfo, error)
}

// Create a wsPeerCore object
func makePeerCore(net *WebsocketNetwork, rootURL string, roundTripper http.RoundTripper, originAddress string) wsPeerCore {
return wsPeerCore{
Expand Down Expand Up @@ -350,6 +357,22 @@ func (wp *wsPeer) Unicast(ctx context.Context, msg []byte, tag protocol.Tag) err
return err
}

// GetUnderlyingConnTCPInfo unwraps the connection and returns statistics about it on supported underlying implementations
//
// (Implements TCPInfoUnicastPeer)
func (wp *wsPeer) GetUnderlyingConnTCPInfo() (*util.TCPInfo, error) {
// unwrap websocket.Conn, requestTrackedConnection, rejectingLimitListenerConn
var uconn net.Conn = wp.conn.UnderlyingConn()
for i := 0; i < 10; i++ {
wconn, ok := uconn.(wrappedConn)
if !ok {
break
}
uconn = wconn.UnderlyingConn()
}
return util.GetConnTCPInfo(uconn)
}

// Respond sends the response of a request message
func (wp *wsPeer) Respond(ctx context.Context, reqMsg IncomingMessage, responseTopics Topics) (e error) {

Expand Down