web: 'Invite someone' page with the command to join through this node

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-19 10:43:46 +01:00
co-authored by Claude Sonnet 5.5
parent f83a305ee5
commit 85c26addf7
9 changed files with 220 additions and 3 deletions
+2 -1
View File
@@ -99,7 +99,8 @@ Add your own bootstrap peers with `--bootstrap /ip4/<addr>/tcp/<port>/p2p/<peer
**Letting a friend join through your node:** with your node running, `allmende
address` prints the command for them (`allmende run --bootstrap <your address>`).
It lists only addresses reachable from the internet, a direct one before one
through a relay; behind a router it can take a minute until there is one.
through a relay; behind a router it can take a minute until there is one. The
web UI shows the same under "Invite someone", with a copy button.
**Running a bootstrap node** helps everyone else connect, and nodes behind a home
router use it as a relay. It needs a public address:
+2 -1
View File
@@ -552,7 +552,8 @@ allmende address # how others can join through th
field of `/api/v1/status`: its addresses reachable from the internet (direct
first, then through a relay; none for loopback and private ones) and prints
`allmende run --bootstrap <address>`. It lets a person join through any node
when the built-in bootstrap name is down.
when the built-in bootstrap name is down. The web UI shows the same under
"Invite someone" (`#/invite`, in the menu once the owner has signed in).
`run` also takes `--no-default-bootstrap`, `--no-dht` and `--no-mdns`, and keeps
the peers it has met in `peers.json` next to its keys.
+76 -1
View File
@@ -193,6 +193,15 @@ var de = {
"detail.map": "Auf OpenStreetMap ansehen (externe Seite)",
"detail.contact": "Kontakt",
"nav.messages": "Meine Nachrichten",
"nav.invite": "Jemanden einladen",
"invite.title": "Jemanden einladen",
"invite.intro": "Wer \xFCber diesen Knoten ins Netz kommen m\xF6chte, startet seinen eigenen Knoten mit diesem Befehl:",
"invite.copy": "Befehl kopieren",
"invite.copied": "Kopiert.",
"invite.copyFailed": "Kopieren ging nicht. Markiere den Befehl und kopiere ihn von Hand.",
"invite.more": "Weitere Adressen dieses Knotens (eine gen\xFCgt):",
"invite.note": "Die Adresse gilt, solange dieser Knoten l\xE4uft. Hinter einem Router l\xE4uft der Weg \xFCber ein Relay, das sich \xE4ndern kann.",
"invite.none": "Dieser Knoten hat noch keine Adresse, die andere erreichen k\xF6nnen. Hinter einem Router dauert das eine Weile, bis er seine \xF6ffentliche Adresse kennt oder ein Relay hat; versuche es in einer Minute noch einmal. Bleibt es leer, hat der Knoten weder eine \xF6ffentliche Adresse noch ein Relay (siehe --public und --announce).",
"contact.title": "Anbieter kontaktieren",
"contact.intro": "Deine Nachricht wird verschl\xFCsselt. Das Netzwerk sieht nur, dass jemand zu dieser Anzeige geschrieben hat, nicht wer und nicht was. Du brauchst kein Konto. Die genaue Adresse gibt der Anbieter selbst frei.",
"contact.rules": "Die erste Nachricht muss kurz sein und darf keine Links enthalten. Das sch\xFCtzt vor Betrug; nach der ersten Antwort des Anbieters entf\xE4llt es.",
@@ -491,6 +500,15 @@ var en = {
"detail.map": "View on OpenStreetMap (external site)",
"detail.contact": "Contact",
"nav.messages": "My messages",
"nav.invite": "Invite someone",
"invite.title": "Invite someone",
"invite.intro": "Someone who wants to join the network through this node starts their own node with this command:",
"invite.copy": "Copy command",
"invite.copied": "Copied.",
"invite.copyFailed": "Copying failed. Select the command and copy it by hand.",
"invite.more": "Other addresses of this node (one is enough):",
"invite.note": "The address works while this node runs. Behind a router the way in goes through a relay, which can change.",
"invite.none": "This node has no address yet that others can reach. Behind a router it takes a while until it knows its public address or has a relay; try again in a minute. If it stays empty, the node has neither a public address nor a relay (see --public and --announce).",
"contact.title": "Contact the owner",
"contact.intro": "Your message is encrypted. The network only sees that someone wrote about this listing, not who and not what. You need no account. The owner releases the exact address themselves.",
"contact.rules": "The first message must be short and must not contain links. This protects against scams; it ends once the owner has replied.",
@@ -6207,6 +6225,61 @@ async function showPublish(editId) {
syncKind();
}
// src/invite.ts
async function showInvite() {
const root = document.getElementById("app");
document.body.classList.remove("wide");
clear(root);
const generation = state.generation;
let share = [];
let failed = false;
try {
const st = await getStatus();
share = Array.isArray(st.share) ? st.share.filter((a) => typeof a === "string") : [];
} catch {
failed = true;
}
if (generation !== state.generation) return;
const panel = h("section", { class: "panel" }, h("h1", null, t("invite.title")));
if (failed) {
append(panel, [h("p", { class: "error" }, t("status.unreachable"))]);
} else if (share.length === 0) {
append(panel, [h("p", null, t("invite.none"))]);
} else {
const command = `allmende run --bootstrap ${share[0]}`;
const status = h("span", { class: "ok", role: "status" });
append(panel, [
h("p", { class: "muted" }, t("invite.intro")),
h("pre", { class: "invite-command" }, command),
h(
"button",
{
type: "button",
onclick: async () => {
try {
await navigator.clipboard.writeText(command);
status.textContent = t("invite.copied");
} catch {
status.textContent = t("invite.copyFailed");
}
}
},
t("invite.copy")
),
" ",
status
]);
if (share.length > 1) {
append(panel, [
h("p", { class: "muted" }, t("invite.more")),
h("ul", null, ...share.slice(1).map((a) => h("li", null, h("code", null, a))))
]);
}
append(panel, [h("p", { class: "muted" }, t("invite.note"))]);
}
append(root, [panel]);
}
// src/places.ts
function fold(s) {
return s.normalize("NFD").replace(/\p{M}/gu, "").replace(/ß/g, "ss").toLowerCase();
@@ -6804,7 +6877,8 @@ function renderNav() {
clear(nav);
append(nav, [
h("a", { href: "#/messages" }, t("nav.messages")),
getToken() && h("a", { href: "#/mine" }, t("nav.owner"))
getToken() && h("a", { href: "#/mine" }, t("nav.owner")),
getToken() && h("a", { href: "#/invite" }, t("nav.invite"))
]);
}
function route() {
@@ -6832,6 +6906,7 @@ function route() {
else if (c) void showConversation(c[1], c[2], c[3]);
else if (path === "/messages") showInbox();
else if (path === "/mine/regions") showRegions();
else if (path === "/invite") void showInvite();
else if (path === "/mine/reports") void showReports();
else if (path === "/mine/new") void showPublish();
else if (edit) void showPublish(edit[1]);
+2
View File
@@ -18,6 +18,8 @@ export interface Status {
cert_expires_at?: number;
/** Whether the owner can renew that certificate here (it needs the recovery phrase). */
can_renew?: boolean;
/** Addresses others can pass to `--bootstrap` to join through this node; absent on older nodes. */
share?: string[];
}
async function getJSON(url: string): Promise<unknown> {
+23
View File
@@ -50,6 +50,18 @@ const de = {
"detail.map": "Auf OpenStreetMap ansehen (externe Seite)",
"detail.contact": "Kontakt",
"nav.messages": "Meine Nachrichten",
"nav.invite": "Jemanden einladen",
"invite.title": "Jemanden einladen",
"invite.intro":
"Wer über diesen Knoten ins Netz kommen möchte, startet seinen eigenen Knoten mit diesem Befehl:",
"invite.copy": "Befehl kopieren",
"invite.copied": "Kopiert.",
"invite.copyFailed": "Kopieren ging nicht. Markiere den Befehl und kopiere ihn von Hand.",
"invite.more": "Weitere Adressen dieses Knotens (eine genügt):",
"invite.note":
"Die Adresse gilt, solange dieser Knoten läuft. Hinter einem Router läuft der Weg über ein Relay, das sich ändern kann.",
"invite.none":
"Dieser Knoten hat noch keine Adresse, die andere erreichen können. Hinter einem Router dauert das eine Weile, bis er seine öffentliche Adresse kennt oder ein Relay hat; versuche es in einer Minute noch einmal. Bleibt es leer, hat der Knoten weder eine öffentliche Adresse noch ein Relay (siehe --public und --announce).",
"contact.title": "Anbieter kontaktieren",
"contact.intro":
"Deine Nachricht wird verschlüsselt. Das Netzwerk sieht nur, dass jemand zu dieser Anzeige geschrieben hat, nicht wer und nicht was. Du brauchst kein Konto. Die genaue Adresse gibt der Anbieter selbst frei.",
@@ -373,6 +385,17 @@ const en: Record<keyof typeof de, string> = {
"detail.map": "View on OpenStreetMap (external site)",
"detail.contact": "Contact",
"nav.messages": "My messages",
"nav.invite": "Invite someone",
"invite.title": "Invite someone",
"invite.intro": "Someone who wants to join the network through this node starts their own node with this command:",
"invite.copy": "Copy command",
"invite.copied": "Copied.",
"invite.copyFailed": "Copying failed. Select the command and copy it by hand.",
"invite.more": "Other addresses of this node (one is enough):",
"invite.note":
"The address works while this node runs. Behind a router the way in goes through a relay, which can change.",
"invite.none":
"This node has no address yet that others can reach. Behind a router it takes a while until it knows its public address or has a relay; try again in a minute. If it stays empty, the node has neither a public address nor a relay (see --public and --announce).",
"contact.title": "Contact the owner",
"contact.intro":
"Your message is encrypted. The network only sees that someone wrote about this listing, not who and not what. You need no account. The owner releases the exact address themselves.",
+67
View File
@@ -0,0 +1,67 @@
// "Invite someone": how a person can join the network through this node.
//
// It shows the command a friend runs to start their own node with this one as
// their first peer (the node's addresses that others can reach, from the status
// the node reports). Useful when the built-in bootstrap name is down, or to
// start a network of one's own.
import { getStatus } from "./api.ts";
import { append, clear, h } from "./dom.ts";
import { t } from "./i18n.ts";
import { state } from "./state.ts";
export async function showInvite(): Promise<void> {
const root = document.getElementById("app")!;
document.body.classList.remove("wide");
clear(root);
const generation = state.generation;
let share: string[] = [];
let failed = false;
try {
const st = await getStatus(); // fresh: a node behind a router learns its address after a while
share = Array.isArray(st.share) ? st.share.filter((a) => typeof a === "string") : [];
} catch {
failed = true;
}
if (generation !== state.generation) return; // the person went somewhere else meanwhile
const panel = h("section", { class: "panel" }, h("h1", null, t("invite.title")));
if (failed) {
append(panel, [h("p", { class: "error" }, t("status.unreachable"))]);
} else if (share.length === 0) {
append(panel, [h("p", null, t("invite.none"))]);
} else {
const command = `allmende run --bootstrap ${share[0]}`;
const status = h("span", { class: "ok", role: "status" });
append(panel, [
h("p", { class: "muted" }, t("invite.intro")),
h("pre", { class: "invite-command" }, command),
h(
"button",
{
type: "button",
onclick: async () => {
try {
await navigator.clipboard.writeText(command);
status.textContent = t("invite.copied");
} catch {
status.textContent = t("invite.copyFailed"); // select and copy by hand
}
},
},
t("invite.copy"),
),
" ",
status,
]);
if (share.length > 1) {
append(panel, [
h("p", { class: "muted" }, t("invite.more")),
h("ul", null, ...share.slice(1).map((a) => h("li", null, h("code", null, a)))),
]);
}
append(panel, [h("p", { class: "muted" }, t("invite.note"))]);
}
append(root, [panel]);
}
+3
View File
@@ -8,6 +8,7 @@ import { showOwner } from "./owner.ts";
import { reportPanel, showReports } from "./reports.ts";
import { getToken, setToken } from "./ownerApi.ts";
import { showPublish } from "./publish.ts";
import { showInvite } from "./invite.ts";
import { showRegions } from "./regions.ts";
import { state, verifyOpts } from "./state.ts";
import { verifyListing, type Listing, type Verdict } from "./verify.ts";
@@ -349,6 +350,7 @@ function renderNav(): void {
append(nav, [
h("a", { href: "#/messages" }, t("nav.messages")),
getToken() && h("a", { href: "#/mine" }, t("nav.owner")),
getToken() && h("a", { href: "#/invite" }, t("nav.invite")),
]);
}
@@ -379,6 +381,7 @@ function route(): void {
else if (c) void showConversation(c[1]!, c[2]!, c[3]!);
else if (path === "/messages") showInbox();
else if (path === "/mine/regions") showRegions();
else if (path === "/invite") void showInvite();
else if (path === "/mine/reports") void showReports();
else if (path === "/mine/new") void showPublish();
else if (edit) void showPublish(edit[1]);
+3
View File
@@ -206,6 +206,8 @@ export interface GatewayOptions {
regions?: string[];
/** The device certificate the node reports in /status; unset, it says nothing (an older node). */
cert?: { expires_at: number; can_renew: boolean };
/** The addresses the node says others can join through; unset, it says nothing (an older node). */
share?: string[];
}
export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
@@ -294,6 +296,7 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
listings: opts.listings.length,
difficulty: DIFFICULTY,
message_difficulty: 6,
...(opts.share ? { share: opts.share } : {}),
...(opts.cert ? { cert_expires_at: opts.cert.expires_at, can_renew: opts.cert.can_renew } : {}),
});
}
+42
View File
@@ -194,3 +194,45 @@ test("the difficulty reported by the node is enforced as a minimum", async () =>
await g.close();
}
});
const SHARE = "/ip4/8.8.8.8/tcp/4001/p2p/12D3KooWTest";
test("the invite page shows the command to join through this node", async () => {
const g = await startGateway({ listings: [], share: [SHARE, "/ip4/1.1.1.1/tcp/4001/p2p/12D3KooWRelay/p2p-circuit/p2p/12D3KooWTest"] });
try {
const page = openPage(g.url, "#/invite");
await page.waitFor(() => page.document.querySelector(".invite-command") !== null, "the command");
assert.equal(page.document.querySelector(".invite-command")!.textContent, `allmende run --bootstrap ${SHARE}`);
assert.match(page.document.querySelector("ul")!.textContent!, /p2p-circuit/, "the second address is listed");
page.close();
} finally {
await g.close();
}
});
test("the invite page says so when the node has no address to share, and for an older node", async () => {
for (const share of [[], undefined]) {
const g = await startGateway({ listings: [], ...(share ? { share } : {}) });
try {
const page = openPage(g.url, "#/invite", "de");
await page.waitFor(() => /noch keine Adresse/.test(page.document.body.textContent!), "the explanation");
assert.equal(page.document.querySelector(".invite-command"), null);
page.close();
} finally {
await g.close();
}
}
});
test("an address in the invite page is shown as text, never as HTML", async () => {
const g = await startGateway({ listings: [], share: [SHARE, `<img src=x onerror="window.__pwned=3">`] });
try {
const page = openPage(g.url, "#/invite");
await page.waitFor(() => page.document.querySelector("ul code") !== null, "the list");
assert.equal(page.document.querySelector("ul img"), null);
assert.equal((page.window as unknown as { __pwned?: number }).__pwned, undefined);
page.close();
} finally {
await g.close();
}
});