logging fixes

This commit is contained in:
Jacek Sieka 2020-06-21 11:14:19 +02:00
parent 9429f2f5eb
commit b99fd88deb
No known key found for this signature in database
GPG Key ID: A1B09461ABB656B8
4 changed files with 13 additions and 13 deletions

View File

@ -47,7 +47,7 @@ proc newMuxerProvider*(creator: MuxerConstructor, codec: string): MuxerProvider
method init(c: MuxerProvider) = method init(c: MuxerProvider) =
proc handler(conn: Connection, proto: string) {.async, gcsafe, closure.} = proc handler(conn: Connection, proto: string) {.async, gcsafe, closure.} =
trace "starting muxer handler", proto=proto, peer=conn trace "starting muxer handler", proto=proto, peer = $conn
try: try:
let let
muxer = c.newMuxer(conn) muxer = c.newMuxer(conn)
@ -64,9 +64,9 @@ method init(c: MuxerProvider) =
checkFutures(await allFinished(futs)) checkFutures(await allFinished(futs))
except CatchableError as exc: except CatchableError as exc:
trace "exception in muxer handler", exc = exc.msg, peer=conn, proto=proto trace "exception in muxer handler", exc = exc.msg, peer = $conn, proto=proto
c.handler = handler c.handler = handler
proc `$`*(m: Muxer): string = proc `$`*(m: Muxer): string =
$m.connection.peerInfo $m.connection

View File

@ -129,7 +129,7 @@ method init*(p: Identify) =
proc identify*(p: Identify, proc identify*(p: Identify,
conn: Connection, conn: Connection,
remotePeerInfo: PeerInfo): Future[IdentifyInfo] {.async, gcsafe.} = remotePeerInfo: PeerInfo): Future[IdentifyInfo] {.async, gcsafe.} =
trace "initiating identify", peer=conn trace "initiating identify", peer = $conn
var message = await conn.readLp(64*1024) var message = await conn.readLp(64*1024)
if len(message) == 0: if len(message) == 0:
trace "identify: Invalid or empty message received!" trace "identify: Invalid or empty message received!"

View File

@ -413,7 +413,7 @@ method write*(sconn: NoiseConnection, message: seq[byte]): Future[void] {.async.
await sconn.stream.write(outbuf) await sconn.stream.write(outbuf)
method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureConn] {.async.} = method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureConn] {.async.} =
debug "Starting Noise handshake", initiator, peer=conn debug "Starting Noise handshake", initiator, peer = $conn
# https://github.com/libp2p/specs/tree/master/noise#libp2p-data-in-handshake-messages # https://github.com/libp2p/specs/tree/master/noise#libp2p-data-in-handshake-messages
let let
@ -454,7 +454,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon
if not remoteSig.verify(verifyPayload, remotePubKey): if not remoteSig.verify(verifyPayload, remotePubKey):
raise newException(NoiseHandshakeError, "Noise handshake signature verify failed.") raise newException(NoiseHandshakeError, "Noise handshake signature verify failed.")
else: else:
debug "Remote signature verified", peer=conn debug "Remote signature verified", peer = $conn
if initiator and not isNil(conn.peerInfo): if initiator and not isNil(conn.peerInfo):
let pid = PeerID.init(remotePubKey) let pid = PeerID.init(remotePubKey)
@ -464,7 +464,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon
var var
failedKey: PublicKey failedKey: PublicKey
discard extractPublicKey(conn.peerInfo.peerId, failedKey) discard extractPublicKey(conn.peerInfo.peerId, failedKey)
debug "Noise handshake, peer infos don't match!", initiator, dealt_peer=conn.peerInfo.peerId, dealt_key=failedKey, received_peer=pid, received_key=remotePubKey debug "Noise handshake, peer infos don't match!", initiator, dealt_peer = $conn.peerInfo.id, dealt_key = $failedKey, received_peer = $pid, received_key = $remotePubKey
raise newException(NoiseHandshakeError, "Noise handshake, peer infos don't match! " & $pid & " != " & $conn.peerInfo.peerId) raise newException(NoiseHandshakeError, "Noise handshake, peer infos don't match! " & $pid & " != " & $conn.peerInfo.peerId)
var secure = new NoiseConnection var secure = new NoiseConnection
@ -481,7 +481,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon
secure.readCs = handshakeRes.cs1 secure.readCs = handshakeRes.cs1
secure.writeCs = handshakeRes.cs2 secure.writeCs = handshakeRes.cs2
debug "Noise handshake completed!", initiator, peer=secure.peerInfo debug "Noise handshake completed!", initiator, peer = $secure.peerInfo
return secure return secure

View File

@ -112,7 +112,7 @@ proc identify(s: Switch, conn: Connection): Future[PeerInfo] {.async, gcsafe.} =
proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} = proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} =
## mux incoming connection ## mux incoming connection
trace "muxing connection", peer=conn trace "muxing connection", peer = $conn
let muxers = toSeq(s.muxers.keys) let muxers = toSeq(s.muxers.keys)
if muxers.len == 0: if muxers.len == 0:
warn "no muxers registered, skipping upgrade flow" warn "no muxers registered, skipping upgrade flow"
@ -120,13 +120,13 @@ proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} =
let muxerName = await s.ms.select(conn, muxers) let muxerName = await s.ms.select(conn, muxers)
if muxerName.len == 0 or muxerName == "na": if muxerName.len == 0 or muxerName == "na":
debug "no muxer available, early exit", peer=conn debug "no muxer available, early exit", peer = $conn
return return
# create new muxer for connection # create new muxer for connection
let muxer = s.muxers[muxerName].newMuxer(conn) let muxer = s.muxers[muxerName].newMuxer(conn)
trace "found a muxer", name=muxerName, peer=conn trace "found a muxer", name=muxerName, peer = $conn
# install stream handler # install stream handler
muxer.streamHandler = s.streamHandler muxer.streamHandler = s.streamHandler