Relay: RELAY_BIND listens on one address (tailnet-only test relays)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! `horizon-relay`: listens on `$PORT` (7000 when unset), limits from the
|
||||
//! `RELAY_*` variables (docs/play-with-friends.md). Prints counts every five
|
||||
//! minutes, nothing else.
|
||||
//! `horizon-relay`: listens on `$PORT` (7000 when unset; `RELAY_BIND` for one
|
||||
//! address), limits from the `RELAY_*` variables (docs/play-with-friends.md).
|
||||
//! Prints counts every five minutes, nothing else.
|
||||
use horizon_relay::{Config, Relay};
|
||||
use std::{net::TcpListener, time::Duration};
|
||||
|
||||
@@ -9,13 +9,19 @@ fn main() {
|
||||
.ok()
|
||||
.and_then(|p| p.trim().parse().ok())
|
||||
.unwrap_or(7000);
|
||||
// Dual-stack where the system allows it, else IPv4.
|
||||
let listener = TcpListener::bind(("::", port))
|
||||
.or_else(|_| TcpListener::bind(("0.0.0.0", port)))
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("horizon-relay: can't listen on port {port}: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
// RELAY_BIND picks one address (e.g. only a tailnet); else dual-stack
|
||||
// where the system allows it, else IPv4.
|
||||
let bind = std::env::var("RELAY_BIND")
|
||||
.ok()
|
||||
.filter(|b| !b.trim().is_empty());
|
||||
let listener = match bind {
|
||||
Some(address) => TcpListener::bind((address.trim(), port)),
|
||||
None => TcpListener::bind(("::", port)).or_else(|_| TcpListener::bind(("0.0.0.0", port))),
|
||||
}
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("horizon-relay: can't listen on port {port}: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
let config = Config::from_env();
|
||||
println!(
|
||||
"horizon-relay {} listening on port {port} (hosts {}, bridges {}, {} KiB/s per stream, per-address limits {})",
|
||||
|
||||
Reference in New Issue
Block a user