mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2026-01-09 03:28:14 -05:00
Add libp2p_dump and libp2p_dump_dir compiler time options. (#359)
* Add `libp2p_dump` and `libp2p_dump_dir` compiler time options. * Add tools/pbcap_parser. * Add mplex control messages decoding.
This commit is contained in:
@@ -21,6 +21,9 @@ import ../../utility
|
||||
import secure,
|
||||
../../crypto/[crypto, chacha20poly1305, curve25519, hkdf]
|
||||
|
||||
when defined(libp2p_dump):
|
||||
import ../../debugutils
|
||||
|
||||
logScope:
|
||||
topics = "noise"
|
||||
|
||||
@@ -403,8 +406,15 @@ method readMessage*(sconn: NoiseConnection): Future[seq[byte]] {.async.} =
|
||||
if size > 0:
|
||||
var buffer = newSeq[byte](size)
|
||||
await sconn.stream.readExactly(addr buffer[0], buffer.len)
|
||||
return sconn.readCs.decryptWithAd([], buffer)
|
||||
when defined(libp2p_dump):
|
||||
let res = sconn.readCs.decryptWithAd([], buffer)
|
||||
dumpMessage(sconn, FlowDirection.Incoming, res)
|
||||
return res
|
||||
else:
|
||||
return sconn.readCs.decryptWithAd([], buffer)
|
||||
else:
|
||||
when defined(libp2p_dump):
|
||||
dumpMessage(sconn, FlowDirection.Incoming, [])
|
||||
trace "Received 0-length message", sconn
|
||||
|
||||
method write*(sconn: NoiseConnection, message: seq[byte]): Future[void] {.async.} =
|
||||
@@ -429,6 +439,10 @@ method write*(sconn: NoiseConnection, message: seq[byte]): Future[void] {.async.
|
||||
outbuf &= besize
|
||||
outbuf &= cipher
|
||||
await sconn.stream.write(outbuf)
|
||||
|
||||
when defined(libp2p_dump):
|
||||
dumpMessage(sconn, FlowDirection.Outgoing, message)
|
||||
|
||||
sconn.activity = true
|
||||
|
||||
method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureConn] {.async.} =
|
||||
|
||||
Reference in New Issue
Block a user