mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2026-01-09 02:28:14 -05:00
fix(quic): setting shortAgent (#1609)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -43,7 +43,7 @@ proc new(
|
||||
quicstream
|
||||
|
||||
method getWrapped*(self: QuicStream): P2PConnection =
|
||||
nil
|
||||
self
|
||||
|
||||
template mapExceptions(body: untyped) =
|
||||
try:
|
||||
@@ -114,6 +114,9 @@ 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:
|
||||
@@ -121,13 +124,20 @@ proc getStream*(
|
||||
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] {.
|
||||
|
||||
Reference in New Issue
Block a user