mirror of
https://github.com/vacp2p/mix.git
synced 2026-01-09 21:18:01 -05:00
fix: code review
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user