@@ -363,6 +363,7 @@ proc buildSurbs(
363363 mixProto: MixProtocol ,
364364 incoming: AsyncQueue [seq [byte ]],
365365 numSurbs: uint8 ,
366+ destPeerId: PeerId ,
366367 exitPeerId: PeerId ,
367368): Result [seq [SURB ], string ] =
368369 var response: seq [SURB ]
@@ -384,26 +385,20 @@ proc buildSurbs(
384385 if mixProto.pubNodeInfo.len < L:
385386 return err (" No. of public mix nodes less than path length" )
386387
387- var
388- pubNodeInfoKeys = toSeq (mixProto.pubNodeInfo.keys)
389- randPeerId: PeerId
390- availableIndices = toSeq (0 ..< numMixNodes)
391-
392- # Remove exit node from nodes to consider for surbs
393- let index = pubNodeInfoKeys.find (exitPeerId)
394- if index != - 1 :
395- availableIndices.del (index)
396- else :
397- return err (" could not find exit node" )
388+ # Remove exit and dest node from nodes to consider for surbs
389+ var pubNodeInfoKeys =
390+ mixProto.pubNodeInfo.keys.toSeq ().filterIt (it != exitPeerId and it != destPeerId)
391+ var availableIndices = toSeq (0 ..< pubNodeInfoKeys.len)
398392
393+ # Select L mix nodes at random
399394 var i = 0
400395 while i < L:
401396 let (multiAddr, mixPubKey, delayMillisec) =
402397 if i < L - 1 :
403398 let randomIndexPosition = cryptoRandomInt (availableIndices.len).valueOr:
404399 return err (" failed to generate random num: " & error)
405400 let selectedIndex = availableIndices[randomIndexPosition]
406- randPeerId = pubNodeInfoKeys[selectedIndex]
401+ let randPeerId = pubNodeInfoKeys[selectedIndex]
407402 availableIndices.del (randomIndexPosition)
408403 debug " Selected mix node for surbs: " , indexInPath = i, peerId = randPeerId
409404 let mixPubInfo = getMixPubInfo (mixProto.pubNodeInfo.getOrDefault (randPeerId))
@@ -448,9 +443,10 @@ proc prepareMsgWithSurbs(
448443 incoming: AsyncQueue [seq [byte ]],
449444 msg: seq [byte ],
450445 numSurbs: uint8 = 0 ,
446+ destPeerId: PeerId ,
451447 exitPeerId: PeerId ,
452448): Result [seq [byte ], string ] =
453- let surbs = mixProto.buildSurbs (incoming, numSurbs, exitPeerId).valueOr:
449+ let surbs = mixProto.buildSurbs (incoming, numSurbs, destPeerId, exitPeerId).valueOr:
454450 return err (error)
455451
456452 let serialized = ? serializeMessageWithSURBs (msg, surbs)
@@ -601,10 +597,10 @@ proc anonymizeLocalProtocolSend*(
601597 mix_messages_error.inc (labelValues = [" Entry" , " LOW_MIX_POOL" ])
602598 return
603599
604- var
605- pubNodeInfoKeys = toSeq (mixProto.pubNodeInfo.keys)
606- randPeerId: PeerId
607- availableIndices = toSeq (0 ..< numMixNodes )
600+ # Skip the destination peer
601+ var pubNodeInfoKeys =
602+ mixProto.pubNodeInfo.keys. toSeq (). filterIt (it != destination.peerId)
603+ var availableIndices = toSeq (0 ..< pubNodeInfoKeys.len )
608604
609605 var i = 0
610606 while i < L:
@@ -613,12 +609,9 @@ proc anonymizeLocalProtocolSend*(
613609 mix_messages_error.inc (labelValues = [" Entry" , " NON_RECOVERABLE" ])
614610 return
615611 let selectedIndex = availableIndices[randomIndexPosition]
616- randPeerId = pubNodeInfoKeys[selectedIndex]
612+ let randPeerId = pubNodeInfoKeys[selectedIndex]
617613 availableIndices.del (randomIndexPosition)
618614
619- # Skip the destination peer
620- if randPeerId == destination.peerId:
621- continue
622615 # Last hop will be the exit node that will forward the request
623616 if i == L - 1 :
624617 exitPeerId = randPeerId
@@ -660,7 +653,9 @@ proc anonymizeLocalProtocolSend*(
660653 return
661654 let destHop = Hop .init (destAddrBytes)
662655
663- let msgWithSurbs = mixProto.prepareMsgWithSurbs (incoming, msg, numSurbs, exitPeerId).valueOr:
656+ let msgWithSurbs = mixProto.prepareMsgWithSurbs (
657+ incoming, msg, numSurbs, destination.peerId, exitPeerId
658+ ).valueOr:
664659 error " Could not prepend SURBs" , err = error
665660 return
666661
0 commit comments