fix senders counting

This commit is contained in:
Youngjoon Lee 2024-05-31 23:17:10 +09:00
parent e1421977ea
commit c94e5fa8ac
No known key found for this signature in database
GPG Key ID: 09B750B5BD6F08A2
3 changed files with 17 additions and 4 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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):