set log level to trace - not enabled by default
This commit is contained in:
parent
f9eed172d4
commit
1df16bdbce
|
@ -55,7 +55,7 @@ proc newChannel*(id: uint,
|
||||||
proc writeHandler(data: seq[byte]): Future[void] {.async, gcsafe.} =
|
proc writeHandler(data: seq[byte]): Future[void] {.async, gcsafe.} =
|
||||||
# writes should happen in sequence
|
# writes should happen in sequence
|
||||||
await chan.asyncLock.acquire()
|
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
|
await conn.writeMsg(chan.id, chan.msgCode, data) # write header
|
||||||
chan.asyncLock.release()
|
chan.asyncLock.release()
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ proc handleConn(f: FloodSub,
|
||||||
##
|
##
|
||||||
|
|
||||||
if conn.peerInfo.peerId.isNone:
|
if conn.peerInfo.peerId.isNone:
|
||||||
debug "no valid PeerId for peer"
|
trace "no valid PeerId for peer"
|
||||||
return
|
return
|
||||||
|
|
||||||
# create new pubsub peer
|
# create new pubsub peer
|
||||||
|
|
|
@ -188,14 +188,14 @@ proc readMessage*(sconn: SecureConnection): Future[seq[byte]] {.async.} =
|
||||||
if sconn.macCheckAndDecode(buf):
|
if sconn.macCheckAndDecode(buf):
|
||||||
result = buf
|
result = buf
|
||||||
else:
|
else:
|
||||||
debug "Message MAC verification failed", buf = toHex(buf)
|
trace "Message MAC verification failed", buf = toHex(buf)
|
||||||
else:
|
else:
|
||||||
debug "Received message header size is more then allowed",
|
trace "Received message header size is more then allowed",
|
||||||
length = length, allowed_length = SecioMaxMessageSize
|
length = length, allowed_length = SecioMaxMessageSize
|
||||||
except AsyncStreamIncompleteError:
|
except AsyncStreamIncompleteError:
|
||||||
debug "Connection dropped while reading"
|
trace "Connection dropped while reading"
|
||||||
except AsyncStreamReadError:
|
except AsyncStreamReadError:
|
||||||
debug "Error reading from connection"
|
trace "Error reading from connection"
|
||||||
|
|
||||||
proc writeMessage*(sconn: SecureConnection, message: seq[byte]) {.async.} =
|
proc writeMessage*(sconn: SecureConnection, message: seq[byte]) {.async.} =
|
||||||
## Write message ``message`` to secure connection ``sconn``.
|
## Write message ``message`` to secure connection ``sconn``.
|
||||||
|
@ -215,7 +215,7 @@ proc writeMessage*(sconn: SecureConnection, message: seq[byte]) {.async.} =
|
||||||
try:
|
try:
|
||||||
await sconn.conn.write(msg)
|
await sconn.conn.write(msg)
|
||||||
except AsyncStreamWriteError:
|
except AsyncStreamWriteError:
|
||||||
debug "Could not write to connection"
|
trace "Could not write to connection"
|
||||||
|
|
||||||
proc newSecureConnection*(conn: Connection, hash: string, cipher: string,
|
proc newSecureConnection*(conn: Connection, hash: string, cipher: string,
|
||||||
secrets: Secret,
|
secrets: Secret,
|
||||||
|
@ -292,7 +292,7 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.}
|
||||||
|
|
||||||
localPeerId = PeerID.init(s.localPublicKey)
|
localPeerId = PeerID.init(s.localPublicKey)
|
||||||
|
|
||||||
debug "Local proposal", schemes = SecioExchanges, ciphers = SecioCiphers,
|
trace "Local proposal", schemes = SecioExchanges, ciphers = SecioCiphers,
|
||||||
hashes = SecioHashes,
|
hashes = SecioHashes,
|
||||||
pubkey = toHex(localBytesPubkey),
|
pubkey = toHex(localBytesPubkey),
|
||||||
peer = localPeerId
|
peer = localPeerId
|
||||||
|
@ -318,7 +318,7 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.}
|
||||||
|
|
||||||
let order = getOrder(remoteBytesPubkey, localNonce, localBytesPubkey,
|
let order = getOrder(remoteBytesPubkey, localNonce, localBytesPubkey,
|
||||||
remoteNonce)
|
remoteNonce)
|
||||||
debug "Remote proposal", schemes = remoteExchanges, ciphers = remoteCiphers,
|
trace "Remote proposal", schemes = remoteExchanges, ciphers = remoteCiphers,
|
||||||
hashes = remoteHashes,
|
hashes = remoteHashes,
|
||||||
pubkey = toHex(remoteBytesPubkey), order = order,
|
pubkey = toHex(remoteBytesPubkey), order = order,
|
||||||
peer = remotePeerId
|
peer = remotePeerId
|
||||||
|
@ -327,10 +327,10 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.}
|
||||||
let cipher = selectBest(order, SecioCiphers, remoteCiphers)
|
let cipher = selectBest(order, SecioCiphers, remoteCiphers)
|
||||||
let hash = selectBest(order, SecioHashes, remoteHashes)
|
let hash = selectBest(order, SecioHashes, remoteHashes)
|
||||||
if len(scheme) == 0 or len(cipher) == 0 or len(hash) == 0:
|
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
|
return
|
||||||
|
|
||||||
debug "Encryption scheme selected", scheme = scheme, cipher = cipher,
|
trace "Encryption scheme selected", scheme = scheme, cipher = cipher,
|
||||||
hash = hash
|
hash = hash
|
||||||
|
|
||||||
var ekeypair = ephemeral(scheme)
|
var ekeypair = ephemeral(scheme)
|
||||||
|
@ -357,15 +357,15 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.}
|
||||||
|
|
||||||
var remoteCorpus = answer & request[4..^1] & remoteEBytesPubkey
|
var remoteCorpus = answer & request[4..^1] & remoteEBytesPubkey
|
||||||
if not remoteESignature.verify(remoteCorpus, remotePubkey):
|
if not remoteESignature.verify(remoteCorpus, remotePubkey):
|
||||||
debug "Signature verification failed", scheme = remotePubkey.scheme,
|
trace "Signature verification failed", scheme = remotePubkey.scheme,
|
||||||
signature = remoteESignature, pubkey = remotePubkey,
|
signature = remoteESignature, pubkey = remotePubkey,
|
||||||
corpus = remoteCorpus
|
corpus = remoteCorpus
|
||||||
return
|
return
|
||||||
|
|
||||||
debug "Signature verified", scheme = remotePubkey.scheme
|
trace "Signature verified", scheme = remotePubkey.scheme
|
||||||
|
|
||||||
if not remoteEPubkey.eckey.initRaw(remoteEBytesPubkey):
|
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)
|
pubkey = toHex(remoteEBytesPubkey)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -393,11 +393,11 @@ proc handshake*(s: Secio, conn: Connection): Future[SecureConnection] {.async.}
|
||||||
var res = await result.readMessage()
|
var res = await result.readMessage()
|
||||||
|
|
||||||
if res != @localNonce:
|
if res != @localNonce:
|
||||||
debug "Nonce verification failed", receivedNonce = toHex(res),
|
trace "Nonce verification failed", receivedNonce = toHex(res),
|
||||||
localNonce = toHex(localNonce)
|
localNonce = toHex(localNonce)
|
||||||
raise newException(CatchableError, "Nonce verification failed")
|
raise newException(CatchableError, "Nonce verification failed")
|
||||||
else:
|
else:
|
||||||
debug "Secure handshake succeeded"
|
trace "Secure handshake succeeded"
|
||||||
|
|
||||||
proc readLoop(sconn: SecureConnection, stream: BufferStream) {.async.} =
|
proc readLoop(sconn: SecureConnection, stream: BufferStream) {.async.} =
|
||||||
while not sconn.conn.closed:
|
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.} =
|
proc handleConn(s: Secio, conn: Connection): Future[Connection] {.async.} =
|
||||||
var sconn = await s.handshake(conn)
|
var sconn = await s.handshake(conn)
|
||||||
proc writeHandler(data: seq[byte]) {.async, gcsafe.} =
|
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)
|
await sconn.writeMessage(data)
|
||||||
|
|
||||||
var stream = newBufferStream(writeHandler)
|
var stream = newBufferStream(writeHandler)
|
||||||
|
|
|
@ -288,7 +288,7 @@ proc newSwitch*(peerInfo: PeerInfo,
|
||||||
|
|
||||||
let s = result # can't capture result
|
let s = result # can't capture result
|
||||||
result.streamHandler = proc(stream: Connection) {.async, gcsafe.} =
|
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
|
await s.ms.handle(stream) # handle incoming connection
|
||||||
|
|
||||||
result.mount(identity)
|
result.mount(identity)
|
||||||
|
|
|
@ -67,7 +67,7 @@ method listen*(t: TcpTransport,
|
||||||
# always get the resolved address in case we're bound to 0.0.0.0:0
|
# always get the resolved address in case we're bound to 0.0.0.0:0
|
||||||
t.ma = MultiAddress.init(t.server.sock.getLocalAddress())
|
t.ma = MultiAddress.init(t.server.sock.getLocalAddress())
|
||||||
result = t.server.join()
|
result = t.server.join()
|
||||||
debug "started node on", address = t.ma
|
trace "started node on", address = t.ma
|
||||||
|
|
||||||
method dial*(t: TcpTransport,
|
method dial*(t: TcpTransport,
|
||||||
address: MultiAddress):
|
address: MultiAddress):
|
||||||
|
|
|
@ -47,7 +47,7 @@ method listen*(t: Transport,
|
||||||
## listen for incoming connections
|
## listen for incoming connections
|
||||||
t.ma = ma
|
t.ma = ma
|
||||||
t.handler = handler
|
t.handler = handler
|
||||||
debug "starting node", address = $ma
|
trace "starting node", address = $ma
|
||||||
|
|
||||||
method dial*(t: Transport,
|
method dial*(t: Transport,
|
||||||
address: MultiAddress):
|
address: MultiAddress):
|
||||||
|
|
|
@ -76,13 +76,13 @@ proc main() {.async.} =
|
||||||
await switch.subscribeToPeer(remotePeer)
|
await switch.subscribeToPeer(remotePeer)
|
||||||
|
|
||||||
proc handler(topic: string, data: seq[byte]): Future[void] {.closure, gcsafe.} =
|
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"))
|
let topic = Base58.encode(cast[seq[byte]]("chat"))
|
||||||
await switch.subscribe(topic, handler)
|
await switch.subscribe(topic, handler)
|
||||||
let msg = cast[seq[byte]]("hello from nim")
|
let msg = cast[seq[byte]]("hello from nim")
|
||||||
await switch.publish(topic, msg)
|
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
|
# TODO: for some reason the connection closes unless I do a forever loop
|
||||||
await allFutures(libp2pFuts)
|
await allFutures(libp2pFuts)
|
||||||
|
|
||||||
|
|
|
@ -237,7 +237,7 @@ suite "Mplex":
|
||||||
mplexListen.streamHandler = handleMplexListen
|
mplexListen.streamHandler = handleMplexListen
|
||||||
listenFut = mplexListen.handle()
|
listenFut = mplexListen.handle()
|
||||||
listenFut.addCallback(proc(udata: pointer) {.gcsafe.}
|
listenFut.addCallback(proc(udata: pointer) {.gcsafe.}
|
||||||
= debug "completed listener")
|
= trace "completed listener")
|
||||||
|
|
||||||
let transport1: TcpTransport = newTransport(TcpTransport)
|
let transport1: TcpTransport = newTransport(TcpTransport)
|
||||||
asyncCheck transport1.listen(ma, connHandler)
|
asyncCheck transport1.listen(ma, connHandler)
|
||||||
|
@ -248,7 +248,7 @@ suite "Mplex":
|
||||||
let mplexDial = newMplex(conn)
|
let mplexDial = newMplex(conn)
|
||||||
let dialFut = mplexDial.handle()
|
let dialFut = mplexDial.handle()
|
||||||
dialFut.addCallback(proc(udata: pointer = nil) {.gcsafe.}
|
dialFut.addCallback(proc(udata: pointer = nil) {.gcsafe.}
|
||||||
= debug "completed dialer")
|
= trace "completed dialer")
|
||||||
for i in 1..10:
|
for i in 1..10:
|
||||||
let stream = await mplexDial.newStream("dialer stream")
|
let stream = await mplexDial.newStream("dialer stream")
|
||||||
await stream.writeLp(&"stream {i} from dialer!")
|
await stream.writeLp(&"stream {i} from dialer!")
|
||||||
|
|
Loading…
Reference in New Issue