mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-05 14:43:11 +00:00
add p2p type config
This commit is contained in:
parent
063efcf5c3
commit
6e66eb7233
@ -10,7 +10,7 @@ import yaml
|
||||
class Config:
|
||||
simulation: SimulationConfig
|
||||
mixnet: MixnetConfig
|
||||
p2p: P2pConfig
|
||||
p2p: P2PConfig
|
||||
measurement: MeasurementConfig
|
||||
adversary: AdversaryConfig
|
||||
|
||||
@ -95,15 +95,22 @@ class MixnetConfig:
|
||||
|
||||
|
||||
@dataclass
|
||||
class P2pConfig:
|
||||
class P2PConfig:
|
||||
# Broadcasting type: naive | gossip
|
||||
type: str
|
||||
# A maximum network latency between nodes directly connected with each other
|
||||
max_network_latency: float
|
||||
|
||||
TYPE_NAIVE = "naive"
|
||||
TYPE_GOSSIP = "gossip"
|
||||
|
||||
def validate(self):
|
||||
assert self.type in [self.TYPE_NAIVE, self.TYPE_GOSSIP]
|
||||
assert self.max_network_latency >= 0
|
||||
|
||||
def description(self):
|
||||
return (
|
||||
f"p2p_type: {self.type}\n"
|
||||
f"max_net_latency: {self.max_network_latency:.2f}"
|
||||
)
|
||||
|
||||
|
||||
@ -26,6 +26,8 @@ mixnet:
|
||||
max_mix_delay: 3
|
||||
|
||||
p2p:
|
||||
# Broadcasting type: naive | gossip
|
||||
type: "naive"
|
||||
# A maximum network latency between nodes directly connected with each other
|
||||
max_network_latency: 0.5
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@ import random
|
||||
|
||||
import simpy
|
||||
|
||||
from config import Config
|
||||
from config import Config, P2PConfig
|
||||
from node import Node
|
||||
from p2p import NaiveBroadcastP2P
|
||||
from p2p import NaiveBroadcastP2P, GossipP2P
|
||||
|
||||
|
||||
class Simulation:
|
||||
@ -18,3 +18,13 @@ class Simulation:
|
||||
|
||||
def run(self):
|
||||
self.env.run(until=self.config.simulation.running_time)
|
||||
|
||||
@classmethod
|
||||
def init_p2p(cls, env: simpy.Environment, config: Config):
|
||||
match config.p2p.type:
|
||||
case P2PConfig.TYPE_NAIVE:
|
||||
return NaiveBroadcastP2P(env, config)
|
||||
case P2PConfig.TYPE_GOSSIP:
|
||||
return GossipP2P(env, config)
|
||||
case _:
|
||||
raise ValueError("Unknown P2P type")
|
||||
Loading…
x
Reference in New Issue
Block a user