From 7bd305471c0ab1a0306e6734915952f236cc88eb Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 4 Feb 2020 15:17:24 +0100 Subject: [PATCH] Make sure the library can compile with json logging in trace mode --- libp2p/muxers/mplex/coder.nim | 4 ++-- libp2p/protocols/identify.nim | 2 +- libp2p/protocols/pubsub/pubsub.nim | 4 ++-- libp2p/protocols/pubsub/pubsubpeer.nim | 2 +- libp2p/protocols/pubsub/rpc/protobuf.nim | 2 +- libp2p/protocols/pubsub/timedcache.nim | 4 ++-- libp2p/protocols/secure/secio.nim | 29 ++++++++++++------------ libp2p/switch.nim | 6 ++--- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/libp2p/muxers/mplex/coder.nim b/libp2p/muxers/mplex/coder.nim index 808b12e8d..7e6c9a4bc 100644 --- a/libp2p/muxers/mplex/coder.nim +++ b/libp2p/muxers/mplex/coder.nim @@ -48,13 +48,13 @@ proc readMsg*(conn: Connection): Future[Option[Msg]] {.async, gcsafe.} = if headerVarint.isNone: return - trace "read header varint", varint = headerVarint + trace "read header varint", varint = $headerVarint let dataLenVarint = await conn.readMplexVarint() var data: seq[byte] if dataLenVarint.isSome and dataLenVarint.get() > 0.uint: data = await conn.read(dataLenVarint.get().int) - trace "read size varint", varint = dataLenVarint + trace "read size varint", varint = $dataLenVarint let header = headerVarint.get() result = some((header shr 3, MessageType(header and 0x7), data)) diff --git a/libp2p/protocols/identify.nim b/libp2p/protocols/identify.nim index 3bed4e0bf..9fae405e1 100644 --- a/libp2p/protocols/identify.nim +++ b/libp2p/protocols/identify.nim @@ -69,7 +69,7 @@ proc decodeMsg*(buf: seq[byte]): IdentifyInfo = result.pubKey = none(PublicKey) var pubKey: PublicKey if pb.getValue(1, pubKey) > 0: - trace "read public key from message", pubKey = pubKey + trace "read public key from message", pubKey = $pubKey result.pubKey = some(pubKey) result.addrs = newSeq[MultiAddress]() diff --git a/libp2p/protocols/pubsub/pubsub.nim b/libp2p/protocols/pubsub/pubsub.nim index e49946876..bcfebf1e1 100644 --- a/libp2p/protocols/pubsub/pubsub.nim +++ b/libp2p/protocols/pubsub/pubsub.nim @@ -70,9 +70,9 @@ method rpcHandler*(p: PubSub, peer: PubSubPeer, rpcMsgs: seq[RPCMsg]) {.async, base.} = ## handle rpc messages - trace "processing RPC message", peer = peer.id, msg = rpcMsgs + trace "processing RPC message", peer = peer.id, msg = $rpcMsgs for m in rpcMsgs: # for all RPC messages - trace "processing messages", msg = rpcMsgs + trace "processing messages", msg = $rpcMsgs if m.subscriptions.len > 0: # if there are any subscriptions for s in m.subscriptions: # subscribe/unsubscribe the peer for each topic p.subscribeTopic(s.topic, s.subscribe, peer.id) diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index d88c88d0a..14851d6c5 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -58,7 +58,7 @@ proc handle*(p: PubSubPeer, conn: Connection) {.async.} = continue let msg = decodeRpcMsg(data) - trace "decoded msg from peer", peer = p.id, msg = msg + trace "decoded msg from peer", peer = p.id, msg = $msg await p.handler(p, @[msg]) p.recvdRpcCache.put($hexData.hash) except CatchableError as exc: diff --git a/libp2p/protocols/pubsub/rpc/protobuf.nim b/libp2p/protocols/pubsub/rpc/protobuf.nim index ed414f64d..a114c9c17 100644 --- a/libp2p/protocols/pubsub/rpc/protobuf.nim +++ b/libp2p/protocols/pubsub/rpc/protobuf.nim @@ -213,7 +213,7 @@ proc decodeMessages*(pb: var ProtoBuffer): seq[Message] {.gcsafe.} = proc encodeRpcMsg*(msg: RPCMsg): ProtoBuffer {.gcsafe.} = result = initProtoBuffer() - trace "encoding msg: ", msg = msg + trace "encoding msg: ", msg = $msg if msg.subscriptions.len > 0: var subs = initProtoBuffer() diff --git a/libp2p/protocols/pubsub/timedcache.nim b/libp2p/protocols/pubsub/timedcache.nim index c7f78c193..51ec6a6d9 100644 --- a/libp2p/protocols/pubsub/timedcache.nim +++ b/libp2p/protocols/pubsub/timedcache.nim @@ -36,7 +36,7 @@ proc put*[V](t: TimedCache[V], key: string, val: V = "", timeout: Duration, - handler: ExpireHandler[V] = nil) = + handler: ExpireHandler[V] = nil) = trace "adding entry to timed cache", key = key t.cache[key] = TimedEntry[V](val: val, handler: handler) @@ -57,7 +57,7 @@ proc put*[V](t: TimedCache[V], handler: ExpireHandler[V] = nil) = t.put(key, val, t.timeout, handler) -proc contains*[V](t: TimedCache[V], key: string): bool = +proc contains*[V](t: TimedCache[V], key: string): bool = t.cache.contains(key) proc del*[V](t: TimedCache[V], key: string) = diff --git a/libp2p/protocols/secure/secio.nim b/libp2p/protocols/secure/secio.nim index fd6307103..ac3970ed4 100644 --- a/libp2p/protocols/secure/secio.nim +++ b/libp2p/protocols/secure/secio.nim @@ -268,19 +268,19 @@ proc transactMessage(conn: Connection, if length <= SecioMaxMessageSize: buf.setLen(length) await conn.readExactly(addr buf[0], length) - trace "Received message body", conn = conn, + trace "Received message body", conn = $conn, length = length, buff = buf result = buf else: - trace "Received size of message exceed limits", conn = conn, + trace "Received size of message exceed limits", conn = $conn, length = length except AsyncStreamIncompleteError: - trace "Connection dropped while reading", conn = conn + trace "Connection dropped while reading", conn = $conn except AsyncStreamReadError: - trace "Error reading from connection", conn = conn + trace "Error reading from connection", conn = $conn except AsyncStreamWriteError: - trace "Could not write to connection", conn = conn + trace "Could not write to connection", conn = $conn proc handshake(s: Secio, conn: Connection): Future[SecureConnection] {.async.} = var @@ -310,7 +310,8 @@ proc handshake(s: Secio, conn: Connection): Future[SecureConnection] {.async.} = localPeerId = PeerID.init(s.localPublicKey) - trace "Local proposal", schemes = SecioExchanges, ciphers = SecioCiphers, + trace "Local proposal", schemes = SecioExchanges, + ciphers = SecioCiphers, hashes = SecioHashes, pubkey = toHex(localBytesPubkey), peer = localPeerId @@ -318,12 +319,12 @@ proc handshake(s: Secio, conn: Connection): Future[SecureConnection] {.async.} = var answer = await transactMessage(conn, request) if len(answer) == 0: - trace "Proposal exchange failed", conn = conn + trace "Proposal exchange failed", conn = $conn raise newException(SecioError, "Proposal exchange failed") if not decodeProposal(answer, remoteNonce, remoteBytesPubkey, remoteExchanges, remoteCiphers, remoteHashes): - trace "Remote proposal decoding failed", conn = conn + trace "Remote proposal decoding failed", conn = $conn raise newException(SecioError, "Remote proposal decoding failed") if not remotePubkey.init(remoteBytesPubkey): @@ -359,11 +360,11 @@ proc handshake(s: Secio, conn: Connection): Future[SecureConnection] {.async.} = var localExchange = createExchange(epubkey, signature.getBytes()) var remoteExchange = await transactMessage(conn, localExchange) if len(remoteExchange) == 0: - trace "Corpus exchange failed", conn = conn + trace "Corpus exchange failed", conn = $conn raise newException(SecioError, "Corpus exchange failed") if not decodeExchange(remoteExchange, remoteEBytesPubkey, remoteEBytesSig): - trace "Remote exchange decoding failed", conn = conn + trace "Remote exchange decoding failed", conn = $conn raise newException(SecioError, "Remote exchange decoding failed") if not remoteESignature.init(remoteEBytesSig): @@ -372,10 +373,10 @@ proc handshake(s: Secio, conn: Connection): Future[SecureConnection] {.async.} = var remoteCorpus = answer & request[4..^1] & remoteEBytesPubkey if not remoteESignature.verify(remoteCorpus, remotePubkey): - trace "Signature verification failed", scheme = remotePubkey.scheme, - signature = remoteESignature, - pubkey = remotePubkey, - corpus = remoteCorpus + trace "Signature verification failed", scheme = $remotePubkey.scheme, + signature = $remoteESignature, + pubkey = $remotePubkey, + corpus = $remoteCorpus raise newException(SecioError, "Signature verification failed") trace "Signature verified", scheme = remotePubkey.scheme diff --git a/libp2p/switch.nim b/libp2p/switch.nim index b112e1d38..f8837b740 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -124,7 +124,7 @@ proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} = await stream.close() # close identify stream - trace "connection's peerInfo", peerInfo = conn.peerInfo + trace "connection's peerInfo", peerInfo = $conn.peerInfo # store it in muxed connections if we have a peer for it if not isNil(conn.peerInfo): @@ -159,7 +159,7 @@ proc getMuxedStream(s: Switch, peerInfo: PeerInfo): Future[Connection] {.async, result = conn proc upgradeOutgoing(s: Switch, conn: Connection): Future[Connection] {.async, gcsafe.} = - trace "handling connection", conn = conn + trace "handling connection", conn = $conn result = conn # don't mux/secure twise @@ -350,7 +350,7 @@ proc newSwitch*(peerInfo: PeerInfo, let s = result # can't capture result result.streamHandler = proc(stream: Connection) {.async, gcsafe.} = - trace "handling connection for", peerInfo = stream.peerInfo + trace "handling connection for", peerInfo = $stream.peerInfo await s.ms.handle(stream) # handle incoming connection result.mount(identity)