use start_delayed helper

This commit is contained in:
Youngjoon Lee 2024-05-16 15:55:09 +09:00
parent 546e90b2e9
commit de554e95d1
No known key found for this signature in database
GPG Key ID: 09B750B5BD6F08A2
2 changed files with 3 additions and 4 deletions

View File

@ -73,9 +73,6 @@ class Node:
and forwards it to the next mix or the entire network if necessary.
@param msg: the message to be processed
"""
# simulating network latency
yield self.env.timeout(random.uniform(0, self.config.max_network_latency))
if isinstance(msg, SphinxPacket):
msg, incentive_tx = msg.unwrap(self.private_key)
if self.is_my_incentive_tx(incentive_tx):

View File

@ -3,6 +3,7 @@ import random
from collections import defaultdict
import simpy
from simpy.util import start_delayed
from config import Config
from sphinx import SphinxPacket
@ -34,7 +35,8 @@ class P2p:
# TODO: gossipsub or something similar
for node in self.nodes:
self.env.process(node.receive_message(msg))
network_delay = random.uniform(0, self.config.max_network_latency)
start_delayed(self.env, node.receive_message(msg), delay=network_delay)
def get_nodes(self, n: int):
return random.sample(self.nodes, n)