@kumiai/rpc 0.13.0 → 0.13.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/lib/directed.js +24 -2
- package/package.json +1 -1
package/lib/directed.js
CHANGED
|
@@ -56,6 +56,19 @@ import { createOpenOncePath } from './open-once.js';
|
|
|
56
56
|
* instead. 30s is a deliberate ceiling — a call the peer means to answer answers well inside it,
|
|
57
57
|
* so its expiry is evidence the call was dropped.
|
|
58
58
|
*/ export const DEFAULT_DIRECTED_REQUEST_TIMEOUT_MS = 30_000;
|
|
59
|
+
const CALL_TYPES = new Set([
|
|
60
|
+
'request',
|
|
61
|
+
'stream',
|
|
62
|
+
'channel',
|
|
63
|
+
'event',
|
|
64
|
+
'send',
|
|
65
|
+
'abort'
|
|
66
|
+
]);
|
|
67
|
+
const REPLY_TYPES = new Set([
|
|
68
|
+
'result',
|
|
69
|
+
'receive',
|
|
70
|
+
'error'
|
|
71
|
+
]);
|
|
59
72
|
/**
|
|
60
73
|
* Directed 1:1 RPC client to a single member, over a hub-tunnel transport whose
|
|
61
74
|
* send/receive topics are the two members' inbox topics for the current epoch.
|
|
@@ -67,6 +80,7 @@ import { createOpenOncePath } from './open-once.js';
|
|
|
67
80
|
const { mux, localDID, memberDID, sendTopicID, receiveTopicID, inbound, wrap, protocol } = params;
|
|
68
81
|
const requestTimeoutMs = params.requestTimeoutMs ?? DEFAULT_DIRECTED_REQUEST_TIMEOUT_MS;
|
|
69
82
|
const { getRandomID } = params.runtime ?? createRuntime();
|
|
83
|
+
const sessionID = getRandomID();
|
|
70
84
|
let unsubscribe;
|
|
71
85
|
const hub = {
|
|
72
86
|
async publish (publishParams) {
|
|
@@ -104,6 +118,14 @@ import { createOpenOncePath } from './open-once.js';
|
|
|
104
118
|
};
|
|
105
119
|
unsubscribe = inbound((message)=>{
|
|
106
120
|
if (closed || message.topicID !== receiveTopicID || message.protocol !== protocol || message.senderDID !== memberDID) return;
|
|
121
|
+
let frame;
|
|
122
|
+
try {
|
|
123
|
+
frame = decodeFrame(message.payload);
|
|
124
|
+
} catch {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (frame.sessionID !== sessionID) return;
|
|
128
|
+
if (frame.kind === 'message' && !REPLY_TYPES.has(frame.body.payload.typ)) return;
|
|
107
129
|
if (resolveNext != null) {
|
|
108
130
|
const resolve = resolveNext;
|
|
109
131
|
resolveNext = undefined;
|
|
@@ -149,7 +171,7 @@ import { createOpenOncePath } from './open-once.js';
|
|
|
149
171
|
};
|
|
150
172
|
const transport = createHubTunnelTransport({
|
|
151
173
|
hub,
|
|
152
|
-
sessionID
|
|
174
|
+
sessionID,
|
|
153
175
|
localDID,
|
|
154
176
|
sendTopicID,
|
|
155
177
|
receiveTopicID
|
|
@@ -368,7 +390,7 @@ import { createOpenOncePath } from './open-once.js';
|
|
|
368
390
|
}
|
|
369
391
|
return;
|
|
370
392
|
}
|
|
371
|
-
if (frame.kind !== 'message') return;
|
|
393
|
+
if (frame.kind !== 'message' || !CALL_TYPES.has(frame.body.payload.typ)) return;
|
|
372
394
|
// Drop a sender mismatch on an established session (splice attempt) BEFORE re-encoding, so a
|
|
373
395
|
// hostile member cannot make us serialise a large frame per rejected splice.
|
|
374
396
|
if (existing != null && existing.senderDID !== senderDID) return;
|