From c94e5fa8ac380489179249b5d92528744267d7e0 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Fri, 31 May 2024 23:17:10 +0900 Subject: [PATCH] fix senders counting --- mixnet/v2/sim/adversary.py | 6 ++++-- mixnet/v2/sim/analysis.py | 11 ++++++++++- mixnet/v2/sim/p2p.py | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/mixnet/v2/sim/adversary.py b/mixnet/v2/sim/adversary.py index 79956c6..35696c2 100644 --- a/mixnet/v2/sim/adversary.py +++ b/mixnet/v2/sim/adversary.py @@ -57,11 +57,13 @@ class Adversary: while queue and queue[0][0] < self.env.now - self.config.adversary.io_window_size: _, delta, sender = queue.popleft() msg_cnt += delta - senders.add(sender) + if delta > 0: + senders.add(sender) # Iterate remaining events that will remain in the new window, and accumulate msg_cnt for _, delta, sender in queue: msg_cnt += delta - senders.add(sender) + if delta > 0: + senders.add(sender) self.msgs_in_node_per_window[-1][node] = (msg_cnt, senders) diff --git a/mixnet/v2/sim/analysis.py b/mixnet/v2/sim/analysis.py index e28632b..647fc67 100644 --- a/mixnet/v2/sim/analysis.py +++ b/mixnet/v2/sim/analysis.py @@ -222,6 +222,15 @@ class Analysis: plt.title('Original Sender Counts') plt.show() + # Create the bar plot for original sender counts + broadcasters = ({node.id: count for node, count in self.sim.p2p.broadcasters.items()}) + plt.figure(figsize=(12, 8)) + plt.bar(list(broadcasters.keys()), list(broadcasters.values())) + plt.xlabel('Node ID') + plt.ylabel('Counts') + plt.title('Broadcasters') + plt.show() + # Calculate the mean and standard deviation of the counts mean = np.mean(values) std_dev = np.std(values) @@ -247,7 +256,7 @@ class Analysis: if self.config.p2p.type == self.config.p2p.TYPE_ONE_TO_ALL: MAX_HOPS = 1 + self.config.mixnet.num_mix_layers else: - MAX_HOPS = (1 + self.config.mixnet.num_mix_layers) * 8 + MAX_HOPS = (1 + self.config.mixnet.num_mix_layers) * 4 for window in range(starting_window - 1, 0, -1): if len(nodes_per_hop) >= MAX_HOPS: diff --git a/mixnet/v2/sim/p2p.py b/mixnet/v2/sim/p2p.py index 5e1e15c..5508e39 100644 --- a/mixnet/v2/sim/p2p.py +++ b/mixnet/v2/sim/p2p.py @@ -3,7 +3,7 @@ from __future__ import annotations import hashlib import random from abc import ABC, abstractmethod -from collections import defaultdict +from collections import defaultdict, Counter from typing import TYPE_CHECKING import simpy @@ -24,6 +24,7 @@ class P2P(ABC): self.nodes = [] self.measurement = Measurement(env, config) self.adversary = Adversary(env, config) + self.broadcasters = Counter() def set_nodes(self, nodes: list["Node"]): self.nodes = nodes @@ -39,6 +40,7 @@ class P2P(ABC): # Yield 0 to ensure that the broadcast is done in the same time step. # Without any yield, SimPy complains that the broadcast func is not a generator. yield self.env.timeout(0) + self.broadcasters[sender] += 1 def send(self, msg: SphinxPacket | bytes, hops_traveled: int, sender: "Node", receiver: "Node", is_first_of_broadcasting: bool):