mirror of
https://github.com/logos-co/nomos-specs.git
synced 2025-02-08 13:33:49 +00:00
randomize network latency
This commit is contained in:
parent
e6db41fbfd
commit
2e58207cf0
@ -38,11 +38,21 @@ class Config:
|
||||
@dataclass
|
||||
class SimulationConfig:
|
||||
duration_sec: int
|
||||
net_latency_sec: float
|
||||
network: NetworkConfig
|
||||
|
||||
def validate(self):
|
||||
assert self.duration_sec > 0
|
||||
assert self.net_latency_sec > 0
|
||||
self.network.validate()
|
||||
|
||||
|
||||
@dataclass
|
||||
class NetworkConfig:
|
||||
max_latency_sec: float
|
||||
seed: random.Random
|
||||
|
||||
def validate(self):
|
||||
assert self.max_latency_sec > 0
|
||||
assert self.seed is not None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -1,6 +1,8 @@
|
||||
simulation:
|
||||
duration_sec: 1000
|
||||
net_latency_sec: 0.01
|
||||
network:
|
||||
max_latency_sec: 0.01
|
||||
seed: 0
|
||||
|
||||
logic:
|
||||
sender_lottery:
|
||||
|
@ -5,12 +5,12 @@ import pandas
|
||||
|
||||
from mixnet.connection import SimplexConnection
|
||||
from mixnet.framework.framework import Framework, Queue
|
||||
from mixnet.sim.config import SimulationConfig
|
||||
from mixnet.sim.config import NetworkConfig
|
||||
|
||||
|
||||
class MeteredRemoteSimplexConnection(SimplexConnection):
|
||||
framework: Framework
|
||||
config: SimulationConfig
|
||||
latency: float
|
||||
outputs: Queue
|
||||
conn: Queue
|
||||
inputs: Queue
|
||||
@ -19,9 +19,9 @@ class MeteredRemoteSimplexConnection(SimplexConnection):
|
||||
input_task: Awaitable
|
||||
input_meters: list[int]
|
||||
|
||||
def __init__(self, config: SimulationConfig, framework: Framework):
|
||||
def __init__(self, config: NetworkConfig, framework: Framework):
|
||||
self.framework = framework
|
||||
self.config = config
|
||||
self.latency = config.seed.random() * config.max_latency_sec
|
||||
self.outputs = framework.queue()
|
||||
self.conn = framework.queue()
|
||||
self.inputs = framework.queue()
|
||||
@ -49,7 +49,7 @@ class MeteredRemoteSimplexConnection(SimplexConnection):
|
||||
data = await self.conn.get()
|
||||
if data is None:
|
||||
break
|
||||
await self.framework.sleep(self.config.net_latency_sec)
|
||||
await self.framework.sleep(self.latency)
|
||||
self.__update_meter(self.input_meters, len(data), start_time)
|
||||
await self.inputs.put(data)
|
||||
|
||||
|
@ -64,7 +64,9 @@ class Simulation:
|
||||
return nodes, conn_stats
|
||||
|
||||
def create_conn(self) -> MeteredRemoteSimplexConnection:
|
||||
return MeteredRemoteSimplexConnection(self.config.simulation, self.framework)
|
||||
return MeteredRemoteSimplexConnection(
|
||||
self.config.simulation.network, self.framework
|
||||
)
|
||||
|
||||
async def run_logic(self, node: Node):
|
||||
lottery_config = self.config.logic.sender_lottery
|
||||
|
Loading…
x
Reference in New Issue
Block a user