Let the owner change regions by place name, without a restart

The p2p node can now add and drop regions while running (SetRegions):
topics, validators, subscriptions and per-region peer discovery start and
stop with them, and a newly followed region catches up by sync.

PUT /api/v1/regions (owner token) applies a change and the node saves it in
regions.json, which wins over --region from then on. The owner's browser
gets a "Regions" page: search a place by name (GeoNames cities, offline,
CC BY 4.0), follow its cell plus any cell within about 40 km.

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-18 10:28:16 +01:00
co-authored by Claude Sonnet 5.5
parent e7bec4fb63
commit fd439710df
24 changed files with 70080 additions and 42 deletions
+67
View File
@@ -0,0 +1,67 @@
// Builds static/places.tsv, the offline list of place names the region picker
// searches, from GeoNames' cities15000.txt (https://download.geonames.org/export/dump/).
//
// curl -O https://download.geonames.org/export/dump/cities15000.zip && unzip cities15000.zip
// node scripts/places.mjs cities15000.txt > static/places.tsv
//
// The data is © GeoNames, licensed CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/):
// the app credits it where places are searched. The output is committed, so
// building the UI needs no download.
//
// One place per line: name, ASCII name, lat, lon, country, population, and for
// larger cities the other Latin-script names people use (Köln: Cologne, Colonia).
// Searching works offline; nothing about where a person looks leaves the device.
import { readFileSync } from "node:fs";
const file = process.argv[2];
if (!file) {
console.error("usage: node scripts/places.mjs cities15000.txt > static/places.tsv");
process.exit(2);
}
const LATIN = /^[\p{Script=Latin}\p{M}\p{Zs}'.\-]+$/u;
const ALT_MIN_POPULATION = 100_000; // exonyms matter for big cities only
const ALT_MAX = 30;
// German names that GeoNames' English-named entries do not carry ("Munich" has
// no "München"), keyed by "English name|country".
const GERMAN = {
"Munich|DE": "München", "Nuremberg|DE": "Nürnberg", "Prague|CZ": "Prag", "Geneva|CH": "Genf",
"Milan|IT": "Mailand", "Rome|IT": "Rom", "Florence|IT": "Florenz", "Venice|IT": "Venedig",
"Naples|IT": "Neapel", "Turin|IT": "Turin", "Warsaw|PL": "Warschau", "Copenhagen|DK": "Kopenhagen",
"Brussels|BE": "Brüssel", "Lisbon|PT": "Lissabon", "Athens|GR": "Athen", "Vienna|AT": "Wien",
"Cologne|DE": "Köln", "Hanover|DE": "Hannover", "Saint Petersburg|RU": "Sankt Petersburg",
"Moscow|RU": "Moskau", "Kyiv|UA": "Kiew", "Bucharest|RO": "Bukarest", "Belgrade|RS": "Belgrad",
"Seville|ES": "Sevilla", "Basel|CH": "Basel", "Bern|CH": "Bern", "Lucerne|CH": "Luzern",
"Strasbourg|FR": "Straßburg", "Luxembourg|LU": "Luxemburg", "Antwerp|BE": "Antwerpen",
};
const fold = (s) =>s.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
const out = [];
for (const line of readFileSync(file, "utf8").split("\n")) {
if (!line) continue;
const f = line.split("\t");
const [, name, ascii, alternates, lat, lon, , , cc] = f;
const population = Number(f[14]);
let alts = [];
if (population >= ALT_MIN_POPULATION) {
const have = new Set([fold(name), fold(ascii)]);
for (const a of alternates.split(",")) {
// Skip other scripts, codes ("CGN"), romanisations with apostrophes
// ("K'oln"), lower-case transliterations ("klwn"), and what we already have.
if (a.length < 4 || !LATIN.test(a) || a === a.toUpperCase() || a.includes("'")) continue;
if (a[0] !== a[0].toUpperCase() || have.has(fold(a))) continue;
have.add(fold(a));
alts.push(a);
}
// Names without spaces first (Cologne before "Colonia Claudia Ara Agrippinensium").
alts = alts.sort((x, y) => x.split(" ").length - y.split(" ").length || x.length - y.length).slice(0, ALT_MAX);
}
const de = GERMAN[`${name}|${cc}`];
if (de && fold(de) !== fold(name) && !alts.some((a) => fold(a) === fold(de))) alts.unshift(de);
out.push([name, ascii === name ? "" : ascii, Number(lat).toFixed(2), Number(lon).toFixed(2), cc, population, alts.join("|")].join("\t"));
}
process.stdout.write(out.join("\n") + "\n");