hopwire 0.1.8 → 0.1.9
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/README.md +2 -0
- package/dist/bin.js +5 -1
- package/dist/cli.js +178 -10
- package/dist/commands/connect.js +23 -7
- package/dist/commands/doctor.js +27 -3
- package/dist/commands/http.js +7 -1
- package/dist/commands/init.js +329 -0
- package/dist/commands/up.js +7 -1
- package/dist/commands/watch.js +22 -6
- package/dist/config-template.js +70 -0
- package/dist/config.js +8 -2
- package/dist/control-plane-client.js +28 -0
- package/dist/main.js +1 -0
- package/dist/output.js +29 -1
- package/dist/p2p.js +249 -24
- package/dist/prompt.js +63 -0
- package/dist/relay.js +545 -0
- package/dist/serve.js +13 -0
- package/node_modules/@hopwire/protocol/dist/index.d.ts +1 -0
- package/node_modules/@hopwire/protocol/dist/index.js +1 -0
- package/node_modules/@hopwire/protocol/dist/relay.d.ts +81 -0
- package/node_modules/@hopwire/protocol/dist/relay.js +102 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ hopwire http 3000 # record and inspect the traffic of the service on
|
|
|
15
15
|
hopwire http 3000 --share # let teammates watch and replay it, peer to peer
|
|
16
16
|
hopwire login # once, for public URLs
|
|
17
17
|
hopwire http 3000 --public # a public HTTPS URL for the service
|
|
18
|
+
hopwire init # write a hopwire.yaml for every service of the project
|
|
19
|
+
hopwire up # start them all
|
|
18
20
|
```
|
|
19
21
|
|
|
20
22
|
Documentation: https://hopwire.to/docs. Terms: https://hopwire.to/terms. Security reports:
|
package/dist/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { openBrowser } from './browser.js';
|
|
3
3
|
import { main } from './main.js';
|
|
4
|
-
import { promptHidden } from './prompt.js';
|
|
4
|
+
import { promptHidden, promptLine } from './prompt.js';
|
|
5
5
|
import { decorate, wantsColor } from './style.js';
|
|
6
6
|
const color = wantsColor(process.stdout, process.env);
|
|
7
7
|
await main({
|
|
@@ -17,6 +17,10 @@ await main({
|
|
|
17
17
|
promptSecret: process.stdin.isTTY
|
|
18
18
|
? (question, stop) => promptHidden(question, process.stdin, process.stderr, stop)
|
|
19
19
|
: undefined,
|
|
20
|
+
// hopwire init asks its questions on standard error, so standard output keeps the lines of the result
|
|
21
|
+
promptLine: process.stdin.isTTY
|
|
22
|
+
? (question, stop) => promptLine(question, process.stdin, process.stderr, stop)
|
|
23
|
+
: undefined,
|
|
20
24
|
// hopwire login opens its sign-in page; the URL is printed too
|
|
21
25
|
openBrowser: (url) => openBrowser(url),
|
|
22
26
|
});
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import { INSPECTOR_DEFAULT_PORT, LOCAL_ENTRY_DEFAULT_PORT, RANDOM_SUBDOMAIN_BYTE
|
|
|
7
7
|
import { bindEdge, boundEdge, readAccount } from './account.js';
|
|
8
8
|
import { startConnect } from './commands/connect.js';
|
|
9
9
|
import { doctor } from './commands/doctor.js';
|
|
10
|
+
import { init } from './commands/init.js';
|
|
10
11
|
import { startHttpTunnel } from './commands/http.js';
|
|
11
12
|
import { login, logout } from './commands/login.js';
|
|
12
13
|
import { startMcp } from './commands/mcp.js';
|
|
@@ -24,6 +25,7 @@ const USAGE = `Usage: hopwire <command>
|
|
|
24
25
|
|
|
25
26
|
Private mode: no account, no servers of ours, end-to-end encrypted between you and the teammates you choose.
|
|
26
27
|
With --team (Team plan) your account's control plane names who gets in; the traffic stays direct.
|
|
28
|
+
With --relay as well, a connection that cannot be made directly goes through our edge, end-to-end encrypted.
|
|
27
29
|
Public mode (--public): a public URL for the service through the edge; it needs an account (hopwire login).
|
|
28
30
|
|
|
29
31
|
Start here:
|
|
@@ -38,6 +40,8 @@ Start here:
|
|
|
38
40
|
Commands:
|
|
39
41
|
hopwire http <port> Forward a local entry point to http://127.0.0.1:<port>, log every exchange
|
|
40
42
|
and show the traffic in the inspector
|
|
43
|
+
hopwire init Write a commented hopwire.yaml for hopwire up by answering a few questions
|
|
44
|
+
(or from --service name=port ... --yes, without questions)
|
|
41
45
|
hopwire up Start every service of hopwire.yaml: one traffic log and one inspector for all,
|
|
42
46
|
public URLs and P2P sharing as the file says
|
|
43
47
|
hopwire id Print the public key of this machine (creates the identity on first use)
|
|
@@ -66,6 +70,10 @@ Options for http:
|
|
|
66
70
|
(Team plan). Needs an account: run hopwire login first. The control plane of the
|
|
67
71
|
account names the keys of the team and gets the public key of this machine; this is
|
|
68
72
|
the one thing private mode asks a server. Your traffic still passes none
|
|
73
|
+
--relay With --team: teammates whose network allows no direct P2P connection (UDP blocked,
|
|
74
|
+
or both sides behind a strict NAT) come in through the relay of your account's edge
|
|
75
|
+
on port 443. End-to-end encrypted: the edge passes on bytes it cannot read, and sees
|
|
76
|
+
addresses, your organisation, keys and byte counts. Direct P2P is always tried first
|
|
69
77
|
--public Serve the service under a public URL through the edge. Needs an account: run
|
|
70
78
|
hopwire login first; the edge is the one its control plane names. HOPWIRE_EDGE_URL
|
|
71
79
|
sets another one. A local edge (ws://127.0.0.1:8787) can be used without an account,
|
|
@@ -86,11 +94,26 @@ Options for http:
|
|
|
86
94
|
--no-ws-capture Log the handshake of a WebSocket but not its messages (by default both directions
|
|
87
95
|
are recorded, up to 64 KiB per message and 2 MB or 10,000 messages per WebSocket)
|
|
88
96
|
|
|
97
|
+
Options for init:
|
|
98
|
+
--config <path> The file to write (default ${HOPWIRE_YAML_FILE} in the working directory). An existing file
|
|
99
|
+
is never replaced. Nothing is contacted; a public service takes the edge and the
|
|
100
|
+
control plane of the account on this machine (hopwire login)
|
|
101
|
+
--yes Ask nothing and write exactly what the flags below say; what is not given stays off
|
|
102
|
+
--service <name>=<port|url>
|
|
103
|
+
With --yes: a service and its port (or an http URL on this machine); can be given
|
|
104
|
+
several times
|
|
105
|
+
--public <name> With --yes: serve this service under a public URL (needs hopwire login); can be
|
|
106
|
+
given several times
|
|
107
|
+
--subdomain <name>=<sub>
|
|
108
|
+
With --yes: the subdomain of a public service, reserved by your organisation
|
|
109
|
+
--share, --team, --allow-agents
|
|
110
|
+
With --yes: p2p.share, p2p.team and p2p.allowAgents, as for http
|
|
111
|
+
|
|
89
112
|
Options for up:
|
|
90
113
|
--config <path> The config file (default ${HOPWIRE_YAML_FILE} in the working directory). A public service
|
|
91
114
|
takes the URL of the edge from edge.url in the file. With controlPlane.url in the file
|
|
92
115
|
it uses your account (hopwire login), without it the dev token in HOPWIRE_DEV_TOKEN.
|
|
93
|
-
p2p.team in the file is --team of http
|
|
116
|
+
p2p.team in the file is --team of http, p2p.relay is --relay
|
|
94
117
|
--no-agent, --agent As for http, for every service; agent: false in the file turns it off too
|
|
95
118
|
--force As for http: stop the tunnel that holds the data directory first
|
|
96
119
|
|
|
@@ -119,6 +142,8 @@ Options for connect:
|
|
|
119
142
|
service); without it only 127.0.0.1:<port> and localhost:<port>. Can be given several times
|
|
120
143
|
--team For a teammate who shares with --team: registers the key of this machine with your
|
|
121
144
|
organisation (hopwire login first) and connects only to a machine of one of its members
|
|
145
|
+
--relay With --team: when no direct connection comes about, go through the relay of your
|
|
146
|
+
account's edge (the teammate shares with --relay); end-to-end encrypted
|
|
122
147
|
|
|
123
148
|
Options for watch:
|
|
124
149
|
--replay-target <url> Local service that replays are sent to, for example http://127.0.0.1:3000;
|
|
@@ -126,6 +151,8 @@ Options for watch:
|
|
|
126
151
|
--inspect <port> Loopback port of the inspector (default ${INSPECTOR_DEFAULT_PORT}, 0 picks a free one)
|
|
127
152
|
--team For a teammate who shares with --team: registers the key of this machine with your
|
|
128
153
|
organisation (hopwire login first), so the sharer lets it in
|
|
154
|
+
--relay With --team: when no direct connection comes about, go through the relay of your
|
|
155
|
+
account's edge (the teammate shares with --relay); end-to-end encrypted
|
|
129
156
|
--agent Let a coding agent on this machine read the exchanges your teammate allowed for
|
|
130
157
|
agents (they share with --allow-agents) through hopwire mcp; never on without it.
|
|
131
158
|
What the agent reads goes to its model provider
|
|
@@ -159,6 +186,7 @@ const COMMAND_OPTIONS = {
|
|
|
159
186
|
'share',
|
|
160
187
|
'allow',
|
|
161
188
|
'team',
|
|
189
|
+
'relay',
|
|
162
190
|
'allow-agents',
|
|
163
191
|
'no-ws-capture',
|
|
164
192
|
'public',
|
|
@@ -170,8 +198,8 @@ const COMMAND_OPTIONS = {
|
|
|
170
198
|
up: ['config', 'agent', 'no-agent', 'force'],
|
|
171
199
|
id: [],
|
|
172
200
|
rotate: [],
|
|
173
|
-
connect: ['port', 'service', 'allow-host', 'team'],
|
|
174
|
-
watch: ['replay-target', 'inspect', 'team', 'agent', 'force'],
|
|
201
|
+
connect: ['port', 'service', 'allow-host', 'team', 'relay'],
|
|
202
|
+
watch: ['replay-target', 'inspect', 'team', 'relay', 'agent', 'force'],
|
|
175
203
|
login: ['api', 'token', 'no-browser'],
|
|
176
204
|
logout: [],
|
|
177
205
|
mcp: ['read-only'],
|
|
@@ -179,6 +207,11 @@ const COMMAND_OPTIONS = {
|
|
|
179
207
|
};
|
|
180
208
|
/** Parses the arguments and starts the command. Resolves with what keeps running, or null when the command is done. */
|
|
181
209
|
export async function run(argv, io) {
|
|
210
|
+
// hopwire init takes --public and --subdomain with other values than http, so it has a parser of its own
|
|
211
|
+
if (commandOf(argv) === 'init') {
|
|
212
|
+
await runInit(argv, io);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
182
215
|
const { values, positionals } = parse(argv);
|
|
183
216
|
const [command, ...rest] = positionals;
|
|
184
217
|
if (values.help) {
|
|
@@ -205,9 +238,7 @@ export async function run(argv, io) {
|
|
|
205
238
|
if (values['data-dir'] === '') {
|
|
206
239
|
throw new UsageError('--data-dir needs the path of a directory');
|
|
207
240
|
}
|
|
208
|
-
|
|
209
|
-
const home = io.env.HOPWIRE_HOME === '' ? undefined : io.env.HOPWIRE_HOME;
|
|
210
|
-
const dataDir = values['data-dir'] ?? home ?? path.join(os.homedir(), '.hopwire');
|
|
241
|
+
const dataDir = resolveDataDir(values['data-dir'], io.env);
|
|
211
242
|
if (command === 'id') {
|
|
212
243
|
noMoreArguments(rest, 0, 'hopwire id');
|
|
213
244
|
io.print((await loadOrCreateIdentity(dataDir)).publicKey.toString('hex'));
|
|
@@ -284,6 +315,7 @@ export async function run(argv, io) {
|
|
|
284
315
|
const port = parsePort(values.port, '--port', 0);
|
|
285
316
|
const service = parseService(values.service);
|
|
286
317
|
const allowHosts = (values['allow-host'] ?? []).map(parseAllowedHost);
|
|
318
|
+
relayNeedsTeam(values);
|
|
287
319
|
return startConnect({
|
|
288
320
|
peerKey,
|
|
289
321
|
port,
|
|
@@ -291,6 +323,7 @@ export async function run(argv, io) {
|
|
|
291
323
|
allowHosts,
|
|
292
324
|
// The account is only read for --team: without it private mode never looks at it
|
|
293
325
|
team: values.team ? await teamAccess('--team', dataDir) : undefined,
|
|
326
|
+
relay: values.relay ? await relayAccess('--relay', dataDir) : undefined,
|
|
294
327
|
dataDir,
|
|
295
328
|
print: io.print,
|
|
296
329
|
bootstrap: parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP),
|
|
@@ -302,6 +335,7 @@ export async function run(argv, io) {
|
|
|
302
335
|
const logKey = parseKey(rest[0], 'The log key');
|
|
303
336
|
const replayTarget = values['replay-target'] === undefined ? null : parseReplayTarget(values['replay-target']);
|
|
304
337
|
const inspectPort = parsePort(values.inspect ?? String(INSPECTOR_DEFAULT_PORT), '--inspect', 0);
|
|
338
|
+
relayNeedsTeam(values);
|
|
305
339
|
return startWatch({
|
|
306
340
|
force: values.force ?? false,
|
|
307
341
|
logKey,
|
|
@@ -309,6 +343,7 @@ export async function run(argv, io) {
|
|
|
309
343
|
inspectPort,
|
|
310
344
|
// The account is only read for --team: without it private mode never looks at it
|
|
311
345
|
team: values.team ? await teamAccess('--team', dataDir) : undefined,
|
|
346
|
+
relay: values.relay ? await relayAccess('--relay', dataDir) : undefined,
|
|
312
347
|
dataDir,
|
|
313
348
|
print: io.print,
|
|
314
349
|
bootstrap: parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP),
|
|
@@ -323,10 +358,7 @@ export async function run(argv, io) {
|
|
|
323
358
|
throw new UsageError('--config needs the path of a config file');
|
|
324
359
|
}
|
|
325
360
|
const cwd = io.cwd ?? process.cwd();
|
|
326
|
-
const file =
|
|
327
|
-
// Sentences about the file name it as the user would: relative to the working directory when it lies in it
|
|
328
|
-
const relative = path.relative(cwd, file);
|
|
329
|
-
const shown = relative.startsWith('..') || path.isAbsolute(relative) ? file : relative;
|
|
361
|
+
const { file, shown } = configFile(cwd, values.config);
|
|
330
362
|
const config = await loadConfig(file, values.config !== undefined, shown);
|
|
331
363
|
const update = createUpdateNotice(readVersion());
|
|
332
364
|
const running = await startUp({
|
|
@@ -341,6 +373,8 @@ export async function run(argv, io) {
|
|
|
341
373
|
: {}),
|
|
342
374
|
// The account is only read for p2p.team: without it private mode never looks at it
|
|
343
375
|
team: config.team ? await teamAccessOfFile(shown, config, dataDir) : undefined,
|
|
376
|
+
// The edge is only contacted for p2p.relay, and then only through the relay
|
|
377
|
+
relay: config.relay ? await relayAccess('p2p.relay', dataDir) : undefined,
|
|
344
378
|
bootstrap: config.share ? parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP) : undefined,
|
|
345
379
|
agent: agent ?? config.agent ?? undefined,
|
|
346
380
|
signal: io.signal,
|
|
@@ -363,6 +397,7 @@ export async function run(argv, io) {
|
|
|
363
397
|
if (values['allow-agents'] && !values.share) {
|
|
364
398
|
throw new UsageError('--allow-agents only works together with --share');
|
|
365
399
|
}
|
|
400
|
+
relayNeedsTeam(values);
|
|
366
401
|
if (values.team && allow.length > 0) {
|
|
367
402
|
throw new UsageError('--team and --allow cannot be combined: with --team the team is the list');
|
|
368
403
|
}
|
|
@@ -390,6 +425,7 @@ export async function run(argv, io) {
|
|
|
390
425
|
allow,
|
|
391
426
|
// The account is only read for --team: without it private mode never looks at it
|
|
392
427
|
team: values.team ? await teamAccess('--team', dataDir) : undefined,
|
|
428
|
+
relay: values.relay ? await relayAccess('--relay', dataDir) : undefined,
|
|
393
429
|
bootstrap: values.share ? parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP) : undefined,
|
|
394
430
|
// Edge URL, token and account are only read for --public: private mode never looks at them
|
|
395
431
|
public: values.public ? update.watch(await parsePublic(values.subdomain, io.env, dataDir)) : undefined,
|
|
@@ -401,6 +437,110 @@ export async function run(argv, io) {
|
|
|
401
437
|
update.print(io.print);
|
|
402
438
|
return running;
|
|
403
439
|
}
|
|
440
|
+
/** The data directory: --data-dir, else HOPWIRE_HOME, else ~/.hopwire. */
|
|
441
|
+
function resolveDataDir(option, env) {
|
|
442
|
+
// A variable that is set but empty counts as not set; as a path it would be the working directory
|
|
443
|
+
const home = env.HOPWIRE_HOME === '' ? undefined : env.HOPWIRE_HOME;
|
|
444
|
+
return option ?? home ?? path.join(os.homedir(), '.hopwire');
|
|
445
|
+
}
|
|
446
|
+
/** The hopwire.yaml of up and init, and how sentences name it: relative to the working directory when it lies in it. */
|
|
447
|
+
function configFile(cwd, option) {
|
|
448
|
+
const file = path.resolve(cwd, option ?? HOPWIRE_YAML_FILE);
|
|
449
|
+
const relative = path.relative(cwd, file);
|
|
450
|
+
return { file, shown: relative.startsWith('..') || path.isAbsolute(relative) ? file : relative };
|
|
451
|
+
}
|
|
452
|
+
/** The command of a command line: the first argument that is neither an option nor the value of --data-dir. */
|
|
453
|
+
function commandOf(argv) {
|
|
454
|
+
for (let index = 0; index < argv.length; index++) {
|
|
455
|
+
const argument = argv[index] ?? '';
|
|
456
|
+
if (argument === '--') {
|
|
457
|
+
return argv[index + 1];
|
|
458
|
+
}
|
|
459
|
+
if (argument === '--data-dir') {
|
|
460
|
+
index++;
|
|
461
|
+
}
|
|
462
|
+
else if (!argument.startsWith('-')) {
|
|
463
|
+
return argument;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
/** hopwire init: its own options, then the questions or the flags of --yes. */
|
|
469
|
+
async function runInit(argv, io) {
|
|
470
|
+
let parsed;
|
|
471
|
+
try {
|
|
472
|
+
parsed = parseArgs({
|
|
473
|
+
args: argv,
|
|
474
|
+
allowPositionals: true,
|
|
475
|
+
options: {
|
|
476
|
+
help: { type: 'boolean', short: 'h' },
|
|
477
|
+
version: { type: 'boolean' },
|
|
478
|
+
'data-dir': { type: 'string' },
|
|
479
|
+
config: { type: 'string' },
|
|
480
|
+
yes: { type: 'boolean' },
|
|
481
|
+
service: { type: 'string', multiple: true },
|
|
482
|
+
public: { type: 'string', multiple: true },
|
|
483
|
+
subdomain: { type: 'string', multiple: true },
|
|
484
|
+
share: { type: 'boolean' },
|
|
485
|
+
team: { type: 'boolean' },
|
|
486
|
+
'allow-agents': { type: 'boolean' },
|
|
487
|
+
},
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
const problem = argumentProblem(error);
|
|
492
|
+
throw new UsageError(problem.endsWith(' is not an option of hopwire') ? `${problem} init` : problem);
|
|
493
|
+
}
|
|
494
|
+
const { values, positionals } = parsed;
|
|
495
|
+
if (values.help) {
|
|
496
|
+
io.print(USAGE);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (values.version) {
|
|
500
|
+
io.print(readVersion());
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
noMoreArguments(positionals, 1, 'hopwire init [--config <path>]');
|
|
504
|
+
if (values['data-dir'] === '') {
|
|
505
|
+
throw new UsageError('--data-dir needs the path of a directory');
|
|
506
|
+
}
|
|
507
|
+
if (values.config === '') {
|
|
508
|
+
throw new UsageError('--config needs the path of the file to write');
|
|
509
|
+
}
|
|
510
|
+
const answered = values.service !== undefined ||
|
|
511
|
+
values.public !== undefined ||
|
|
512
|
+
values.subdomain !== undefined ||
|
|
513
|
+
values.share === true ||
|
|
514
|
+
values.team === true ||
|
|
515
|
+
values['allow-agents'] === true;
|
|
516
|
+
if (answered && values.yes !== true) {
|
|
517
|
+
throw new UsageError('--service, --public, --subdomain, --share, --team and --allow-agents of hopwire init only work together with --yes');
|
|
518
|
+
}
|
|
519
|
+
const flags = values.yes === true
|
|
520
|
+
? {
|
|
521
|
+
services: values.service ?? [],
|
|
522
|
+
public: values.public ?? [],
|
|
523
|
+
subdomains: values.subdomain ?? [],
|
|
524
|
+
share: values.share ?? false,
|
|
525
|
+
team: values.team ?? false,
|
|
526
|
+
allowAgents: values['allow-agents'] ?? false,
|
|
527
|
+
}
|
|
528
|
+
: null;
|
|
529
|
+
const cwd = io.cwd ?? process.cwd();
|
|
530
|
+
const { file, shown } = configFile(cwd, values.config);
|
|
531
|
+
const promptLine = io.promptLine;
|
|
532
|
+
await init({
|
|
533
|
+
file,
|
|
534
|
+
shown,
|
|
535
|
+
named: values.config !== undefined,
|
|
536
|
+
cwd,
|
|
537
|
+
dataDir: resolveDataDir(values['data-dir'], io.env),
|
|
538
|
+
flags,
|
|
539
|
+
ask: promptLine === undefined ? undefined : (question) => promptLine(question, io.signal),
|
|
540
|
+
say: (line) => (io.notice ?? io.print)(line),
|
|
541
|
+
print: io.print,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
404
544
|
/** --agent or --no-agent; undefined leaves the choice to hopwire.yaml or the default (on, decision 139). */
|
|
405
545
|
function agentChoice(values) {
|
|
406
546
|
if (values.agent && values['no-agent']) {
|
|
@@ -428,6 +568,7 @@ function parse(argv) {
|
|
|
428
568
|
share: { type: 'boolean' },
|
|
429
569
|
allow: { type: 'string', multiple: true },
|
|
430
570
|
team: { type: 'boolean' },
|
|
571
|
+
relay: { type: 'boolean' },
|
|
431
572
|
'allow-agents': { type: 'boolean' },
|
|
432
573
|
'allow-host': { type: 'string', multiple: true },
|
|
433
574
|
port: { type: 'string' },
|
|
@@ -651,6 +792,10 @@ async function tokensForEdge(dataDir, account, named, mismatch) {
|
|
|
651
792
|
* for --team (or p2p.team), the one case in which private mode asks a server anything.
|
|
652
793
|
*/
|
|
653
794
|
async function teamAccess(option, dataDir) {
|
|
795
|
+
return accountClient(option, dataDir);
|
|
796
|
+
}
|
|
797
|
+
/** The control plane of the stored account, for --team and --relay. */
|
|
798
|
+
async function accountClient(option, dataDir) {
|
|
654
799
|
const account = await readAccount(dataDir);
|
|
655
800
|
if (account === null) {
|
|
656
801
|
throw new HopwireError(`${option} needs an account in an organisation on the Team plan: run hopwire login first. Without an account, restrict access with --allow <pubkey> (p2p.allow in hopwire.yaml) instead.`);
|
|
@@ -658,6 +803,29 @@ async function teamAccess(option, dataDir) {
|
|
|
658
803
|
const { createControlPlaneClient } = await import('./control-plane-client.js');
|
|
659
804
|
return createControlPlaneClient({ url: account.controlPlaneUrl, apiToken: account.apiToken });
|
|
660
805
|
}
|
|
806
|
+
/** --relay pairs machines of one organisation only, so it needs --team. */
|
|
807
|
+
function relayNeedsTeam(values) {
|
|
808
|
+
if (values.relay && !values.team) {
|
|
809
|
+
throw new UsageError('--relay only works together with --team: the relay of the edge (Team plan) only pairs machines of one organisation');
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* What --relay (or p2p.relay) needs besides --team: the edge the account is bound to, which carries the relay, and the
|
|
814
|
+
* control plane, which issues the relay tokens. Loaded only for --relay, the one case in which private mode contacts
|
|
815
|
+
* the edge, and then only when no direct connection comes about.
|
|
816
|
+
*/
|
|
817
|
+
async function relayAccess(option, dataDir) {
|
|
818
|
+
const client = await accountClient(option, dataDir);
|
|
819
|
+
let edgeUrl = await boundEdge(dataDir);
|
|
820
|
+
if (edgeUrl === null) {
|
|
821
|
+
const named = (await client.me()).edgeUrl;
|
|
822
|
+
if (named === null) {
|
|
823
|
+
throw new HopwireError(`${option} goes through the edge of your account, but its control plane names none; run hopwire login again, or leave ${option} out.`);
|
|
824
|
+
}
|
|
825
|
+
edgeUrl = await bindEdge(dataDir, named);
|
|
826
|
+
}
|
|
827
|
+
return { edgeUrl, tokens: client };
|
|
828
|
+
}
|
|
661
829
|
/** p2p.team of a hopwire.yaml: the account has to be one at the control plane the file names, when it names one. */
|
|
662
830
|
async function teamAccessOfFile(file, config, dataDir) {
|
|
663
831
|
const account = await readAccount(dataDir);
|
package/dist/commands/connect.js
CHANGED
|
@@ -2,7 +2,7 @@ import { once } from 'node:events';
|
|
|
2
2
|
import net, {} from 'node:net';
|
|
3
3
|
import { HopwireError, listenError } from '../errors.js';
|
|
4
4
|
import { loadOrCreateIdentity } from '../identity.js';
|
|
5
|
-
import { MODE_P2P, MODE_P2P_TEAM, connectGuide, printable, shortKey } from '../output.js';
|
|
5
|
+
import { MODE_P2P, MODE_P2P_RELAYED, MODE_P2P_TEAM, connectGuide, printable, relayedLine, shortKey } from '../output.js';
|
|
6
6
|
import { Supervisor, unlessAborted } from '../supervisor.js';
|
|
7
7
|
/**
|
|
8
8
|
* `hopwire connect <peer-key> --port <p>`: a loopback listener whose every TCP connection becomes one end-to-end
|
|
@@ -22,6 +22,12 @@ export async function startConnect(options) {
|
|
|
22
22
|
throw new HopwireError(`No member of ${organisation} has registered the key ${shortKey(options.peerKey)}; check the key, and that your teammate shares with --team (or p2p.team in hopwire.yaml) from an account in that organisation. Without --team this command connects to any key.`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
let relay;
|
|
26
|
+
if (options.relay !== undefined) {
|
|
27
|
+
// Loaded only here: without --relay nothing opens a relay socket
|
|
28
|
+
const { relaySetup } = await import('../relay.js');
|
|
29
|
+
relay = relaySetup(options.relay, ownKey);
|
|
30
|
+
}
|
|
25
31
|
const { PeerConnectError, createPeerConnector } = await import('../p2p.js');
|
|
26
32
|
options.signal?.throwIfAborted();
|
|
27
33
|
const connector = createPeerConnector({
|
|
@@ -29,6 +35,7 @@ export async function startConnect(options) {
|
|
|
29
35
|
peerKey: options.peerKey,
|
|
30
36
|
service: options.service,
|
|
31
37
|
bootstrap: options.bootstrap,
|
|
38
|
+
relay,
|
|
32
39
|
});
|
|
33
40
|
// Closed in the order of every command: the listener and its connections, then the DHT node
|
|
34
41
|
const supervisor = new Supervisor();
|
|
@@ -40,7 +47,7 @@ export async function startConnect(options) {
|
|
|
40
47
|
probe.destroy();
|
|
41
48
|
}
|
|
42
49
|
catch (error) {
|
|
43
|
-
throw error instanceof PeerConnectError ? connectError(error.code, options, ownKey) : error;
|
|
50
|
+
throw error instanceof PeerConnectError ? connectError(error.code, options, ownKey, error.problem) : error;
|
|
44
51
|
}
|
|
45
52
|
const clients = new Set();
|
|
46
53
|
/** Hosts whose refusal was said already: one line each, and no more than a few */
|
|
@@ -52,7 +59,10 @@ export async function startConnect(options) {
|
|
|
52
59
|
admit(client, answeredHosts(port, options.allowHosts ?? []), () => bridge(client, connector, (error) => {
|
|
53
60
|
// The client only sees a closed connection; the reason is said here
|
|
54
61
|
const code = error instanceof PeerConnectError ? error.code : 'UNKNOWN';
|
|
55
|
-
|
|
62
|
+
const problem = error instanceof PeerConnectError ? error.problem : null;
|
|
63
|
+
options.print(error instanceof PeerConnectError && error.limit
|
|
64
|
+
? `Limit ${problem ?? 'a limit of the relay'}`
|
|
65
|
+
: connectError(code, options, ownKey, problem).message);
|
|
56
66
|
}), (host) => {
|
|
57
67
|
const shown = printableHost(host);
|
|
58
68
|
if (!refused.has(shown) && refused.size < REFUSALS_SAID) {
|
|
@@ -78,12 +88,16 @@ export async function startConnect(options) {
|
|
|
78
88
|
// Stopped at the last step: nothing is reported as running
|
|
79
89
|
options.signal?.throwIfAborted();
|
|
80
90
|
const url = `http://127.0.0.1:${server.address().port}`;
|
|
81
|
-
|
|
91
|
+
const relayed = connector.relayed() && options.relay !== undefined;
|
|
92
|
+
options.print(relayed ? MODE_P2P_RELAYED : organisation === null ? MODE_P2P : MODE_P2P_TEAM);
|
|
82
93
|
options.print(`Forwarding ${url} -> peer ${options.peerKey}${options.service === null ? '' : ` (service ${options.service})`}`);
|
|
83
94
|
options.print(`Peer key ${ownKey}`);
|
|
84
95
|
if (organisation !== null) {
|
|
85
96
|
options.print(`Team ${organisation}: the peer is a machine of a member, and this machine's key is registered there`);
|
|
86
97
|
}
|
|
98
|
+
if (relayed && options.relay !== undefined) {
|
|
99
|
+
options.print(relayedLine(options.relay.edgeUrl));
|
|
100
|
+
}
|
|
87
101
|
// What reaches the peer is recorded there (spec decision 112): said before anything is sent
|
|
88
102
|
options.print(CONNECT_RECORDING_NOTICE);
|
|
89
103
|
for (const line of connectGuide(url)) {
|
|
@@ -194,9 +208,11 @@ function bridge(client, connector, onUnreachable) {
|
|
|
194
208
|
});
|
|
195
209
|
}
|
|
196
210
|
/** One sentence for a stream that could not be opened: what happened and what to do. */
|
|
197
|
-
function connectError(code, options, ownKey) {
|
|
211
|
+
function connectError(code, options, ownKey, relayProblem = null) {
|
|
198
212
|
const peer = shortKey(options.peerKey);
|
|
199
213
|
switch (code) {
|
|
214
|
+
case 'relay':
|
|
215
|
+
return new HopwireError(`No direct connection to the peer ${peer} came about, and the relay did not connect either: ${relayProblem ?? 'it failed'}.`);
|
|
200
216
|
case 'PEER_NOT_FOUND':
|
|
201
217
|
return new HopwireError(`No peer with the key ${peer} was found; check the key, your network connection and that your teammate's tunnel is running and shared (--share, or p2p.share in hopwire.yaml).`);
|
|
202
218
|
case 'unknown_service':
|
|
@@ -215,7 +231,7 @@ function connectError(code, options, ownKey) {
|
|
|
215
231
|
? `The peer ${peer} was found but did not accept the connection; if your teammate uses --allow, it has to list this machine's key ${ownKey}. If your teammate shares with --team, run this command with --team.`
|
|
216
232
|
: `The peer ${peer} was found but did not accept the connection; if your teammate uses --allow instead of --team, it has to list this machine's key ${ownKey}. Otherwise try again in a minute.`);
|
|
217
233
|
default:
|
|
218
|
-
// Hole punching failed in one of its ways
|
|
219
|
-
return new HopwireError(`No direct connection to the peer ${peer} was possible (${code});
|
|
234
|
+
// Hole punching failed in one of its ways, and no relay was asked for
|
|
235
|
+
return new HopwireError(`No direct connection to the peer ${peer} was possible (${code}); try again from another network, or, on the Team plan, connect through the relay of the edge with --team --relay (your teammate shares with --relay too).`);
|
|
220
236
|
}
|
|
221
237
|
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -29,9 +29,11 @@ export async function doctor(options) {
|
|
|
29
29
|
print(`Config ${await config(options.cwd)}`);
|
|
30
30
|
print(`Proxy ${proxy(options.env ?? process.env)}`);
|
|
31
31
|
print(`Network ${options.network ? await network(options) : NOT_CHECKED}`);
|
|
32
|
+
const edge = options.network ? await relayEdge(dataDir) : null;
|
|
33
|
+
print(`Relay ${options.network ? await relay(edge) : RELAY_NOT_CHECKED}`);
|
|
32
34
|
print('');
|
|
33
35
|
print(options.network
|
|
34
|
-
? 'Nothing was sent to us. The network check joined the DHT for a moment; its nodes saw the IP address of this machine.'
|
|
36
|
+
? `${edge === null ? 'Nothing was sent to us. ' : ''}The network check joined the DHT for a moment; its nodes saw the IP address of this machine.${edge === null ? '' : ' It also asked the edge of your account whether its relay answers, without a token: the edge saw the IP address, nothing else.'}`
|
|
35
37
|
: 'Nothing was sent anywhere: this report was put together on this machine without a network connection.');
|
|
36
38
|
print('It holds no keys, no tokens and no traffic. If you paste it into a bug report, read it first: the paths can name your user.');
|
|
37
39
|
}
|
|
@@ -53,6 +55,7 @@ function proxy(env) {
|
|
|
53
55
|
return error instanceof Error ? error.message : String(error);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
58
|
+
const RELAY_NOT_CHECKED = 'not checked. hopwire doctor --network also tests whether the relay of your edge (--team --relay, Team plan) can be reached from here, when this machine is logged in';
|
|
56
59
|
const NOT_CHECKED = 'not checked. hopwire doctor --network tests whether this network allows direct P2P connections; for that it joins the public DHT, whose nodes see your IP address';
|
|
57
60
|
/** Whether a file or directory is there, and whether others than its owner can get at it. */
|
|
58
61
|
async function entry(file, expected, missing = 'missing') {
|
|
@@ -112,7 +115,7 @@ async function network(options) {
|
|
|
112
115
|
const { probeNetwork } = await import('../p2p.js');
|
|
113
116
|
const found = await probeNetwork({ bootstrap: options.bootstrap, signal: options.signal });
|
|
114
117
|
if (found === 'unreachable') {
|
|
115
|
-
return 'the DHT could not be reached within 15 seconds;
|
|
118
|
+
return 'the DHT could not be reached within 15 seconds; direct P2P with teammates (--share, connect, watch) will not work from this network. On the Team plan --team --relay goes through the relay of the edge instead. A tunnel on this machine alone and public mode do not need the DHT';
|
|
116
119
|
}
|
|
117
120
|
if (found === 'open') {
|
|
118
121
|
return 'direct P2P works: this machine can be reached from outside without hole punching';
|
|
@@ -120,7 +123,28 @@ async function network(options) {
|
|
|
120
123
|
if (found === 'consistent') {
|
|
121
124
|
return 'direct P2P should work: this network keeps one outside port per connection, which is what hole punching needs';
|
|
122
125
|
}
|
|
123
|
-
return 'direct P2P will often fail from here: this network picks a new outside port for every destination (a symmetric NAT). It still works when the teammate is on a network that keeps its port; two networks of this kind cannot connect.
|
|
126
|
+
return 'direct P2P will often fail from here: this network picks a new outside port for every destination (a symmetric NAT). It still works when the teammate is on a network that keeps its port; two networks of this kind cannot connect directly. On the Team plan --team --relay goes through the relay of the edge then; public mode works from here';
|
|
127
|
+
}
|
|
128
|
+
/** The edge whose relay is checked: the one the logged-in account is bound to; null when there is none. */
|
|
129
|
+
async function relayEdge(dataDir) {
|
|
130
|
+
try {
|
|
131
|
+
return (await readAccount(dataDir)) === null ? null : await boundEdge(dataDir);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Whether the relay of the edge answers from this network. */
|
|
138
|
+
async function relay(edge) {
|
|
139
|
+
if (edge === null) {
|
|
140
|
+
return 'not checked: this machine is not logged in, or its account has no edge yet (the relay is for --team --relay on the Team plan)';
|
|
141
|
+
}
|
|
142
|
+
// Loaded only here: the one module that opens a relay socket
|
|
143
|
+
const { probeRelay } = await import('../relay.js');
|
|
144
|
+
const found = await probeRelay(edge);
|
|
145
|
+
return found.reachable
|
|
146
|
+
? `the relay of ${edge.origin} can be reached from here: --team --relay works on this network when direct P2P does not`
|
|
147
|
+
: `the relay of ${edge.origin} cannot be reached from here (${found.problem})`;
|
|
124
148
|
}
|
|
125
149
|
function message(error) {
|
|
126
150
|
return printable(error instanceof Error ? error.message : String(error));
|
package/dist/commands/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatLimitReached, formatMeteredUsage, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
|
|
1
|
+
import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatLimitReached, formatMeteredUsage, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
|
|
2
2
|
import { startServing } from '../serve.js';
|
|
3
3
|
export { INSPECTOR_FILES } from '../serve.js';
|
|
4
4
|
/**
|
|
@@ -22,6 +22,8 @@ export async function startHttpTunnel(options) {
|
|
|
22
22
|
allow,
|
|
23
23
|
team: options.team,
|
|
24
24
|
onTeamEvent: (event, organisation) => options.print(formatTeamEvent(event, organisation)),
|
|
25
|
+
relay: options.relay,
|
|
26
|
+
onRelayEvent: (event) => options.print(formatRelayEvent(event)),
|
|
25
27
|
bootstrap: options.bootstrap,
|
|
26
28
|
inspectorFiles: options.inspectorFiles,
|
|
27
29
|
agent: options.agent,
|
|
@@ -60,6 +62,9 @@ export async function startHttpTunnel(options) {
|
|
|
60
62
|
if (peerKey !== null) {
|
|
61
63
|
options.print(`Peer key ${peerKey}`);
|
|
62
64
|
options.print(shareNotice(access));
|
|
65
|
+
if (serving.relay !== null) {
|
|
66
|
+
options.print(relayLine(serving.relay.edgeUrl, serving.relay.problem));
|
|
67
|
+
}
|
|
63
68
|
if (options.allowAgents === true) {
|
|
64
69
|
options.print(AGENTS_ALLOWED_LINE);
|
|
65
70
|
}
|
|
@@ -90,6 +95,7 @@ export async function startHttpTunnel(options) {
|
|
|
90
95
|
logKey,
|
|
91
96
|
allowed: access,
|
|
92
97
|
restrictWith: '--allow <their key>',
|
|
98
|
+
relay: serving.relay !== null,
|
|
93
99
|
},
|
|
94
100
|
inspector: inspectorUrl !== null,
|
|
95
101
|
widenWith: { share: '--share', public: '--public' },
|