| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- from __future__ import annotations
- import json
- from dataclasses import dataclass
- from pathlib import Path
- from typing import Literal
- Strategy = Literal["broadcast", "top2", "top3", "top4", "backup"]
- @dataclass
- class RelayNode:
- name: str
- host: str
- port: int
- token: str
- weight: int = 100
- @dataclass
- class Config:
- relays: list[RelayNode]
- strategy: Strategy = "top3"
- redundancy: int = 3
- tcp_warmup_bytes: int = 1048576
- probe_interval: float = 15.0
- tcp_loser_grace_ms: int = 1500
- @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", "top3"),
- redundancy=raw.get("redundancy", 3),
- tcp_warmup_bytes=raw.get("tcp_warmup_bytes", 1048576),
- probe_interval=raw.get("probe_interval", 15.0),
- tcp_loser_grace_ms=raw.get("tcp_loser_grace_ms", 1500),
- )
|