feat: -c/--config and -i/--identity flags for multi-instance relay
Enables running multiple relays on the same machine: wzp-relay -c ~/.wzp1/config.toml -i ~/.wzp1/relay-identity --listen :4433 wzp-relay -c ~/.wzp2/config.toml -i ~/.wzp2/relay-identity --listen :4434 wzp-relay -c ~/.wzp3/config.toml -i ~/.wzp3/relay-identity --listen :4435 Config auto-creation: if the config file doesn't exist, writes an example config with all fields documented and commented. The relay starts with defaults but the file is ready to edit. Identity auto-generation: if the identity file doesn't exist, generates a new random seed (OsRng via wzp_crypto::Seed::generate) and saves it. Subsequent starts load the same identity. Short flags: -c for --config, -i for --identity. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -122,3 +122,56 @@ pub fn load_config(path: &str) -> Result<RelayConfig, anyhow::Error> {
|
||||
let config: RelayConfig = toml::from_str(&content)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// Load config from path, or create an example config file if it doesn't exist.
|
||||
pub fn load_or_create_config(path: &str) -> Result<RelayConfig, anyhow::Error> {
|
||||
let p = std::path::Path::new(path);
|
||||
if p.exists() {
|
||||
return load_config(path);
|
||||
}
|
||||
// Create parent directory if needed
|
||||
if let Some(parent) = p.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
// Write example config
|
||||
let example = EXAMPLE_CONFIG;
|
||||
std::fs::write(p, example)?;
|
||||
eprintln!("Created example config at {path} — edit it and restart.");
|
||||
let config: RelayConfig = toml::from_str(example)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// Example TOML configuration written when --config points to a non-existent file.
|
||||
pub const EXAMPLE_CONFIG: &str = r#"# WarzonePhone Relay Configuration
|
||||
# See docs/ADMINISTRATION.md for full reference.
|
||||
|
||||
# Listen address for client connections
|
||||
listen_addr = "0.0.0.0:4433"
|
||||
|
||||
# Maximum concurrent sessions
|
||||
# max_sessions = 100
|
||||
|
||||
# Prometheus metrics endpoint (uncomment to enable)
|
||||
# metrics_port = 9090
|
||||
|
||||
# featherChat auth endpoint (uncomment to enable)
|
||||
# auth_url = "https://chat.example.com/v1/auth/validate"
|
||||
|
||||
# Federation: peer relays we connect to (outbound)
|
||||
# [[peers]]
|
||||
# url = "relay-b.example.com:4433"
|
||||
# fingerprint = "aa:bb:cc:dd:..."
|
||||
# label = "Relay B"
|
||||
|
||||
# Federation: relays we trust inbound connections from
|
||||
# [[trusted]]
|
||||
# fingerprint = "ee:ff:00:11:..."
|
||||
# label = "Relay X"
|
||||
|
||||
# Global rooms bridged across all federated peers
|
||||
# [[global_rooms]]
|
||||
# name = "general"
|
||||
|
||||
# Debug: log packet headers for a room ("*" for all)
|
||||
# debug_tap = "*"
|
||||
"#;
|
||||
|
||||
Reference in New Issue
Block a user