Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

Commit 70a17d1

Browse files
committed
fix: code review
1 parent 15c995e commit 70a17d1

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

mix/config.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ const
1515
surbSize* = headerSize + k + addrSize
1616
# Size of a surb packet inside the message payload
1717
surbLenSize* = 1 # Size of the field storing the number of surbs
18-
surbIdLen* = 16 # Size of the identifier used when sending a message with surb
18+
surbIdLen* = k # Size of the identifier used when sending a message with surb
1919
defaultSurbs* = uint8(4) # Default number of SURBs to send

mix/entry_connection.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ proc new*(
241241
): T {.raises: [].} =
242242
let params = params.get(MixParameters())
243243
let expectReply = params.expectReply.get(false)
244-
let surbs =
244+
let numSurbs =
245245
if expectReply:
246246
params.numSurbs.get(defaultSurbs)
247247
else:
@@ -271,7 +271,7 @@ proc new*(
271271
(Opt.none(PeerId), Opt.some(MixDestination.init(dest.peerId, dest.address)))
272272

273273
await srcMix.anonymizeLocalProtocolSend(
274-
instance.incoming, msg, codec, peerId, destination, surbs
274+
instance.incoming, msg, codec, peerId, destination, numSurbs
275275
)
276276
except CatchableError as e:
277277
error "Error during execution of anonymizeLocalProtocolSend: ", err = e.msg

mix/mix_protocol.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ proc handleMixNodeConnection(
220220
await nextHopConn.close()
221221
except CatchableError as e:
222222
error "Failed to close outgoing stream: ", err = e.msg
223-
mix_messages_error.inc(labelValues = ["Intermediate", "DAIL_FAILED"])
223+
mix_messages_error.inc(labelValues = ["Intermediate", "DIAL_FAILED"])
224224
of Duplicate:
225225
mix_messages_error.inc(labelValues = ["Intermediate/Exit", "DUPLICATE"])
226226
discard

mix/serialization.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ type
184184
proc serializeMessageWithSURBs*(
185185
msg: seq[byte], surbs: seq[SURB]
186186
): Result[seq[byte], string] =
187-
if surbs.len > high(int8):
187+
if surbs.len > (messageSize - surbLenSize - 1) div surbSize:
188188
return err("too many SURBs")
189+
189190
let surbBytes =
190191
surbs.mapIt(?it.hop.serialize() & ?it.header.serialize() & it.key).concat()
191192
ok(byte(surbs.len) & surbBytes & msg)
@@ -211,6 +212,10 @@ proc extractSURBs*(msg: seq[byte]): Result[(seq[SURB], seq[byte]), string] =
211212
var offset = 0
212213
let surbsLenBytes = ?readBytes(msg, offset, 1)
213214
let surbsLen = int(surbsLenBytes[0])
215+
216+
if surbsLen > (messageSize - surbLenSize - 1) div surbSize:
217+
return err("too many SURBs")
218+
214219
var surbs: seq[SURB] = newSeq[SURB](surbsLen)
215220
for i in 0 ..< surbsLen:
216221
let hopBytes = ?readBytes(msg, offset, addrSize)

0 commit comments

Comments
 (0)