2024-02-05 09:04:02 +01:00
|
|
|
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
|
|
|
|
|
2024-02-08 15:39:50 +09:00
|
|
|
from mixnet.config import (
|
2024-06-27 17:32:22 +09:00
|
|
|
GlobalConfig,
|
2024-06-26 15:55:00 +09:00
|
|
|
MixMembership,
|
|
|
|
NodeConfig,
|
|
|
|
NodeInfo,
|
2024-02-08 15:39:50 +09:00
|
|
|
)
|
2024-01-25 18:04:55 +09:00
|
|
|
|
|
|
|
|
2024-06-27 18:04:51 +09:00
|
|
|
def init_mixnet_config(
|
|
|
|
num_nodes: int,
|
|
|
|
) -> tuple[GlobalConfig, list[NodeConfig], dict[bytes, X25519PrivateKey]]:
|
2024-06-26 15:55:00 +09:00
|
|
|
transmission_rate_per_sec = 3
|
2024-06-28 12:26:44 +09:00
|
|
|
peering_degree = 6
|
2024-06-27 17:32:22 +09:00
|
|
|
max_mix_path_length = 3
|
2024-06-26 15:55:00 +09:00
|
|
|
node_configs = [
|
2024-06-28 12:26:44 +09:00
|
|
|
NodeConfig(X25519PrivateKey.generate(), peering_degree, max_mix_path_length)
|
2024-06-26 15:55:00 +09:00
|
|
|
for _ in range(num_nodes)
|
|
|
|
]
|
2024-06-27 17:32:22 +09:00
|
|
|
global_config = GlobalConfig(
|
|
|
|
MixMembership(
|
2024-06-27 18:04:51 +09:00
|
|
|
[
|
|
|
|
NodeInfo(node_config.private_key.public_key())
|
|
|
|
for node_config in node_configs
|
|
|
|
]
|
2024-06-27 17:32:22 +09:00
|
|
|
),
|
|
|
|
transmission_rate_per_sec,
|
|
|
|
max_mix_path_length,
|
2024-02-05 09:04:02 +01:00
|
|
|
)
|
2024-06-27 18:04:51 +09:00
|
|
|
key_map = {
|
|
|
|
node_config.private_key.public_key().public_bytes_raw(): node_config.private_key
|
|
|
|
for node_config in node_configs
|
|
|
|
}
|
|
|
|
return (global_config, node_configs, key_map)
|