Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ All notable changes to Veil. Dates are dd/mm/yyyy.
port opening is on.
- The log says when each media link to another member comes up and how (direct, punched,
relayed), and once if it has not come up after 20 seconds, on both sides of the link.
- **The host is warned when guests cannot see each other.** Guests reach each other through
the host's own rendezvous. If someone is in the call but has not registered there after 10
seconds, the host sees "Guests may not see each other" and veil.log names who. Before, the
warning came only when the router refused the second port, and a port that opened but
could not be reached went unnoticed.
- Guests log whether they registered with the call's rendezvous, and why not.
- **A guest who joins is no longer missed by the others' first dial.** Members ask the
rendezvous to introduce them to a new guest as soon as it joins, often before the guest has
registered there. That request was dropped, so the first attempt waited out its timeout. The
rendezvous now passes it on when the guest registers.

## 0.1.18, 05/12/2026

Expand Down
1 change: 1 addition & 0 deletions crates/veil-app/src/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn call(your_name: &str, is_host: bool, now: Instant) -> Call {
router: crate::model::RouterPort::Off,
reach: crate::model::Reachable::Unknown,
server_down: false,
members_apart: false,
outbox: Vec::new(),
unread: 0,
moderators: Vec::new(),
Expand Down
30 changes: 29 additions & 1 deletion crates/veil-app/src/engine/helper_evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,41 @@ pub(super) struct HelperWatch {
impl HelperWatch {
/// The evidence at start. Write it with [`Self::write`].
pub fn start(call: &CallNode, needed: bool, hosting: bool) -> Self {
Self {
let watch = Self {
connected: call.has_rendezvous(),
issue: call.helper_issue(),
needed,
hosting,
};
// Hosts log their helper in the host loop.
if needed && !hosting {
crate::note!("{}", watch.line());
}
watch
}

/// Rewrites the row when the live state differs. Returns the new connection state.
pub fn refresh(&mut self, shared: &Shared, call: &CallNode) -> bool {
if self.observe(call.has_rendezvous(), call.helper_issue()) {
let watch = *self;
if watch.needed && !watch.hosting {
crate::note!("{}", watch.line());
}
shared.diagnose(|d| watch.write(d));
}
self.connected
}

/// The log line for this state. Other members reach this one through the rendezvous, so
/// a missing registration is what a failed member-to-member link most often comes down to.
fn line(self) -> String {
match (self.connected, self.issue) {
(true, _) => String::from("rendezvous: registered in the call's room"),
(false, Some(issue)) => format!("rendezvous: not registered: {issue:?}"),
(false, None) => String::from("rendezvous: not registered yet"),
}
}

/// Whether `connected` and `issue` change what the report shows.
fn observe(&mut self, connected: bool, issue: Option<HelperIssue>) -> bool {
// A lost connection with no recorded kind yet keeps the last typed one.
Expand Down Expand Up @@ -118,6 +136,16 @@ mod tests {
assert_eq!(report.problem, Some(Problem::NoUdpReply));
}

#[test]
fn the_log_line_says_whether_and_why_not_registered() {
let mut watch = watch();
assert_eq!(watch.line(), "rendezvous: not registered: Identity");
watch.issue = None;
assert_eq!(watch.line(), "rendezvous: not registered yet");
watch.connected = true;
assert_eq!(watch.line(), "rendezvous: registered in the call's room");
}

#[test]
fn a_guest_row_does_not_touch_hosting() {
let mut watch = HelperWatch {
Expand Down
29 changes: 19 additions & 10 deletions crates/veil-app/src/engine/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use veil_net::{Node, NodeAddr};
use veil_rendezvous::{Refusal, RendezvousServer, room_tag};
use veil_security::Identity;

mod apart;
mod forwarder_check;
mod hosting;
mod moderated;
Expand Down Expand Up @@ -129,8 +130,8 @@ pub async fn run(
(Some(node), Some(_)) => node.resolve_ipv6().await,
_ => None,
};
let (rendezvous, rendezvous6) = match configured {
Some(addr) => (addr, None),
let (rendezvous, rendezvous6, own_room) = match configured {
Some(addr) => (addr, None, None),
None => own_server(lan, Own::Rendezvous, &identity, room_id, config.local_only, v6)?,
};
let forwarder = match (
Expand Down Expand Up @@ -271,6 +272,8 @@ pub async fn run(
v6_port,
rendezvous6,
relay_v6_port,
own_room,
apart: apart::Unregistered::default(),
at6,
reach,
persistent,
Expand Down Expand Up @@ -362,15 +365,15 @@ enum Own {
/// Starts a rendezvous or forwarder for this call only: it serves `host`'s room `room_id` and
/// refuses everyone else's, so strangers who find its port cannot use this upload.
/// Returns its node and, for a rendezvous given the host's public IPv6 address `v6`, that
/// address when it listens there too.
/// address when it listens there too, and its room to read who registered.
fn own_server(
lan: Option<IpAddr>,
kind: Own,
host: &Identity,
room_id: [u8; 16],
local_only: bool,
v6: Option<Ipv6Addr>,
) -> Result<(NodeAddr, Option<Ipv6Addr>), String> {
) -> Result<(NodeAddr, Option<Ipv6Addr>, Option<apart::OwnRoom>), String> {
let what = match kind {
Own::Rendezvous => "rendezvous",
Own::Forwarder => "forwarder",
Expand Down Expand Up @@ -404,19 +407,25 @@ fn own_server(
};
// `bind_any` falls back to IPv4 where the system has no dual-stack socket.
let v6 = v6.filter(|_| dual && !local_only && node.ipv6());
let mut own_room = None;
match kind {
Own::Rendezvous => drop(tokio::spawn(
RendezvousServer::new(node)
.only_room(room_tag(&room_id), host.public())
.run(),
)),
Own::Rendezvous => {
let tag = room_tag(&room_id);
let server = RendezvousServer::new(node).only_room(tag, host.public());
own_room = Some(apart::OwnRoom {
roster: server.roster(),
tag,
host: host.public(),
});
drop(tokio::spawn(server.run()));
}
Own::Forwarder => drop(tokio::spawn(
ForwarderServer::new(node, Limits::default())
.only_host(host.public())
.run(),
)),
}
Ok((addr, v6))
Ok((addr, v6, own_room))
}

/// The link to show for `full`: a short one when that works as well, otherwise `full` itself.
Expand Down
137 changes: 137 additions & 0 deletions crates/veil-app/src/engine/host/apart.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//! Spots members who are in the call but not registered on the host's own rendezvous.
//!
//! Members link to each other only through the host's rendezvous: introductions for a punch,
//! and the relay when that fails. A member the rendezvous has never seen can reach the host
//! but no other member. Router answers cannot show this (a port can map and still be
//! unreachable), so the host reads who actually registered (`veil_rendezvous::Roster`).
//!
//! Invariants:
//! - A member gets [`GRACE`] to register after it is first seen in the call, since joiners
//! register while they connect and a rejoin re-registers.
//! - Each member is reported once when it goes overdue, and once when it registers after that.
//! - "Apart" needs two or more other members: with one, there is nobody to be apart from.
//! - Only ever compares keys; addresses never leave the rendezvous.

use std::collections::{HashMap, HashSet};
use std::time::{Duration, Instant};

use veil_rendezvous::Roster;
use veil_security::PublicId;

/// The host's own rendezvous room, read for who registered in it.
pub(in crate::engine) struct OwnRoom {
pub roster: Roster,
pub tag: [u8; 32],
pub host: PublicId,
}

impl OwnRoom {
pub fn registered(&self) -> Vec<PublicId> {
self.roster.registered(self.tag, self.host)
}
}

/// How long a member may be in the call without registering before it counts as overdue.
pub(super) const GRACE: Duration = Duration::from_secs(10);

/// What changed in one check.
#[derive(Debug, Default, PartialEq, Eq)]
pub(in crate::engine) struct Change {
/// Members that just went overdue.
pub late: Vec<PublicId>,
/// Overdue members that have now registered.
pub back: Vec<PublicId>,
/// Whether members are apart now: one is overdue and there is someone to be apart from.
pub apart: bool,
}

#[derive(Default)]
pub(in crate::engine) struct Unregistered {
/// Members not registered, with when that was first seen.
since: HashMap<PublicId, Instant>,
/// Members already reported overdue.
reported: HashSet<PublicId>,
/// Whether the host is shown the warning now.
pub shown: bool,
}

impl Unregistered {
/// Compares `others` (everyone in the call but the host) with the keys `registered` on
/// the rendezvous at `now`.
pub fn check(&mut self, others: &[PublicId], registered: &[PublicId], now: Instant) -> Change {
let registered: HashSet<&PublicId> = registered.iter().collect();
let mut change = Change::default();
self.since.retain(|member, _| others.contains(member));
self.reported.retain(|member| others.contains(member));
for member in others {
if registered.contains(member) {
self.since.remove(member);
if self.reported.remove(member) {
change.back.push(*member);
}
continue;
}
let since = *self.since.entry(*member).or_insert(now);
if now.duration_since(since) >= GRACE && self.reported.insert(*member) {
change.late.push(*member);
}
}
change.apart = !self.reported.is_empty() && others.len() >= 2;
change
}
}

#[cfg(test)]
mod tests {
use super::*;

fn key(n: u8) -> PublicId {
PublicId([n; 32])
}

#[test]
fn a_member_gets_the_grace_period_then_is_reported_once() {
let mut watch = Unregistered::default();
let start = Instant::now();
let others = [key(1), key(2)];
let registered = [key(1)];
let change = watch.check(&others, &registered, start);
assert!(
change.late.is_empty() && !change.apart,
"still within the grace period"
);
let change = watch.check(&others, &registered, start + GRACE);
assert_eq!(change.late, vec![key(2)]);
assert!(change.apart);
let change = watch.check(&others, &registered, start + GRACE * 2);
assert!(change.late.is_empty(), "reported once");
assert!(change.apart, "still apart");
}

#[test]
fn registering_late_is_reported_and_ends_apart() {
let mut watch = Unregistered::default();
let start = Instant::now();
let others = [key(1), key(2)];
watch.check(&others, &[key(1)], start);
watch.check(&others, &[key(1)], start + GRACE);
let change = watch.check(&others, &[key(1), key(2)], start + GRACE * 2);
assert_eq!(change.back, vec![key(2)]);
assert!(!change.apart);
}

#[test]
fn one_other_member_is_never_apart_and_leavers_are_forgotten() {
let mut watch = Unregistered::default();
let start = Instant::now();
let change = watch.check(&[key(1)], &[], start + GRACE);
assert!(!change.apart, "nobody to be apart from");
watch.check(&[key(1)], &[], start + GRACE * 2);
let change = watch.check(&[key(3), key(4)], &[key(3), key(4)], start + GRACE * 3);
assert!(
change.back.is_empty(),
"a member who left is not reported back"
);
assert!(!change.apart);
}
}
27 changes: 27 additions & 0 deletions crates/veil-app/src/engine/host/hosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use veil_call::{CallNode, HostEvent, HostHandle, RelayAddrs};
use veil_net::NodeAddr;
use veil_security::PublicId;

use super::apart::{OwnRoom, Unregistered};
use super::forwarder_check::{PendingPlan, checked_plan, finish_checked_plan, own_check};
use super::{
check, close_router, hosted_addresses, moderated, new_invite, next_router, next_v6,
Expand Down Expand Up @@ -65,6 +66,9 @@ pub(in crate::engine) struct Hosting {
pub rendezvous6: Option<Ipv6Addr>,
/// That rendezvous port's IPv6 pinhole, asked for with the call's.
pub relay_v6_port: Option<V6Port>,
/// The host's own rendezvous room, when it runs one (`apart.rs`).
pub own_room: Option<OwnRoom>,
pub apart: Unregistered,
pub at6: Option<SocketAddr>,
pub reach: Reachability,
pub persistent: bool,
Expand Down Expand Up @@ -117,6 +121,28 @@ impl Hosting {
self.shared.update(|view| view.handover.choices = shown);
}

/// Notes members in the call that never registered on this host's own rendezvous, so other
/// members cannot reach them, and warns while any are (`apart.rs`).
fn check_apart<L>(&mut self, roster: &[(L, PublicId)], me: PublicId) {
let Some(own) = &self.own_room else { return };
let others: Vec<PublicId> = roster.iter().map(|(_, d)| *d).filter(|d| *d != me).collect();
let change = self.apart.check(&others, &own.registered(), Instant::now());
for member in &change.late {
crate::note!(
"rendezvous: {} is in the call but not registered here, so other members cannot reach it",
short(member)
);
}
for member in &change.back {
crate::note!("rendezvous: {} registered", short(member));
}
if change.apart != self.apart.shown {
self.apart.shown = change.apart;
let apart = change.apart;
self.shared.update(|view| view.members_apart = apart);
}
}

/// Runs the call until this device leaves it, ends it or hands it over.
pub async fn run(mut self, commands: &mut UnboundedReceiver<Command>) -> Result<(), String> {
let me = self.me;
Expand Down Expand Up @@ -267,6 +293,7 @@ impl Hosting {
let down = self.server_down;
self.shared.update(|view| view.server_down = down);
}
self.check_apart(&roster, me);
if self.persistent && handing.is_none()
&& let Ok(choices) = self.host.choices().await
{
Expand Down
Loading