feat!: universal redesign — drop Minecraft stack, single-crate architecture
- remove Java plugins (velocity/paper), dashboard, all MC-specific code
(handshake, death_code, varint, hostname-HMAC); available in history pre-v0.2
- merge crates/* into one package with src/bin/{rampart,rampart-manager,rampart-cli}
- ProtocolHandler trait + registry (no implementations yet), universal PoW kept
- XDP: universal L3/L4 filter (xdp/core/) + pluggable hook API (xdp/hooks/),
fix IPv6 saddr bug; clang build verified
- docs: bilingual knowledge base (docs/kb/: attacks x4, defense-levels,
practice x3), rewrite README/architecture for universal concept
- TODO.md v4.0: <=300-line module limit, competitor benchmark section (ref/)
- deploy/CI/docs cleanup: no MC references, new binary names
cargo build/clippy(-D warnings)/test green (55 tests)
This commit is contained in:
parent
7d15dfd45e
commit
08e26df73f
179 changed files with 5044 additions and 11519 deletions
|
|
@ -1,299 +0,0 @@
|
|||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub bind: BindConfig,
|
||||
#[serde(default)]
|
||||
pub backend: BackendConfig,
|
||||
#[serde(default)]
|
||||
pub hmac: HmacConfig,
|
||||
#[serde(default)]
|
||||
pub workers: WorkerConfig,
|
||||
#[serde(default)]
|
||||
pub limits: LimitsConfig,
|
||||
#[serde(default)]
|
||||
pub store: StoreConfig,
|
||||
#[serde(default)]
|
||||
pub xdp: XdpConfig,
|
||||
#[serde(default)]
|
||||
pub death_code: DeathCodeConfig,
|
||||
#[serde(default)]
|
||||
pub logging: LoggingConfig,
|
||||
#[serde(default)]
|
||||
pub metrics: MetricsConfig,
|
||||
#[serde(default)]
|
||||
pub pow: PowConfig,
|
||||
#[serde(default)]
|
||||
pub whitelist: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
pub struct BindConfig {
|
||||
#[serde(default = "default_bind_address")]
|
||||
pub address: String,
|
||||
#[serde(default = "default_bind_port")]
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
fn default_bind_address() -> String {
|
||||
"0.0.0.0".to_string()
|
||||
}
|
||||
fn default_bind_port() -> u16 {
|
||||
25565
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
pub struct BackendConfig {
|
||||
#[serde(default = "default_backend_address")]
|
||||
pub address: String,
|
||||
#[serde(default = "default_backend_port")]
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
fn default_backend_address() -> String {
|
||||
"127.0.0.1".to_string()
|
||||
}
|
||||
fn default_backend_port() -> u16 {
|
||||
25566
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct HmacConfig {
|
||||
#[serde(default)]
|
||||
pub secret: String,
|
||||
#[serde(default = "default_key_rotation")]
|
||||
pub key_rotation_interval_secs: u64,
|
||||
#[serde(default = "default_signature_ttl")]
|
||||
pub signature_ttl_secs: u64,
|
||||
}
|
||||
|
||||
fn default_key_rotation() -> u64 {
|
||||
3600
|
||||
}
|
||||
|
||||
fn default_signature_ttl() -> u64 {
|
||||
60
|
||||
}
|
||||
|
||||
impl Default for HmacConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
secret: String::new(),
|
||||
key_rotation_interval_secs: 3600,
|
||||
signature_ttl_secs: 60,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct WorkerConfig {
|
||||
#[serde(default = "default_worker_count")]
|
||||
pub count: usize,
|
||||
}
|
||||
|
||||
fn default_worker_count() -> usize {
|
||||
4
|
||||
}
|
||||
|
||||
impl Default for WorkerConfig {
|
||||
fn default() -> Self {
|
||||
Self { count: 4 }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct LimitsConfig {
|
||||
#[serde(default = "default_handshake_timeout")]
|
||||
pub handshake_timeout_secs: u64,
|
||||
#[serde(default = "default_max_connections_per_ip")]
|
||||
pub max_connections_per_ip: u32,
|
||||
#[serde(default = "default_rate_limit_login")]
|
||||
pub rate_limit_login_pps: f64,
|
||||
#[serde(default = "default_rate_limit_status")]
|
||||
pub rate_limit_status_pps: f64,
|
||||
#[serde(default = "default_rate_limit_burst")]
|
||||
pub rate_limit_burst: f64,
|
||||
}
|
||||
|
||||
fn default_handshake_timeout() -> u64 {
|
||||
5
|
||||
}
|
||||
fn default_max_connections_per_ip() -> u32 {
|
||||
10
|
||||
}
|
||||
fn default_rate_limit_login() -> f64 {
|
||||
5.0
|
||||
}
|
||||
fn default_rate_limit_status() -> f64 {
|
||||
2.0
|
||||
}
|
||||
fn default_rate_limit_burst() -> f64 {
|
||||
10.0
|
||||
}
|
||||
|
||||
impl Default for LimitsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
handshake_timeout_secs: 5,
|
||||
max_connections_per_ip: 10,
|
||||
rate_limit_login_pps: 5.0,
|
||||
rate_limit_status_pps: 2.0,
|
||||
rate_limit_burst: 10.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct StoreConfig {
|
||||
pub redis_url: Option<String>,
|
||||
#[serde(default = "default_blacklist_cache_ttl")]
|
||||
pub blacklist_cache_ttl_secs: u64,
|
||||
pub clickhouse_url: Option<String>,
|
||||
}
|
||||
|
||||
fn default_blacklist_cache_ttl() -> u64 {
|
||||
300
|
||||
}
|
||||
|
||||
impl Default for StoreConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
redis_url: None,
|
||||
blacklist_cache_ttl_secs: 300,
|
||||
clickhouse_url: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct XdpConfig {
|
||||
#[serde(default)]
|
||||
pub enabled: bool,
|
||||
#[serde(default = "default_xdp_interface")]
|
||||
pub interface: String,
|
||||
}
|
||||
|
||||
fn default_xdp_interface() -> String {
|
||||
"eth0".to_string()
|
||||
}
|
||||
|
||||
impl Default for XdpConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: false,
|
||||
interface: "eth0".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct LoggingConfig {
|
||||
#[serde(default = "default_log_level")]
|
||||
pub level: String,
|
||||
#[serde(default = "default_log_format")]
|
||||
pub format: String,
|
||||
}
|
||||
|
||||
fn default_log_level() -> String {
|
||||
"info".to_string()
|
||||
}
|
||||
fn default_log_format() -> String {
|
||||
"text".to_string()
|
||||
}
|
||||
|
||||
impl Default for LoggingConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
level: "info".to_string(),
|
||||
format: "text".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct MetricsConfig {
|
||||
#[serde(default = "default_metrics_enabled")]
|
||||
pub enabled: bool,
|
||||
#[serde(default = "default_metrics_port")]
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
fn default_metrics_enabled() -> bool {
|
||||
true
|
||||
}
|
||||
fn default_metrics_port() -> u16 {
|
||||
9090
|
||||
}
|
||||
|
||||
impl Default for MetricsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
port: 9090,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct DeathCodeConfig {
|
||||
#[serde(default = "default_death_code_enabled")]
|
||||
pub enabled: bool,
|
||||
#[serde(default = "default_death_code_ban_duration")]
|
||||
pub ban_duration_secs: u64,
|
||||
}
|
||||
|
||||
fn default_death_code_enabled() -> bool {
|
||||
true
|
||||
}
|
||||
fn default_death_code_ban_duration() -> u64 {
|
||||
3600
|
||||
}
|
||||
|
||||
impl Default for DeathCodeConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
ban_duration_secs: 3600,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct PowConfig {
|
||||
#[serde(default = "default_pow_enabled")]
|
||||
pub enabled: bool,
|
||||
#[serde(default = "default_pow_difficulty")]
|
||||
pub difficulty: u8,
|
||||
}
|
||||
|
||||
fn default_pow_enabled() -> bool {
|
||||
// PoW выключен по умолчанию: текущий текстовый challenge отправляется до
|
||||
// handshake и несовместим с ванильными MC-клиентами — они не умеют его
|
||||
// решать, поэтому при enabled=true никто не сможет зайти на сервер.
|
||||
// Включать только после появления клиентского мода или PoW, совместимого
|
||||
// с протоколом Minecraft.
|
||||
false
|
||||
}
|
||||
|
||||
fn default_pow_difficulty() -> u8 {
|
||||
4
|
||||
}
|
||||
|
||||
impl Default for PowConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: false,
|
||||
difficulty: 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_file(path: &str) -> anyhow::Result<Self> {
|
||||
let contents = fs::read_to_string(path)?;
|
||||
let config: Config = toml::from_str(&contents)?;
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue