From 5189a735c71c2c6e461172530cce8fac2a4e5e8e Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 00:42:02 +0200 Subject: [PATCH] Invite codes: one address per LAN, no unique-local IPv6, the macOS firewall prompt in the docs Co-Authored-By: Claude Opus 5.5 --- crates/horizon-friends/src/reach.rs | 29 +++++++++++++++-------------- docs/play-with-friends.md | 3 ++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/crates/horizon-friends/src/reach.rs b/crates/horizon-friends/src/reach.rs index 12550a59f..49e447466 100644 --- a/crates/horizon-friends/src/reach.rs +++ b/crates/horizon-friends/src/reach.rs @@ -64,8 +64,8 @@ fn virtual_interface(name: &str) -> bool { } /// This machine's addresses worth offering, best first: private IPv4 (the -/// LAN), shared IPv4 (Tailscale's 100.64/10, CGNAT), other IPv4, global -/// IPv6, unique-local IPv6 (some VPNs). No link-local; loopback on request. +/// LAN), shared IPv4 (Tailscale's 100.64/10, CGNAT), other IPv4, one global +/// IPv6. No link-local or unique-local; loopback on request. pub fn interface_addresses(loopback: bool) -> Vec { let mut found: Vec<(u8, IpAddr)> = Vec::new(); for i in if_addrs::get_if_addrs().unwrap_or_default() { @@ -88,8 +88,8 @@ pub fn interface_addresses(loopback: bool) -> Vec { IpAddr::V6(v6) if v6.is_loopback() || v6.is_unspecified() => continue, // fe80::/10. IpAddr::V6(v6) if v6.segments()[0] & 0xffc0 == 0xfe80 => continue, - // fc00::/7. - IpAddr::V6(v6) if v6.segments()[0] & 0xfe00 == 0xfc00 => 4, + // fc00::/7: VPNs that use it (Tailscale) also give an IPv4 address. + IpAddr::V6(v6) if v6.segments()[0] & 0xfe00 == 0xfc00 => continue, IpAddr::V6(_) => 3, }; if !found.iter().any(|(_, a)| *a == ip) { @@ -97,17 +97,18 @@ pub fn interface_addresses(loopback: bool) -> Vec { } } found.sort_by_key(|(r, _)| *r); - // One IPv6 address per kind is enough (temporary addresses multiply them). - let mut out = Vec::new(); - let mut v6_kinds = Vec::new(); - for (rank, ip) in found { - if ip.is_ipv6() { - if v6_kinds.contains(&rank) { - continue; - } - v6_kinds.push(rank); + // One global IPv6 address is enough (temporary addresses multiply + // them), and one address per /24 (Wi-Fi and Ethernet on the same LAN). + let mut out: Vec = Vec::new(); + for (_, ip) in found { + let same = out.iter().any(|o| match (o, ip) { + (IpAddr::V6(_), IpAddr::V6(_)) => true, + (IpAddr::V4(a), IpAddr::V4(b)) => a.octets()[..3] == b.octets()[..3], + _ => false, + }); + if !same { + out.push(ip); } - out.push(ip); } out } diff --git a/docs/play-with-friends.md b/docs/play-with-friends.md index 08f1ace8d..eae5082da 100644 --- a/docs/play-with-friends.md +++ b/docs/play-with-friends.md @@ -192,7 +192,8 @@ host's version), `host_unreachable`, `full`, `rate_limited`, `bad_request`. machine with a public address, e.g. a VPS). - **"Couldn't reach your friend's game"** (guest): the host's note under the code says why. A firewall on the host computer can also block the direct port: allow `horizon-client` on private and public - networks. + networks (Windows asks the first time; on macOS answer "Allow" when asked whether Horizon may accept + incoming network connections). - **"The code has a typo"**: copy it again; codes are only letters and digits in groups of five. - **"This short code works through your friend's relay"**: enter the relay's address under Join a friend, or ask for the full code.