freertc 0.1.32 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +204 -12
  2. package/bin/freertc.mjs +38 -633
  3. package/migrations/0001_initial.sql +43 -0
  4. package/migrations/0002_kademlia_overlay.sql +32 -0
  5. package/migrations/0003_announcement_role.sql +4 -0
  6. package/package.json +44 -17
  7. package/public/app.js +746 -169
  8. package/public/icon-180.png +0 -0
  9. package/public/icon-192.png +0 -0
  10. package/public/index.html +200 -799
  11. package/public/pigeonlogo.svg +51 -0
  12. package/scripts/d1-schema.sql +36 -0
  13. package/scripts/deploy-cloudflare.mjs +190 -0
  14. package/scripts/dev-server.mjs +54 -7
  15. package/scripts/generate-relay-identity.mjs +14 -0
  16. package/scripts/name-setup.mjs +332 -0
  17. package/scripts/node-relay.mjs +1128 -0
  18. package/scripts/project-bootstrap.mjs +13 -6
  19. package/scripts/wrangler-install-wizard.mjs +21 -11
  20. package/src/client.js +3468 -0
  21. package/src/direct/cert.js +95 -0
  22. package/src/direct/common.js +187 -0
  23. package/src/direct/dial.js +47 -0
  24. package/src/direct/directory.js +230 -0
  25. package/src/direct/listener.js +201 -0
  26. package/src/direct/lookup.js +75 -0
  27. package/src/direct/names.js +150 -0
  28. package/src/direct/node-relay-direct.js +170 -0
  29. package/src/direct/portmap.js +214 -0
  30. package/src/direct/reachable.js +40 -0
  31. package/src/direct/record.js +188 -0
  32. package/src/index.js +1401 -199
  33. package/src/kademlia.js +133 -0
  34. package/src/node/account-sync.js +98 -0
  35. package/src/node/cost-meter.js +92 -0
  36. package/src/node/d1-sqlite.js +108 -0
  37. package/src/node/data-dir.js +66 -0
  38. package/src/node/durable-object.js +58 -0
  39. package/src/node/lan-beacon.js +55 -0
  40. package/src/node/link-crypto.js +99 -0
  41. package/src/node/relay-links.js +385 -0
  42. package/src/node/relay-name.js +193 -0
  43. package/src/node/relay-pq.js +68 -0
  44. package/src/node/relay-stats.js +276 -0
  45. package/src/node/stats-page.js +281 -0
  46. package/src/node/websocket-pair.js +117 -0
  47. package/src/punch/offer.js +143 -0
  48. package/src/punch/rendezvous.js +124 -0
  49. package/src/punch/transport.js +257 -0
  50. package/src/relay-fetch.js +131 -0
  51. package/src/relay-id.js +74 -0
  52. package/src/relay-identity.js +298 -0
  53. package/src/relay-overlay.js +857 -0
  54. package/src/tunnel/client.js +276 -0
  55. package/src/tunnel/frames.js +64 -0
  56. package/src/tunnel/home.js +271 -0
  57. package/wrangler.template.jsonc +34 -9
  58. package/wrangler.workers-dev.jsonc +20 -3
  59. package/scripts/non-cloudflare-server.mjs +0 -433
  60. package/scripts/postinstall-message.mjs +0 -133
@@ -6,12 +6,19 @@ import { fileURLToPath } from 'node:url';
6
6
  const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
7
7
 
8
8
  export const PACKAGE_ROOT = path.resolve(SCRIPT_DIR, '..');
9
-
10
9
  const PROJECT_FILE_MAPPINGS = [
11
10
  ['src/index.js', 'src/index.js'],
11
+ ['src/kademlia.js', 'src/kademlia.js'],
12
+ ['src/relay-id.js', 'src/relay-id.js'],
13
+ ['src/relay-identity.js', 'src/relay-identity.js'],
14
+ ['src/relay-overlay.js', 'src/relay-overlay.js'],
12
15
  ['public/index.html', 'public/index.html'],
13
16
  ['public/app.js', 'public/app.js'],
17
+ ['migrations/0001_initial.sql', 'migrations/0001_initial.sql'],
18
+ ['migrations/0002_kademlia_overlay.sql', 'migrations/0002_kademlia_overlay.sql'],
14
19
  ['scripts/d1-schema.sql', 'scripts/d1-schema.sql'],
20
+ ['scripts/deploy-cloudflare.mjs', 'scripts/deploy-cloudflare.mjs'],
21
+ ['scripts/project-bootstrap.mjs', 'scripts/project-bootstrap.mjs'],
15
22
  ['wrangler.template.jsonc', 'wrangler.template.jsonc'],
16
23
  ['wrangler.workers-dev.jsonc', 'wrangler.workers-dev.jsonc']
17
24
  ];
@@ -65,22 +72,22 @@ export function ensureProjectFiles(projectRoot) {
65
72
  return [];
66
73
  }
67
74
 
68
- const synced = [];
75
+ const copied = [];
69
76
 
70
77
  for (const [sourceRelativePath, targetRelativePath] of PROJECT_FILE_MAPPINGS) {
71
78
  const sourcePath = path.join(PACKAGE_ROOT, sourceRelativePath);
72
79
  const targetPath = path.join(targetRoot, targetRelativePath);
73
80
 
74
- if (!fs.existsSync(sourcePath)) {
81
+ if (fs.existsSync(targetPath) || !fs.existsSync(sourcePath)) {
75
82
  continue;
76
83
  }
77
84
 
78
85
  fs.mkdirSync(path.dirname(targetPath), { recursive: true });
79
86
  fs.copyFileSync(sourcePath, targetPath);
80
- synced.push(targetRelativePath);
87
+ copied.push(targetRelativePath);
81
88
  }
82
89
 
83
- return synced;
90
+ return copied;
84
91
  }
