| 1234567891011121314151617181920212223242526272829303132333435363738 |
- from __future__ import annotations
- import json
- from dataclasses import dataclass
- from pathlib import Path
- from typing import Literal
- Strategy = Literal["broadcast", "top2", "backup"]
- @dataclass
- class RelayNode:
- name: str
- host: str
- port: int
- token: str
- weight: int = 100
- @dataclass
- class Config:
- relays: list[RelayNode]
- strategy: Strategy = "top2"
- redundancy: int = 2
- tcp_warmup_bytes: int = 65536
- probe_interval: float = 15.0
- @classmethod
- def load(cls, path: str) -> "Config":
- raw = json.loads(Path(path).read_text())
- relays = [RelayNode(**item) for item in raw["relays"]]
- return cls(
- relays=relays,
- strategy=raw.get("strategy", "top2"),
- redundancy=raw.get("redundancy", 2),
- tcp_warmup_bytes=raw.get("tcp_warmup_bytes", 65536),
- probe_interval=raw.get("probe_interval", 15.0),
- )
|