From b99fd88deb18c6e4c2b06b1faa3c5d5729be52a0 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Sun, 21 Jun 2020 11:14:19 +0200 Subject: [PATCH] logging fixes --- libp2p/muxers/muxer.nim | 6 +++--- libp2p/protocols/identify.nim | 2 +- libp2p/protocols/secure/noise.nim | 10 +++++----- libp2p/switch.nim | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libp2p/muxers/muxer.nim b/libp2p/muxers/muxer.nim index efe31a80b..999188b60 100644 --- a/libp2p/muxers/muxer.nim +++ b/libp2p/muxers/muxer.nim @@ -47,7 +47,7 @@ proc newMuxerProvider*(creator: MuxerConstructor, codec: string): MuxerProvider method init(c: MuxerProvider) = 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: let muxer = c.newMuxer(conn) @@ -64,9 +64,9 @@ method init(c: MuxerProvider) = checkFutures(await allFinished(futs)) 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 proc `$`*(m: Muxer): string = - $m.connection.peerInfo + $m.connection diff --git a/libp2p/protocols/identify.nim b/libp2p/protocols/identify.nim index da46d6ce4..0f410ca7d 100644 --- a/libp2p/protocols/identify.nim +++ b/libp2p/protocols/identify.nim @@ -129,7 +129,7 @@ method init*(p: Identify) = proc identify*(p: Identify, conn: Connection, remotePeerInfo: PeerInfo): Future[IdentifyInfo] {.async, gcsafe.} = - trace "initiating identify", peer=conn + trace "initiating identify", peer = $conn var message = await conn.readLp(64*1024) if len(message) == 0: trace "identify: Invalid or empty message received!" diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index 0e8d204b4..59d88af27 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -413,7 +413,7 @@ method write*(sconn: NoiseConnection, message: seq[byte]): Future[void] {.async. await sconn.stream.write(outbuf) 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 let @@ -439,7 +439,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon remotePubKeyBytes: seq[byte] remoteSig: Signature remoteSigBytes: seq[byte] - + if remoteProof.getLengthValue(1, remotePubKeyBytes) <= 0: raise newException(NoiseHandshakeError, "Failed to deserialize remote public key bytes. (initiator: " & $initiator & ", peer: " & $conn.peerInfo.peerId & ")") if remoteProof.getLengthValue(2, remoteSigBytes) <= 0: @@ -454,7 +454,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon if not remoteSig.verify(verifyPayload, remotePubKey): raise newException(NoiseHandshakeError, "Noise handshake signature verify failed.") else: - debug "Remote signature verified", peer=conn + debug "Remote signature verified", peer = $conn if initiator and not isNil(conn.peerInfo): let pid = PeerID.init(remotePubKey) @@ -464,7 +464,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon var failedKey: PublicKey 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) var secure = new NoiseConnection @@ -481,7 +481,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon secure.readCs = handshakeRes.cs1 secure.writeCs = handshakeRes.cs2 - debug "Noise handshake completed!", initiator, peer=secure.peerInfo + debug "Noise handshake completed!", initiator, peer = $secure.peerInfo return secure diff --git a/libp2p/switch.nim b/libp2p/switch.nim index becd99fc3..56045c03e 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -70,7 +70,7 @@ proc secure(s: Switch, conn: Connection): Future[Connection] {.async, gcsafe.} = let secureProtocol = s.secureManagers.filterIt(it.codec == manager) # ms.select should deal with the correctness of this # let's avoid duplicating checks but detect if it fails to do it properly - doAssert(secureProtocol.len > 0) + doAssert(secureProtocol.len > 0) result = await secureProtocol[0].secure(conn, true) proc identify(s: Switch, conn: Connection): Future[PeerInfo] {.async, gcsafe.} = @@ -112,7 +112,7 @@ proc identify(s: Switch, conn: Connection): Future[PeerInfo] {.async, gcsafe.} = proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} = ## mux incoming connection - trace "muxing connection", peer=conn + trace "muxing connection", peer = $conn let muxers = toSeq(s.muxers.keys) if muxers.len == 0: 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) if muxerName.len == 0 or muxerName == "na": - debug "no muxer available, early exit", peer=conn + debug "no muxer available, early exit", peer = $conn return # create new muxer for connection 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 muxer.streamHandler = s.streamHandler