wire-mesh-core 1.8.0 → 1.9.0
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.
|
@@ -357,12 +357,13 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
357
357
|
setToken(token) {
|
|
358
358
|
currentToken = token;
|
|
359
359
|
},
|
|
360
|
-
async sendManageRequest(command, scope, targetDevice, token) {
|
|
360
|
+
async sendManageRequest(command, scope, targetDevice, token, timeoutMs) {
|
|
361
361
|
if (connection === null || state.status !== "connected") throw new Error("not connected");
|
|
362
362
|
if (targetDevice !== void 0) await ensureRelayPairing(targetDevice);
|
|
363
363
|
const frame = buildManageRequest(command, scope, token);
|
|
364
|
+
const requestId = frame["request-id"];
|
|
364
365
|
const outcome = new Promise((resolve, reject) => {
|
|
365
|
-
pendingManageRequests.set(
|
|
366
|
+
pendingManageRequests.set(requestId, {
|
|
366
367
|
resolve,
|
|
367
368
|
reject
|
|
368
369
|
});
|
|
@@ -373,7 +374,15 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
373
374
|
});
|
|
374
375
|
await transmit(frame, targetDevice !== void 0);
|
|
375
376
|
emit();
|
|
376
|
-
return outcome;
|
|
377
|
+
if (timeoutMs === void 0) return outcome;
|
|
378
|
+
return Promise.race([outcome, new Promise((resolve) => {
|
|
379
|
+
setTimeout(() => {
|
|
380
|
+
if (pendingManageRequests.delete(requestId)) resolve({
|
|
381
|
+
result: "error",
|
|
382
|
+
code: "timeout"
|
|
383
|
+
});
|
|
384
|
+
}, timeoutMs);
|
|
385
|
+
})]);
|
|
377
386
|
},
|
|
378
387
|
async sendRevocationAnnounce(entries) {
|
|
379
388
|
if (connection === null || state.status !== "connected") throw new Error("not connected");
|
|
@@ -81,8 +81,8 @@ export interface MeshSession {
|
|
|
81
81
|
setToken: (token: CapabilityToken) => void;
|
|
82
82
|
/** Announces one or more already-minted revocation-entries to the peer. Sent directly over the connection, never relay-wrapped -- revocation-announce is a gossiped broadcast, not a request addressed to a specific peer, so it has no targetDevice/token parameters the way sendManageRequest does. */
|
|
83
83
|
sendRevocationAnnounce: (entries: readonly RevocationEntry[]) => Promise<void>;
|
|
84
|
-
/** Sends a manage-request and resolves with the matching manage-response's outcome, correlated by request-id. When targetDevice is given, the request is routed to that specific peer via an established relay-connect pairing (wrapped as relay-data) rather than sent directly over this session's own Connection -- relay-hub deliberately drops manage-request/manage-response frames sent to it directly, since routing between two connected peers is not the relay role's business, so a specific peer reachable only through a relay hub can only be addressed this way. Absent, this sends directly over the Connection exactly as before. When token is given, it is attached to this one request instead of whatever setToken last set -- a single session routinely needs a different token per request when its peer shares more than one scope with this side (e.g. several core/room memberships over one connection), and a session-global token can only ever be correct for one of them. Absent, this request carries setToken's own session-global token exactly as before. */
|
|
85
|
-
sendManageRequest: (command: ManageCommand, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, token?: CapabilityToken) => Promise<ManageOutcome>;
|
|
84
|
+
/** Sends a manage-request and resolves with the matching manage-response's outcome, correlated by request-id. When targetDevice is given, the request is routed to that specific peer via an established relay-connect pairing (wrapped as relay-data) rather than sent directly over this session's own Connection -- relay-hub deliberately drops manage-request/manage-response frames sent to it directly, since routing between two connected peers is not the relay role's business, so a specific peer reachable only through a relay hub can only be addressed this way. Absent, this sends directly over the Connection exactly as before. When token is given, it is attached to this one request instead of whatever setToken last set -- a single session routinely needs a different token per request when its peer shares more than one scope with this side (e.g. several core/room memberships over one connection), and a session-global token can only ever be correct for one of them. Absent, this request carries setToken's own session-global token exactly as before. When timeoutMs is given, the returned promise resolves with `{ result: "error", code: "timeout" }` rather than hanging forever if no manage-response arrives in time -- a held-open request (a human approval, a not-yet-online peer) otherwise has no way for the caller to give up on it. Absent, this request waits exactly as before, with no time limit of its own. */
|
|
85
|
+
sendManageRequest: (command: ManageCommand, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, token?: CapabilityToken, timeoutMs?: number) => Promise<ManageOutcome>;
|
|
86
86
|
close: () => Promise<void>;
|
|
87
87
|
}
|
|
88
88
|
export declare function createMeshSession(transport: Readonly<Transport>, identity: Readonly<IdentityPort>, clock?: Readonly<Clock>, reconnect?: ReconnectPolicy | null,
|
|
@@ -81,8 +81,8 @@ export interface MeshSession {
|
|
|
81
81
|
setToken: (token: CapabilityToken) => void;
|
|
82
82
|
/** Announces one or more already-minted revocation-entries to the peer. Sent directly over the connection, never relay-wrapped -- revocation-announce is a gossiped broadcast, not a request addressed to a specific peer, so it has no targetDevice/token parameters the way sendManageRequest does. */
|
|
83
83
|
sendRevocationAnnounce: (entries: readonly RevocationEntry[]) => Promise<void>;
|
|
84
|
-
/** Sends a manage-request and resolves with the matching manage-response's outcome, correlated by request-id. When targetDevice is given, the request is routed to that specific peer via an established relay-connect pairing (wrapped as relay-data) rather than sent directly over this session's own Connection -- relay-hub deliberately drops manage-request/manage-response frames sent to it directly, since routing between two connected peers is not the relay role's business, so a specific peer reachable only through a relay hub can only be addressed this way. Absent, this sends directly over the Connection exactly as before. When token is given, it is attached to this one request instead of whatever setToken last set -- a single session routinely needs a different token per request when its peer shares more than one scope with this side (e.g. several core/room memberships over one connection), and a session-global token can only ever be correct for one of them. Absent, this request carries setToken's own session-global token exactly as before. */
|
|
85
|
-
sendManageRequest: (command: ManageCommand, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, token?: CapabilityToken) => Promise<ManageOutcome>;
|
|
84
|
+
/** Sends a manage-request and resolves with the matching manage-response's outcome, correlated by request-id. When targetDevice is given, the request is routed to that specific peer via an established relay-connect pairing (wrapped as relay-data) rather than sent directly over this session's own Connection -- relay-hub deliberately drops manage-request/manage-response frames sent to it directly, since routing between two connected peers is not the relay role's business, so a specific peer reachable only through a relay hub can only be addressed this way. Absent, this sends directly over the Connection exactly as before. When token is given, it is attached to this one request instead of whatever setToken last set -- a single session routinely needs a different token per request when its peer shares more than one scope with this side (e.g. several core/room memberships over one connection), and a session-global token can only ever be correct for one of them. Absent, this request carries setToken's own session-global token exactly as before. When timeoutMs is given, the returned promise resolves with `{ result: "error", code: "timeout" }` rather than hanging forever if no manage-response arrives in time -- a held-open request (a human approval, a not-yet-online peer) otherwise has no way for the caller to give up on it. Absent, this request waits exactly as before, with no time limit of its own. */
|
|
85
|
+
sendManageRequest: (command: ManageCommand, scope: Readonly<CapabilityScope>, targetDevice?: DeviceId, token?: CapabilityToken, timeoutMs?: number) => Promise<ManageOutcome>;
|
|
86
86
|
close: () => Promise<void>;
|
|
87
87
|
}
|
|
88
88
|
export declare function createMeshSession(transport: Readonly<Transport>, identity: Readonly<IdentityPort>, clock?: Readonly<Clock>, reconnect?: ReconnectPolicy | null,
|
|
@@ -356,12 +356,13 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
356
356
|
setToken(token) {
|
|
357
357
|
currentToken = token;
|
|
358
358
|
},
|
|
359
|
-
async sendManageRequest(command, scope, targetDevice, token) {
|
|
359
|
+
async sendManageRequest(command, scope, targetDevice, token, timeoutMs) {
|
|
360
360
|
if (connection === null || state.status !== "connected") throw new Error("not connected");
|
|
361
361
|
if (targetDevice !== void 0) await ensureRelayPairing(targetDevice);
|
|
362
362
|
const frame = buildManageRequest(command, scope, token);
|
|
363
|
+
const requestId = frame["request-id"];
|
|
363
364
|
const outcome = new Promise((resolve, reject) => {
|
|
364
|
-
pendingManageRequests.set(
|
|
365
|
+
pendingManageRequests.set(requestId, {
|
|
365
366
|
resolve,
|
|
366
367
|
reject
|
|
367
368
|
});
|
|
@@ -372,7 +373,15 @@ function createSessionCore(identity, clock, reconnect, dial, onPeerAdvert, addre
|
|
|
372
373
|
});
|
|
373
374
|
await transmit(frame, targetDevice !== void 0);
|
|
374
375
|
emit();
|
|
375
|
-
return outcome;
|
|
376
|
+
if (timeoutMs === void 0) return outcome;
|
|
377
|
+
return Promise.race([outcome, new Promise((resolve) => {
|
|
378
|
+
setTimeout(() => {
|
|
379
|
+
if (pendingManageRequests.delete(requestId)) resolve({
|
|
380
|
+
result: "error",
|
|
381
|
+
code: "timeout"
|
|
382
|
+
});
|
|
383
|
+
}, timeoutMs);
|
|
384
|
+
})]);
|
|
376
385
|
},
|
|
377
386
|
async sendRevocationAnnounce(entries) {
|
|
378
387
|
if (connection === null || state.status !== "connected") throw new Error("not connected");
|