From f82b93387bbb1c040c9c61472386850f1be03bb2 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Tue, 21 May 2024 15:13:14 +0900 Subject: [PATCH] refactor: padding payload --- mixnet/v2/sim/node.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mixnet/v2/sim/node.py b/mixnet/v2/sim/node.py index 77e688d..f2a2596 100644 --- a/mixnet/v2/sim/node.py +++ b/mixnet/v2/sim/node.py @@ -87,11 +87,7 @@ class Node: if self.is_my_incentive_tx(incentive_tx): self.log("Receiving SphinxPacket. It's mine!") if msg.is_all_unwrapped(): - # Pad the final msg to the same size as a SphinxPacket, - # assuming that the final msg is going to be sent via secure channels (TLS, Noise, etc.) - final_padded_msg = (msg.payload - + self.PADDING_SEPARATOR - + bytes(len(msg) - len(msg.payload) - len(self.PADDING_SEPARATOR))) + final_padded_msg = self.pad_payload(msg.payload, len(msg)) self.env.process(self.p2p.broadcast(self, final_padded_msg)) else: # TODO: use Poisson delay or something else, if necessary @@ -106,6 +102,15 @@ class Node: def build_payload(self) -> bytes: return b"P" + bytes(self.config.mixnet.payload_size - len(b"P")) + def pad_payload(self, payload: bytes, target_size: int) -> bytes: + """ + Pad the final msg to the target size (e.g. the same size as a SphinxPacket), + assuming that the final msg is going to be sent via secure channels (TLS, Noise, etc.) + """ + return (payload + + self.PADDING_SEPARATOR + + bytes(target_size - len(payload) - len(self.PADDING_SEPARATOR))) + # TODO: This is a dummy logic @classmethod def create_incentive_tx(cls, mix_public_key: X25519PublicKey) -> Attachment: