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
4 changes: 4 additions & 0 deletions libp2p/muxers/muxer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ method newStream*(
.} =
raiseAssert("[Muxer.newStream] abstract method not implemented!")

when defined(libp2p_agents_metrics):
method setShortAgent*(m: Muxer, shortAgent: string) {.base, gcsafe.} =
m.connection.shortAgent = shortAgent

method close*(m: Muxer) {.base, async: (raises: []).} =
if m.connection != nil:
await m.connection.close()
Expand Down
2 changes: 1 addition & 1 deletion libp2p/peerstore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ proc identify*(
info.agentVersion.get("").split("/")[0].safeToLowerAscii().get("")
if KnownLibP2PAgentsSeq.contains(shortAgent):
knownAgent = shortAgent
muxer.connection.setShortAgent(knownAgent)
muxer.setShortAgent(knownAgent)

peerStore.updatePeerInfo(info, stream.observedAddr)
finally:
Expand Down
5 changes: 4 additions & 1 deletion libp2p/stream/connection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ when defined(libp2p_agents_metrics):
var conn = s
while conn != nil:
conn.shortAgent = shortAgent
conn = conn.getWrapped()
let wrapped = conn.getWrapped()
if wrapped == conn:
break
conn = wrapped

proc new*(
C: type Connection,
Expand Down
14 changes: 12 additions & 2 deletions libp2p/transports/quictransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ proc new(
quicstream

method getWrapped*(self: QuicStream): P2PConnection =
nil
self

template mapExceptions(body: untyped) =
try:
Expand Down Expand Up @@ -114,20 +114,30 @@ proc getStream*(
await stream.write(@[]) # QUIC streams do not exist until data is sent

let qs = QuicStream.new(stream, session.observedAddr, session.peerId)
when defined(libp2p_agents_metrics):
qs.shortAgent = session.shortAgent

session.streams.add(qs)
return qs
except CatchableError as exc:
# TODO: incomingStream is using {.async.} with no raises
raise (ref QuicTransportError)(msg: "error in getStream: " & exc.msg, parent: exc)

method getWrapped*(self: QuicSession): P2PConnection =
nil
self

# Muxer
type QuicMuxer = ref object of Muxer
quicSession: QuicSession
handleFut: Future[void]

when defined(libp2p_agents_metrics):
method setShortAgent*(m: QuicMuxer, shortAgent: string) =
m.quicSession.shortAgent = shortAgent
for s in m.quicSession.streams:
s.shortAgent = shortAgent
m.connection.shortAgent = shortAgent

method newStream*(
m: QuicMuxer, name: string = "", lazy: bool = false
): Future[P2PConnection] {.
Expand Down
Loading