This commit is contained in:
Youngjoon Lee 2024-05-31 12:14:15 +09:00
parent 382aff1890
commit f415624ff0
No known key found for this signature in database
GPG Key ID: 09B750B5BD6F08A2
1 changed files with 15 additions and 13 deletions

View File

@ -168,34 +168,36 @@ class Analysis:
def timing_attack(self): def timing_attack(self):
""" """
pick a random message. i.e. pick a random node pick a random node received a message.
then, track back the message to the sender then, track back the message to the sender
until until
- there is no message to track back within a reasonable time window - there is no message to track back within a reasonable time window
- enough hops have been traversed - enough hops have been traversed
""" """
for t in range(len(self.sim.p2p.adversary.msgs_in_node_per_window)-1, 0, -1): window = len(self.sim.p2p.adversary.msgs_in_node_per_window) - 1
items = self.sim.p2p.adversary.msgs_in_node_per_window[t].items() while window >= 0:
items = self.sim.p2p.adversary.msgs_in_node_per_window[window].items()
actual_receivers = [node for node, (msg_cnt, senders) in items if len(senders) > 0] actual_receivers = [node for node, (msg_cnt, senders) in items if len(senders) > 0]
if len(actual_receivers) == 0: if len(actual_receivers) == 0:
window -= 1
continue continue
receiver = random.choice(actual_receivers) receiver = random.choice(actual_receivers)
nodes_per_hop = self.timing_attack_with(receiver, t) nodes_per_hop = self.timing_attack_with(receiver, window)
self.print_nodes_per_hop(nodes_per_hop) self.print_nodes_per_hop(nodes_per_hop, window)
break window -= len(nodes_per_hop)
def timing_attack_with(self, starting_node: "Node", starting_time: int): def timing_attack_with(self, starting_node: "Node", starting_window: int):
_, senders = self.sim.p2p.adversary.msgs_in_node_per_window[starting_time][starting_node] _, senders = self.sim.p2p.adversary.msgs_in_node_per_window[starting_window][starting_node]
nodes_per_hop = [Counter(senders)] nodes_per_hop = [Counter(senders)]
MAX_HOPS = 4 * 8 MAX_HOPS = 4 * 8
for t in range(starting_time-1, 0, -1): for window in range(starting_window - 1, 0, -1):
if len(nodes_per_hop) >= MAX_HOPS: if len(nodes_per_hop) >= MAX_HOPS:
break break
next_nodes = Counter() next_nodes = Counter()
for node in nodes_per_hop[-1]: for node in nodes_per_hop[-1]:
_, senders = self.sim.p2p.adversary.msgs_in_node_per_window[t][node] _, senders = self.sim.p2p.adversary.msgs_in_node_per_window[window][node]
next_nodes.update(senders) next_nodes.update(senders)
if len(next_nodes) == 0: if len(next_nodes) == 0:
break break
@ -204,6 +206,6 @@ class Analysis:
return nodes_per_hop return nodes_per_hop
@staticmethod @staticmethod
def print_nodes_per_hop(nodes_per_hop): def print_nodes_per_hop(nodes_per_hop, starting_window: int):
for i, nodes in enumerate(nodes_per_hop): for hop, nodes in enumerate(nodes_per_hop):
print(f"hop-{i}: {len(nodes)} nodes: {sorted([node.id for node in nodes])}") print(f"hop-{hop} from w-{starting_window}: {len(nodes)} nodes: {sorted([node.id for node in nodes])}")