85
92
 
86
93
  export function resolveWranglerCommand(cwd = process.cwd()) {
@@ -110,4 +117,4 @@ export function resolveWranglerCommand(cwd = process.cwd()) {
110
117
  }
111
118
 
112
119
  return { command: 'npx', baseArgs: ['wrangler'], source: 'npx' };
113
- }
120
+ }
@@ -15,6 +15,8 @@ const ROOT = resolveProjectRoot(process.cwd());
15
15
  const WRANGLER_CONFIG = path.join(ROOT, 'wrangler.jsonc');
16
16
  const WRANGLER_TEMPLATE = path.join(ROOT, 'wrangler.template.jsonc');
17
17
  const D1_SCHEMA_FILE = path.join(ROOT, 'scripts', 'd1-schema.sql');
18
+ // Seeds for joining the public network. Any relay can be one; a relay asks them one at a time.
19
+ const PUBLIC_SEED_URLS = 'wss://peer.ooo/ws,wss://decentralize.ooo/ws';
18
20
 
19
21
  function readProjectName(dir) {
20
22
  const pkgPath = path.join(dir, 'package.json');
@@ -319,10 +321,10 @@ function patchVar(text, varName, value) {
319
321
  if (re.test(text)) {
320
322
  return text.replace(re, `$1"${value}"`);
321
323
  }
322
- // If not found, inject after RELAY_PEER_ID line (best-effort)
324
+ // If not found, inject at the top of each vars block (best-effort)
323
325
  return text.replace(
324
- /("RELAY_PEER_ID"\s*:\s*"[^"]*")/g,
325
- `$1,\n "${varName}": "${value}"`
326
+ /("vars"\s*:\s*\{)/g,
327
+ `$1\n "${varName}": "${value}",`
326
328
  );
327
329
  }
328
330
 
@@ -416,7 +418,7 @@ async function main() {
416
418
  }
417
419
 
418
420
  if (copiedFiles.length > 0) {
419
- console.log('Overwrote package-managed files in this project:');
421
+ console.log('Copied package files into this project:');
420
422
  for (const file of copiedFiles) {
421
423
  console.log(` - ${file}`);
422
424
  }
@@ -447,7 +449,7 @@ async function main() {
447
449
  if (copiedFiles.length === 0) {
448
450
  console.log('Required worker files already exist in this project.');
449
451
  } else {
450
- console.log('Project files overwritten from the published freertc package.');
452
+ console.log('Project bootstrapped from the published freertc package.');
451
453
  }
452
454
 
453
455
  resolveWrangler();
@@ -570,18 +572,21 @@ async function main() {
570
572
 
571
573
  // Federation opt-in
572
574
  console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
573
- console.log('\nGlobal peer network: contribute your relay to peer.ooo federation?');
574
- console.log('When enabled, peers across all federated relays can discover each other.');
575
- const joinGlobal = await rl.question('Join global network at peer.ooo? [Y/n]: ');
575
+ console.log('\nPublic relay network: join it through its seed relays?');
576
+ console.log('When enabled, peers across all joined relays can discover each other.');
577
+ console.log('No relay is a hub: any relay can be a seed, and a seed points you at the relays closest to you.');
578
+ const joinGlobal = await rl.question('Join the public network? [Y/n]: ');
576
579
  let updatedText = fs.readFileSync(WRANGLER_CONFIG, 'utf8');
577
580
  if (yes(joinGlobal, true)) {
578
581
  const relayNameAnswer = (await rl.question('Relay display name [press Enter to skip]: ')).trim();
579
- updatedText = patchVar(updatedText, 'GLOBAL_RELAY_URL', 'wss://peer.ooo/ws');
582
+ updatedText = patchVar(updatedText, 'KADEMLIA_BOOTSTRAP_URLS', PUBLIC_SEED_URLS);
583
+ updatedText = removeVar(updatedText, 'GLOBAL_RELAY_URL');
580
584
  if (relayNameAnswer) {
581
585
  updatedText = patchVar(updatedText, 'RELAY_NAME', relayNameAnswer);
582
586
  }
583
- console.log('✓ GLOBAL_RELAY_URL set to wss://peer.ooo/ws');
587
+ console.log(`✓ KADEMLIA_BOOTSTRAP_URLS set to ${PUBLIC_SEED_URLS}`);
584
588
  } else {
589
+ updatedText = removeVar(updatedText, 'KADEMLIA_BOOTSTRAP_URLS');
585
590
  updatedText = removeVar(updatedText, 'GLOBAL_RELAY_URL');
586
591
  updatedText = removeVar(updatedText, 'RELAY_NAME');
587
592
  console.log('✓ Skipped global network — relay will operate standalone.');
@@ -667,7 +672,12 @@ async function main() {
667
672
 
668
673
  const doDeploy = await rl.question('Deploy now (freertc deploy)? [Y/n]: ');
669
674
  if (yes(doDeploy, true)) {
670
- const deployResult = runWranglerCapture(['deploy', '--env', 'production'], { allowFailure: true });
675
+ const deployResult = runCapture(process.execPath, [
676
+ path.join(PACKAGE_ROOT, 'scripts', 'deploy-cloudflare.mjs'),
677
+ '--env',
678
+ 'production',
679
+ '--skip-health-check'
680
+ ], { allowFailure: true });
671
681
  if (deployResult.stdout) process.stdout.write(deployResult.stdout);
672
682
  if (deployResult.stderr) process.stderr.write(deployResult.stderr);
673
683
  if (!deployResult.ok) {