messages numbers and send/recv logs

This commit is contained in:
benbierens 2025-01-08 15:43:45 +01:00
parent 6e2d601ecd
commit d9a821e7be
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
4 changed files with 19 additions and 4 deletions

View File

@ -31,6 +31,7 @@ type
handler*: RPCHandler
sendConn: Connection
getConn: ConnProvider
num: int32
proc connected*(b: NetworkPeer): bool =
not(isNil(b.sendConn)) and
@ -45,6 +46,7 @@ proc readLoop*(b: NetworkPeer, conn: Connection) {.async.} =
let
data = await conn.readLp(MaxMessageSize.int)
msg = Message.protobufDecode(data).mapFailure().tryGet()
trace "MsgReceived", num = msg.num
await b.handler(b, msg)
except CancelledError:
trace "Read loop cancelled"
@ -61,14 +63,23 @@ proc connect*(b: NetworkPeer): Future[Connection] {.async.} =
asyncSpawn b.readLoop(b.sendConn)
return b.sendConn
proc send*(b: NetworkPeer, msg: Message) {.async.} =
proc send*(b: NetworkPeer, msga: Message) {.async.} =
let conn = await b.connect()
inc b.num
if b.num > 9:
b.num = 1
var msg = msga
msg.num = b.num
if isNil(conn):
warn "Unable to get send connection for peer message not sent", peer = b.id
return
trace "MsgSending", num = msg.num
await conn.writeLp(protobufEncode(msg))
trace "MsgSent", num = msg.num
proc broadcast*(b: NetworkPeer, msg: Message) =
proc sendAwaiter() {.async.} =

View File

@ -63,6 +63,7 @@ type
pendingBytes*: uint
account*: AccountMessage
payment*: StateChannelUpdate
num*: int32
#
# Encoding Message into seq[byte] in Protobuf format
@ -139,6 +140,7 @@ proc protobufEncode*(value: Message): seq[byte] =
ipb.write(5, value.pendingBytes)
ipb.write(6, value.account)
ipb.write(7, value.payment)
ipb.write(8, value.num.uint64)
ipb.finish()
ipb.buffer
@ -260,6 +262,7 @@ proc protobufDecode*(_: type Message, msg: seq[byte]): ProtoResult[Message] =
value = Message()
pb = initProtoBuffer(msg, maxSize = MaxMessageSize)
ipb: ProtoBuffer
field: uint64
sublist: seq[seq[byte]]
if ? pb.getField(1, ipb):
value.wantList = ? WantList.decode(ipb)
@ -274,4 +277,6 @@ proc protobufDecode*(_: type Message, msg: seq[byte]): ProtoResult[Message] =
value.account = ? AccountMessage.decode(ipb)
if ? pb.getField(7, ipb):
value.payment = ? StateChannelUpdate.decode(ipb)
if ? pb.getField(8, field):
value.num = int32(field)
ok(value)

View File

@ -1,2 +1,2 @@
docker build --build-arg MAKE_PARALLEL=4 --build-arg NIMFLAGS="-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_proof_failures=true -d:codex_use_hardhat=false -d:codex_enable_log_counter=true -d:verify_circuit=true" --build-arg NAT_IP_AUTO=true -t thatbenbierens/nim-codex:blkex-cancelpresence-18-s -f codex.Dockerfile ..
docker push thatbenbierens/nim-codex:blkex-cancelpresence-18-s
docker build --build-arg MAKE_PARALLEL=4 --build-arg NIMFLAGS="-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_proof_failures=true -d:codex_use_hardhat=false -d:codex_enable_log_counter=true -d:verify_circuit=true" --build-arg NAT_IP_AUTO=true -t thatbenbierens/nim-codex:blkex-cancelpresence-20-s -f codex.Dockerfile ..
docker push thatbenbierens/nim-codex:blkex-cancelpresence-20-s

View File

@ -28,7 +28,6 @@ WORKDIR ${BUILD_HOME}
COPY . .
RUN make -j ${MAKE_PARALLEL} update
RUN make -j ${MAKE_PARALLEL}
RUN make -j ${MAKE_PARALLEL} cirdl
# Create
FROM ${IMAGE}