From 66004c60f04d01e2de6dfcd04495193eaaa68e9b Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Wed, 15 May 2024 16:34:09 +0900 Subject: [PATCH] add message_prob and prep_time --- mixnet/v2/sim/node.py | 14 ++++++++++++-- requirements.txt | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mixnet/v2/sim/node.py b/mixnet/v2/sim/node.py index 1b0b46c..1bb5dae 100644 --- a/mixnet/v2/sim/node.py +++ b/mixnet/v2/sim/node.py @@ -29,12 +29,22 @@ class Node: Creates/encapsulate a message and send it to the network through the mixnet """ while True: - msg = self.create_message() # TODO: Use the realistic cover traffic emission rate - yield self.env.timeout(2) + yield self.env.timeout(self.config.message_interval) + + if not self.is_message_sender(): + continue + + prep_time = random.uniform(0, self.config.max_message_prep_time) + yield self.env.timeout(prep_time) + self.log("Sending a message to the mixnet") + msg = self.create_message() self.env.process(self.p2p.broadcast(msg)) + def is_message_sender(self) -> bool: + return random.random() < self.config.message_prob + def create_message(self) -> SphinxPacket: """ Creates a message using the Sphinx format diff --git a/requirements.txt b/requirements.txt index 13b4439..4f54ad5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,5 @@ simpy==4.1.1 pandas==2.2.2 matplotlib==3.8.4 seaborn==0.13.2 +pyyaml==6.0.1 +dacite==1.8.1