From 610d95a6fab23b045795a216cf0bc2c7f06756c8 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Mon, 13 May 2024 09:04:35 +0900 Subject: [PATCH] add cover --- mixnet/v2/sim/node.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mixnet/v2/sim/node.py b/mixnet/v2/sim/node.py index 4fd3208..7e8b0e9 100644 --- a/mixnet/v2/sim/node.py +++ b/mixnet/v2/sim/node.py @@ -10,6 +10,8 @@ from p2p import P2p class Node: N_MIXES_IN_PATH = 2 + REAL_PAYLOAD = b"BLOCK" + COVER_PAYLOAD = b"COVER" def __init__(self, id: int, env: simpy.Environment, p2p: P2p): self.id = id @@ -38,7 +40,8 @@ class Node: public_keys = [mix.public_key for mix in mixes] # TODO: replace with realistic tx incentive_txs = [Node.create_incentive_tx(mix.public_key) for mix in mixes] - return SphinxPacket(public_keys, incentive_txs, b"Hello, world!") + payload = random.choice([self.REAL_PAYLOAD, self.COVER_PAYLOAD]) + return SphinxPacket(public_keys, incentive_txs, payload) def receive_message(self, msg: SphinxPacket | bytes): """ @@ -53,7 +56,7 @@ class Node: msg, incentive_tx = msg.unwrap(self.private_key) if self.is_my_incentive_tx(incentive_tx): self.log("Receiving SphinxPacket. It's mine!") - if msg.is_all_unwrapped(): + if msg.is_all_unwrapped() and msg.payload == self.REAL_PAYLOAD: self.env.process(self.p2p.broadcast(msg.payload)) else: # TODO: use Poisson delay