Reason Network: your team's coding agents, talking to each other. The engine behind `reason network`.
Rust agent-to-agentai-agentsclaude-codecodexcoding-agentscursorgrokirohmcpmcp-servermulti-agentpeer-to-peerreason
A join never dials this machine
Lars Talian874608954029
diff --git a/src/net.rs b/src/net.rsindex 979e3dd..2e4ea93 100644--- a/src/net.rs+++ b/src/net.rs@@ -222,9 +222,15 @@ pub struct Joined {pub unreachable: bool,}-/// Joins a team: asks each machine in turn (the ticket's, or the one an invite code points at) to let us in.+/// Joins a team: asks each machine in turn (the ticket's, or the one an invite code points at) to let us in. Never+/// this machine, which a link it made itself names first.pub async fn join(endpoint: &Endpoint, peers: &[EndpointAddr], req: &JoinRequest) -> Joined {- let mut last = anyhow!("the invite lists no machines");+ let peers: Vec<&EndpointAddr> = peers.iter().filter(|a| a.id != endpoint.id()).collect();+ let mut last = if peers.is_empty() {+ anyhow!("this link names only this computer, which can't let itself in: ask a teammate for a fresh link")+ } else {+ anyhow!("the invite lists no machines")+ };let mut refused = Refusals::default();let mut unreachable = false;for addr in peers {@@ -869,6 +875,25 @@ mod tests {}}+ #[tokio::test]+ async fn a_link_naming_only_this_machine_says_so() {+ let key = SecretKey::generate();+ let endpoint = bind(key.clone(), Some("https://relay.example.com"), false).await.unwrap();+ let req = JoinRequest {+ team: String::new(),+ secret: String::new(),+ person: "alex".into(),+ machine: "mini".into(),+ proof: None,+ owner_only: false,+ };+ let joined = join(&endpoint, &[EndpointAddr::new(key.public())], &req).await;+ endpoint.close().await;+ let e = joined.result.err().unwrap().to_string();+ assert!(e.contains("names only this computer"), "{e}");+ assert!(!joined.unreachable);+ }+#[test]fn the_default_relay_is_reasons_and_none_of_n0s() {let relays = default_relays();diff --git a/tests/e2e/two_machines.py b/tests/e2e/two_machines.pyindex 2475a3f..945b391 100644--- a/tests/e2e/two_machines.py+++ b/tests/e2e/two_machines.py@@ -223,6 +223,11 @@ check("…and gets the invite line", "Join the Reason Network: https://reasonmactime.sleep(3)out = cli("alex", "team")check("…which every machine takes", re.search(r"alex \(verified\)\s+mini", out) is not None, out)+# A link this machine made names it first: after leaving, it rejoins through the others on it.+mini_link = re.search(r"(https://\S+#rn1-\S+)", run(mini, "link")[1]).group(1)+run(mini, "leave")+_, out = run(mini, "join", mini_link, "--proof", proof("u_alex", "alex", mini_ep), "--no-setup")+check("a machine that left rejoins with a link it made itself", "Joined team vibes as alex on mini." in out, out)run(mini, "leave")run(mini, "stop")out = cli("alice", "join", link.group(1), "--as", "bob", "--no-setup")@@ -231,12 +236,16 @@ check("joining a second team is refused while yours has others, and says how to# Installed on its own and started a team by itself first: the team link still just works.sam = dict(env("alice"), REASON_NETWORK_HOME=os.path.join(D, "sam"), REASON_NETWORK_MACHINE="mini")r = subprocess.run([BIN, "init", "solo", "--as", "sam", "--no-setup"], env=sam, capture_output=True, text=True, timeout=90)+solo_link = re.search(r"(https://\S+#rn1-\S+)", run(sam, "link")[1]).group(1)# (With a link as earlier builds wrote it.)old_link = link.group(1).replace("#rn1-", "#tincan1")r = subprocess.run([BIN, "join", old_link, "--as", "sam", "--no-setup"], env=sam, capture_output=True, text=True, timeout=90)check("a team of one is swapped for the team you join (a tincan1 link)", "Joined team vibes as sam on mini." in r.stdout, r.stdout + r.stderr)check("…unverified, without a proof", re.search(r"sam\s+mini", r.stdout) is not None and "sam (verified)" not in r.stdout, r.stdout)subprocess.run([BIN, "leave"], env=sam, capture_output=True, timeout=60)+_, out = run(sam, "join", solo_link, "--as", "sam", "--no-setup")+check("a link that names only this machine, which left, says to ask for a fresh one",+ "names only this computer" in out and "fresh link" in out and "ourself" not in out, out)subprocess.run([BIN, "stop"], env=sam, capture_output=True)os.makedirs(os.path.join(D, "bob"), exist_ok=True)bob = dict(env("alice"), REASON_NETWORK_HOME=os.path.join(D, "bob"), REASON_NETWORK_MACHINE="nuc")