@minip2p/core 0.9.1 → 0.10.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 +2 -2
- package/dist/backend.d.ts +49 -6
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +64 -2
- package/dist/backend.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sdk.d.ts +34 -8
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +131 -40
- package/dist/sdk.js.map +1 -1
- package/dist/serde-backend.d.ts +125 -0
- package/dist/serde-backend.d.ts.map +1 -0
- package/dist/serde-backend.js +603 -0
- package/dist/serde-backend.js.map +1 -0
- package/dist/types.d.ts +113 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +21 -2
- package/dist/types.js.map +1 -1
- package/package.json +6 -1
- package/src/backend.ts +105 -6
- package/src/index.ts +4 -1
- package/src/sdk.ts +155 -42
- package/src/serde-backend.ts +833 -0
- package/src/types.ts +114 -18
package/README.md
CHANGED
|
@@ -39,11 +39,11 @@ for await (const event of endpoint.events({ signal })) {
|
|
|
39
39
|
}
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
A peer holds one connection at a time. `connectionEstablished` and `connectionClosed` mark the peer connecting and disconnecting; when a newer connection takes the peer's slot, a single `connectionReplaced` (`{ peerId, oldConnId, newConnId }`) stands in for both, the peer stays connected, and streams and pending opens on `oldConnId` end with `StreamClosedError`. `peerReady` carries the `connId` that completed Identify and fires once per connection. `waitPeerReady` follows the peer's current connection, so a stale `peerReady` for a replaced connection never resolves it; it resolves at once when `connectionInfo(peerId).readyProtocols` shows the current connection is already ready, and rejects with `PeerDisconnectedError` when that connection closes.
|
|
42
|
+
A peer holds one connection at a time. `connectionEstablished` and `connectionClosed` mark the peer connecting and disconnecting, and `connectionClosed` carries a `reason` (`ConnectionCloseReason`: `local`, `remote` with the peer's `code`, `timedOut`, `stalled`, or `error` with a `message`); when a newer connection takes the peer's slot, a single `connectionReplaced` (`{ peerId, oldConnId, newConnId }`) stands in for both, the peer stays connected, and streams and pending opens on `oldConnId` end with `StreamClosedError`. `peerReady` carries the `connId` that completed Identify and fires once per connection. `waitPeerReady` follows the peer's current connection, so a stale `peerReady` for a replaced connection never resolves it; it resolves at once when `connectionInfo(peerId).readyProtocols` shows the current connection is already ready, and rejects with `PeerDisconnectedError` when that connection closes.
|
|
43
43
|
|
|
44
44
|
`connect` accepts a Connection target: a peer ID, one complete peer multiaddress, or a list of complete addresses naming one peer. For a Connection attempt, a timeout ends only the local wait (`cancelOnTimeout: true` opts into cancelling), an aborted `signal` cancels the attempt (the wait settles from its terminal), and a terminal lost to event overflow rejects with `ConnectResultLostError`. Waits never stop unrelated events from reaching other subscribers.
|
|
45
45
|
|
|
46
|
-
Use `endpoint.on("stream", handler)` to claim inbound streams. Operations accept `{ timeoutMs, signal }`; the default timeout is 65 seconds and `timeoutMs: 0` disables it.
|
|
46
|
+
Use `endpoint.on("stream", handler)` to claim inbound streams. Operations accept `{ timeoutMs, signal }`; the default timeout is 65 seconds and `timeoutMs: 0` disables it. Streams implement `Symbol.dispose`. `endpoint.close(timeoutMs = 500)` rejects outstanding operations at once, then resolves with an `EndpointCloseReport` (`{ reason, outcome?, unfinished }`) once native has disconnected peers and drained for up to `timeoutMs` (`0` tears down at once); `onClose` observers receive the same report then. The deadline bounds teardown time, not delivery of accepted writes. Endpoints implement `Symbol.asyncDispose` (awaits `close()`) and `Symbol.dispose` (starts it).
|
|
47
47
|
|
|
48
48
|
`create` throws `InvalidConfigError` when native rejects the configuration. Its `capability` (`Gossipsub`, `Mdns`, `Discovery`, `Transport`, or `Options`, from `ConfigCapability`) names the part to change, and `detail` carries the native diagnostic. A malformed listen address and a socket the platform refused are not config errors; they keep their native error codes.
|
|
49
49
|
|
package/dist/backend.d.ts
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
+
import { CloseOutcome } from "./types.js";
|
|
1
2
|
import type { Bytes, ConnectionInfo, IdentifyInfo, KnownPeerInfo, Minip2pConfig, PathKind, P2pEvent, Reachability, RelayReservationInfo } from "./types.js";
|
|
3
|
+
/** How the native endpoint's close drain ended (`EndpointClosed`). */
|
|
4
|
+
export interface BackendClosed {
|
|
5
|
+
readonly outcome: CloseOutcome;
|
|
6
|
+
/** Peers whose connections were still tracked, each once. */
|
|
7
|
+
readonly unfinished: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The peers `EndpointClosed`'s unfinished connections name, each once. An
|
|
11
|
+
* inbound handshake that had not identified its peer names none.
|
|
12
|
+
*/
|
|
13
|
+
export declare const unfinishedPeers: (unfinished: readonly {
|
|
14
|
+
readonly peerId?: string | undefined;
|
|
15
|
+
}[]) => string[];
|
|
16
|
+
/**
|
|
17
|
+
* A native adapter's side of {@link Minip2pBackend.close}: stops native once,
|
|
18
|
+
* then resolves with the native `EndpointClosed` the adapter hands to
|
|
19
|
+
* {@link settle}, or at once when no driver started.
|
|
20
|
+
*/
|
|
21
|
+
export declare class NativeCloseLatch {
|
|
22
|
+
#private;
|
|
23
|
+
constructor();
|
|
24
|
+
/** Whether `close` was called; later native events can be ignored. */
|
|
25
|
+
get requested(): boolean;
|
|
26
|
+
/** Records the native `EndpointClosed`, which may precede `close`. */
|
|
27
|
+
settle(closed: BackendClosed): void;
|
|
28
|
+
/**
|
|
29
|
+
* Runs `stop` on the first call, then resolves once native closed and
|
|
30
|
+
* `release`, if any, ran; a `stop` that throws resolves `Failed`. Later
|
|
31
|
+
* calls return the same promise, which never rejects.
|
|
32
|
+
*/
|
|
33
|
+
close(started: boolean, stop: () => void, release?: () => void): Promise<BackendClosed>;
|
|
34
|
+
}
|
|
35
|
+
/** A native connection snapshot: {@link ConnectionInfo} with the raw path. */
|
|
36
|
+
export interface BackendConnectionInfo extends Omit<ConnectionInfo, "path"> {
|
|
37
|
+
readonly path: PathKind;
|
|
38
|
+
}
|
|
2
39
|
/** Full native identity allocated for an outbound stream. */
|
|
3
40
|
export interface BackendOpenStream {
|
|
4
41
|
/** Endpoint-local connection carrying the stream. */
|
|
@@ -31,8 +68,14 @@ export interface Minip2pBackend {
|
|
|
31
68
|
* elided, dropped, or coalesced into an earlier one.
|
|
32
69
|
*/
|
|
33
70
|
eventHandled?: (event: P2pEvent) => void;
|
|
34
|
-
/**
|
|
35
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Requests native shutdown, draining for up to `timeoutMs` (`0` tears down
|
|
73
|
+
* at once), and resolves with the native `EndpointClosed`, the driver's
|
|
74
|
+
* last event, once the native endpoint is released. Idempotent: later
|
|
75
|
+
* calls return the same promise and their timeout is ignored. Resolves at
|
|
76
|
+
* once for a backend whose `start` failed. Never rejects.
|
|
77
|
+
*/
|
|
78
|
+
close: (timeoutMs: number) => Promise<BackendClosed>;
|
|
36
79
|
/** Returns the local peer ID. */
|
|
37
80
|
peerId: () => string;
|
|
38
81
|
/** Returns bound peer multiaddresses. */
|
|
@@ -49,10 +92,10 @@ export interface Minip2pBackend {
|
|
|
49
92
|
discoveryNowMs: () => number | undefined;
|
|
50
93
|
/** Returns the active relay reservation. */
|
|
51
94
|
activeReservation: () => RelayReservationInfo | undefined;
|
|
52
|
-
/** Returns the
|
|
95
|
+
/** Returns the path of a peer's established connection. */
|
|
53
96
|
path: (peerId: string) => PathKind | undefined;
|
|
54
|
-
/** Returns
|
|
55
|
-
connectionInfo: (peerId: string) =>
|
|
97
|
+
/** Returns a snapshot of a peer's established connection. */
|
|
98
|
+
connectionInfo: (peerId: string) => BackendConnectionInfo | undefined;
|
|
56
99
|
/** Builds a circuit address through a relay. */
|
|
57
100
|
circuitAddress: (relayAddress: string, peerId: string) => string;
|
|
58
101
|
/** Returns the native reachability state. */
|
|
@@ -113,7 +156,7 @@ export { resolveEndpointConfig, type BackendEndpointConfig } from "./config.js";
|
|
|
113
156
|
export { EventDrain } from "./event-drain.js";
|
|
114
157
|
export { ConnectionIdMap, u64ToNumber } from "./native-ids.js";
|
|
115
158
|
export { SettleHandles, eventStream } from "./settle-handles.js";
|
|
116
|
-
export { P2pEvent_Tags, PathKind_Tags, type P2pEvent, type P2pEventByTag, type PathKind, } from "./types.js";
|
|
159
|
+
export { ConnectionCloseReason_Tags, P2pEvent_Tags, PathKind_Tags, type P2pEvent, type P2pEventByTag, type PathKind, type RawConnectionCloseReason, } from "./types.js";
|
|
117
160
|
/**
|
|
118
161
|
* The parts of a native `FfiError` an adapter reads off its toolchain's error
|
|
119
162
|
* value: the variant name, its detail field, and an `InvalidConfig`'s
|
package/dist/backend.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAoB,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EACV,KAAK,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,eACd,SAAS;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,EAAE,KAC9D,MAAM,EAIR,CAAC;AAEF;;;;GAIG;AACH,qBAAa,gBAAgB;;IAK3B,cAKC;IAED,sEAAsE;IACtE,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,sEAAsE;IACtE,MAAM,CAAC,MAAM,EAAE,aAAa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,EACb,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAMD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,iCAIvB,iBAAiB,KAAG,KAAK,GAAG,SAoB9B,CAAC;AAEF,gFAAgF;AAChF,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,cAAc,CAAC;IAClD,iBAAiB,EAAE,MAAM,UAAU,CAAC;IACpC,mBAAmB,EAAE,CAAC,SAAS,EAAE,KAAK,KAAK,MAAM,CAAC;IAClD,cAAc,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAClE"}
|
package/dist/backend.js
CHANGED
|
@@ -1,10 +1,72 @@
|
|
|
1
1
|
import { BackpressureError, InvalidConfigError, MessageTooLargeError, NotPermittedError, } from "./errors.js";
|
|
2
|
-
import { ConfigCapability } from "./types.js";
|
|
2
|
+
import { CloseOutcome, ConfigCapability } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The peers `EndpointClosed`'s unfinished connections name, each once. An
|
|
5
|
+
* inbound handshake that had not identified its peer names none.
|
|
6
|
+
*/
|
|
7
|
+
export const unfinishedPeers = (unfinished) => [
|
|
8
|
+
...new Set(unfinished.flatMap(({ peerId }) => (peerId === undefined ? [] : [peerId]))),
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* A native adapter's side of {@link Minip2pBackend.close}: stops native once,
|
|
12
|
+
* then resolves with the native `EndpointClosed` the adapter hands to
|
|
13
|
+
* {@link settle}, or at once when no driver started.
|
|
14
|
+
*/
|
|
15
|
+
export class NativeCloseLatch {
|
|
16
|
+
#closed;
|
|
17
|
+
#resolve;
|
|
18
|
+
#closing;
|
|
19
|
+
constructor() {
|
|
20
|
+
// oxlint-disable-next-line promise/avoid-new -- Settled by a native event, not a callback API.
|
|
21
|
+
this.#closed = new Promise((resolve) => {
|
|
22
|
+
this.#resolve = resolve;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** Whether `close` was called; later native events can be ignored. */
|
|
26
|
+
get requested() {
|
|
27
|
+
return this.#closing !== undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Records the native `EndpointClosed`, which may precede `close`. */
|
|
30
|
+
settle(closed) {
|
|
31
|
+
this.#resolve?.(closed);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runs `stop` on the first call, then resolves once native closed and
|
|
35
|
+
* `release`, if any, ran; a `stop` that throws resolves `Failed`. Later
|
|
36
|
+
* calls return the same promise, which never rejects.
|
|
37
|
+
*/
|
|
38
|
+
close(started, stop, release) {
|
|
39
|
+
this.#closing ??= this.#finish(started, stop, release);
|
|
40
|
+
return this.#closing;
|
|
41
|
+
}
|
|
42
|
+
async #finish(started, stop, release) {
|
|
43
|
+
let closed;
|
|
44
|
+
try {
|
|
45
|
+
stop();
|
|
46
|
+
// Without a driver, native released the endpoint at once.
|
|
47
|
+
closed = started
|
|
48
|
+
? await this.#closed
|
|
49
|
+
: { outcome: CloseOutcome.Drained, unfinished: [] };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Native failed to stop (a trap): no `EndpointClosed` will come, but
|
|
53
|
+
// close still never rejects and still releases.
|
|
54
|
+
closed = { outcome: CloseOutcome.Failed, unfinished: [] };
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
release?.();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// The endpoint is closed either way; the report still stands.
|
|
61
|
+
}
|
|
62
|
+
return closed;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
3
65
|
export { resolveEndpointConfig } from "./config.js";
|
|
4
66
|
export { EventDrain } from "./event-drain.js";
|
|
5
67
|
export { ConnectionIdMap, u64ToNumber } from "./native-ids.js";
|
|
6
68
|
export { SettleHandles, eventStream } from "./settle-handles.js";
|
|
7
|
-
export { P2pEvent_Tags, PathKind_Tags, } from "./types.js";
|
|
69
|
+
export { ConnectionCloseReason_Tags, P2pEvent_Tags, PathKind_Tags, } from "./types.js";
|
|
8
70
|
// Each capability's name is its value, so an own key is a capability.
|
|
9
71
|
const isConfigCapability = (name) => Object.hasOwn(ConfigCapability, name);
|
|
10
72
|
/**
|
package/dist/backend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAoB5D;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAA+D,EACrD,EAAE,CAAC;IACb,GAAG,IAAI,GAAG,CACR,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAC3E;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAClB,OAAO,CAAyB;IACzC,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AO,EAAE,qBAAqB,EAA8B,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EACL,0BAA0B,EAC1B,aAAa,EACb,aAAa,GAKd,MAAM,YAAY,CAAC;AAapB,sEAAsE;AACtE,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAA4B,EAAE,CACpE,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAExC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,UAAU,EACV,MAAM,EACN,GAAG,GACe,EAAqB,EAAE;IACzC,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,cAAc,EAAE,CAAC;YACpB,OAAO,IAAI,iBAAiB,EAAE,CAAC;QACjC,CAAC;QACD,KAAK,iBAAiB,EAAE,CAAC;YACvB,OAAO,IAAI,oBAAoB,EAAE,CAAC;QACpC,CAAC;QACD,KAAK,cAAc,EAAE,CAAC;YACpB,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,eAAe,EAAE,CAAC;YACrB,OAAO,UAAU,KAAK,SAAS,IAAI,kBAAkB,CAAC,UAAU,CAAC;gBAC/D,CAAC,CAAC,IAAI,kBAAkB,CAAC,UAAU,EAAE,MAAM,IAAI,EAAE,CAAC;gBAClD,CAAC,CAAC,SAAS,CAAC;QAChB,CAAC;QACD,SAAS,CAAC;YACR,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { AbortError, BackpressureError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, InvalidConfigError, MessageTooLargeError, NotPermittedError, OpenStreamError, PeerDisconnectedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
2
2
|
export { Minip2pBase, Stream, type StreamEventMap } from "./sdk.js";
|
|
3
|
-
export { ConfigCapability, DiscoverySource, DriverFailureKind, EndpointErrorKind, MdnsFailureKind, NatErrorKind, Reachability, type Bytes, type
|
|
3
|
+
export { CloseOutcome, ConfigCapability, DiscoverySource, DriverFailureKind, EndpointErrorKind, MdnsFailureKind, NatErrorKind, Reachability, type Bytes, type ConnectionCloseReason, type ConnectionInfo, type ConnectOptions, type ConnectResult, type ConnectTarget, type EndpointCloseReason, type EndpointCloseReport, type EventsOptions, type IdentifyInfo, type InboundStreamMeta, type KnownPeerInfo, type Minip2pCatchAllEventMap, type Minip2pConfig, type Minip2pDiscoveryOptions, type Minip2pEvent, type Minip2pMdnsOptions, type Minip2pNamedEventMap, type OnceOptions, type OpOptions, type Path, type RelayReservationInfo, type Unsubscribe, type WaitForOptions, } from "./types.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,KAAK,KAAK,EACV,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,KAAK,KAAK,EACV,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { AbortError, BackpressureError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, InvalidConfigError, MessageTooLargeError, NotPermittedError, OpenStreamError, PeerDisconnectedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
2
2
|
export { Minip2pBase, Stream } from "./sdk.js";
|
|
3
|
-
export { ConfigCapability, DiscoverySource, DriverFailureKind, EndpointErrorKind, MdnsFailureKind, NatErrorKind, Reachability, } from "./types.js";
|
|
3
|
+
export { CloseOutcome, ConfigCapability, DiscoverySource, DriverFailureKind, EndpointErrorKind, MdnsFailureKind, NatErrorKind, Reachability, } from "./types.js";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,GAyBb,MAAM,YAAY,CAAC"}
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Minip2pBackend } from "./backend.js";
|
|
2
|
-
import type { Bytes,
|
|
2
|
+
import type { Bytes, ConnectionInfo, ConnectOptions, ConnectResult, ConnectTarget, EndpointCloseReport, EventsOptions, IdentifyInfo, InboundStreamMeta, KnownPeerInfo, Minip2pEvent, Minip2pNamedEventMap, OnceOptions, OpOptions, Path, Reachability, RelayReservationInfo, Unsubscribe, WaitForOptions } from "./types.js";
|
|
3
3
|
type EventKind = keyof Minip2pNamedEventMap;
|
|
4
4
|
type NamedHandler<Kind extends EventKind> = (payload: Minip2pNamedEventMap[Kind]) => void;
|
|
5
5
|
type CatchAllHandler = (event: Minip2pEvent) => void;
|
|
@@ -145,14 +145,33 @@ export declare class Minip2pBase {
|
|
|
145
145
|
} & Minip2pNamedEventMap[Kind]>): Promise<{
|
|
146
146
|
readonly type: Kind;
|
|
147
147
|
} & Minip2pNamedEventMap[Kind]>;
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Registers a one-shot endpoint shutdown observer. It stays registered
|
|
150
|
+
* through the native close drain and fires once that finishes, with the
|
|
151
|
+
* same report {@link close} resolves with. A no-op once it has fired.
|
|
152
|
+
*/
|
|
153
|
+
onClose(handler: (report: EndpointCloseReport) => void): Unsubscribe;
|
|
154
|
+
/**
|
|
155
|
+
* Stops the endpoint: rejects outstanding operations and drops listeners
|
|
156
|
+
* at once, then has native disconnect peers and drain for up to
|
|
157
|
+
* `timeoutMs` (default 500; `0` tears down at once, best effort). Resolves
|
|
158
|
+
* with the close report once the drain finished, after `onClose`
|
|
159
|
+
* observers ran; it never rejects. The deadline bounds teardown time only,
|
|
160
|
+
* not delivery of accepted writes: QUIC discards queued writes and TCP may
|
|
161
|
+
* abort. Idempotent: a later call returns the same promise, including
|
|
162
|
+
* after a driver failure closed the endpoint.
|
|
163
|
+
*/
|
|
164
|
+
close(timeoutMs?: number): Promise<EndpointCloseReport>;
|
|
165
|
+
/** Starts {@link close} with the default drain, without waiting for it. */
|
|
152
166
|
[Symbol.dispose](): void;
|
|
167
|
+
/** {@link close} with the default drain, for `await using`. */
|
|
168
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
153
169
|
/** Returns this endpoint's base58 peer ID. */
|
|
154
170
|
peerId(): string;
|
|
155
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Returns the currently bound peer multiaddresses. A WebTransport
|
|
173
|
+
* listener's certhashes rotate; `listenAddressesChanged` says when.
|
|
174
|
+
*/
|
|
156
175
|
listenAddrs(): string[];
|
|
157
176
|
/** Returns peer IDs with live transport connections. */
|
|
158
177
|
connectedPeers(): string[];
|
|
@@ -170,9 +189,16 @@ export declare class Minip2pBase {
|
|
|
170
189
|
get circuitAddress(): string | undefined;
|
|
171
190
|
/** Returns the latest AutoNAT reachability verdict. */
|
|
172
191
|
reachability(): Reachability;
|
|
173
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* Returns the path of `peerId`'s established connection; `undefined` only
|
|
194
|
+
* while the peer is not connected.
|
|
195
|
+
*/
|
|
174
196
|
path(peerId: string): Path | undefined;
|
|
175
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* Returns a snapshot of `peerId`'s established connection: its connection
|
|
199
|
+
* ID, remote address, path, and Identify protocols once ready;
|
|
200
|
+
* `undefined` while the peer is not connected.
|
|
201
|
+
*/
|
|
176
202
|
connectionInfo(peerId: string): ConnectionInfo | undefined;
|
|
177
203
|
/** Returns whether the native driver is accepting work. */
|
|
178
204
|
isRunning(): boolean;
|
package/dist/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,cAAc,EACf,MAAM,cAAc,CAAC;AAsBtB,OAAO,KAAK,EACV,KAAK,EAEL,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,aAAa,EAEb,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,SAAS,EAGT,IAAI,EAGJ,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,cAAc,EACf,MAAM,YAAY,CAAC;AAuCpB,KAAK,SAAS,GAAG,MAAM,oBAAoB,CAAC;AAE5C,KAAK,YAAY,CAAC,IAAI,SAAS,SAAS,IAAI,CAC1C,OAAO,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAChC,IAAI,CAAC;AACV,KAAK,eAAe,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAohBrD,gFAAgF;AAChF,qBAAa,MAAM;;IACjB,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IAuBnC;;;;OAIG;IACH,kBAAkB,SAAiC;IAEnD,YACE,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,iBAAiB,EACvB,UAAU,EAAE,MA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,MAAM,GAAG,KAAK,GAAG,IAAI,CAGjD;IAED,oEAAoE;IACpE,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAGpC;IAED;;;;;;OAMG;IACH,aAAa,CACX,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,SAAc,GACtB,OAAO,CAAC;QACT,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;KACvC,CAAC,CAoCD;IAED,gFAAgF;IAChF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAsB7D;IAED,2DAA2D;IAC3D,UAAU,CACR,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,SAAc,GACtB,OAAO,CAAC,MAAM,CAAC,CAwDjB;IAED;;;;;;;;;OASG;IACH,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAK1C;IAED;;;;OAIG;IACH,OAAO,CACL,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAQxB;IAED;;;;;;;;;;;OAWG;IACH,iBAAiB,CACf,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAoDxB;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAIrC;IAED,gDAAgD;IAChD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAG/B;CA6mBF"}
|
package/dist/sdk.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/* oxlint-disable default-case, func-style, max-classes-per-file, no-await-in-loop, no-empty-function, no-loop-func, no-use-before-define, promise/avoid-new, promise/prefer-await-to-callbacks, promise/prefer-await-to-then, typescript/no-invalid-void-type, unicorn/consistent-function-scoping, unicorn/no-new-array, unicorn/no-useless-spread, unicorn/no-useless-undefined -- Promise adapters, sequential async iterators, void event payloads, snapshot fan-out, and bounded queues are deliberate SDK internals. */
|
|
2
2
|
import { AbortError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, OpenStreamError, PeerDisconnectedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
3
|
-
import { P2pEvent_Tags, PathKind_Tags } from "./types.js";
|
|
3
|
+
import { CloseOutcome, ConnectionCloseReason_Tags, P2pEvent_Tags, PathKind_Tags, } from "./types.js";
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 65_000;
|
|
5
|
+
/**
|
|
6
|
+
* Default close drain: the Rust `minip2p::DEFAULT_CLOSE_TIMEOUT` (500 ms)
|
|
7
|
+
* that `Endpoint::close` and native's `DEFAULT_STOP_TIMEOUT_MS` use.
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_CLOSE_TIMEOUT_MS = 500;
|
|
5
10
|
const EVENT_QUEUE_CAP = 4096;
|
|
6
11
|
const EVENT_FLUSH_BATCH = 256;
|
|
7
12
|
const CONNECT_TERMINAL_CAP = 1024;
|
|
@@ -873,6 +878,9 @@ export class Minip2pBase {
|
|
|
873
878
|
#dropped = 0;
|
|
874
879
|
#flushScheduled = false;
|
|
875
880
|
#closed = false;
|
|
881
|
+
/** Settles once the native drain finished and close observers ran. */
|
|
882
|
+
#closing;
|
|
883
|
+
#closeReported = false;
|
|
876
884
|
constructor(backend, relayAddresses) {
|
|
877
885
|
this.#backend = backend;
|
|
878
886
|
this.#relayAddrs = relayAddresses;
|
|
@@ -882,7 +890,7 @@ export class Minip2pBase {
|
|
|
882
890
|
});
|
|
883
891
|
}
|
|
884
892
|
catch (error) {
|
|
885
|
-
backend.close();
|
|
893
|
+
void backend.close(0);
|
|
886
894
|
throw error;
|
|
887
895
|
}
|
|
888
896
|
}
|
|
@@ -1006,26 +1014,48 @@ export class Minip2pBase {
|
|
|
1006
1014
|
this.#waiters.add(waiter);
|
|
1007
1015
|
});
|
|
1008
1016
|
}
|
|
1009
|
-
/**
|
|
1017
|
+
/**
|
|
1018
|
+
* Registers a one-shot endpoint shutdown observer. It stays registered
|
|
1019
|
+
* through the native close drain and fires once that finishes, with the
|
|
1020
|
+
* same report {@link close} resolves with. A no-op once it has fired.
|
|
1021
|
+
*/
|
|
1010
1022
|
onClose(handler) {
|
|
1011
|
-
if (this.#
|
|
1023
|
+
if (this.#closeReported) {
|
|
1012
1024
|
return () => { };
|
|
1013
1025
|
}
|
|
1014
1026
|
return subscribe(this.#closeHandlers, handler);
|
|
1015
1027
|
}
|
|
1016
|
-
/**
|
|
1017
|
-
|
|
1018
|
-
|
|
1028
|
+
/**
|
|
1029
|
+
* Stops the endpoint: rejects outstanding operations and drops listeners
|
|
1030
|
+
* at once, then has native disconnect peers and drain for up to
|
|
1031
|
+
* `timeoutMs` (default 500; `0` tears down at once, best effort). Resolves
|
|
1032
|
+
* with the close report once the drain finished, after `onClose`
|
|
1033
|
+
* observers ran; it never rejects. The deadline bounds teardown time only,
|
|
1034
|
+
* not delivery of accepted writes: QUIC discards queued writes and TCP may
|
|
1035
|
+
* abort. Idempotent: a later call returns the same promise, including
|
|
1036
|
+
* after a driver failure closed the endpoint.
|
|
1037
|
+
*/
|
|
1038
|
+
close(timeoutMs = DEFAULT_CLOSE_TIMEOUT_MS) {
|
|
1039
|
+
assertTimeout(timeoutMs);
|
|
1040
|
+
return this.#teardown(new ClosedError(), timeoutMs);
|
|
1019
1041
|
}
|
|
1042
|
+
/** Starts {@link close} with the default drain, without waiting for it. */
|
|
1020
1043
|
[Symbol.dispose]() {
|
|
1021
|
-
this.close();
|
|
1044
|
+
void this.close();
|
|
1045
|
+
}
|
|
1046
|
+
/** {@link close} with the default drain, for `await using`. */
|
|
1047
|
+
async [Symbol.asyncDispose]() {
|
|
1048
|
+
await this.close();
|
|
1022
1049
|
}
|
|
1023
1050
|
/** Returns this endpoint's base58 peer ID. */
|
|
1024
1051
|
peerId() {
|
|
1025
1052
|
this.#assertOpen();
|
|
1026
1053
|
return this.#backend.peerId();
|
|
1027
1054
|
}
|
|
1028
|
-
/**
|
|
1055
|
+
/**
|
|
1056
|
+
* Returns the currently bound peer multiaddresses. A WebTransport
|
|
1057
|
+
* listener's certhashes rotate; `listenAddressesChanged` says when.
|
|
1058
|
+
*/
|
|
1029
1059
|
listenAddrs() {
|
|
1030
1060
|
this.#assertOpen();
|
|
1031
1061
|
return this.#backend.listenAddrs();
|
|
@@ -1076,16 +1106,26 @@ export class Minip2pBase {
|
|
|
1076
1106
|
this.#assertOpen();
|
|
1077
1107
|
return this.#backend.reachability();
|
|
1078
1108
|
}
|
|
1079
|
-
/**
|
|
1109
|
+
/**
|
|
1110
|
+
* Returns the path of `peerId`'s established connection; `undefined` only
|
|
1111
|
+
* while the peer is not connected.
|
|
1112
|
+
*/
|
|
1080
1113
|
path(peerId) {
|
|
1081
1114
|
this.#assertOpen();
|
|
1082
1115
|
const path = this.#backend.path(peerId);
|
|
1083
1116
|
return path === undefined ? undefined : normalizePath(path);
|
|
1084
1117
|
}
|
|
1085
|
-
/**
|
|
1118
|
+
/**
|
|
1119
|
+
* Returns a snapshot of `peerId`'s established connection: its connection
|
|
1120
|
+
* ID, remote address, path, and Identify protocols once ready;
|
|
1121
|
+
* `undefined` while the peer is not connected.
|
|
1122
|
+
*/
|
|
1086
1123
|
connectionInfo(peerId) {
|
|
1087
1124
|
this.#assertOpen();
|
|
1088
|
-
|
|
1125
|
+
const info = this.#backend.connectionInfo(peerId);
|
|
1126
|
+
return info === undefined
|
|
1127
|
+
? undefined
|
|
1128
|
+
: { ...info, path: normalizePath(info.path) };
|
|
1089
1129
|
}
|
|
1090
1130
|
/** Returns whether the native driver is accepting work. */
|
|
1091
1131
|
isRunning() {
|
|
@@ -1504,10 +1544,14 @@ export class Minip2pBase {
|
|
|
1504
1544
|
}
|
|
1505
1545
|
}
|
|
1506
1546
|
#dispatchNative(event) {
|
|
1547
|
+
// Backends resolve `close` with it instead of delivering it.
|
|
1548
|
+
if (event.tag === P2pEvent_Tags.EndpointClosed) {
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1507
1551
|
if (event.tag === P2pEvent_Tags.DriverFailed) {
|
|
1508
1552
|
const failure = new DriverFailedError(event.inner.kind, event.inner.detail);
|
|
1509
1553
|
this.#dispatch("driverFailed", event.inner, event.inner);
|
|
1510
|
-
this.#teardown(
|
|
1554
|
+
void this.#teardown(failure, 0);
|
|
1511
1555
|
return;
|
|
1512
1556
|
}
|
|
1513
1557
|
if (event.tag === P2pEvent_Tags.StreamReady) {
|
|
@@ -1816,49 +1860,70 @@ export class Minip2pBase {
|
|
|
1816
1860
|
item = this.#queue.shift();
|
|
1817
1861
|
}
|
|
1818
1862
|
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1863
|
+
/**
|
|
1864
|
+
* Closes the endpoint once, rejecting what is outstanding with `cause`;
|
|
1865
|
+
* later calls return the first call's promise. A
|
|
1866
|
+
* {@link DriverFailedError} cause reports a `driverFailed` close.
|
|
1867
|
+
*/
|
|
1868
|
+
#teardown(cause, timeoutMs) {
|
|
1869
|
+
if (this.#closing !== undefined) {
|
|
1870
|
+
return this.#closing;
|
|
1822
1871
|
}
|
|
1823
1872
|
this.#closed = true;
|
|
1824
|
-
const closeHandlers = [...this.#closeHandlers];
|
|
1825
|
-
this.#closeHandlers.clear();
|
|
1826
1873
|
this.#clearQueue();
|
|
1827
1874
|
this.#dropped = 0;
|
|
1828
1875
|
this.#named.clear();
|
|
1829
1876
|
this.#catchAll.clear();
|
|
1877
|
+
// Native is asked to close before anything below can call back in: a
|
|
1878
|
+
// re-entrant close returns this promise.
|
|
1879
|
+
let closed;
|
|
1880
|
+
try {
|
|
1881
|
+
closed = this.#backend.close(timeoutMs);
|
|
1882
|
+
}
|
|
1883
|
+
catch {
|
|
1884
|
+
closed = Promise.resolve({
|
|
1885
|
+
outcome: CloseOutcome.Failed,
|
|
1886
|
+
unfinished: [],
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
const closing = closed.then(({ outcome, unfinished }) => {
|
|
1890
|
+
const report = cause instanceof DriverFailedError
|
|
1891
|
+
? { error: cause, reason: "driverFailed", unfinished }
|
|
1892
|
+
: { outcome, reason: "close", unfinished };
|
|
1893
|
+
this.#closeReported = true;
|
|
1894
|
+
const closeHandlers = [...this.#closeHandlers];
|
|
1895
|
+
this.#closeHandlers.clear();
|
|
1896
|
+
for (const handler of closeHandlers) {
|
|
1897
|
+
try {
|
|
1898
|
+
handler(report);
|
|
1899
|
+
}
|
|
1900
|
+
catch {
|
|
1901
|
+
// Close notification is outside the now-closed event queue.
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
return report;
|
|
1905
|
+
});
|
|
1906
|
+
this.#closing = closing;
|
|
1830
1907
|
for (const waiter of [...this.#waiters]) {
|
|
1831
|
-
this.#settleWaiter(waiter,
|
|
1908
|
+
this.#settleWaiter(waiter, cause);
|
|
1832
1909
|
}
|
|
1833
1910
|
for (const attempt of this.#connects.values()) {
|
|
1834
|
-
attempt.settle?.({ error, ok: false });
|
|
1911
|
+
attempt.settle?.({ error: cause, ok: false });
|
|
1835
1912
|
}
|
|
1836
1913
|
this.#connects.clear();
|
|
1837
1914
|
this.#terminalConnects.clear();
|
|
1838
1915
|
for (const pending of this.#pendingOpens.takeAll()) {
|
|
1839
1916
|
clearPendingOpen(pending);
|
|
1840
|
-
pending.reject(
|
|
1917
|
+
pending.reject(cause);
|
|
1841
1918
|
}
|
|
1842
1919
|
for (const stream of this.#streams.takeAll()) {
|
|
1843
|
-
stream.terminal(
|
|
1920
|
+
stream.terminal(cause);
|
|
1844
1921
|
}
|
|
1845
1922
|
for (const ping of this.#pings.values()) {
|
|
1846
|
-
ping.cancel(
|
|
1923
|
+
ping.cancel(cause);
|
|
1847
1924
|
}
|
|
1848
1925
|
this.#pings.clear();
|
|
1849
|
-
|
|
1850
|
-
this.#backend.close();
|
|
1851
|
-
}
|
|
1852
|
-
finally {
|
|
1853
|
-
for (const handler of closeHandlers) {
|
|
1854
|
-
try {
|
|
1855
|
-
handler(reason);
|
|
1856
|
-
}
|
|
1857
|
-
catch {
|
|
1858
|
-
// Close notification is outside the now-closed event queue.
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1926
|
+
return closing;
|
|
1862
1927
|
}
|
|
1863
1928
|
#assertOpen() {
|
|
1864
1929
|
if (this.#closed) {
|
|
@@ -1895,6 +1960,7 @@ const SDK_EVENT_NAMES = {
|
|
|
1895
1960
|
[P2pEvent_Tags.PingTimeout]: "pingTimeout",
|
|
1896
1961
|
[P2pEvent_Tags.EndpointError]: "endpointError",
|
|
1897
1962
|
[P2pEvent_Tags.ReachabilityChanged]: "reachabilityChanged",
|
|
1963
|
+
[P2pEvent_Tags.ListenAddressesChanged]: "listenAddressesChanged",
|
|
1898
1964
|
[P2pEvent_Tags.PublicAddressesChanged]: "publicAddressesChanged",
|
|
1899
1965
|
[P2pEvent_Tags.RelayReserved]: "relayReserved",
|
|
1900
1966
|
[P2pEvent_Tags.RelayReservationLost]: "relayReservationLost",
|
|
@@ -1935,15 +2001,40 @@ function normalizeEvent(event) {
|
|
|
1935
2001
|
to: normalizePath(event.inner.to),
|
|
1936
2002
|
};
|
|
1937
2003
|
}
|
|
2004
|
+
else if (event.tag === P2pEvent_Tags.ConnectionClosed) {
|
|
2005
|
+
payload = {
|
|
2006
|
+
...event.inner,
|
|
2007
|
+
reason: normalizeCloseReason(event.inner.reason),
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
1938
2010
|
return { payload: payload, type };
|
|
1939
2011
|
}
|
|
2012
|
+
function normalizeCloseReason(reason) {
|
|
2013
|
+
switch (reason.tag) {
|
|
2014
|
+
case ConnectionCloseReason_Tags.Local: {
|
|
2015
|
+
return { kind: "local" };
|
|
2016
|
+
}
|
|
2017
|
+
case ConnectionCloseReason_Tags.Remote: {
|
|
2018
|
+
return { code: reason.inner.code, kind: "remote" };
|
|
2019
|
+
}
|
|
2020
|
+
case ConnectionCloseReason_Tags.TimedOut: {
|
|
2021
|
+
return { kind: "timedOut" };
|
|
2022
|
+
}
|
|
2023
|
+
case ConnectionCloseReason_Tags.Stalled: {
|
|
2024
|
+
return { kind: "stalled" };
|
|
2025
|
+
}
|
|
2026
|
+
case ConnectionCloseReason_Tags.Error: {
|
|
2027
|
+
return { kind: "error", message: reason.inner.message };
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
1940
2031
|
function normalizePath(path) {
|
|
1941
2032
|
switch (path.tag) {
|
|
1942
|
-
case PathKind_Tags.
|
|
1943
|
-
return { kind: "
|
|
2033
|
+
case PathKind_Tags.Direct: {
|
|
2034
|
+
return { kind: "direct" };
|
|
1944
2035
|
}
|
|
1945
|
-
case PathKind_Tags.
|
|
1946
|
-
return { kind: "
|
|
2036
|
+
case PathKind_Tags.Punched: {
|
|
2037
|
+
return { kind: "punched" };
|
|
1947
2038
|
}
|
|
1948
2039
|
case PathKind_Tags.Relayed: {
|
|
1949
2040
|
return { kind: "relayed", relayPeerId: path.inner.relayPeerId };
|