hopwire 0.7.0 → 0.8.1

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/dist/cli.js CHANGED
@@ -6,7 +6,7 @@ import { INSPECTOR_DEFAULT_PORT, LOCAL_ENTRY_DEFAULT_PORT, RANDOM_SUBDOMAIN_BYTE
6
6
  import { bindEdge, boundEdge, isProfileName, readAccount } from './account.js';
7
7
  import { startConnect } from './commands/connect.js';
8
8
  import { doctor } from './commands/doctor.js';
9
- import { init } from './commands/init.js';
9
+ import { gitIgnores, init } from './commands/init.js';
10
10
  import { startHttpTunnel } from './commands/http.js';
11
11
  import { login, logout, profiles, use } from './commands/login.js';
12
12
  import { startMcp } from './commands/mcp.js';
@@ -564,7 +564,13 @@ export async function run(argv, io) {
564
564
  let inFile = settingsOfConfig(loaded, undefined);
565
565
  const settings = {
566
566
  current: io.view?.settings ?? settingsOfConfig(loaded, agent),
567
+ facts: {
568
+ entries: running.services.map((service) => service.url),
569
+ inspector: new URL(running.inspectorUrl).origin,
570
+ customDomains: running.services.map((service) => service.customDomains),
571
+ },
567
572
  file: { shown, exists: true },
573
+ ignored: () => gitIgnores(file),
568
574
  save: async (next) => {
569
575
  await saveToConfigFile(file, shown, inFile, next);
570
576
  inFile = next;
@@ -576,21 +582,28 @@ export async function run(argv, io) {
576
582
  noMoreArguments(rest, 1, 'hopwire http <port>');
577
583
  // The Settings tab restarted the tunnel: its settings stand in for those of the command line
578
584
  const wanted = io.view?.settings;
579
- if (wanted !== undefined) {
580
- const isPublic = wanted.services[0]?.public ?? false;
585
+ const wantedService = wanted?.services[0];
586
+ if (wanted !== undefined && wantedService !== undefined) {
587
+ const logPaths = wantedService.logs.map((log) => log.path);
581
588
  Object.assign(values, {
589
+ name: wantedService.name,
582
590
  share: wanted.share,
583
591
  team: wanted.team,
584
592
  relay: wanted.relay,
585
- public: isPublic,
593
+ allow: wanted.share && !wanted.team && wanted.allow.length > 0 ? wanted.allow : undefined,
594
+ public: wantedService.public,
595
+ subdomain: wantedService.public ? (wantedService.subdomain ?? undefined) : undefined,
586
596
  'no-ws-capture': !wanted.websocket,
587
597
  agent: wanted.agent ? values.agent : undefined,
588
598
  'no-agent': !wanted.agent,
589
- subdomain: isPublic ? values.subdomain : undefined,
599
+ log: logPaths.length > 0 ? logPaths : undefined,
590
600
  });
591
601
  if (!wanted.share) {
592
602
  // What only works with sharing goes with it; a later change that shares again reads the command line anew
593
- Object.assign(values, { allow: undefined, 'allow-agents': undefined, 'share-logs': undefined });
603
+ Object.assign(values, { 'allow-agents': undefined, 'share-logs': undefined });
604
+ }
605
+ if (logPaths.length === 0) {
606
+ Object.assign(values, { 'share-logs': undefined, 'log-request-id': undefined });
594
607
  }
595
608
  }
596
609
  if (values.inspect !== undefined && values['no-inspect']) {
@@ -655,7 +668,13 @@ export async function run(argv, io) {
655
668
  relay: values.relay ? await relayAccess('--relay', store) : undefined,
656
669
  bootstrap: values.share ? parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP) : undefined,
657
670
  // Edge URL, token and account are only read for --public: private mode never looks at them
658
- public: values.public ? update.watch(await parsePublic(values.subdomain, io.env, store)) : undefined,
671
+ public: values.public
672
+ ? update.watch({
673
+ ...(await parsePublic(values.subdomain, io.env, store)),
674
+ // Basic Auth has no flag: it comes from the Settings tab, for this run
675
+ ...(wantedService?.basicAuth != null ? { basicAuth: wantedService.basicAuth } : {}),
676
+ })
677
+ : undefined,
659
678
  agent: agentChoice(values),
660
679
  captureWebSocket: !(values['no-ws-capture'] ?? false),
661
680
  logs,
@@ -674,11 +693,28 @@ export async function run(argv, io) {
674
693
  share: values.share ?? false,
675
694
  team: values.team ?? false,
676
695
  relay: values.relay ?? false,
696
+ allow,
677
697
  websocket: !(values['no-ws-capture'] ?? false),
678
698
  agent: agentChoice(values) !== false,
679
- services: [{ name: serviceName, public: values.public ?? false }],
699
+ services: [
700
+ {
701
+ name: serviceName,
702
+ target: `http://127.0.0.1:${port}`,
703
+ public: values.public ?? false,
704
+ // What the Settings tab holds is kept while the public URL is off
705
+ subdomain: values.subdomain ?? wantedService?.subdomain ?? null,
706
+ basicAuth: wantedService?.basicAuth ?? null,
707
+ logs: (values.log ?? []).map((given, index) => ({ path: given, name: logs[index]?.name ?? given })),
708
+ },
709
+ ],
710
+ },
711
+ facts: {
712
+ entries: [running.url],
713
+ inspector: running.inspectorUrl === null ? null : new URL(running.inspectorUrl).origin,
714
+ customDomains: [running.customDomains ?? []],
680
715
  },
681
716
  file: { shown: target.shown, exists: view.created !== undefined },
717
+ ignored: () => gitIgnores(target.file),
682
718
  save: async (next) => {
683
719
  if (view.created !== undefined) {
684
720
  await saveToConfigFile(target.file, target.shown, view.created.before, next);
@@ -692,9 +728,6 @@ export async function run(argv, io) {
692
728
  await createConfigFile({
693
729
  file: target.file,
694
730
  shown: target.shown,
695
- serviceName,
696
- local: new URL(`http://127.0.0.1:${port}`),
697
- subdomain: values.subdomain ?? null,
698
731
  urls: account === null || edgeUrl === null
699
732
  ? null
700
733
  : { edgeUrl, controlPlaneUrl: account.controlPlaneUrl },
@@ -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_RELAYED, MODE_P2P_TEAM, connectGuide, printable, relayedLine, shortKey } from '../output.js';
5
+ import { MODE_P2P, MODE_P2P_RELAYED, MODE_P2P_TEAM, TEAMMATE_NETWORK_HINT, 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
@@ -214,7 +214,7 @@ function connectError(code, options, ownKey, relayProblem = null) {
214
214
  case 'relay':
215
215
  return new HopwireError(`No direct connection to the peer ${peer} came about, and the relay did not connect either: ${relayProblem ?? 'it failed'}.`);
216
216
  case 'PEER_NOT_FOUND':
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).`);
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). ${TEAMMATE_NETWORK_HINT}`);
218
218
  case 'unknown_service':
219
219
  return new HopwireError(`The peer has no service named "${options.service ?? ''}"; ask your teammate for the name it was started with (--name, or the service name in hopwire.yaml).`);
220
220
  case 'service_required':
@@ -15,7 +15,8 @@ import { printable } from '../output.js';
15
15
  *
16
16
  * Without --network it opens no connection at all. With --network it joins the DHT for a moment (the public one:
17
17
  * its nodes see the IP address of this machine, as with --share) and says whether this network lets two machines
18
- * connect directly, which is what private mode needs.
18
+ * connect directly, which is what private mode needs: with a teammate on another network (from the NAT of this one)
19
+ * and with one on this same network (by a connection from this machine to itself through the outside address).
19
20
  */
20
21
  export async function doctor(options) {
21
22
  const { print, dataDir } = options;
@@ -29,7 +30,9 @@ export async function doctor(options) {
29
30
  print(`Account ${await account(store)}`);
30
31
  print(`Config ${await config(options.cwd)}`);
31
32
  print(`Proxy ${proxy(options.env ?? process.env)}`);
32
- print(`Network ${options.network ? await network(options) : NOT_CHECKED}`);
33
+ const probe = options.network ? await network(options) : null;
34
+ print(`Network ${probe === null ? NOT_CHECKED : probe[0]}`);
35
+ print(`Same network ${probe === null ? SAME_NETWORK_NOT_CHECKED : probe[1]}`);
33
36
  const edge = options.network ? await relayEdge(store) : null;
34
37
  print(`Relay ${options.network ? await relay(edge) : RELAY_NOT_CHECKED}`);
35
38
  // Only with --network: the list comes from the control plane, and without it nothing leaves the machine
@@ -39,7 +42,7 @@ export async function doctor(options) {
39
42
  }
40
43
  print('');
41
44
  print(options.network
42
- ? `${edge === null && domains === 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.'}${domains === null ? '' : ' It asked the control plane of your account for its custom domains, with your API token.'}`
45
+ ? `${edge === null && domains === null ? 'Nothing was sent to us. ' : ''}The network check joined the DHT for a moment and connected this machine to itself under a throwaway key; DHT 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.'}${domains === null ? '' : ' It asked the control plane of your account for its custom domains, with your API token.'}`
43
46
  : 'Nothing was sent anywhere: this report was put together on this machine without a network connection.');
44
47
  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.');
45
48
  }
@@ -62,6 +65,7 @@ function proxy(env) {
62
65
  }
63
66
  }
64
67
  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';
68
+ const SAME_NETWORK_NOT_CHECKED = 'not checked. hopwire doctor --network also tests whether two machines on this network can connect directly when the network keeps them apart locally';
65
69
  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';
66
70
  /** Whether a file or directory is there, and whether others than its owner can get at it. */
67
71
  async function entry(file, expected, missing = 'missing') {
@@ -119,21 +123,40 @@ async function config(cwd) {
119
123
  return `${HOPWIRE_YAML_FILE} cannot be used: ${message(error)}`;
120
124
  }
121
125
  }
122
- /** What the DHT says about the network this machine is on. */
126
+ /** What the DHT says about the network this machine is on: the Network and the Same network line. */
123
127
  async function network(options) {
124
128
  // Loaded only for --network: the one module that creates a DHT node
125
129
  const { probeNetwork } = await import('../p2p.js');
126
- const found = await probeNetwork({ bootstrap: options.bootstrap, signal: options.signal });
127
- if (found === 'unreachable') {
128
- 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';
130
+ return networkLines(await probeNetwork({ bootstrap: options.bootstrap, signal: options.signal }));
131
+ }
132
+ /** What to do when direct P2P does not come about: the relay on the Team plan, else public mode. */
133
+ const RELAY_INSTEAD = 'On the Team plan both sides add --team --relay to go through the relay of the edge; without it, public mode works from here';
134
+ /** The Network and the Same network line of the report for what `probeNetwork` found. */
135
+ export function networkLines(probe) {
136
+ return [natLine(probe), sameNetworkLine(probe)];
137
+ }
138
+ function natLine({ nat }) {
139
+ if (nat === 'unreachable') {
140
+ return `no DHT node answered from this network within 15 seconds (UDP blocked?); direct P2P with teammates (--share, connect, watch) will not work from this network. ${RELAY_INSTEAD}. A tunnel on this machine alone does not need the DHT`;
129
141
  }
130
- if (found === 'open') {
142
+ if (nat === 'open') {
131
143
  return 'direct P2P works: this machine can be reached from outside without hole punching';
132
144
  }
133
- if (found === 'consistent') {
134
- return 'direct P2P should work: this network keeps one outside port per connection, which is what hole punching needs';
145
+ if (nat === 'consistent') {
146
+ return 'direct P2P with teammates on other networks should work: this network keeps one outside port per connection, which is what hole punching needs';
147
+ }
148
+ 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. ${RELAY_INSTEAD}`;
149
+ }
150
+ function sameNetworkLine({ nat, sameNetwork }) {
151
+ if (sameNetwork === 'works') {
152
+ return 'a teammate on this same network can connect directly: a connection to the outside address of this network comes back in';
153
+ }
154
+ if (sameNetwork === 'fails') {
155
+ return `direct P2P with a teammate on this same network will fail unless the network lets the two machines reach each other locally; guest and office Wi-Fi often do not, and this network does not send a connection to its own outside address back in. ${RELAY_INSTEAD}`;
135
156
  }
136
- 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';
157
+ return nat === 'unreachable'
158
+ ? 'not tested: the DHT could not be reached'
159
+ : 'not tested: the test connection to this machine itself did not get as far as a hole punch; run hopwire doctor --network again';
137
160
  }
138
161
  /** The edge whose relay is checked: the one the logged-in account is bound to; null when there is none. */
139
162
  async function relayEdge(store) {
@@ -1,5 +1,5 @@
1
1
  import { formatDrift } from '../shapes.js';
2
- import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, exchangeSink, formatPeerEvent, formatLimitReached, formatLogNotice, logLines, formatMeteredUsage, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, mainPublicUrl, publicUrlText, } from '../output.js';
2
+ import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, dhtUnreachableLine, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, exchangeSink, formatPeerEvent, formatLimitReached, formatLogNotice, logLines, formatMeteredUsage, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, mainPublicUrl, publicUrlText, } from '../output.js';
3
3
  import { startServing } from '../serve.js';
4
4
  export { INSPECTOR_FILES } from '../serve.js';
5
5
  /**
@@ -77,6 +77,9 @@ export async function startHttpTunnel(options) {
77
77
  if (peerKey !== null) {
78
78
  options.print(`Peer key ${peerKey}`);
79
79
  options.print(shareNotice(access));
80
+ if (serving.dhtReached === false) {
81
+ options.print(dhtUnreachableLine({ team: serving.team !== null, relay: serving.relay !== null }));
82
+ }
80
83
  if (serving.relay !== null) {
81
84
  options.print(relayLine(serving.relay.edgeUrl, serving.relay.problem));
82
85
  }
@@ -123,7 +126,7 @@ export async function startHttpTunnel(options) {
123
126
  for (const line of stopped) {
124
127
  options.print(line);
125
128
  }
126
- return { kind: 'http', url, inspectorUrl, agentSocket, logKey, peerKey, publicUrl, ended, close };
129
+ return { kind: 'http', url, inspectorUrl, agentSocket, logKey, peerKey, publicUrl, customDomains, ended, close };
127
130
  }
128
131
  /** One line for a change of the connection to the edge, or for a daily limit of the plan that was reached. */
129
132
  export function formatBridgeEvent(event) {
@@ -3,7 +3,7 @@ import { randomBytes } from 'node:crypto';
3
3
  import path from 'node:path';
4
4
  import { LOCAL_ENTRY_DEFAULT_PORT, RANDOM_SUBDOMAIN_BYTES, randomSubdomain } from '@hopwire/protocol';
5
5
  import { HopwireError } from '../errors.js';
6
- import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, exchangeSink, formatPeerEvent, formatLogNotice, logLines, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, mainPublicUrl, publicUrlText, } from '../output.js';
6
+ import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, dhtUnreachableLine, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, exchangeSink, formatPeerEvent, formatLogNotice, logLines, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, mainPublicUrl, publicUrlText, } from '../output.js';
7
7
  import { startServing } from '../serve.js';
8
8
  import { formatBridgeEvent } from './http.js';
9
9
  /**
@@ -100,6 +100,9 @@ export async function startUp(options) {
100
100
  if (serving.peerKey !== null) {
101
101
  options.print(`Peer key ${serving.peerKey}`);
102
102
  options.print(shareNotice(access, 'p2p.allow in hopwire.yaml'));
103
+ if (serving.dhtReached === false) {
104
+ options.print(dhtUnreachableLine({ team: serving.team !== null, relay: serving.relay !== null, yaml: true }));
105
+ }
103
106
  if (serving.relay !== null) {
104
107
  options.print(relayLine(serving.relay.edgeUrl, serving.relay.problem));
105
108
  }
@@ -7,7 +7,7 @@ import { startInspectorServer } from '../inspector-server.js';
7
7
  import { createInterceptor } from '../interceptor.js';
8
8
  import { InFlightExchanges, followLogFile } from '../log-follow.js';
9
9
  import { REMOTE_LOG_BUDGET_BYTES } from '../log.js';
10
- import { MODE_P2P, MODE_P2P_RELAYED, MODE_P2P_TEAM, exchangeSink, formatLogNotice, logLines, printable, relayedLine, shortKey, watchAgentLine, watchGuide, } from '../output.js';
10
+ import { MODE_P2P, MODE_P2P_RELAYED, MODE_P2P_TEAM, TEAMMATE_NETWORK_HINT, exchangeSink, formatLogNotice, logLines, printable, relayedLine, shortKey, watchAgentLine, watchGuide, } from '../output.js';
11
11
  import { INSPECTOR_FILES } from '../serve.js';
12
12
  import { Supervisor, unlessAborted } from '../supervisor.js';
13
13
  /**
@@ -213,7 +213,7 @@ function joinError(code, logKey, ownKey, team, relayProblem = null) {
213
213
  : `The sharer of the log ${shortKey(logKey)} was found but no direct connection came about, and the relay did not connect either: ${relayProblem}.`);
214
214
  }
215
215
  if (code === 'not_found') {
216
- return new HopwireError(`Nobody is sharing the log ${shortKey(logKey)} right now; check the key, your network connection and that your teammate's tunnel is running and shared (--share, or p2p.share in hopwire.yaml).`);
216
+ return new HopwireError(`Nobody is sharing the log ${shortKey(logKey)} right now; check the key, your network connection and that your teammate's tunnel is running and shared (--share, or p2p.share in hopwire.yaml). ${TEAMMATE_NETWORK_HINT}`);
217
217
  }
218
218
  return new HopwireError(team
219
219
  ? `The sharer of the log ${shortKey(logKey)} was found but no connection came about: either no direct connection was possible (on the Team plan --relay goes through the relay of the edge then, when the sharer uses it too), or it shares with another team than the one this machine is logged in to, or it runs with --allow, which then has to list this machine's key ${ownKey}.`
@@ -200,7 +200,7 @@ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
200
200
  OTHER DEALINGS IN THE FONT SOFTWARE.
201
201
 
202
202
  ==============================================================================
203
- @vue/reactivity 3.5.46 (MIT)
203
+ @vue/reactivity 3.5.47 (MIT)
204
204
  ==============================================================================
205
205
 
206
206
  The MIT License (MIT)
@@ -226,7 +226,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
226
226
  THE SOFTWARE.
227
227
 
228
228
  ==============================================================================
229
- @vue/runtime-core 3.5.46 (MIT)
229
+ @vue/runtime-core 3.5.47 (MIT)
230
230
  ==============================================================================
231
231
 
232
232
  The MIT License (MIT)
@@ -252,7 +252,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
252
252
  THE SOFTWARE.
253
253
 
254
254
  ==============================================================================
255
- @vue/runtime-dom 3.5.46 (MIT)
255
+ @vue/runtime-dom 3.5.47 (MIT)
256
256
  ==============================================================================
257
257
 
258
258
  The MIT License (MIT)
@@ -278,7 +278,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
278
278
  THE SOFTWARE.
279
279
 
280
280
  ==============================================================================
281
- @vue/shared 3.5.46 (MIT)
281
+ @vue/shared 3.5.47 (MIT)
282
282
  ==============================================================================
283
283
 
284
284
  The MIT License (MIT)