diff --git a/mixnet/v2/sim/config.py b/mixnet/v2/sim/config.py index ba58943..fa9a19f 100644 --- a/mixnet/v2/sim/config.py +++ b/mixnet/v2/sim/config.py @@ -22,6 +22,8 @@ class Config: cover_message_prob: float # A maximum preparation time (delay) before sending the message max_message_prep_time: float + # A maximum network latency between nodes directly connected with each other + max_network_latency: float @classmethod def load(cls, yaml_path: str) -> Self: @@ -40,5 +42,6 @@ class Config: assert weight >= 1 assert config.cover_message_prob >= 0 assert config.max_message_prep_time >= 0 + assert config.max_network_latency >= 0 return config diff --git a/mixnet/v2/sim/config.yaml b/mixnet/v2/sim/config.yaml index 6dea132..9ce7f3b 100644 --- a/mixnet/v2/sim/config.yaml +++ b/mixnet/v2/sim/config.yaml @@ -13,4 +13,6 @@ real_message_prob_weights: [10, 8, 12] # A probability of sending a cover message within a cycle if not sending a real message cover_message_prob: 0.2 # A maximum preparation time (delay) before sending the message -max_message_prep_time: 0.3 \ No newline at end of file +max_message_prep_time: 0.3 +# A maximum network latency between nodes directly connected with each other +max_network_latency: 0.5 \ No newline at end of file diff --git a/mixnet/v2/sim/node.py b/mixnet/v2/sim/node.py index dc282cd..23d20dc 100644 --- a/mixnet/v2/sim/node.py +++ b/mixnet/v2/sim/node.py @@ -74,7 +74,7 @@ class Node: @param msg: the message to be processed """ # simulating network latency - yield self.env.timeout(random.randint(0, 3)) + yield self.env.timeout(random.uniform(0, self.config.max_network_latency)) if isinstance(msg, SphinxPacket): msg, incentive_tx = msg.unwrap(self.private_key)