Lines 2-42javascript
2// SPDX-License-Identifier: Apache-2.0
4 * Quick-Tunnel escalation — #520 rung 5 of the NAT ladder.
5 * TypeScript port of iicp-client-python/tunnel.py (0f97ca1).
7 * When every NAT variant fails (no direct endpoint, no UPnP pinhole, no IPv6
8 * GUA, no relay-capable peer in the directory), the node can still become
9 * publicly reachable with ZERO account, domain, or router changes: spawn
10 * `cloudflared tunnel --url http://127.0.0.1:<port>` and register the issued
11 * `https://*.trycloudflare.com` URL as the endpoint.
13 * Lifecycle is fully automatic: setup (binary detection — never auto-installed),
14 * initiation (spawn + URL parse ≤20 s), supervision (bounded respawn; URL
15 * rotates → caller re-registers), teardown (close() idempotent + process-exit
16 * hook so a normal exit never orphans the child).
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.QuickTunnel = exports.INSTALL_HINT = exports.TUNNEL_DEAD_RETRY_MAX_MS = exports.TUNNEL_DEAD_RETRY_INITIAL_MS = exports.TUNNEL_CREATE_JITTER_MAX_MS = exports.TUNNEL_CREATE_LEASE_MS = exports.TUNNEL_CREATE_MIN_INTERVAL_MS = exports.TUNNEL_RATE_LIMIT_COOLDOWN_MS = exports.TUNNEL_DOH_TIMEOUT_MS
20exports.__resetQuickTunnelRateLimitForTests = __resetQuickTunnelRateLimitForTests;
21exports.cloudflaredPath = cloudflaredPath;
22exports.openQuickTunnel = openQuickTunnel;
23const node_child_process_1 = require("node:child_process");
24const fs = require("node:fs");
HighChild Process
Package source references child process execution.
dist/tunnel.jsView on unpkg · L22 25const os = require("node:os");
26const path = require("node:path");
27const URL_RE = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/;
28/** cloudflared usually prints the URL within ~5 s; 20 s covers slow first runs. */
29exports.TUNNEL_START_TIMEOUT_MS = 20_000;
31 * Bounded self-healing: this many CONSECUTIVE failed respawns (without the tunnel
32 * recovering to a healthy state in between) → give up. Resets to 0 once a respawned
33 * tunnel passes a health check, so a long-running relay heals indefinitely. (#538)
35exports.MAX_RESPAWNS = 3;
37 * Active liveness check of the tunnel's OWN public URL — catches the failure mode the
38 * process-exit watcher misses: cloudflared still running but the edge connection
39 * dropped, so the URL is unreachable while the node looks healthy (the recurring
40 * dead-endpoint bug, #538). Probe every interval; after this many consecutive failures,
41 * force a tunnel restart (kill → exit hook respawns → new URL → re-register).