diff --git a/mixnet/v2/sim/config.py b/mixnet/v2/sim/config.py index 2f1647c..ba58943 100644 --- a/mixnet/v2/sim/config.py +++ b/mixnet/v2/sim/config.py @@ -10,9 +10,17 @@ class Config: running_time: int num_nodes: int num_mix_layers: int + # An interval of sending a new real/cover message + # A probability of actually sending a message depends on the following parameters. message_interval: int - real_message_prob: float # TODO: should be proportional to its stake + # A probability of sending a real message within one cycle + real_message_prob: float + # A weight of real message emission probability of some nodes + # The length of the list should be <= num_nodes. + real_message_prob_weights: list[float] + # A probability of sending a cover message within one cycle if not sending a real message cover_message_prob: float + # A maximum preparation time (delay) before sending the message max_message_prep_time: float @classmethod @@ -26,9 +34,11 @@ class Config: assert config.num_nodes > 0 assert 0 < config.num_mix_layers <= config.num_nodes assert config.message_interval > 0 - assert config.real_message_prob >= 0 + assert config.real_message_prob > 0 + assert len(config.real_message_prob_weights) <= config.num_nodes + for weight in config.real_message_prob_weights: + assert weight >= 1 assert config.cover_message_prob >= 0 - assert config.real_message_prob + config.cover_message_prob <= 1 assert config.max_message_prep_time >= 0 return config diff --git a/mixnet/v2/sim/config.yaml b/mixnet/v2/sim/config.yaml index c2b866d..fef3b6b 100644 --- a/mixnet/v2/sim/config.yaml +++ b/mixnet/v2/sim/config.yaml @@ -1,9 +1,15 @@ running_time: 30 num_nodes: 100 num_mix_layers: 3 +# An interval of sending a new real/cover message +# A probability of actually sending a message depends on the following parameters. message_interval: 1 -# (real_message_prob + cover_message_prob) should be <= 1 -# If the sum is < 1, then the remaining probability is for sending nothing. -real_message_prob: 0.01 +# A probability of sending a real message within a cycle +real_message_prob: 0.1 +# A weight of real message emission probability of some nodes +# The length of the list should be <= num_nodes. +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 diff --git a/mixnet/v2/sim/node.py b/mixnet/v2/sim/node.py index 0f2006a..dc282cd 100644 --- a/mixnet/v2/sim/node.py +++ b/mixnet/v2/sim/node.py @@ -44,13 +44,18 @@ class Node: def payload_to_send(self) -> bytes | None: rnd = random.random() - if rnd < self.config.real_message_prob: + if rnd < self.real_message_prob(): return self.REAL_PAYLOAD - elif rnd < self.config.real_message_prob + self.config.cover_message_prob: + elif rnd < self.config.cover_message_prob: return self.COVER_PAYLOAD else: return None + def real_message_prob(self): + weight = self.config.real_message_prob_weights[self.id] \ + if self.id < len(self.config.real_message_prob_weights) else 0 + return self.config.real_message_prob * weight + def create_message(self, payload: bytes) -> SphinxPacket: """ Creates a message using the Sphinx format