@genkaku/protocol 0.1.12 → 0.1.13
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/dial.d.ts +9 -0
- package/dist/dial.d.ts.map +1 -1
- package/dist/dial.js +19 -12
- package/package.json +1 -1
package/dist/dial.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ import type { OpenEnvelope } from './workerSession.ts';
|
|
|
5
5
|
/** Direct dials before a worker's address is considered unreachable and the
|
|
6
6
|
* seed-VM relay path is preferred for subsequent sessions. */
|
|
7
7
|
export declare const DIRECT_ATTEMPTS_BEFORE_RELAY = 3;
|
|
8
|
+
/** A circuit-relayed connection carries a relay-imposed byte/duration limit, so
|
|
9
|
+
* libp2p marks it "limited" and refuses new streams unless the caller opts in.
|
|
10
|
+
* Every GenKaKu protocol is application data and must opt in; on a direct
|
|
11
|
+
* connection the flag is ignored.
|
|
12
|
+
*
|
|
13
|
+
* The timeout is per call — sharing one AbortSignal would abort every dial made
|
|
14
|
+
* after the module's first five seconds. An unreachable peer must not stall a
|
|
15
|
+
* marketplace listing behind a TCP timeout. */
|
|
16
|
+
export declare const DIAL_TIMEOUT_MS = 5000;
|
|
8
17
|
export type DialRoute = 'direct' | 'relay';
|
|
9
18
|
/** Build `/p2p-circuit` addresses for `peerId` from the relays the seed handed
|
|
10
19
|
* out. The relay hop keeps its own `/p2p/<id>`; ours is appended last. */
|
package/dist/dial.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dial.d.ts","sourceRoot":"","sources":["../src/dial.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,EAAyB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAEnE,OAAO,EAAY,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AAGjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;A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AAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAsC1F;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnF,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgCtE;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAiClG"}
|
package/dist/dial.js
CHANGED
|
@@ -22,8 +22,15 @@ const directFailures = new Map();
|
|
|
22
22
|
/** A circuit-relayed connection carries a relay-imposed byte/duration limit, so
|
|
23
23
|
* libp2p marks it "limited" and refuses new streams unless the caller opts in.
|
|
24
24
|
* Every GenKaKu protocol is application data and must opt in; on a direct
|
|
25
|
-
* connection the flag is ignored.
|
|
26
|
-
|
|
25
|
+
* connection the flag is ignored.
|
|
26
|
+
*
|
|
27
|
+
* The timeout is per call — sharing one AbortSignal would abort every dial made
|
|
28
|
+
* after the module's first five seconds. An unreachable peer must not stall a
|
|
29
|
+
* marketplace listing behind a TCP timeout. */
|
|
30
|
+
export const DIAL_TIMEOUT_MS = 5_000;
|
|
31
|
+
function streamOpts(timeoutMs = DIAL_TIMEOUT_MS) {
|
|
32
|
+
return { signal: AbortSignal.timeout(timeoutMs), runOnLimitedConnection: true };
|
|
33
|
+
}
|
|
27
34
|
/** Build `/p2p-circuit` addresses for `peerId` from the relays the seed handed
|
|
28
35
|
* out. The relay hop keeps its own `/p2p/<id>`; ours is appended last. */
|
|
29
36
|
export function circuitAddrsFor(relays, peerId) {
|
|
@@ -121,7 +128,7 @@ export async function dialWorker(node, addr) {
|
|
|
121
128
|
}
|
|
122
129
|
return {
|
|
123
130
|
async open(env) {
|
|
124
|
-
openStream = await node.dialProtocol(ma, '/genkaku/open/0',
|
|
131
|
+
openStream = await node.dialProtocol(ma, '/genkaku/open/0', streamOpts());
|
|
125
132
|
// errors surface via the read side
|
|
126
133
|
openSinkDone = openStream.sink(oq.source()).catch(() => { });
|
|
127
134
|
oq.push(lpEncode(env));
|
|
@@ -155,7 +162,7 @@ export async function dialWorker(node, addr) {
|
|
|
155
162
|
onError(cb) { errCbs.add(cb); },
|
|
156
163
|
async sendReceipt(jobId, seq, amount, sig = '', inputHash = ZERO_HASH, outputHash = ZERO_HASH) {
|
|
157
164
|
if (!receiptStream) {
|
|
158
|
-
receiptStream = await node.dialProtocol(ma, '/genkaku/receipt/0',
|
|
165
|
+
receiptStream = await node.dialProtocol(ma, '/genkaku/receipt/0', streamOpts());
|
|
159
166
|
receiptSinkDone = receiptStream.sink(rq.source()).catch(() => { });
|
|
160
167
|
}
|
|
161
168
|
rq.push(lpEncode({
|
|
@@ -183,7 +190,7 @@ export async function dialWorker(node, addr) {
|
|
|
183
190
|
export async function helloWorker(node, addr) {
|
|
184
191
|
const expectedPeer = peerIdOf(addr);
|
|
185
192
|
const nonce = newNonce();
|
|
186
|
-
const stream = await node.dialProtocol(multiaddr(addr), '/genkaku/hello/0',
|
|
193
|
+
const stream = await node.dialProtocol(multiaddr(addr), '/genkaku/hello/0', streamOpts());
|
|
187
194
|
let reply;
|
|
188
195
|
try {
|
|
189
196
|
stream.sink([lpEncode({ proto: 'hello/0', nonce })]).catch(() => { });
|
|
@@ -308,7 +315,7 @@ export async function fetchOffers(node, addr) {
|
|
|
308
315
|
});
|
|
309
316
|
}
|
|
310
317
|
async function fetchOfferBoard(node, addr) {
|
|
311
|
-
const s = await node.dialProtocol(multiaddr(addr), '/genkaku/offers/0',
|
|
318
|
+
const s = await node.dialProtocol(multiaddr(addr), '/genkaku/offers/0', streamOpts());
|
|
312
319
|
const reader = new FrameReader();
|
|
313
320
|
let board = [];
|
|
314
321
|
for await (const chunk of s.source) {
|
|
@@ -335,7 +342,7 @@ export async function fetchSeedPeers(node, addr) {
|
|
|
335
342
|
// takes the native path.
|
|
336
343
|
if (addr.startsWith('http://') || addr.startsWith('https://')) {
|
|
337
344
|
try {
|
|
338
|
-
const res = await fetch(`${addr.replace(/\/$/, '')}/peers
|
|
345
|
+
const res = await fetch(`${addr.replace(/\/$/, '')}/peers`, { signal: AbortSignal.timeout(DIAL_TIMEOUT_MS) });
|
|
339
346
|
if (!res.ok)
|
|
340
347
|
return [];
|
|
341
348
|
const body = (await res.json());
|
|
@@ -347,7 +354,7 @@ export async function fetchSeedPeers(node, addr) {
|
|
|
347
354
|
return [];
|
|
348
355
|
}
|
|
349
356
|
}
|
|
350
|
-
const s = await node.dialProtocol(multiaddr(addr), '/genkaku/peers/0',
|
|
357
|
+
const s = await node.dialProtocol(multiaddr(addr), '/genkaku/peers/0', streamOpts());
|
|
351
358
|
const reader = new FrameReader();
|
|
352
359
|
for await (const chunk of s.source) {
|
|
353
360
|
reader.push(chunk);
|
|
@@ -366,7 +373,7 @@ export async function fetchSeedPeers(node, addr) {
|
|
|
366
373
|
export async function fetchSeedRelays(node, seed) {
|
|
367
374
|
if (seed.startsWith('http://') || seed.startsWith('https://')) {
|
|
368
375
|
try {
|
|
369
|
-
const res = await fetch(`${seed.replace(/\/$/, '')}/peers
|
|
376
|
+
const res = await fetch(`${seed.replace(/\/$/, '')}/peers`, { signal: AbortSignal.timeout(DIAL_TIMEOUT_MS) });
|
|
370
377
|
if (!res.ok)
|
|
371
378
|
return [];
|
|
372
379
|
const body = (await res.json());
|
|
@@ -381,7 +388,7 @@ export async function fetchSeedRelays(node, seed) {
|
|
|
381
388
|
if (node == null)
|
|
382
389
|
return [];
|
|
383
390
|
try {
|
|
384
|
-
const s = await node.dialProtocol(multiaddr(seed), '/genkaku/peers/0',
|
|
391
|
+
const s = await node.dialProtocol(multiaddr(seed), '/genkaku/peers/0', streamOpts());
|
|
385
392
|
const reader = new FrameReader();
|
|
386
393
|
for await (const chunk of s.source) {
|
|
387
394
|
reader.push(chunk);
|
|
@@ -409,7 +416,7 @@ export async function fetchSeedRelays(node, seed) {
|
|
|
409
416
|
* digest JobEscrow.settle recovers against the session's worker address.
|
|
410
417
|
*/
|
|
411
418
|
export async function requestSettleCosign(node, addr, args) {
|
|
412
|
-
const s = await node.dialProtocol(multiaddr(addr), '/genkaku/settle/0',
|
|
419
|
+
const s = await node.dialProtocol(multiaddr(addr), '/genkaku/settle/0', streamOpts());
|
|
413
420
|
const reader = new FrameReader();
|
|
414
421
|
let reply = null;
|
|
415
422
|
const sinkDone = s.sink([lpEncode({
|
|
@@ -452,7 +459,7 @@ export async function announceToSeed(node, seed, addrs) {
|
|
|
452
459
|
: [seed];
|
|
453
460
|
for (const target of targets) {
|
|
454
461
|
try {
|
|
455
|
-
const s = await node.dialProtocol(multiaddr(target), '/genkaku/announce/0',
|
|
462
|
+
const s = await node.dialProtocol(multiaddr(target), '/genkaku/announce/0', streamOpts());
|
|
456
463
|
try {
|
|
457
464
|
s.sink([lpEncode({ proto: 'announce/0', addrs })]).catch(() => { });
|
|
458
465
|
const reader = new FrameReader();
|
package/package.json
CHANGED