fix: code review

This commit is contained in:
Richard Ramos
2025-09-05 12:23:11 -04:00
parent 15c995eb81
commit 70a17d138b
4 changed files with 10 additions and 5 deletions

View File

@@ -15,5 +15,5 @@ const
surbSize* = headerSize + k + addrSize
# Size of a surb packet inside the message payload
surbLenSize* = 1 # Size of the field storing the number of surbs
surbIdLen* = 16 # Size of the identifier used when sending a message with surb
surbIdLen* = k # Size of the identifier used when sending a message with surb
defaultSurbs* = uint8(4) # Default number of SURBs to send

View File

@@ -241,7 +241,7 @@ proc new*(
): T {.raises: [].} =
let params = params.get(MixParameters())
let expectReply = params.expectReply.get(false)
let surbs =
let numSurbs =
if expectReply:
params.numSurbs.get(defaultSurbs)
else:
@@ -271,7 +271,7 @@ proc new*(
(Opt.none(PeerId), Opt.some(MixDestination.init(dest.peerId, dest.address)))
await srcMix.anonymizeLocalProtocolSend(
instance.incoming, msg, codec, peerId, destination, surbs
instance.incoming, msg, codec, peerId, destination, numSurbs
)
except CatchableError as e:
error "Error during execution of anonymizeLocalProtocolSend: ", err = e.msg

View File

@@ -220,7 +220,7 @@ proc handleMixNodeConnection(
await nextHopConn.close()
except CatchableError as e:
error "Failed to close outgoing stream: ", err = e.msg
mix_messages_error.inc(labelValues = ["Intermediate", "DAIL_FAILED"])
mix_messages_error.inc(labelValues = ["Intermediate", "DIAL_FAILED"])
of Duplicate:
mix_messages_error.inc(labelValues = ["Intermediate/Exit", "DUPLICATE"])
discard

View File

@@ -184,8 +184,9 @@ type
proc serializeMessageWithSURBs*(
msg: seq[byte], surbs: seq[SURB]
): Result[seq[byte], string] =
if surbs.len > high(int8):
if surbs.len > (messageSize - surbLenSize - 1) div surbSize:
return err("too many SURBs")
let surbBytes =
surbs.mapIt(?it.hop.serialize() & ?it.header.serialize() & it.key).concat()
ok(byte(surbs.len) & surbBytes & msg)
@@ -211,6 +212,10 @@ proc extractSURBs*(msg: seq[byte]): Result[(seq[SURB], seq[byte]), string] =
var offset = 0
let surbsLenBytes = ?readBytes(msg, offset, 1)
let surbsLen = int(surbsLenBytes[0])
if surbsLen > (messageSize - surbLenSize - 1) div surbSize:
return err("too many SURBs")
var surbs: seq[SURB] = newSeq[SURB](surbsLen)
for i in 0 ..< surbsLen:
let hopBytes = ?readBytes(msg, offset, addrSize)