wire-mesh-core 1.48.0 → 1.48.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/dist/adapters/frame-codec.cjs +9 -0
- package/dist/adapters/frame-codec.d.cts +3 -1
- package/dist/adapters/frame-codec.d.mts +3 -1
- package/dist/adapters/frame-codec.mjs +9 -1
- package/dist/domain/mesh-session.cjs +28 -18
- package/dist/domain/mesh-session.d.cts +3 -1
- package/dist/domain/mesh-session.d.mts +3 -1
- package/dist/domain/mesh-session.mjs +29 -19
- package/dist/domain/relay-hub.cjs +2 -1
- package/dist/domain/relay-hub.mjs +2 -1
- package/package.json +1 -1
|
@@ -5,6 +5,14 @@ let cbor2 = require("cbor2");
|
|
|
5
5
|
function messageFromFrame(frame) {
|
|
6
6
|
return new Uint8Array((0, cbor2.encode)(frame, cbor2.cdeEncodeOptions));
|
|
7
7
|
}
|
|
8
|
+
/** Wraps frame as a relay-data-frame's own opaque payload, stamping to-device when the caller knows which established pairing to address it to (wire-mesh#30) -- the outbound counterpart to tryDecodeFrame's own doc comment below, which describes the inbound side of the same relay-data envelope. Omitting toDevice leaves the frame unaddressed, which the receiving hub then routes via its own most-recently-established-pairing fallback. */
|
|
9
|
+
function wrapRelayData(frame, toDevice) {
|
|
10
|
+
return {
|
|
11
|
+
type: "relay-data",
|
|
12
|
+
payload: messageFromFrame(frame),
|
|
13
|
+
...toDevice !== void 0 ? { "to-device": toDevice } : {}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
8
16
|
/** A frame that fails schema validation, caught separately from a decode failure so it can be dropped without disconnecting. */
|
|
9
17
|
var SchemaInvalidFrameError = class extends Error {
|
|
10
18
|
constructor(message) {
|
|
@@ -35,3 +43,4 @@ exports.SchemaInvalidFrameError = SchemaInvalidFrameError;
|
|
|
35
43
|
exports.decodeMessage = decodeMessage;
|
|
36
44
|
exports.messageFromFrame = messageFromFrame;
|
|
37
45
|
exports.tryDecodeFrame = tryDecodeFrame;
|
|
46
|
+
exports.wrapRelayData = wrapRelayData;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { N as Frame } from "../protocol-CNFRVx9w.cjs";
|
|
1
|
+
import { D as DeviceId, N as Frame, ft as RelayDataFrame } from "../protocol-CNFRVx9w.cjs";
|
|
2
2
|
//#region src/adapters/frame-codec.d.ts
|
|
3
3
|
export declare function messageFromFrame(frame: Frame): Uint8Array<ArrayBuffer>;
|
|
4
|
+
/** Wraps frame as a relay-data-frame's own opaque payload, stamping to-device when the caller knows which established pairing to address it to (wire-mesh#30) -- the outbound counterpart to tryDecodeFrame's own doc comment below, which describes the inbound side of the same relay-data envelope. Omitting toDevice leaves the frame unaddressed, which the receiving hub then routes via its own most-recently-established-pairing fallback. */
|
|
5
|
+
export declare function wrapRelayData(frame: Frame, toDevice?: DeviceId): RelayDataFrame;
|
|
4
6
|
/** A frame that fails schema validation, caught separately from a decode failure so it can be dropped without disconnecting. */
|
|
5
7
|
export declare class SchemaInvalidFrameError extends Error {
|
|
6
8
|
constructor(message: string);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { N as Frame } from "../protocol-CNFRVx9w.mjs";
|
|
1
|
+
import { D as DeviceId, N as Frame, ft as RelayDataFrame } from "../protocol-CNFRVx9w.mjs";
|
|
2
2
|
//#region src/adapters/frame-codec.d.ts
|
|
3
3
|
export declare function messageFromFrame(frame: Frame): Uint8Array<ArrayBuffer>;
|
|
4
|
+
/** Wraps frame as a relay-data-frame's own opaque payload, stamping to-device when the caller knows which established pairing to address it to (wire-mesh#30) -- the outbound counterpart to tryDecodeFrame's own doc comment below, which describes the inbound side of the same relay-data envelope. Omitting toDevice leaves the frame unaddressed, which the receiving hub then routes via its own most-recently-established-pairing fallback. */
|
|
5
|
+
export declare function wrapRelayData(frame: Frame, toDevice?: DeviceId): RelayDataFrame;
|
|
4
6
|
/** A frame that fails schema validation, caught separately from a decode failure so it can be dropped without disconnecting. */
|
|
5
7
|
export declare class SchemaInvalidFrameError extends Error {
|
|
6
8
|
constructor(message: string);
|
|
@@ -4,6 +4,14 @@ import { cdeDecodeOptions, cdeEncodeOptions, decode, encode } from "cbor2";
|
|
|
4
4
|
function messageFromFrame(frame) {
|
|
5
5
|
return new Uint8Array(encode(frame, cdeEncodeOptions));
|
|
6
6
|
}
|
|
7
|
+
/** Wraps frame as a relay-data-frame's own opaque payload, stamping to-device when the caller knows which established pairing to address it to (wire-mesh#30) -- the outbound counterpart to tryDecodeFrame's own doc comment below, which describes the inbound side of the same relay-data envelope. Omitting toDevice leaves the frame unaddressed, which the receiving hub then routes via its own most-recently-established-pairing fallback. */
|
|
8
|
+
function wrapRelayData(frame, toDevice) {
|
|
9
|
+
return {
|
|
10
|
+
type: "relay-data",
|
|
11
|
+
payload: messageFromFrame(frame),
|
|
12
|
+
...toDevice !== void 0 ? { "to-device": toDevice } : {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
7
15
|
/** A frame that fails schema validation, caught separately from a decode failure so it can be dropped without disconnecting. */
|
|
8
16
|
var SchemaInvalidFrameError = class extends Error {
|
|
9
17
|
constructor(message) {
|
|
@@ -30,4 +38,4 @@ function tryDecodeFrame(bytes) {
|
|
|
30
38
|
return result.success ? result.data : null;
|
|
31
39
|
}
|
|
32
40
|
//#endregion
|
|
33
|
-
export { SchemaInvalidFrameError, decodeMessage, messageFromFrame, tryDecodeFrame };
|
|
41
|
+
export { SchemaInvalidFrameError, decodeMessage, messageFromFrame, tryDecodeFrame, wrapRelayData };
|
|
@@ -2,6 +2,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_domain_device_id = require("./device-id.cjs");
|
|
3
3
|
const require_domain_handshake = require("./handshake.cjs");
|
|
4
4
|
const require_adapters_frame_codec = require("../adapters/frame-codec.cjs");
|
|
5
|
+
//#region src/domain/relay-pairing.ts
|
|
6
|
+
function createRelayPairings() {
|
|
7
|
+
const established = /* @__PURE__ */ new Map();
|
|
8
|
+
return {
|
|
9
|
+
has: (device) => established.has(require_domain_device_id.deviceIdToHex(device)),
|
|
10
|
+
add: (device) => {
|
|
11
|
+
established.set(require_domain_device_id.deviceIdToHex(device), device);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
5
16
|
//#region src/domain/mesh-session.ts
|
|
6
17
|
const MS_PER_SECOND = 1e3;
|
|
7
18
|
/** peer-advert's own three typed fields -- reserved so a `sendGossipUpdate` caller can never override the session's own device-id, address list, or freshness timestamp by supplying an extension of the same name. */
|
|
@@ -45,7 +56,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
45
56
|
let attempt = 0;
|
|
46
57
|
let currentToken = null;
|
|
47
58
|
let nextRequestId = 0;
|
|
48
|
-
|
|
59
|
+
const relayPairings = createRelayPairings();
|
|
49
60
|
const pendingManageRequests = /* @__PURE__ */ new Map();
|
|
50
61
|
const incomingWaiters = [];
|
|
51
62
|
const incomingBacklog = [];
|
|
@@ -90,15 +101,11 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
90
101
|
...token !== null ? { token } : {}
|
|
91
102
|
};
|
|
92
103
|
}
|
|
93
|
-
/** Sends a frame, wrapping it as relay-data first when viaRelay is set -- the single choke point every outbound manage-request/manage-response passes through, so a consumer of sendManageRequest/respond never needs its own relay-wrapping logic. */
|
|
94
|
-
async function transmit(frame, viaRelay) {
|
|
104
|
+
/** Sends a frame, wrapping it as relay-data first when viaRelay is set -- the single choke point every outbound manage-request/manage-response passes through, so a consumer of sendManageRequest/respond never needs its own relay-wrapping logic. When relaying, toDevice is stamped onto the outer relay-data-frame's own `to-device` field so the hub addresses it to the correct pairing directly (wire-mesh#30) rather than falling back to whichever pairing it last saw -- the one case this is omitted is a response to a request that itself arrived with no from-device to echo back, which is left to that same hub fallback exactly as an unaddressed relay-data always has been. */
|
|
105
|
+
async function transmit(frame, viaRelay, toDevice) {
|
|
95
106
|
if (connection === null) throw new Error("not connected");
|
|
96
107
|
if (viaRelay) {
|
|
97
|
-
|
|
98
|
-
type: "relay-data",
|
|
99
|
-
payload: require_adapters_frame_codec.messageFromFrame(frame)
|
|
100
|
-
};
|
|
101
|
-
await connection.send(relayFrame);
|
|
108
|
+
await connection.send(require_adapters_frame_codec.wrapRelayData(frame, toDevice));
|
|
102
109
|
return;
|
|
103
110
|
}
|
|
104
111
|
await connection.send(frame);
|
|
@@ -111,15 +118,18 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
111
118
|
pending.resolve(frame.outcome);
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
|
-
|
|
121
|
+
/** relayFrame is present only for a manage-request that arrived wrapped in relay-data, and is that same outer relay-data-frame -- its own to-device/from-device fields carry whatever addressing it received. See IncomingManageRequest's own fromDevice/toDevice doc comments for what each means and why neither is ever guessed from pairing state. */
|
|
122
|
+
function applyManageRequest(frame, relayFrame) {
|
|
115
123
|
const requestId = frame["request-id"];
|
|
116
|
-
const fromDevice =
|
|
124
|
+
const fromDevice = relayFrame?.["from-device"];
|
|
125
|
+
const toDevice = relayFrame?.["to-device"];
|
|
117
126
|
emitIncomingManageRequest({
|
|
118
127
|
requestId,
|
|
119
128
|
command: frame.command,
|
|
120
129
|
scope: frame.scope,
|
|
121
130
|
...frame.token !== void 0 ? { token: frame.token } : {},
|
|
122
131
|
...fromDevice !== void 0 ? { fromDevice } : {},
|
|
132
|
+
...toDevice !== void 0 ? { toDevice } : {},
|
|
123
133
|
respond: async (outcome) => {
|
|
124
134
|
const response = {
|
|
125
135
|
type: "manage-response",
|
|
@@ -130,7 +140,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
130
140
|
direction: "sent",
|
|
131
141
|
frame: response
|
|
132
142
|
});
|
|
133
|
-
await transmit(response,
|
|
143
|
+
await transmit(response, relayFrame !== void 0, fromDevice);
|
|
134
144
|
emit();
|
|
135
145
|
}
|
|
136
146
|
});
|
|
@@ -144,7 +154,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
144
154
|
frame: inner
|
|
145
155
|
});
|
|
146
156
|
if (inner.type === "manage-response") applyManageResponse(inner);
|
|
147
|
-
else applyManageRequest(inner,
|
|
157
|
+
else applyManageRequest(inner, frame);
|
|
148
158
|
return;
|
|
149
159
|
}
|
|
150
160
|
frameLog.push({
|
|
@@ -165,15 +175,15 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
165
175
|
});
|
|
166
176
|
onPeerAdvert?.(advert);
|
|
167
177
|
}
|
|
168
|
-
else if (frame.type === "relay-inbound")
|
|
178
|
+
else if (frame.type === "relay-inbound") relayPairings.add(frame["source-device"]);
|
|
169
179
|
else if (frame.type === "manage-response") applyManageResponse(frame);
|
|
170
|
-
else if (frame.type === "manage-request") applyManageRequest(frame
|
|
180
|
+
else if (frame.type === "manage-request") applyManageRequest(frame);
|
|
171
181
|
else if (frame.type === "revocation-announce") for (const entry of frame.entries) emitRevocationEntry(entry);
|
|
172
182
|
}
|
|
173
|
-
/** Establishes a relay-connect pairing to targetDevice if this session isn't already paired with it -- a no-op when it already is, whether that pairing was established by this session's own prior relay-connect (initiator role) or learned from an incoming relay-inbound (target role, replying back to whoever dialed it). relay-connect has no ack frame: the initiator proceeds to relay-data right after sending it. */
|
|
183
|
+
/** Establishes a relay-connect pairing to targetDevice if this session isn't already paired with it -- a no-op when it already is, whether that pairing was established by this session's own prior relay-connect (initiator role) or learned from an incoming relay-inbound (target role, replying back to whoever dialed it). Pairing with a new target never tears down an existing pairing with a different one: this connection can hold several simultaneously (wire-mesh#30's own multiplexed adjacency map), so a later request back to an already-paired target must not re-send relay-connect for it. relay-connect has no ack frame: the initiator proceeds to relay-data right after sending it. */
|
|
174
184
|
async function ensureRelayPairing(targetDevice) {
|
|
175
185
|
if (connection === null) throw new Error("not connected");
|
|
176
|
-
if (
|
|
186
|
+
if (relayPairings.has(targetDevice)) return;
|
|
177
187
|
const relayConnect = {
|
|
178
188
|
type: "relay-connect",
|
|
179
189
|
"target-device": targetDevice
|
|
@@ -183,7 +193,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
183
193
|
frame: relayConnect
|
|
184
194
|
});
|
|
185
195
|
await connection.send(relayConnect);
|
|
186
|
-
|
|
196
|
+
relayPairings.add(targetDevice);
|
|
187
197
|
emit();
|
|
188
198
|
}
|
|
189
199
|
let localHandshakeSent = localHandshake([]);
|
|
@@ -395,7 +405,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
395
405
|
direction: "sent",
|
|
396
406
|
frame
|
|
397
407
|
});
|
|
398
|
-
await transmit(frame, targetDevice !== void 0);
|
|
408
|
+
await transmit(frame, targetDevice !== void 0, targetDevice);
|
|
399
409
|
emit();
|
|
400
410
|
if (timeoutMs === void 0) return outcome;
|
|
401
411
|
return Promise.race([outcome, new Promise((resolve) => {
|
|
@@ -38,8 +38,10 @@ export interface IncomingManageRequest {
|
|
|
38
38
|
command: ManageCommand;
|
|
39
39
|
scope: CapabilityScope;
|
|
40
40
|
token?: CapabilityToken;
|
|
41
|
-
/** The device-id of the peer this request was relayed on behalf of, present only when the request arrived wrapped in a relay-data frame
|
|
41
|
+
/** The device-id of the peer this request was relayed on behalf of, read directly from the enclosing relay-data-frame's own `from-device` field (stamped by the hub on every frame it forwards, wire-mesh#30) -- present only when the request arrived wrapped in a relay-data frame that carried one. A caller that needs to address a further request back to the same peer (one not sent via respond(), which already routes back correctly on its own) passes this as sendManageRequest's targetDevice. Never inferred from which relay pairing happens to be most recently established: a connection can hold several concurrent pairings (wire-mesh#30's own multiplexed adjacency map), so only the frame's own per-message addressing can say who actually sent it. */
|
|
42
42
|
fromDevice?: DeviceId;
|
|
43
|
+
/** The device-id this request's relay-data frame was explicitly addressed to, read from its own `to-device` field -- present only when the request arrived relay-wrapped and the frame carried one. A caller fronting more than one locally-addressable device behind a single hub connection (a gateway advertising several local peers through the same relay pairing) uses this to decide whether the request is for this device or should be routed on to a different local peer it also advertises; this session has no such routing logic of its own, since it represents exactly one identity. */
|
|
44
|
+
toDevice?: DeviceId;
|
|
43
45
|
respond: (outcome: ManageOutcome) => Promise<void>;
|
|
44
46
|
}
|
|
45
47
|
export type HandshakeStatus = {
|
|
@@ -38,8 +38,10 @@ export interface IncomingManageRequest {
|
|
|
38
38
|
command: ManageCommand;
|
|
39
39
|
scope: CapabilityScope;
|
|
40
40
|
token?: CapabilityToken;
|
|
41
|
-
/** The device-id of the peer this request was relayed on behalf of, present only when the request arrived wrapped in a relay-data frame
|
|
41
|
+
/** The device-id of the peer this request was relayed on behalf of, read directly from the enclosing relay-data-frame's own `from-device` field (stamped by the hub on every frame it forwards, wire-mesh#30) -- present only when the request arrived wrapped in a relay-data frame that carried one. A caller that needs to address a further request back to the same peer (one not sent via respond(), which already routes back correctly on its own) passes this as sendManageRequest's targetDevice. Never inferred from which relay pairing happens to be most recently established: a connection can hold several concurrent pairings (wire-mesh#30's own multiplexed adjacency map), so only the frame's own per-message addressing can say who actually sent it. */
|
|
42
42
|
fromDevice?: DeviceId;
|
|
43
|
+
/** The device-id this request's relay-data frame was explicitly addressed to, read from its own `to-device` field -- present only when the request arrived relay-wrapped and the frame carried one. A caller fronting more than one locally-addressable device behind a single hub connection (a gateway advertising several local peers through the same relay pairing) uses this to decide whether the request is for this device or should be routed on to a different local peer it also advertises; this session has no such routing logic of its own, since it represents exactly one identity. */
|
|
44
|
+
toDevice?: DeviceId;
|
|
43
45
|
respond: (outcome: ManageOutcome) => Promise<void>;
|
|
44
46
|
}
|
|
45
47
|
export type HandshakeStatus = {
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { deviceIdToHex } from "./device-id.mjs";
|
|
2
2
|
import { negotiate } from "./handshake.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { tryDecodeFrame, wrapRelayData } from "../adapters/frame-codec.mjs";
|
|
4
|
+
//#region src/domain/relay-pairing.ts
|
|
5
|
+
function createRelayPairings() {
|
|
6
|
+
const established = /* @__PURE__ */ new Map();
|
|
7
|
+
return {
|
|
8
|
+
has: (device) => established.has(deviceIdToHex(device)),
|
|
9
|
+
add: (device) => {
|
|
10
|
+
established.set(deviceIdToHex(device), device);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
4
15
|
//#region src/domain/mesh-session.ts
|
|
5
16
|
const MS_PER_SECOND = 1e3;
|
|
6
17
|
/** peer-advert's own three typed fields -- reserved so a `sendGossipUpdate` caller can never override the session's own device-id, address list, or freshness timestamp by supplying an extension of the same name. */
|
|
@@ -44,7 +55,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
44
55
|
let attempt = 0;
|
|
45
56
|
let currentToken = null;
|
|
46
57
|
let nextRequestId = 0;
|
|
47
|
-
|
|
58
|
+
const relayPairings = createRelayPairings();
|
|
48
59
|
const pendingManageRequests = /* @__PURE__ */ new Map();
|
|
49
60
|
const incomingWaiters = [];
|
|
50
61
|
const incomingBacklog = [];
|
|
@@ -89,15 +100,11 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
89
100
|
...token !== null ? { token } : {}
|
|
90
101
|
};
|
|
91
102
|
}
|
|
92
|
-
/** Sends a frame, wrapping it as relay-data first when viaRelay is set -- the single choke point every outbound manage-request/manage-response passes through, so a consumer of sendManageRequest/respond never needs its own relay-wrapping logic. */
|
|
93
|
-
async function transmit(frame, viaRelay) {
|
|
103
|
+
/** Sends a frame, wrapping it as relay-data first when viaRelay is set -- the single choke point every outbound manage-request/manage-response passes through, so a consumer of sendManageRequest/respond never needs its own relay-wrapping logic. When relaying, toDevice is stamped onto the outer relay-data-frame's own `to-device` field so the hub addresses it to the correct pairing directly (wire-mesh#30) rather than falling back to whichever pairing it last saw -- the one case this is omitted is a response to a request that itself arrived with no from-device to echo back, which is left to that same hub fallback exactly as an unaddressed relay-data always has been. */
|
|
104
|
+
async function transmit(frame, viaRelay, toDevice) {
|
|
94
105
|
if (connection === null) throw new Error("not connected");
|
|
95
106
|
if (viaRelay) {
|
|
96
|
-
|
|
97
|
-
type: "relay-data",
|
|
98
|
-
payload: messageFromFrame(frame)
|
|
99
|
-
};
|
|
100
|
-
await connection.send(relayFrame);
|
|
107
|
+
await connection.send(wrapRelayData(frame, toDevice));
|
|
101
108
|
return;
|
|
102
109
|
}
|
|
103
110
|
await connection.send(frame);
|
|
@@ -110,15 +117,18 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
110
117
|
pending.resolve(frame.outcome);
|
|
111
118
|
}
|
|
112
119
|
}
|
|
113
|
-
|
|
120
|
+
/** relayFrame is present only for a manage-request that arrived wrapped in relay-data, and is that same outer relay-data-frame -- its own to-device/from-device fields carry whatever addressing it received. See IncomingManageRequest's own fromDevice/toDevice doc comments for what each means and why neither is ever guessed from pairing state. */
|
|
121
|
+
function applyManageRequest(frame, relayFrame) {
|
|
114
122
|
const requestId = frame["request-id"];
|
|
115
|
-
const fromDevice =
|
|
123
|
+
const fromDevice = relayFrame?.["from-device"];
|
|
124
|
+
const toDevice = relayFrame?.["to-device"];
|
|
116
125
|
emitIncomingManageRequest({
|
|
117
126
|
requestId,
|
|
118
127
|
command: frame.command,
|
|
119
128
|
scope: frame.scope,
|
|
120
129
|
...frame.token !== void 0 ? { token: frame.token } : {},
|
|
121
130
|
...fromDevice !== void 0 ? { fromDevice } : {},
|
|
131
|
+
...toDevice !== void 0 ? { toDevice } : {},
|
|
122
132
|
respond: async (outcome) => {
|
|
123
133
|
const response = {
|
|
124
134
|
type: "manage-response",
|
|
@@ -129,7 +139,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
129
139
|
direction: "sent",
|
|
130
140
|
frame: response
|
|
131
141
|
});
|
|
132
|
-
await transmit(response,
|
|
142
|
+
await transmit(response, relayFrame !== void 0, fromDevice);
|
|
133
143
|
emit();
|
|
134
144
|
}
|
|
135
145
|
});
|
|
@@ -143,7 +153,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
143
153
|
frame: inner
|
|
144
154
|
});
|
|
145
155
|
if (inner.type === "manage-response") applyManageResponse(inner);
|
|
146
|
-
else applyManageRequest(inner,
|
|
156
|
+
else applyManageRequest(inner, frame);
|
|
147
157
|
return;
|
|
148
158
|
}
|
|
149
159
|
frameLog.push({
|
|
@@ -164,15 +174,15 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
164
174
|
});
|
|
165
175
|
onPeerAdvert?.(advert);
|
|
166
176
|
}
|
|
167
|
-
else if (frame.type === "relay-inbound")
|
|
177
|
+
else if (frame.type === "relay-inbound") relayPairings.add(frame["source-device"]);
|
|
168
178
|
else if (frame.type === "manage-response") applyManageResponse(frame);
|
|
169
|
-
else if (frame.type === "manage-request") applyManageRequest(frame
|
|
179
|
+
else if (frame.type === "manage-request") applyManageRequest(frame);
|
|
170
180
|
else if (frame.type === "revocation-announce") for (const entry of frame.entries) emitRevocationEntry(entry);
|
|
171
181
|
}
|
|
172
|
-
/** Establishes a relay-connect pairing to targetDevice if this session isn't already paired with it -- a no-op when it already is, whether that pairing was established by this session's own prior relay-connect (initiator role) or learned from an incoming relay-inbound (target role, replying back to whoever dialed it). relay-connect has no ack frame: the initiator proceeds to relay-data right after sending it. */
|
|
182
|
+
/** Establishes a relay-connect pairing to targetDevice if this session isn't already paired with it -- a no-op when it already is, whether that pairing was established by this session's own prior relay-connect (initiator role) or learned from an incoming relay-inbound (target role, replying back to whoever dialed it). Pairing with a new target never tears down an existing pairing with a different one: this connection can hold several simultaneously (wire-mesh#30's own multiplexed adjacency map), so a later request back to an already-paired target must not re-send relay-connect for it. relay-connect has no ack frame: the initiator proceeds to relay-data right after sending it. */
|
|
173
183
|
async function ensureRelayPairing(targetDevice) {
|
|
174
184
|
if (connection === null) throw new Error("not connected");
|
|
175
|
-
if (
|
|
185
|
+
if (relayPairings.has(targetDevice)) return;
|
|
176
186
|
const relayConnect = {
|
|
177
187
|
type: "relay-connect",
|
|
178
188
|
"target-device": targetDevice
|
|
@@ -182,7 +192,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
182
192
|
frame: relayConnect
|
|
183
193
|
});
|
|
184
194
|
await connection.send(relayConnect);
|
|
185
|
-
|
|
195
|
+
relayPairings.add(targetDevice);
|
|
186
196
|
emit();
|
|
187
197
|
}
|
|
188
198
|
let localHandshakeSent = localHandshake([]);
|
|
@@ -394,7 +404,7 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
394
404
|
direction: "sent",
|
|
395
405
|
frame
|
|
396
406
|
});
|
|
397
|
-
await transmit(frame, targetDevice !== void 0);
|
|
407
|
+
await transmit(frame, targetDevice !== void 0, targetDevice);
|
|
398
408
|
emit();
|
|
399
409
|
if (timeoutMs === void 0) return outcome;
|
|
400
410
|
return Promise.race([outcome, new Promise((resolve) => {
|