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:
Ludovic Marie
2026-10-14 23:47:56 +02:00
parent 5d29f31663
commit c7f30d2105
+16 -10
View File
@@ -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 {})",