@minip2p/core 0.8.2 → 0.9.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/README.md +8 -2
- package/dist/backend.d.ts +30 -13
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +15 -5
- package/dist/backend.js.map +1 -1
- package/dist/errors.d.ts +13 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/native-ids.d.ts +18 -3
- package/dist/native-ids.d.ts.map +1 -1
- package/dist/native-ids.js +50 -6
- package/dist/native-ids.js.map +1 -1
- package/dist/sdk.d.ts +3 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +157 -14
- package/dist/sdk.js.map +1 -1
- package/dist/settle-handles.d.ts +30 -0
- package/dist/settle-handles.d.ts.map +1 -0
- package/dist/settle-handles.js +69 -0
- package/dist/settle-handles.js.map +1 -0
- package/dist/types.d.ts +71 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +35 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/backend.ts +46 -21
- package/src/errors.ts +20 -0
- package/src/index.ts +3 -0
- package/src/native-ids.ts +54 -6
- package/src/sdk.ts +166 -28
- package/src/settle-handles.ts +78 -0
- package/src/types.ts +97 -9
package/src/sdk.ts
CHANGED
|
@@ -328,6 +328,33 @@ class StreamTable<Value> {
|
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
+
/** Every connection a native event names. */
|
|
332
|
+
const connectionsOf = (event: P2pEvent): number[] => {
|
|
333
|
+
if (!("inner" in event)) {
|
|
334
|
+
return [];
|
|
335
|
+
}
|
|
336
|
+
const { inner } = event;
|
|
337
|
+
return [
|
|
338
|
+
"connId" in inner ? inner.connId : undefined,
|
|
339
|
+
"oldConnId" in inner ? inner.oldConnId : undefined,
|
|
340
|
+
"newConnId" in inner ? inner.newConnId : undefined,
|
|
341
|
+
].filter((id): id is number => typeof id === "number");
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Native events that leave a connection unseen. Anything else naming it is
|
|
346
|
+
* something the application acts on or must hear about, so it keeps the
|
|
347
|
+
* connection's events.
|
|
348
|
+
*/
|
|
349
|
+
const UNSEEN_CONNECTION_TAGS: ReadonlySet<string> = new Set<P2pEvent["tag"]>([
|
|
350
|
+
P2pEvent_Tags.PeerReady,
|
|
351
|
+
P2pEvent_Tags.IdentifyReceived,
|
|
352
|
+
P2pEvent_Tags.EndpointError,
|
|
353
|
+
P2pEvent_Tags.StreamRemoteWriteClosed,
|
|
354
|
+
P2pEvent_Tags.StreamWriteStopped,
|
|
355
|
+
P2pEvent_Tags.StreamClosed,
|
|
356
|
+
]);
|
|
357
|
+
|
|
331
358
|
/** The native per-stream event an item carries, if any. */
|
|
332
359
|
const streamEventOf = (
|
|
333
360
|
item: QueueItem
|
|
@@ -348,6 +375,15 @@ const streamEventOf = (
|
|
|
348
375
|
* A peer-opened stream that closes without data before its `StreamReady`
|
|
349
376
|
* is dispatched leaves the queue whole, so a peer opening and closing
|
|
350
377
|
* streams cannot grow it; its events still reach `release`.
|
|
378
|
+
*
|
|
379
|
+
* Connections follow the same rule (ADR 0012): one that ends without data
|
|
380
|
+
* before any of its events was dispatched, whichever side dialed it, leaves
|
|
381
|
+
* with every event naming it. One replaced instead folds into its
|
|
382
|
+
* successor: its queued `ConnectionEstablished` is renamed to the successor
|
|
383
|
+
* and the `ConnectionReplaced` goes (as it does when the capacity already
|
|
384
|
+
* dropped that `ConnectionEstablished`). A connection the application knows
|
|
385
|
+
* otherwise -- a stream it opened, a ping result, an attempt or path event
|
|
386
|
+
* naming it -- is kept.
|
|
351
387
|
*/
|
|
352
388
|
class EventQueue {
|
|
353
389
|
readonly #items = new Map<number, QueueItem>();
|
|
@@ -359,6 +395,14 @@ class EventQueue {
|
|
|
359
395
|
* queued item ids; `undefined` once one carried data.
|
|
360
396
|
*/
|
|
361
397
|
readonly #unseen = new StreamTable<number[] | undefined>();
|
|
398
|
+
/** Connections whose `ConnectionEstablished` is queued and unseen. */
|
|
399
|
+
readonly #unseenConnections = new Set<number>();
|
|
400
|
+
/**
|
|
401
|
+
* Live connections the application learned of outside the queue, so a
|
|
402
|
+
* later replacement fold must not make them unseen; each leaves with its
|
|
403
|
+
* end.
|
|
404
|
+
*/
|
|
405
|
+
readonly #knownConnections = new Set<number>();
|
|
362
406
|
readonly #capacity: number;
|
|
363
407
|
readonly #release: (item: QueueItem) => void;
|
|
364
408
|
#next = 0;
|
|
@@ -380,14 +424,14 @@ class EventQueue {
|
|
|
380
424
|
const merged =
|
|
381
425
|
newest === undefined ? undefined : coalesceData(newest, item);
|
|
382
426
|
if (merged !== undefined && this.#newest !== undefined) {
|
|
383
|
-
// A data event retires no adapter IDs, so the absorbed one needs no
|
|
384
|
-
// `eventHandled`.
|
|
385
427
|
this.#items.set(this.#newest, merged);
|
|
428
|
+
// The absorbed event is handled: its adapter state goes now.
|
|
429
|
+
this.#release(item);
|
|
386
430
|
return undefined;
|
|
387
431
|
}
|
|
388
432
|
const id = this.#next;
|
|
389
433
|
this.#next += 1;
|
|
390
|
-
if (this.#elideUnseen(item, id)) {
|
|
434
|
+
if (this.#elideUnseen(item, id) || this.#elideConnection(item)) {
|
|
391
435
|
return undefined;
|
|
392
436
|
}
|
|
393
437
|
this.#items.set(id, item);
|
|
@@ -410,15 +454,114 @@ class EventQueue {
|
|
|
410
454
|
return undefined;
|
|
411
455
|
}
|
|
412
456
|
const item = this.#remove(oldest);
|
|
413
|
-
if (
|
|
414
|
-
item
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
457
|
+
if (item?.source === "native") {
|
|
458
|
+
if (item.event.tag === P2pEvent_Tags.StreamReady) {
|
|
459
|
+
this.#unseen.delete(item.event.inner.connId, item.event.inner.streamId);
|
|
460
|
+
}
|
|
461
|
+
for (const connId of connectionsOf(item.event)) {
|
|
462
|
+
this.#unseenConnections.delete(connId);
|
|
463
|
+
}
|
|
418
464
|
}
|
|
419
465
|
return item;
|
|
420
466
|
}
|
|
421
467
|
|
|
468
|
+
/** The application learned of `connId` outside the queue. */
|
|
469
|
+
markConnectionSeen(connId: number): void {
|
|
470
|
+
this.#unseenConnections.delete(connId);
|
|
471
|
+
this.#knownConnections.add(connId);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Records `item` against the unseen connections it names. Returns whether
|
|
476
|
+
* it ended or replaced one that carried no data, which leaves the queue
|
|
477
|
+
* with that connection's items instead.
|
|
478
|
+
*/
|
|
479
|
+
#elideConnection(item: QueueItem): boolean {
|
|
480
|
+
if (item.source !== "native") {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
const { event } = item;
|
|
484
|
+
switch (event.tag) {
|
|
485
|
+
case P2pEvent_Tags.ConnectionEstablished: {
|
|
486
|
+
if (!this.#knownConnections.has(event.inner.connId)) {
|
|
487
|
+
this.#unseenConnections.add(event.inner.connId);
|
|
488
|
+
}
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
case P2pEvent_Tags.ConnectionClosed: {
|
|
492
|
+
this.#knownConnections.delete(event.inner.connId);
|
|
493
|
+
if (!this.#unseenConnections.delete(event.inner.connId)) {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
this.#removeConnection(event.inner.connId);
|
|
497
|
+
this.#release(item);
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
case P2pEvent_Tags.ConnectionReplaced: {
|
|
501
|
+
const { newConnId, oldConnId } = event.inner;
|
|
502
|
+
this.#knownConnections.delete(oldConnId);
|
|
503
|
+
if (!this.#unseenConnections.delete(oldConnId)) {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
this.#renameOpening(oldConnId, newConnId);
|
|
507
|
+
this.#removeConnection(oldConnId);
|
|
508
|
+
if (!this.#knownConnections.has(newConnId)) {
|
|
509
|
+
this.#unseenConnections.add(newConnId);
|
|
510
|
+
}
|
|
511
|
+
this.#release(item);
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
case P2pEvent_Tags.StreamReady: {
|
|
515
|
+
if (event.inner.initiatedLocally) {
|
|
516
|
+
this.#unseenConnections.delete(event.inner.connId);
|
|
517
|
+
}
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
default: {
|
|
521
|
+
if (!UNSEEN_CONNECTION_TAGS.has(event.tag)) {
|
|
522
|
+
for (const connId of connectionsOf(event)) {
|
|
523
|
+
this.#unseenConnections.delete(connId);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** Renames the queued `ConnectionEstablished` of `from` to `to`. */
|
|
532
|
+
#renameOpening(from: number, to: number): void {
|
|
533
|
+
for (const [id, queued] of this.#items) {
|
|
534
|
+
if (
|
|
535
|
+
queued.source === "native" &&
|
|
536
|
+
queued.event.tag === P2pEvent_Tags.ConnectionEstablished &&
|
|
537
|
+
queued.event.inner.connId === from
|
|
538
|
+
) {
|
|
539
|
+
this.#items.set(id, {
|
|
540
|
+
event: {
|
|
541
|
+
...queued.event,
|
|
542
|
+
inner: { ...queued.event.inner, connId: to },
|
|
543
|
+
},
|
|
544
|
+
source: "native",
|
|
545
|
+
});
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** Removes every queued item naming `connId`, releasing each. */
|
|
552
|
+
#removeConnection(connId: number): void {
|
|
553
|
+
for (const [id, queued] of [...this.#items]) {
|
|
554
|
+
if (
|
|
555
|
+
queued.source === "native" &&
|
|
556
|
+
connectionsOf(queued.event).includes(connId)
|
|
557
|
+
) {
|
|
558
|
+
this.#remove(id);
|
|
559
|
+
this.#release(queued);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
this.#unseen.takeConnection(connId);
|
|
563
|
+
}
|
|
564
|
+
|
|
422
565
|
/**
|
|
423
566
|
* Records `item` (as `id`) against an unseen peer stream. Returns whether
|
|
424
567
|
* it closed one that carried no data, which leaves the queue whole.
|
|
@@ -647,7 +790,7 @@ export class Stream {
|
|
|
647
790
|
}
|
|
648
791
|
this.#writeEnded = new StreamClosedError("The stream write side closed");
|
|
649
792
|
if (this.#writes.length === 0) {
|
|
650
|
-
this.#backend.closeStreamWrite(this.
|
|
793
|
+
this.#backend.closeStreamWrite(this.connId, this.streamId);
|
|
651
794
|
return;
|
|
652
795
|
}
|
|
653
796
|
this.#closeWriteQueued = true;
|
|
@@ -662,7 +805,7 @@ export class Stream {
|
|
|
662
805
|
this.#discardUnread();
|
|
663
806
|
return;
|
|
664
807
|
}
|
|
665
|
-
this.#backend.resetStream(this.
|
|
808
|
+
this.#backend.resetStream(this.connId, this.streamId);
|
|
666
809
|
this.terminal();
|
|
667
810
|
}
|
|
668
811
|
|
|
@@ -676,7 +819,7 @@ export class Stream {
|
|
|
676
819
|
return;
|
|
677
820
|
}
|
|
678
821
|
try {
|
|
679
|
-
this.#backend.abandonStream(this.
|
|
822
|
+
this.#backend.abandonStream(this.connId, this.streamId);
|
|
680
823
|
} catch {
|
|
681
824
|
// A native close can overtake its queued terminal event.
|
|
682
825
|
}
|
|
@@ -820,11 +963,7 @@ export class Stream {
|
|
|
820
963
|
if (this.#closeWriteQueued) {
|
|
821
964
|
this.#closeWriteQueued = false;
|
|
822
965
|
try {
|
|
823
|
-
this.#backend.closeStreamWrite(
|
|
824
|
-
this.peerId,
|
|
825
|
-
this.connId,
|
|
826
|
-
this.streamId
|
|
827
|
-
);
|
|
966
|
+
this.#backend.closeStreamWrite(this.connId, this.streamId);
|
|
828
967
|
} catch {
|
|
829
968
|
// A deferred close has no caller left to throw to; the stream
|
|
830
969
|
// already ended, and its terminal event reports that.
|
|
@@ -835,7 +974,6 @@ export class Stream {
|
|
|
835
974
|
let accepted: boolean;
|
|
836
975
|
try {
|
|
837
976
|
accepted = this.#backend.sendStream(
|
|
838
|
-
this.peerId,
|
|
839
977
|
this.connId,
|
|
840
978
|
this.streamId,
|
|
841
979
|
head.data
|
|
@@ -1381,6 +1519,8 @@ export class Minip2pBase {
|
|
|
1381
1519
|
let identity: { readonly connId: number; readonly streamId: number };
|
|
1382
1520
|
try {
|
|
1383
1521
|
identity = this.#backend.openStream(peerId, protocolId);
|
|
1522
|
+
// The application now knows the connection: its end must reach it.
|
|
1523
|
+
this.#queue.markConnectionSeen(identity.connId);
|
|
1384
1524
|
} catch (error) {
|
|
1385
1525
|
return Promise.reject(
|
|
1386
1526
|
new OpenStreamError({
|
|
@@ -1433,6 +1573,9 @@ export class Minip2pBase {
|
|
|
1433
1573
|
* Every internal dial, relay fallback, and path upgrade belongs to that ID,
|
|
1434
1574
|
* and the attempt ends with exactly one terminal event: `pathEstablished`,
|
|
1435
1575
|
* `connectFailed`, or `connectCancelled`. Only malformed targets throw.
|
|
1576
|
+
*
|
|
1577
|
+
* A peer that is already connected keeps its connection: the attempt
|
|
1578
|
+
* settles on it and the addresses passed are not dialed.
|
|
1436
1579
|
*/
|
|
1437
1580
|
startConnect(target: ConnectTarget): number {
|
|
1438
1581
|
this.#assertOpen();
|
|
@@ -1629,11 +1772,7 @@ export class Minip2pBase {
|
|
|
1629
1772
|
clearPendingOpen(pending);
|
|
1630
1773
|
pending.reject(error);
|
|
1631
1774
|
try {
|
|
1632
|
-
this.#backend.abandonStream(
|
|
1633
|
-
pending.peerId,
|
|
1634
|
-
pending.connId,
|
|
1635
|
-
pending.streamId
|
|
1636
|
-
);
|
|
1775
|
+
this.#backend.abandonStream(pending.connId, pending.streamId);
|
|
1637
1776
|
} catch {
|
|
1638
1777
|
// The operation is already failed; native cleanup is best effort.
|
|
1639
1778
|
}
|
|
@@ -2067,11 +2206,7 @@ export class Minip2pBase {
|
|
|
2067
2206
|
clearPendingOpen(pending);
|
|
2068
2207
|
pending.reject(error);
|
|
2069
2208
|
try {
|
|
2070
|
-
this.#backend.abandonStream(
|
|
2071
|
-
pending.peerId,
|
|
2072
|
-
pending.connId,
|
|
2073
|
-
pending.streamId
|
|
2074
|
-
);
|
|
2209
|
+
this.#backend.abandonStream(pending.connId, pending.streamId);
|
|
2075
2210
|
} catch {
|
|
2076
2211
|
// Cleanup failure must not replace the caller's timeout or abort.
|
|
2077
2212
|
}
|
|
@@ -2219,6 +2354,8 @@ const SDK_EVENT_NAMES: {
|
|
|
2219
2354
|
[P2pEvent_Tags.PeerUpdated]: "peerUpdated",
|
|
2220
2355
|
[P2pEvent_Tags.PeerExpired]: "peerExpired",
|
|
2221
2356
|
[P2pEvent_Tags.DiscoveryDialFailed]: "discoveryDialFailed",
|
|
2357
|
+
[P2pEvent_Tags.MdnsFailed]: "mdnsFailed",
|
|
2358
|
+
[P2pEvent_Tags.MdnsRecovered]: "mdnsRecovered",
|
|
2222
2359
|
[P2pEvent_Tags.DiscoveryProtocolViolation]: "discoveryProtocolViolation",
|
|
2223
2360
|
};
|
|
2224
2361
|
|
|
@@ -2240,7 +2377,8 @@ function normalizeEvent(
|
|
|
2240
2377
|
payload: AnyPayload;
|
|
2241
2378
|
} {
|
|
2242
2379
|
const type = SDK_EVENT_NAMES[event.tag];
|
|
2243
|
-
|
|
2380
|
+
// A native variant without fields arrives without `inner`.
|
|
2381
|
+
let payload: unknown = "inner" in event ? event.inner : {};
|
|
2244
2382
|
if (event.tag === P2pEvent_Tags.PathEstablished) {
|
|
2245
2383
|
payload = { ...event.inner, path: normalizePath(event.inner.path) };
|
|
2246
2384
|
} else if (event.tag === P2pEvent_Tags.InboundPathEstablished) {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { P2pEvent_Tags } from "./types.js";
|
|
2
|
+
import type { P2pEvent } from "./types.js";
|
|
3
|
+
|
|
4
|
+
/** The public stream a backend event names, when it names one. */
|
|
5
|
+
export const eventStream = (
|
|
6
|
+
event: P2pEvent
|
|
7
|
+
): { readonly connId: number; readonly streamId: number } | undefined => {
|
|
8
|
+
switch (event.tag) {
|
|
9
|
+
case P2pEvent_Tags.StreamReady:
|
|
10
|
+
case P2pEvent_Tags.StreamData:
|
|
11
|
+
case P2pEvent_Tags.StreamWriteAccepted:
|
|
12
|
+
case P2pEvent_Tags.StreamWriteStopped:
|
|
13
|
+
case P2pEvent_Tags.StreamRemoteWriteClosed:
|
|
14
|
+
case P2pEvent_Tags.StreamClosed: {
|
|
15
|
+
return event.inner;
|
|
16
|
+
}
|
|
17
|
+
default: {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Native identities of streams whose events the SDK has not finished
|
|
25
|
+
* handling: the acknowledgement-only handle that outlives a stream's
|
|
26
|
+
* connection (ADR 0012).
|
|
27
|
+
*
|
|
28
|
+
* An adapter releases a connection's public ID as soon as it normalizes the
|
|
29
|
+
* event that ends it, so stream operations behind that event fail. Bytes the
|
|
30
|
+
* stream already delivered still hold the ended connection's native slot
|
|
31
|
+
* until they are acknowledged or abandoned, though, and the SDK may only get
|
|
32
|
+
* to them afterwards: dispatching a late `StreamReady`, discarding data for
|
|
33
|
+
* a stream it no longer tracks, or reading bytes kept after a FIN. Each
|
|
34
|
+
* normalized stream event holds its stream's handle until `eventHandled`, so
|
|
35
|
+
* those paths still reach native; a stream consumer captured while it was
|
|
36
|
+
* held keeps working after. With no event left in flight, the handle goes.
|
|
37
|
+
*/
|
|
38
|
+
export class SettleHandles<Native> {
|
|
39
|
+
readonly #handles = new Map<
|
|
40
|
+
number,
|
|
41
|
+
Map<number, { native: Native; held: number }>
|
|
42
|
+
>();
|
|
43
|
+
|
|
44
|
+
/** Holds `native` for the stream of one normalized event. */
|
|
45
|
+
hold(connId: number, streamId: number, native: Native): void {
|
|
46
|
+
let streams = this.#handles.get(connId);
|
|
47
|
+
if (streams === undefined) {
|
|
48
|
+
streams = new Map();
|
|
49
|
+
this.#handles.set(connId, streams);
|
|
50
|
+
}
|
|
51
|
+
const handle = streams.get(streamId);
|
|
52
|
+
if (handle === undefined) {
|
|
53
|
+
streams.set(streamId, { held: 1, native });
|
|
54
|
+
} else {
|
|
55
|
+
handle.held += 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Releases one event's hold, once the SDK handled it. */
|
|
60
|
+
release(connId: number, streamId: number): void {
|
|
61
|
+
const streams = this.#handles.get(connId);
|
|
62
|
+
const handle = streams?.get(streamId);
|
|
63
|
+
if (streams === undefined || handle === undefined) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
handle.held -= 1;
|
|
67
|
+
if (handle.held === 0) {
|
|
68
|
+
streams.delete(streamId);
|
|
69
|
+
if (streams.size === 0) {
|
|
70
|
+
this.#handles.delete(connId);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get(connId: number, streamId: number): Native | undefined {
|
|
76
|
+
return this.#handles.get(connId)?.get(streamId)?.native;
|
|
77
|
+
}
|
|
78
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -52,6 +52,45 @@ export const DiscoverySource = {
|
|
|
52
52
|
export type DiscoverySource =
|
|
53
53
|
(typeof DiscoverySource)[keyof typeof DiscoverySource];
|
|
54
54
|
|
|
55
|
+
/** Categories of an mDNS failure reported by `mdnsFailed`. */
|
|
56
|
+
export const MdnsFailureKind = {
|
|
57
|
+
/** A goodbye could not be sent before shutdown gave up on a full send buffer. */
|
|
58
|
+
Congested: "Congested",
|
|
59
|
+
/** The interface id space is exhausted. */
|
|
60
|
+
InterfaceIdsExhausted: "InterfaceIdsExhausted",
|
|
61
|
+
/** Platform I/O failed. */
|
|
62
|
+
Io: "Io",
|
|
63
|
+
/** An interface has no usable address. */
|
|
64
|
+
NoInterfaceAddress: "NoInterfaceAddress",
|
|
65
|
+
/** A datagram is larger than the carrier can ever send. */
|
|
66
|
+
Oversized: "Oversized",
|
|
67
|
+
/** A send named an interface that has gone away. */
|
|
68
|
+
UnknownInterface: "UnknownInterface",
|
|
69
|
+
/** The platform cannot provide mDNS sockets. */
|
|
70
|
+
Unsupported: "Unsupported",
|
|
71
|
+
} as const;
|
|
72
|
+
export type MdnsFailureKind =
|
|
73
|
+
(typeof MdnsFailureKind)[keyof typeof MdnsFailureKind];
|
|
74
|
+
|
|
75
|
+
/** The part of an endpoint's configuration an `InvalidConfigError` names. */
|
|
76
|
+
export const ConfigCapability = {
|
|
77
|
+
/** Signed discovery or peer-book settings. */
|
|
78
|
+
Discovery: "Discovery",
|
|
79
|
+
/** Gossipsub settings. */
|
|
80
|
+
Gossipsub: "Gossipsub",
|
|
81
|
+
/** mDNS settings. */
|
|
82
|
+
Mdns: "Mdns",
|
|
83
|
+
/**
|
|
84
|
+
* The endpoint's own options: listen addresses, protocols, NAT and relay
|
|
85
|
+
* policy, auto-dial.
|
|
86
|
+
*/
|
|
87
|
+
Options: "Options",
|
|
88
|
+
/** QUIC or TCP transport settings. */
|
|
89
|
+
Transport: "Transport",
|
|
90
|
+
} as const;
|
|
91
|
+
export type ConfigCapability =
|
|
92
|
+
(typeof ConfigCapability)[keyof typeof ConfigCapability];
|
|
93
|
+
|
|
55
94
|
/** Fatal native-driver failure categories. */
|
|
56
95
|
export const DriverFailureKind = {
|
|
57
96
|
Invariant: "Invariant",
|
|
@@ -198,9 +237,20 @@ export interface Minip2pNamedEventMap {
|
|
|
198
237
|
readonly connId: number;
|
|
199
238
|
readonly protocols: readonly string[];
|
|
200
239
|
};
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
240
|
+
/** An Identify snapshot arrived on `connId`. */
|
|
241
|
+
identifyReceived: {
|
|
242
|
+
readonly peerId: string;
|
|
243
|
+
readonly connId: number;
|
|
244
|
+
readonly info: IdentifyInfo;
|
|
245
|
+
};
|
|
246
|
+
/** A ping round trip completed on `connId`. */
|
|
247
|
+
pingRttMeasured: {
|
|
248
|
+
readonly peerId: string;
|
|
249
|
+
readonly connId: number;
|
|
250
|
+
readonly rttMs: number;
|
|
251
|
+
};
|
|
252
|
+
/** A ping sent on `connId` timed out. */
|
|
253
|
+
pingTimeout: { readonly peerId: string; readonly connId: number };
|
|
204
254
|
stream: Stream;
|
|
205
255
|
endpointError: {
|
|
206
256
|
readonly kind: EndpointErrorKind;
|
|
@@ -229,12 +279,18 @@ export interface Minip2pNamedEventMap {
|
|
|
229
279
|
inboundPathEstablished: {
|
|
230
280
|
readonly peerId: string;
|
|
231
281
|
readonly path: Path;
|
|
282
|
+
/** Circuit connection carrying the path. */
|
|
283
|
+
readonly connId: number;
|
|
232
284
|
};
|
|
233
285
|
pathUpgraded: {
|
|
234
286
|
readonly connectId: number;
|
|
235
287
|
readonly peerId: string;
|
|
236
288
|
readonly from: Path;
|
|
237
289
|
readonly to: Path;
|
|
290
|
+
/** Connection that carried `from`. */
|
|
291
|
+
readonly oldConnId: number;
|
|
292
|
+
/** Connection carrying `to`. */
|
|
293
|
+
readonly newConnId: number;
|
|
238
294
|
};
|
|
239
295
|
holePunchFailed: {
|
|
240
296
|
readonly connectId: number;
|
|
@@ -251,7 +307,13 @@ export interface Minip2pNamedEventMap {
|
|
|
251
307
|
readonly connectId: number;
|
|
252
308
|
readonly peerId: string;
|
|
253
309
|
};
|
|
254
|
-
inboundDirectUpgrade: {
|
|
310
|
+
inboundDirectUpgrade: {
|
|
311
|
+
readonly peerId: string;
|
|
312
|
+
/** Circuit connection that carried the relayed path. */
|
|
313
|
+
readonly oldConnId: number;
|
|
314
|
+
/** Direct connection now carrying the peer. */
|
|
315
|
+
readonly newConnId: number;
|
|
316
|
+
};
|
|
255
317
|
message: {
|
|
256
318
|
readonly fromPeerId: string;
|
|
257
319
|
readonly topics: readonly string[];
|
|
@@ -281,6 +343,14 @@ export interface Minip2pNamedEventMap {
|
|
|
281
343
|
};
|
|
282
344
|
peerExpired: { readonly peerId: string };
|
|
283
345
|
discoveryDialFailed: { readonly peerId: string; readonly reason: string };
|
|
346
|
+
/**
|
|
347
|
+
* mDNS hit a hard failure. It keeps running and retries; this fires once
|
|
348
|
+
* per change in failure state, and `mdnsRecovered` follows once a retry
|
|
349
|
+
* succeeds. A goodbye that failed during shutdown is final.
|
|
350
|
+
*/
|
|
351
|
+
mdnsFailed: { readonly kind: MdnsFailureKind; readonly detail: string };
|
|
352
|
+
/** mDNS recovered from its last `mdnsFailed`. Carries no fields. */
|
|
353
|
+
mdnsRecovered: Readonly<Record<never, never>>;
|
|
284
354
|
discoveryProtocolViolation: {
|
|
285
355
|
readonly peerId?: string;
|
|
286
356
|
readonly source: DiscoverySource;
|
|
@@ -427,6 +497,8 @@ export const P2pEvent_Tags = {
|
|
|
427
497
|
IdentifyReceived: "IdentifyReceived",
|
|
428
498
|
InboundDirectUpgrade: "InboundDirectUpgrade",
|
|
429
499
|
InboundPathEstablished: "InboundPathEstablished",
|
|
500
|
+
MdnsFailed: "MdnsFailed",
|
|
501
|
+
MdnsRecovered: "MdnsRecovered",
|
|
430
502
|
Message: "Message",
|
|
431
503
|
PathEstablished: "PathEstablished",
|
|
432
504
|
PathUpgraded: "PathUpgraded",
|
|
@@ -484,13 +556,16 @@ export type P2pEvent =
|
|
|
484
556
|
| RawEvent<typeof P2pEvent_Tags.PeerReady, Minip2pNamedEventMap["peerReady"]>
|
|
485
557
|
| RawEvent<
|
|
486
558
|
typeof P2pEvent_Tags.IdentifyReceived,
|
|
487
|
-
|
|
559
|
+
Minip2pNamedEventMap["identifyReceived"]
|
|
488
560
|
>
|
|
489
561
|
| RawEvent<
|
|
490
562
|
typeof P2pEvent_Tags.PingRttMeasured,
|
|
491
|
-
|
|
563
|
+
Minip2pNamedEventMap["pingRttMeasured"]
|
|
564
|
+
>
|
|
565
|
+
| RawEvent<
|
|
566
|
+
typeof P2pEvent_Tags.PingTimeout,
|
|
567
|
+
Minip2pNamedEventMap["pingTimeout"]
|
|
492
568
|
>
|
|
493
|
-
| RawEvent<typeof P2pEvent_Tags.PingTimeout, { peerId: string }>
|
|
494
569
|
| RawEvent<typeof P2pEvent_Tags.StreamReady, InboundStreamMeta>
|
|
495
570
|
| RawEvent<
|
|
496
571
|
typeof P2pEvent_Tags.StreamData,
|
|
@@ -538,11 +613,18 @@ export type P2pEvent =
|
|
|
538
613
|
>
|
|
539
614
|
| RawEvent<
|
|
540
615
|
typeof P2pEvent_Tags.InboundPathEstablished,
|
|
541
|
-
{ peerId: string; path: PathKind }
|
|
616
|
+
{ peerId: string; path: PathKind; connId: number }
|
|
542
617
|
>
|
|
543
618
|
| RawEvent<
|
|
544
619
|
typeof P2pEvent_Tags.PathUpgraded,
|
|
545
|
-
{
|
|
620
|
+
{
|
|
621
|
+
connectId: number;
|
|
622
|
+
peerId: string;
|
|
623
|
+
from: PathKind;
|
|
624
|
+
to: PathKind;
|
|
625
|
+
oldConnId: number;
|
|
626
|
+
newConnId: number;
|
|
627
|
+
}
|
|
546
628
|
>
|
|
547
629
|
| RawEvent<
|
|
548
630
|
typeof P2pEvent_Tags.HolePunchFailed,
|
|
@@ -593,6 +675,12 @@ export type P2pEvent =
|
|
|
593
675
|
typeof P2pEvent_Tags.DiscoveryDialFailed,
|
|
594
676
|
Minip2pNamedEventMap["discoveryDialFailed"]
|
|
595
677
|
>
|
|
678
|
+
| RawEvent<
|
|
679
|
+
typeof P2pEvent_Tags.MdnsFailed,
|
|
680
|
+
Minip2pNamedEventMap["mdnsFailed"]
|
|
681
|
+
>
|
|
682
|
+
// A variant without fields has no `inner`, as both runtimes deliver it.
|
|
683
|
+
| { readonly tag: typeof P2pEvent_Tags.MdnsRecovered }
|
|
596
684
|
| RawEvent<
|
|
597
685
|
typeof P2pEvent_Tags.DiscoveryProtocolViolation,
|
|
598
686
|
Minip2pNamedEventMap["discoveryProtocolViolation"]
|