@claw-link/gateway-host 0.3.0 → 0.3.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claw-link/gateway-host",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "ClawLink Host Gateway — a secure, outbound-only worker that bridges a local agent CLI (OpenClaw, Hermes, Claude, Codex, Cursor) to your ClawLink agents. No inbound ports; authenticated per-agent by a Host Token.",
5
5
  "homepage": "https://claw-link.co",
6
6
  "bin": {
@@ -8,30 +8,51 @@
8
8
  // consumer: buf = await p2p.fetch(bridge, cid, key) // resolve a peer + P2P fetch, else null
9
9
  //
10
10
  // `key` is a 32-byte Buffer (the per-transfer AEAD key, derived from the capsule's authorization).
11
+ const os = require('os');
11
12
  const core = require('./core');
12
13
 
14
+ // The QUIC socket binds 0.0.0.0 (all interfaces), but the native local_addr() reports 127.0.0.1 —
15
+ // dialable only on THIS machine. For Mac↔Mac on a LAN we must announce a routable IPv4 instead.
16
+ // (Cross-network/NAT hole-punching is a later rung; a peer that can't be reached falls back to relay.)
17
+ function lanIpv4() {
18
+ for (const list of Object.values(os.networkInterfaces())) {
19
+ for (const i of list || []) {
20
+ if (i && i.family === 'IPv4' && !i.internal) return i.address;
21
+ }
22
+ }
23
+ return null;
24
+ }
25
+
13
26
  class P2P {
14
27
  constructor(logger) {
15
28
  this.logger = logger || { info() {}, warn() {} };
16
29
  this.node = null;
17
30
  this.starting = null;
31
+ this.announceAddr = null; // routable addr we hand to peers (LAN IP : QUIC port)
18
32
  }
19
33
 
20
34
  available() {
21
35
  return !!(core.available && core.Transport);
22
36
  }
23
37
 
24
- /** Start the native QUIC node once (idempotent). Returns the local transport addr, or null. */
38
+ /** Start the native QUIC node once (idempotent). Returns the routable announce addr, or null. */
25
39
  async start() {
26
40
  if (!this.available()) return null;
27
- if (this.node) return this.node.localAddr();
41
+ if (this.announceAddr) return this.announceAddr;
28
42
  if (!this.starting) {
29
43
  this.starting = core.Transport.create()
30
- .then((n) => { this.node = n; this.logger.info(`p2p transport up (core ${core.version}) at ${n.localAddr()}`); return n; })
44
+ .then((n) => {
45
+ this.node = n;
46
+ const port = String(n.localAddr()).split(':').pop();
47
+ const ip = lanIpv4();
48
+ this.announceAddr = ip ? `${ip}:${port}` : n.localAddr(); // routable from other LAN hosts
49
+ this.logger.info(`p2p transport up (core ${core.version}) listening :${port}, announce ${this.announceAddr}`);
50
+ return n;
51
+ })
31
52
  .catch((e) => { this.logger.warn('p2p transport start failed (using central relay):', e.message); this.node = null; return null; });
32
53
  }
33
54
  await this.starting;
34
- return this.node ? this.node.localAddr() : null;
55
+ return this.node ? this.announceAddr : null;
35
56
  }
36
57
 
37
58
  /** Offer a blob for P2P fetch: AEAD-encrypt + store locally, announce cid→addr. Returns cid|null. */
package/src/worker.js CHANGED
@@ -19,8 +19,9 @@ const VERSION = (() => { try { return require('../package.json').version; } catc
19
19
  // Generous (matches the server's 15-min reaper) so legitimate long generations,
20
20
  // which keep producing output, are never the ones that hit it.
21
21
  const JOB_MAX_MS = Number(process.env.CLAWHOST_JOB_MAX_MS) || 15 * 60 * 1000;
22
- // Offer outputs larger than this over P2P (matches the engine's TRANSPORT_MIN_BYTES).
23
- const TRANSPORT_MIN_BYTES = 32 * 1024;
22
+ // Offer outputs larger than this over P2P (must match the engine's TRANSPORT_MIN_BYTES).
23
+ // Lowered to 1 KiB for validation so a normal reply triggers P2P; raise for production.
24
+ const TRANSPORT_MIN_BYTES = Number(process.env.CLAWHOST_TRANSPORT_MIN) || 1024;
24
25
 
25
26
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
26
27
  let stopping = false;