@minip2p/core 0.11.2 → 0.11.3
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/errors.d.ts +27 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +36 -3
- 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/sdk.d.ts +15 -4
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +70 -21
- package/dist/sdk.js.map +1 -1
- package/dist/types.d.ts +56 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +26 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +42 -4
- package/src/index.ts +4 -0
- package/src/sdk.ts +75 -21
- package/src/types.ts +67 -10
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ 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, 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.
|
|
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. When the connection's first Identify failed, the rejection is `IdentifyFailedError`, a `PeerDisconnectedError` with `connId` and `kind` (the `IdentifyFailure`). `identifyFailed` (`{ peerId, connId, cause }`, `cause` from `IdentifyFailure`: `TimedOut`, `OpenFailed`, `Rejected`, `ClosedEarly`, or `Malformed`) reports that failure; the connection never becomes ready, its `connectionClosed` follows, and Identify is not retried, so redial to try again.
|
|
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
|
|
|
@@ -62,7 +62,7 @@ const endpoint = Minip2p.create({
|
|
|
62
62
|
});
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
`timeouts` overrides the protocol deadlines, in milliseconds: `negotiationMs` (one outbound stream's protocol negotiation), `identifyMs` (the time a connection's first Identify may take; the connection is closed if it fails or runs out) and `pingMs` (one ping
|
|
65
|
+
`timeouts` overrides the protocol deadlines, in milliseconds: `negotiationMs` (one outbound stream's protocol negotiation), `identifyMs` (the time a connection's first Identify may take, its negotiation included; the connection is closed if it fails or runs out) and `pingMs` (one ping, from opening its stream to the echo). `identifyMs` defaults to 30 s and the others to 10 s; omitted fields keep their default. Raise them on links whose loaded RTT exceeds a few seconds. `waitPeerReady`'s default timeout allows a connect plus `identifyMs`. A zero throws `InvalidConfigError` with capability `Options`. Unlike `limits`, `timeouts` applies in `@minip2p/web` too. The `minip2p-rs` README's Deadlines table lists every deadline and how they relate.
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
68
|
const endpoint = Minip2p.create({
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConfigCapability, DriverFailureKind, EndpointErrorKind, NatErrorKind } from "./types.js";
|
|
1
|
+
import type { ConfigCapability, DriverFailureKind, EndpointErrorKind, IdentifyFailure, NatErrorKind, PingFailure } from "./types.js";
|
|
2
2
|
/** Pubsub rejected a publish because its bounded native queue is full. */
|
|
3
3
|
export declare class BackpressureError extends Error {
|
|
4
4
|
constructor();
|
|
@@ -81,7 +81,32 @@ export declare class ConnectResultUnavailableError extends Error {
|
|
|
81
81
|
export declare class PeerDisconnectedError extends Error {
|
|
82
82
|
readonly peerId: string;
|
|
83
83
|
readonly operation?: string;
|
|
84
|
-
|
|
84
|
+
/** `reason`, when given, is appended to the message. */
|
|
85
|
+
constructor(peerId: string, operation?: string, reason?: string);
|
|
86
|
+
}
|
|
87
|
+
/** A ping attempt failed natively; `kind` (the `pingFailed` event's `cause`) says why. */
|
|
88
|
+
export declare class PingFailedError extends Error {
|
|
89
|
+
readonly peerId: string;
|
|
90
|
+
/** The connection the ping was sent on. */
|
|
91
|
+
readonly connId: number;
|
|
92
|
+
/** Why the ping failed. */
|
|
93
|
+
readonly kind: PingFailure;
|
|
94
|
+
constructor(options: {
|
|
95
|
+
peerId: string;
|
|
96
|
+
connId: number;
|
|
97
|
+
cause: PingFailure;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The peer's connection failed its first Identify, so it never became ready
|
|
102
|
+
* and was closed. `kind` is the `identifyFailed` event's `cause`. Rejects `waitPeerReady`; redial to try again.
|
|
103
|
+
*/
|
|
104
|
+
export declare class IdentifyFailedError extends PeerDisconnectedError {
|
|
105
|
+
/** The connection whose first Identify failed. */
|
|
106
|
+
readonly connId: number;
|
|
107
|
+
/** Why Identify failed. */
|
|
108
|
+
readonly kind: IdentifyFailure;
|
|
109
|
+
constructor(peerId: string, connId: number, kind: IdentifyFailure);
|
|
85
110
|
}
|
|
86
111
|
/** Outbound stream opening or protocol negotiation failed. */
|
|
87
112
|
export declare class OpenStreamError extends Error {
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,0EAA0E;AAC1E,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,cAGC;CACF;AAED,wDAAwD;AACxD,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,cAGC;CACF;AAED,2DAA2D;AAC3D,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAO,SAAmC,EAGrD;CACF;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,sDAAsD;IACtD,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IACtC,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAKvD;CACF;AAED,qDAAqD;AACrD,qBAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAO,SAA8B,EAGhD;CACF;AAED,qEAAqE;AACrE,qBAAa,YAAa,SAAQ,KAAK;IACrC,sDAAsD;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;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AM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB,EAQA;CACF;AAED,6DAA6D;AAC7D,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAO,SAA6C,EAG/D;CACF;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE/B,YAAY,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAOlD;CACF;AAED,yEAAyE;AACzE,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,cAGC;CACF"}
|
package/dist/errors.js
CHANGED
|
@@ -130,15 +130,48 @@ export class ConnectResultUnavailableError extends Error {
|
|
|
130
130
|
export class PeerDisconnectedError extends Error {
|
|
131
131
|
peerId;
|
|
132
132
|
operation;
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
/** `reason`, when given, is appended to the message. */
|
|
134
|
+
constructor(peerId, operation, reason) {
|
|
135
|
+
const base = operation === undefined
|
|
135
136
|
? `Peer ${peerId} disconnected`
|
|
136
|
-
: `Peer ${peerId} disconnected during ${operation}
|
|
137
|
+
: `Peer ${peerId} disconnected during ${operation}`;
|
|
138
|
+
super(reason === undefined ? base : `${base}: ${reason}`);
|
|
137
139
|
this.name = "PeerDisconnectedError";
|
|
138
140
|
this.peerId = peerId;
|
|
139
141
|
this.operation = operation;
|
|
140
142
|
}
|
|
141
143
|
}
|
|
144
|
+
/** A ping attempt failed natively; `kind` (the `pingFailed` event's `cause`) says why. */
|
|
145
|
+
export class PingFailedError extends Error {
|
|
146
|
+
peerId;
|
|
147
|
+
/** The connection the ping was sent on. */
|
|
148
|
+
connId;
|
|
149
|
+
/** Why the ping failed. */
|
|
150
|
+
kind;
|
|
151
|
+
constructor(options) {
|
|
152
|
+
super(`Ping to ${options.peerId} failed: ${options.cause}`);
|
|
153
|
+
this.name = "PingFailedError";
|
|
154
|
+
this.peerId = options.peerId;
|
|
155
|
+
this.connId = options.connId;
|
|
156
|
+
this.kind = options.cause;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The peer's connection failed its first Identify, so it never became ready
|
|
161
|
+
* and was closed. `kind` is the `identifyFailed` event's `cause`. Rejects `waitPeerReady`; redial to try again.
|
|
162
|
+
*/
|
|
163
|
+
export class IdentifyFailedError extends PeerDisconnectedError {
|
|
164
|
+
/** The connection whose first Identify failed. */
|
|
165
|
+
connId;
|
|
166
|
+
/** Why Identify failed. */
|
|
167
|
+
kind;
|
|
168
|
+
constructor(peerId, connId, kind) {
|
|
169
|
+
super(peerId, "waitPeerReady", `Identify failed (${kind})`);
|
|
170
|
+
this.name = "IdentifyFailedError";
|
|
171
|
+
this.connId = connId;
|
|
172
|
+
this.kind = kind;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
142
175
|
/** Outbound stream opening or protocol negotiation failed. */
|
|
143
176
|
export class OpenStreamError extends Error {
|
|
144
177
|
/** Machine-readable native error category, or a synchronous adapter error. */
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,4FAA4F;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAW5F,0EAA0E;AAC1E,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C;QACE,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,wDAAwD;AACxD,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,kDAAkD,CAAC,CAAC;QAC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C;QAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;CACF;AAED,6DAA6D;AAC7D,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAO,GAAG,0CAA0C;QAC9D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,yEAAyE;IAChE,QAAQ,CAAS;IAC1B,yCAAyC;IAChC,aAAa,CAAS;IAE/B,YAAY,QAAgB,EAAE,aAAqB;QACjD,KAAK,CACH,qCAAqC,QAAQ,6CAA6C,aAAa,GAAG,CAC3G,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF;AAED,yEAAyE;AACzE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD;QACE,KAAK,CAAC,kEAAkE,CAAC,CAAC;QAC1E,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AbortError, BackpressureError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, InvalidConfigError, MessageTooLargeError, NotPermittedError, OpenStreamError, PeerDisconnectedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
1
|
+
export { AbortError, BackpressureError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, IdentifyFailedError, InvalidConfigError, MessageTooLargeError, NotPermittedError, OpenStreamError, PeerDisconnectedError, PingFailedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
2
2
|
export { Minip2pBase, Stream, type StreamEventMap } from "./sdk.js";
|
|
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 Minip2pCongestionController, type Minip2pConfig, type Minip2pDiscoveryOptions, type Minip2pEvent, type Minip2pLimits, type Minip2pMdnsOptions, type Minip2pNamedEventMap, type Minip2pQuicLimits, type Minip2pTcpLimits, type Minip2pTimeouts, type Minip2pYamuxLimits, type OnceOptions, type OpOptions, type Path, type RelayReservationInfo, type Unsubscribe, type WaitForOptions, } from "./types.js";
|
|
3
|
+
export { CloseOutcome, ConfigCapability, DiscoverySource, DriverFailureKind, EndpointErrorKind, IdentifyFailure, MdnsFailureKind, NatErrorKind, PingFailure, 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 Minip2pCongestionController, type Minip2pConfig, type Minip2pDiscoveryOptions, type Minip2pEvent, type Minip2pLimits, type Minip2pMdnsOptions, type Minip2pNamedEventMap, type Minip2pQuicLimits, type Minip2pTcpLimits, type Minip2pTimeouts, type Minip2pYamuxLimits, 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,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,2BAA2B,EAChC,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC"}
|
|
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,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,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,eAAe,EACf,YAAY,EACZ,WAAW,EACX,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,2BAA2B,EAChC,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,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
|
-
export { AbortError, BackpressureError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, InvalidConfigError, MessageTooLargeError, NotPermittedError, OpenStreamError, PeerDisconnectedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
1
|
+
export { AbortError, BackpressureError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, IdentifyFailedError, InvalidConfigError, MessageTooLargeError, NotPermittedError, OpenStreamError, PeerDisconnectedError, PingFailedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
2
2
|
export { Minip2pBase, Stream } from "./sdk.js";
|
|
3
|
-
export { CloseOutcome, ConfigCapability, DiscoverySource, DriverFailureKind, EndpointErrorKind, MdnsFailureKind, NatErrorKind, Reachability, } from "./types.js";
|
|
3
|
+
export { CloseOutcome, ConfigCapability, DiscoverySource, DriverFailureKind, EndpointErrorKind, IdentifyFailure, MdnsFailureKind, NatErrorKind, PingFailure, 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,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,GA+Bb,MAAM,YAAY,CAAC"}
|
|
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,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,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,eAAe,EACf,YAAY,EACZ,WAAW,EACX,YAAY,GA+Bb,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, ConnectionInfo, ConnectOptions, ConnectResult, ConnectTarget, EndpointCloseReport, EventsOptions, IdentifyInfo, InboundStreamMeta, KnownPeerInfo, Minip2pEvent, Minip2pNamedEventMap, OnceOptions, OpOptions, Path, Reachability, RelayReservationInfo, Unsubscribe, WaitForOptions } from "./types.js";
|
|
2
|
+
import type { Bytes, ConnectionInfo, ConnectOptions, ConnectResult, ConnectTarget, EndpointCloseReport, EventsOptions, IdentifyInfo, InboundStreamMeta, KnownPeerInfo, Minip2pConfig, 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;
|
|
@@ -124,7 +124,7 @@ export interface StreamEventMap {
|
|
|
124
124
|
*/
|
|
125
125
|
export declare class Minip2pBase {
|
|
126
126
|
#private;
|
|
127
|
-
protected constructor(backend: Minip2pBackend,
|
|
127
|
+
protected constructor(backend: Minip2pBackend, config: Pick<Minip2pConfig, "relays" | "timeouts">);
|
|
128
128
|
/** Subscribes to one named event and returns an idempotent unsubscribe. */
|
|
129
129
|
on<Kind extends EventKind>(type: Kind, handler: NamedHandler<Kind>): Unsubscribe;
|
|
130
130
|
/** Subscribes to the catch-all metadata event stream. */
|
|
@@ -214,16 +214,27 @@ export declare class Minip2pBase {
|
|
|
214
214
|
addProtocol(protocolId: string): void;
|
|
215
215
|
/**
|
|
216
216
|
* Waits until the peer's current connection is ready, or rejects if the
|
|
217
|
-
* peer disconnects
|
|
217
|
+
* peer disconnects: with `IdentifyFailedError` (a `PeerDisconnectedError`
|
|
218
|
+
* whose `kind` is the cause) when that connection's first Identify failed.
|
|
218
219
|
*
|
|
219
220
|
* A `peerReady` resolves it only while its connection is still the peer's
|
|
220
221
|
* current one, so a stale `peerReady` for a replaced connection does not.
|
|
222
|
+
* The default timeout outlasts a connect plus the first-Identify deadline
|
|
223
|
+
* (`timeouts.identifyMs`), so the native side settles readiness first.
|
|
221
224
|
*/
|
|
222
225
|
waitPeerReady(peerId: string, options?: OpOptions): Promise<{
|
|
223
226
|
readonly peerId: string;
|
|
224
227
|
readonly protocols: readonly string[];
|
|
225
228
|
}>;
|
|
226
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* Measures round-trip latency in milliseconds. Calls join the peer's
|
|
231
|
+
* running attempt, including one whose earlier callers timed out or
|
|
232
|
+
* aborted, until it ends. Rejects with {@link PingFailedError} when the native ping fails (its
|
|
233
|
+
* `pingMs` deadline covers the open, negotiation and echo), and with
|
|
234
|
+
* {@link PeerDisconnectedError} when the connection closes first, or with
|
|
235
|
+
* {@link EventQueueOverflowError} when events are lost and its result may
|
|
236
|
+
* be among them.
|
|
237
|
+
*/
|
|
227
238
|
ping(peerId: string, options?: OpOptions): Promise<number>;
|
|
228
239
|
/** Opens and negotiates an application-protocol stream. */
|
|
229
240
|
openStream(peerId: string, protocolId: string, options?: OpOptions): Promise<Stream>;
|
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,EAGV,cAAc,EACf,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,cAAc,EACf,MAAM,cAAc,CAAC;AAwBtB,OAAO,KAAK,EACV,KAAK,EAEL,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,aAAa,EAEb,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,SAAS,EAGT,IAAI,EAGJ,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,cAAc,EACf,MAAM,YAAY,CAAC;AA8CpB,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;I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MAAM,EAAE,MAAM,GAAG,IAAI,CAG/B;CAknBF"}
|
package/dist/sdk.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
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
|
-
import { AbortError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, OpenStreamError, PeerDisconnectedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
2
|
+
import { AbortError, ClosedError, ConnectCancelledError, ConnectFailedError, ConnectResultLostError, ConnectResultUnavailableError, DriverFailedError, EventQueueOverflowError, IdentifyFailedError, OpenStreamError, PeerDisconnectedError, PingFailedError, StreamClosedError, TimeoutError, WriteBufferFullError, } from "./errors.js";
|
|
3
3
|
import { CloseOutcome, ConnectionCloseReason_Tags, P2pEvent_Tags, PathKind_Tags, } from "./types.js";
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 65_000;
|
|
5
|
+
/** The native connect deadline and default first-Identify deadline. */
|
|
6
|
+
const CONNECT_DEADLINE_MS = 30_000;
|
|
7
|
+
const IDENTIFY_DEADLINE_MS = 30_000;
|
|
8
|
+
/** Margin a readiness wait keeps past the native deadlines. */
|
|
9
|
+
const READY_SLACK_MS = 5000;
|
|
10
|
+
/** The longest delay `setTimeout` honours; longer ones fire at once. */
|
|
11
|
+
const MAX_TIMER_MS = 2_147_483_647;
|
|
5
12
|
/**
|
|
6
13
|
* Default close drain: the Rust `minip2p::DEFAULT_CLOSE_TIMEOUT` (500 ms)
|
|
7
14
|
* that `Endpoint::close` and native's `DEFAULT_STOP_TIMEOUT_MS` use.
|
|
@@ -189,6 +196,7 @@ const connectionsOf = (event) => {
|
|
|
189
196
|
const UNSEEN_CONNECTION_TAGS = new Set([
|
|
190
197
|
P2pEvent_Tags.PeerReady,
|
|
191
198
|
P2pEvent_Tags.IdentifyReceived,
|
|
199
|
+
P2pEvent_Tags.IdentifyFailed,
|
|
192
200
|
P2pEvent_Tags.EndpointError,
|
|
193
201
|
P2pEvent_Tags.StreamRemoteWriteClosed,
|
|
194
202
|
P2pEvent_Tags.StreamWriteStopped,
|
|
@@ -863,6 +871,8 @@ const consumeUntracked = (backend, inner) => {
|
|
|
863
871
|
export class Minip2pBase {
|
|
864
872
|
#backend;
|
|
865
873
|
#relayAddrs;
|
|
874
|
+
/** `waitPeerReady`'s default timeout: connect + Identify + slack. */
|
|
875
|
+
#readyTimeoutMs;
|
|
866
876
|
#named = new Map();
|
|
867
877
|
#catchAll = new Set();
|
|
868
878
|
#closeHandlers = new Set();
|
|
@@ -881,9 +891,12 @@ export class Minip2pBase {
|
|
|
881
891
|
/** Settles once the native drain finished and close observers ran. */
|
|
882
892
|
#closing;
|
|
883
893
|
#closeReported = false;
|
|
884
|
-
constructor(backend,
|
|
894
|
+
constructor(backend, config) {
|
|
885
895
|
this.#backend = backend;
|
|
886
|
-
this.#relayAddrs =
|
|
896
|
+
this.#relayAddrs = config.relays ?? [];
|
|
897
|
+
this.#readyTimeoutMs = Math.min(CONNECT_DEADLINE_MS +
|
|
898
|
+
(config.timeouts?.identifyMs ?? IDENTIFY_DEADLINE_MS) +
|
|
899
|
+
READY_SLACK_MS, MAX_TIMER_MS);
|
|
887
900
|
try {
|
|
888
901
|
backend.start((event) => {
|
|
889
902
|
this.#enqueueNative(event);
|
|
@@ -1158,10 +1171,13 @@ export class Minip2pBase {
|
|
|
1158
1171
|
}
|
|
1159
1172
|
/**
|
|
1160
1173
|
* Waits until the peer's current connection is ready, or rejects if the
|
|
1161
|
-
* peer disconnects
|
|
1174
|
+
* peer disconnects: with `IdentifyFailedError` (a `PeerDisconnectedError`
|
|
1175
|
+
* whose `kind` is the cause) when that connection's first Identify failed.
|
|
1162
1176
|
*
|
|
1163
1177
|
* A `peerReady` resolves it only while its connection is still the peer's
|
|
1164
1178
|
* current one, so a stale `peerReady` for a replaced connection does not.
|
|
1179
|
+
* The default timeout outlasts a connect plus the first-Identify deadline
|
|
1180
|
+
* (`timeouts.identifyMs`), so the native side settles readiness first.
|
|
1165
1181
|
*/
|
|
1166
1182
|
waitPeerReady(peerId, options = {}) {
|
|
1167
1183
|
// One snapshot, so readiness, connection and protocols agree.
|
|
@@ -1176,6 +1192,7 @@ export class Minip2pBase {
|
|
|
1176
1192
|
const removeExternalAbort = listenAbort(options.signal, () => {
|
|
1177
1193
|
controller.abort();
|
|
1178
1194
|
});
|
|
1195
|
+
const timeoutMs = options.timeoutMs ?? this.#readyTimeoutMs;
|
|
1179
1196
|
// Events trail the native state, so a queued `peerReady` counts only if
|
|
1180
1197
|
// its connection is still the peer's current one; a replaced
|
|
1181
1198
|
// connection's readiness never resolves the wait.
|
|
@@ -1184,40 +1201,66 @@ export class Minip2pBase {
|
|
|
1184
1201
|
predicate: (event) => event.peerId === peerId &&
|
|
1185
1202
|
this.#backend.connectionInfo(peerId)?.connId === event.connId,
|
|
1186
1203
|
signal: controller.signal,
|
|
1204
|
+
timeoutMs,
|
|
1187
1205
|
}).then(({ protocols }) => ({ peerId, protocols }));
|
|
1206
|
+
// The failed connection may already be gone natively, so a failure
|
|
1207
|
+
// counts if it names the peer's current connection or, once native has
|
|
1208
|
+
// none, the last one this wait knew.
|
|
1209
|
+
let knownConnId = info?.connId;
|
|
1210
|
+
const identifyFailed = this.waitFor("identifyFailed", {
|
|
1211
|
+
...options,
|
|
1212
|
+
predicate: (event) => {
|
|
1213
|
+
if (event.peerId !== peerId) {
|
|
1214
|
+
return false;
|
|
1215
|
+
}
|
|
1216
|
+
knownConnId =
|
|
1217
|
+
this.#backend.connectionInfo(peerId)?.connId ?? knownConnId;
|
|
1218
|
+
return (knownConnId ?? event.connId) === event.connId;
|
|
1219
|
+
},
|
|
1220
|
+
signal: controller.signal,
|
|
1221
|
+
timeoutMs,
|
|
1222
|
+
}).then(({ connId, cause }) => {
|
|
1223
|
+
throw new IdentifyFailedError(peerId, connId, cause);
|
|
1224
|
+
});
|
|
1188
1225
|
const disconnected = this.waitFor("connectionClosed", {
|
|
1189
1226
|
...options,
|
|
1190
1227
|
predicate: (event) => event.peerId === peerId &&
|
|
1191
1228
|
!this.#backend.connectedPeers().includes(peerId),
|
|
1192
1229
|
signal: controller.signal,
|
|
1230
|
+
timeoutMs,
|
|
1193
1231
|
}).then(() => {
|
|
1194
1232
|
throw new PeerDisconnectedError(peerId, "waitPeerReady");
|
|
1195
1233
|
});
|
|
1196
|
-
return Promise.race([ready, disconnected]).finally(() => {
|
|
1234
|
+
return Promise.race([ready, identifyFailed, disconnected]).finally(() => {
|
|
1197
1235
|
removeExternalAbort?.();
|
|
1198
1236
|
controller.abort();
|
|
1199
1237
|
});
|
|
1200
1238
|
}
|
|
1201
|
-
/**
|
|
1239
|
+
/**
|
|
1240
|
+
* Measures round-trip latency in milliseconds. Calls join the peer's
|
|
1241
|
+
* running attempt, including one whose earlier callers timed out or
|
|
1242
|
+
* aborted, until it ends. Rejects with {@link PingFailedError} when the native ping fails (its
|
|
1243
|
+
* `pingMs` deadline covers the open, negotiation and echo), and with
|
|
1244
|
+
* {@link PeerDisconnectedError} when the connection closes first, or with
|
|
1245
|
+
* {@link EventQueueOverflowError} when events are lost and its result may
|
|
1246
|
+
* be among them.
|
|
1247
|
+
*/
|
|
1202
1248
|
ping(peerId, options = {}) {
|
|
1203
1249
|
this.#assertOpen();
|
|
1204
1250
|
let operation = this.#pings.get(peerId);
|
|
1205
1251
|
if (operation === undefined) {
|
|
1252
|
+
// Native events are flushed asynchronously, so none can arrive before
|
|
1253
|
+
// the operation below listens.
|
|
1254
|
+
this.#backend.ping(peerId);
|
|
1206
1255
|
operation = this.#runPing(peerId);
|
|
1256
|
+
// Kept until its terminal event, even after every caller stops
|
|
1257
|
+
// waiting: a later call joins the native attempt still running, so an
|
|
1258
|
+
// older attempt's result never settles a newer one.
|
|
1207
1259
|
this.#pings.set(peerId, operation);
|
|
1208
1260
|
const current = operation;
|
|
1209
1261
|
void operation.promise.then(() => this.#removePing(peerId, current), () => this.#removePing(peerId, current));
|
|
1210
|
-
this.#backend.ping(peerId);
|
|
1211
1262
|
}
|
|
1212
|
-
operation.
|
|
1213
|
-
const current = operation;
|
|
1214
|
-
return withOptions(operation.promise, options).finally(() => {
|
|
1215
|
-
current.callers -= 1;
|
|
1216
|
-
if (current.callers === 0 && this.#pings.get(peerId) === current) {
|
|
1217
|
-
current.cancel(new AbortError("No ping callers remain"));
|
|
1218
|
-
this.#pings.delete(peerId);
|
|
1219
|
-
}
|
|
1220
|
-
});
|
|
1263
|
+
return withOptions(operation.promise, options);
|
|
1221
1264
|
}
|
|
1222
1265
|
/** Opens and negotiates an application-protocol stream. */
|
|
1223
1266
|
openStream(peerId, protocolId, options = {}) {
|
|
@@ -1397,10 +1440,10 @@ export class Minip2pBase {
|
|
|
1397
1440
|
resolve(event.rttMs);
|
|
1398
1441
|
}
|
|
1399
1442
|
});
|
|
1400
|
-
const
|
|
1443
|
+
const offFailed = this.on("pingFailed", (event) => {
|
|
1401
1444
|
if (event.peerId === peerId) {
|
|
1402
1445
|
finish();
|
|
1403
|
-
reject(new
|
|
1446
|
+
reject(new PingFailedError(event));
|
|
1404
1447
|
}
|
|
1405
1448
|
});
|
|
1406
1449
|
const offClosed = this.on("connectionClosed", (event) => {
|
|
@@ -1412,7 +1455,7 @@ export class Minip2pBase {
|
|
|
1412
1455
|
});
|
|
1413
1456
|
cleanup = () => {
|
|
1414
1457
|
offRtt();
|
|
1415
|
-
|
|
1458
|
+
offFailed();
|
|
1416
1459
|
offClosed();
|
|
1417
1460
|
};
|
|
1418
1461
|
const finish = () => {
|
|
@@ -1423,7 +1466,6 @@ export class Minip2pBase {
|
|
|
1423
1466
|
};
|
|
1424
1467
|
});
|
|
1425
1468
|
return {
|
|
1426
|
-
callers: 0,
|
|
1427
1469
|
cancel: (error) => {
|
|
1428
1470
|
if (!settled) {
|
|
1429
1471
|
settled = true;
|
|
@@ -1578,6 +1620,12 @@ export class Minip2pBase {
|
|
|
1578
1620
|
}
|
|
1579
1621
|
if (event.tag === P2pEvent_Tags.EventsDropped) {
|
|
1580
1622
|
this.#connectResultsLost(event.inner.terminalConnectIds);
|
|
1623
|
+
// A ping's result may be among the lost events, and a ping kept
|
|
1624
|
+
// without it would never settle, so end every pending ping.
|
|
1625
|
+
for (const ping of this.#pings.values()) {
|
|
1626
|
+
ping.cancel(new EventQueueOverflowError());
|
|
1627
|
+
}
|
|
1628
|
+
this.#pings.clear();
|
|
1581
1629
|
}
|
|
1582
1630
|
const normalized = normalizeEvent(event);
|
|
1583
1631
|
this.#dispatch(normalized.type, normalized.payload, normalized.payload);
|
|
@@ -1956,8 +2004,9 @@ const SDK_EVENT_NAMES = {
|
|
|
1956
2004
|
[P2pEvent_Tags.ConnectionReplaced]: "connectionReplaced",
|
|
1957
2005
|
[P2pEvent_Tags.PeerReady]: "peerReady",
|
|
1958
2006
|
[P2pEvent_Tags.IdentifyReceived]: "identifyReceived",
|
|
2007
|
+
[P2pEvent_Tags.IdentifyFailed]: "identifyFailed",
|
|
1959
2008
|
[P2pEvent_Tags.PingRttMeasured]: "pingRttMeasured",
|
|
1960
|
-
[P2pEvent_Tags.
|
|
2009
|
+
[P2pEvent_Tags.PingFailed]: "pingFailed",
|
|
1961
2010
|
[P2pEvent_Tags.EndpointError]: "endpointError",
|
|
1962
2011
|
[P2pEvent_Tags.ReachabilityChanged]: "reachabilityChanged",
|
|
1963
2012
|
[P2pEvent_Tags.ListenAddressesChanged]: "listenAddressesChanged",
|