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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ProtocolError } from './frames.js';
|
|
2
|
+
import { isPublicKeyHex } from './p2p.js';
|
|
3
|
+
/**
|
|
4
|
+
* The relay for strict networks (spec phase 12, decision 136): with --relay on the Team plan, private mode goes
|
|
5
|
+
* through the edge when no direct connection comes about. Both CLIs open a WebSocket to the edge; the edge pairs a
|
|
6
|
+
* dial with a listener of the same organisation and pipes the bytes. Over the pipe both CLIs run the same Noise
|
|
7
|
+
* handshake as on the DHT path, so the edge passes on bytes it cannot read.
|
|
8
|
+
*
|
|
9
|
+
* - The sharer keeps a listen socket (RELAY_LISTEN_PATH) open for its topics: the public key of its machine (what
|
|
10
|
+
* `hopwire connect` dials) and the discovery key of its traffic log (what `hopwire watch` dials).
|
|
11
|
+
* - A peer opens a dial socket (RELAY_DIAL_PATH?target=<topic>). The edge tells the listener (a dial message), the
|
|
12
|
+
* listener opens an accept socket (RELAY_ACCEPT_PATH?dial=<id>), and the edge tells the dialer it is paired. From
|
|
13
|
+
* then on every binary message of one side is the next binary message of the other.
|
|
14
|
+
* - Every socket carries a relay token of the control plane (Authorization: Bearer), audience RELAY_TOKEN_AUDIENCE.
|
|
15
|
+
*/
|
|
16
|
+
/** The sharer's socket: `?topic=<hex>` once per topic. */
|
|
17
|
+
export const RELAY_LISTEN_PATH = '/_hopwire/relay/listen';
|
|
18
|
+
/** A peer's socket: `?target=<hex>`, the topic it wants to reach. */
|
|
19
|
+
export const RELAY_DIAL_PATH = '/_hopwire/relay/dial';
|
|
20
|
+
/** The sharer's answer to one dial: `?dial=<id>`, the id of the dial message. */
|
|
21
|
+
export const RELAY_ACCEPT_PATH = '/_hopwire/relay/accept';
|
|
22
|
+
/** Audience (`aud`) of a relay token; the edge takes it only on the relay paths, and nowhere else takes it. */
|
|
23
|
+
export const RELAY_TOKEN_AUDIENCE = 'hopwire-relay';
|
|
24
|
+
/** Topics one listen socket may name: the machine key and the discovery key of the log, with room to spare. */
|
|
25
|
+
export const RELAY_MAX_TOPICS = 4;
|
|
26
|
+
/** How long the edge holds a dial for the listener to accept it. */
|
|
27
|
+
export const RELAY_DIAL_TIMEOUT_MS = 10_000;
|
|
28
|
+
/** A pipe without a byte in either direction for this long is closed. */
|
|
29
|
+
export const RELAY_IDLE_TIMEOUT_MS = 10 * 60_000;
|
|
30
|
+
/** Bytes waiting to go out on one side of a pipe above which the edge stops reading the other side. */
|
|
31
|
+
export const RELAY_BACKPRESSURE_BYTES = 1024 * 1024;
|
|
32
|
+
/** Largest binary message on a relay socket; the CLI sends at most RELAY_CHUNK_BYTES of data in one. */
|
|
33
|
+
export const RELAY_MESSAGE_MAX_BYTES = 256 * 1024;
|
|
34
|
+
export const RELAY_CHUNK_BYTES = 64 * 1024;
|
|
35
|
+
/** Pipes one organisation may have open at once, unless the edge is configured otherwise (RELAY_PIPES_PER_ORG). */
|
|
36
|
+
export const RELAY_PIPES_PER_ORG_DEFAULT = 20;
|
|
37
|
+
/** Relayed bytes per organisation and UTC day on the Team plan, unless configured otherwise (provisional). */
|
|
38
|
+
export const RELAY_BYTES_PER_DAY_DEFAULT = 20_000_000_000;
|
|
39
|
+
/** Close codes of relay sockets. */
|
|
40
|
+
export const RELAY_CLOSE = {
|
|
41
|
+
/** The token of a listener expired; the CLI comes back with a new one */
|
|
42
|
+
tokenExpired: 4001,
|
|
43
|
+
/** A pipe had no byte for RELAY_IDLE_TIMEOUT_MS */
|
|
44
|
+
idle: 4009,
|
|
45
|
+
/** A limit of the organisation: open pipes or relayed bytes of the day; the reason names which */
|
|
46
|
+
limit: 4029,
|
|
47
|
+
/** Nobody of the organisation listens on the topic of a dial */
|
|
48
|
+
noListener: 4404,
|
|
49
|
+
/** The listener did not accept a dial in time */
|
|
50
|
+
dialTimeout: 4408,
|
|
51
|
+
};
|
|
52
|
+
/** The reasons of a RELAY_CLOSE.limit close. */
|
|
53
|
+
export const RELAY_LIMIT_REASONS = ['relay_pipes', 'relay_bytes'];
|
|
54
|
+
/** What a dial id looks like: 32 hexadecimal characters the edge made up. */
|
|
55
|
+
const DIAL_ID = /^[0-9a-f]{32}$/;
|
|
56
|
+
export function isRelayDialId(value) {
|
|
57
|
+
return DIAL_ID.test(value);
|
|
58
|
+
}
|
|
59
|
+
/** A topic as the relay takes it: a public key or discovery key as 64 hexadecimal characters, lower case. */
|
|
60
|
+
export function isRelayTopic(value) {
|
|
61
|
+
return isPublicKeyHex(value) && value === value.toLowerCase();
|
|
62
|
+
}
|
|
63
|
+
export function encodeRelayControl(message) {
|
|
64
|
+
return JSON.stringify(message);
|
|
65
|
+
}
|
|
66
|
+
/** Reads a control message of the edge. Throws ProtocolError for anything else. */
|
|
67
|
+
export function decodeRelayControl(text) {
|
|
68
|
+
let value;
|
|
69
|
+
try {
|
|
70
|
+
value = JSON.parse(text);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
throw new ProtocolError('A relay control message is not JSON');
|
|
74
|
+
}
|
|
75
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
76
|
+
throw new ProtocolError('A relay control message is not an object');
|
|
77
|
+
}
|
|
78
|
+
const message = value;
|
|
79
|
+
if (message.type === 'paired') {
|
|
80
|
+
return { type: 'paired' };
|
|
81
|
+
}
|
|
82
|
+
if (message.type === 'dial' &&
|
|
83
|
+
typeof message.dial === 'string' &&
|
|
84
|
+
isRelayDialId(message.dial) &&
|
|
85
|
+
typeof message.topic === 'string' &&
|
|
86
|
+
isRelayTopic(message.topic)) {
|
|
87
|
+
return { type: 'dial', dial: message.dial, topic: message.topic };
|
|
88
|
+
}
|
|
89
|
+
throw new ProtocolError('Unknown relay control message');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The first byte of every binary message between two CLIs on a pipe. The edge never looks at it: it passes whole
|
|
93
|
+
* messages on.
|
|
94
|
+
*/
|
|
95
|
+
export const RELAY_FRAME = {
|
|
96
|
+
/** The rest is bytes of the encrypted stream */
|
|
97
|
+
data: 0,
|
|
98
|
+
/** The rest is one encrypted datagram next to the stream (the flow control of hopwire connect) */
|
|
99
|
+
datagram: 1,
|
|
100
|
+
/** The sender will send no more stream bytes */
|
|
101
|
+
end: 2,
|
|
102
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hopwire",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"mcpName": "to.hopwire/hopwire",
|
|
5
5
|
"description": "Record, share and replay the HTTP traffic of your local services: private P2P sharing with teammates, and public HTTPS URLs.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@hopwire/protocol": "0.1.0",
|
|
35
|
+
"@hyperswarm/secret-stream": "^6.9.2",
|
|
35
36
|
"corestore": "^7.16.1",
|
|
36
37
|
"hypercore": "^11.40.5",
|
|
37
38
|
"hyperdht": "^6.37.0",
|