From 1df16bdbce2d1c982cec14793d8f6688bb3da5e0 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 6 Nov 2019 12:25:33 -0600 Subject: [PATCH] set log level to trace - not enabled by default --- libp2p/muxers/mplex/lpchannel.nim | 2 +- libp2p/protocols/pubsub/floodsub.nim | 2 +- libp2p/protocols/secure/secio.nim | 30 ++++++++++++++-------------- libp2p/switch.nim | 2 +- libp2p/transports/tcptransport.nim | 2 +- libp2p/transports/transport.nim | 2 +- tests/test.nim | 4 ++-- tests/testmplex.nim | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libp2p/muxers/mplex/lpchannel.nim b/libp2p/muxers/mplex/lpchannel.nim index 27cf6e2..0eb665b 100644 --- a/libp2p/muxers/mplex/lpchannel.nim +++ b/libp2p/muxers/mplex/lpchannel.nim @@ -55,7 +55,7 @@ proc newChannel*(id: uint, proc writeHandler(data: seq[byte]): Future[void] {.async, gcsafe.} = # writes should happen in sequence await chan.asyncLock.acquire() - info "writeHandler: sending data ", data = data.toHex(), id = chan.id + trace "writeHandler: sending data ", data = data.toHex(), id = chan.id await conn.writeMsg(chan.id, chan.msgCode, data) # write header chan.asyncLock.release() diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim index e0118db..979ebb6 100644 --- a/libp2p/protocols/pubsub/floodsub.nim +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -105,7 +105,7 @@ proc handleConn(f: FloodSub, ## if conn.peerInfo.peerId.isNone: - debug "no valid PeerId for peer" + trace "no valid PeerId for peer" return # create new pubsub peer diff --git a/libp2p/protocols/secure/secio.nim b/libp2p/protocols/secure/secio.nim index b92a3fc..c473ba1 100644 --- a/libp2p/protocols/secure/secio.nim +++ b/libp2p/protocols/secure/secio.nim @@ -188,14 +188,14 @@ proc readMessage*(sconn: SecureConnection): Future[seq[byte]] {.async.} = if sconn.macCheckAndDecode(buf): result = buf else: - debug "Message MAC verification failed", buf = toHex(buf) + trace "Message MAC verification failed", buf = toHex(buf) else: - debug "Received message header size is more then allowed", + trace "Received message header size is more then allowed", length = length, allowed_length = SecioMaxMessageSize except AsyncStreamIncompleteError: - debug "Connection dropped while reading" + trace "Connection dropped while reading" except AsyncStreamReadError: - debug "Error reading from connection" + trace "Error reading from connection" proc writeMessage*(sconn: SecureConnection, message: seq[byte]) {.async.} = ## Write message ``message`` to secure connection ``sconn``. @@ -215,7 +215,7 @@ proc writeMessage*(sconn: SecureConnection, message: seq[byte]) {.async.} = try: await sconn.conn.write(msg) except AsyncStreamWriteError: - debug "Could not write to connection" + trace "Could not write to connection" proc newSecureConnection*(conn: Connection, hash: string, cipher: string, secrets: Secret, @@ -292,7 +292,7 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.} localPeerId = PeerID.init(s.localPublicKey) - debug "Local proposal", schemes = SecioExchanges, ciphers = SecioCiphers, + trace "Local proposal", schemes = SecioExchanges, ciphers = SecioCiphers, hashes = SecioHashes, pubkey = toHex(localBytesPubkey), peer = localPeerId @@ -318,7 +318,7 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.} let order = getOrder(remoteBytesPubkey, localNonce, localBytesPubkey, remoteNonce) - debug "Remote proposal", schemes = remoteExchanges, ciphers = remoteCiphers, + trace "Remote proposal", schemes = remoteExchanges, ciphers = remoteCiphers, hashes = remoteHashes, pubkey = toHex(remoteBytesPubkey), order = order, peer = remotePeerId @@ -327,10 +327,10 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.} let cipher = selectBest(order, SecioCiphers, remoteCiphers) let hash = selectBest(order, SecioHashes, remoteHashes) if len(scheme) == 0 or len(cipher) == 0 or len(hash) == 0: - debug "No algorithms in common", peer = remotePeerId + trace "No algorithms in common", peer = remotePeerId return - debug "Encryption scheme selected", scheme = scheme, cipher = cipher, + trace "Encryption scheme selected", scheme = scheme, cipher = cipher, hash = hash var ekeypair = ephemeral(scheme) @@ -357,15 +357,15 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.} var remoteCorpus = answer & request[4..^1] & remoteEBytesPubkey if not remoteESignature.verify(remoteCorpus, remotePubkey): - debug "Signature verification failed", scheme = remotePubkey.scheme, + trace "Signature verification failed", scheme = remotePubkey.scheme, signature = remoteESignature, pubkey = remotePubkey, corpus = remoteCorpus return - debug "Signature verified", scheme = remotePubkey.scheme + trace "Signature verified", scheme = remotePubkey.scheme if not remoteEPubkey.eckey.initRaw(remoteEBytesPubkey): - debug "Remote ephemeral public key incorrect or corrupted", + trace "Remote ephemeral public key incorrect or corrupted", pubkey = toHex(remoteEBytesPubkey) return @@ -393,11 +393,11 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.} var res = await result.readMessage() if res != @localNonce: - debug "Nonce verification failed", receivedNonce = toHex(res), + trace "Nonce verification failed", receivedNonce = toHex(res), localNonce = toHex(localNonce) raise newException(CatchableError, "Nonce verification failed") else: - debug "Secure handshake succeeded" + trace "Secure handshake succeeded" proc readLoop(sconn: SecureConnection, stream: BufferStream) {.async.} = while not sconn.conn.closed: @@ -413,7 +413,7 @@ proc readLoop(sconn: SecureConnection, stream: BufferStream) {.async.} = proc handleConn(s: Secio, conn: Connection): Future[Connection] {.async.} = var sconn = await s.handshake(conn) proc writeHandler(data: seq[byte]) {.async, gcsafe.} = - debug "sending encrypted bytes", bytes = data.toHex() + trace "sending encrypted bytes", bytes = data.toHex() await sconn.writeMessage(data) var stream = newBufferStream(writeHandler) diff --git a/libp2p/switch.nim b/libp2p/switch.nim index f802f69..baaf63d 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -288,7 +288,7 @@ proc newSwitch*(peerInfo: PeerInfo, let s = result # can't capture result result.streamHandler = proc(stream: Connection) {.async, gcsafe.} = - debug "handling connection for", peerInfo = stream.peerInfo + trace "handling connection for", peerInfo = stream.peerInfo await s.ms.handle(stream) # handle incoming connection result.mount(identity) diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index 095a396..a8bf39d 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -67,7 +67,7 @@ method listen*(t: TcpTransport, # always get the resolved address in case we're bound to 0.0.0.0:0 t.ma = MultiAddress.init(t.server.sock.getLocalAddress()) result = t.server.join() - debug "started node on", address = t.ma + trace "started node on", address = t.ma method dial*(t: TcpTransport, address: MultiAddress): diff --git a/libp2p/transports/transport.nim b/libp2p/transports/transport.nim index 1e196cd..c101369 100644 --- a/libp2p/transports/transport.nim +++ b/libp2p/transports/transport.nim @@ -47,7 +47,7 @@ method listen*(t: Transport, ## listen for incoming connections t.ma = ma t.handler = handler - debug "starting node", address = $ma + trace "starting node", address = $ma method dial*(t: Transport, address: MultiAddress): diff --git a/tests/test.nim b/tests/test.nim index 0e78bdb..541ac85 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -76,13 +76,13 @@ proc main() {.async.} = await switch.subscribeToPeer(remotePeer) proc handler(topic: string, data: seq[byte]): Future[void] {.closure, gcsafe.} = - debug "IN HANDLER" + trace "IN HANDLER" let topic = Base58.encode(cast[seq[byte]]("chat")) await switch.subscribe(topic, handler) let msg = cast[seq[byte]]("hello from nim") await switch.publish(topic, msg) - # debug "published message from test" + # trace "published message from test" # TODO: for some reason the connection closes unless I do a forever loop await allFutures(libp2pFuts) diff --git a/tests/testmplex.nim b/tests/testmplex.nim index adb1105..1bd44dd 100644 --- a/tests/testmplex.nim +++ b/tests/testmplex.nim @@ -237,7 +237,7 @@ suite "Mplex": mplexListen.streamHandler = handleMplexListen listenFut = mplexListen.handle() listenFut.addCallback(proc(udata: pointer) {.gcsafe.} - = debug "completed listener") + = trace "completed listener") let transport1: TcpTransport = newTransport(TcpTransport) asyncCheck transport1.listen(ma, connHandler) @@ -248,7 +248,7 @@ suite "Mplex": let mplexDial = newMplex(conn) let dialFut = mplexDial.handle() dialFut.addCallback(proc(udata: pointer = nil) {.gcsafe.} - = debug "completed dialer") + = trace "completed dialer") for i in 1..10: let stream = await mplexDial.newStream("dialer stream") await stream.writeLp(&"stream {i} from dialer!")