@minip2p/core 0.6.0 → 0.7.0
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 +4 -2
- package/dist/backend.d.ts +18 -14
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +1 -0
- package/dist/backend.js.map +1 -1
- package/dist/config.d.ts +36 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +59 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +28 -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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sdk.d.ts +38 -22
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +180 -103
- package/dist/sdk.js.map +1 -1
- package/dist/types.d.ts +48 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/backend.ts +15 -13
- package/src/config.ts +122 -0
- package/src/errors.ts +34 -0
- package/src/index.ts +5 -2
- package/src/sdk.ts +224 -149
- package/src/types.ts +62 -25
package/src/types.ts
CHANGED
|
@@ -88,20 +88,6 @@ export const NatErrorKind = {
|
|
|
88
88
|
} as const;
|
|
89
89
|
export type NatErrorKind = (typeof NatErrorKind)[keyof typeof NatErrorKind];
|
|
90
90
|
|
|
91
|
-
/** Listen configuration for one enabled transport. */
|
|
92
|
-
export interface Minip2pTransportOptions {
|
|
93
|
-
/** Exact listen multiaddresses. Omit to listen on IPv4 and IPv6 defaults. */
|
|
94
|
-
readonly listen?: readonly [string, ...string[]];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Transports enabled by an endpoint. */
|
|
98
|
-
export interface Minip2pTransports {
|
|
99
|
-
/** Enables QUIC with defaults or explicit options. */
|
|
100
|
-
readonly quic?: true | Minip2pTransportOptions;
|
|
101
|
-
/** Enables TCP with defaults or explicit options. */
|
|
102
|
-
readonly tcp?: true | Minip2pTransportOptions;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
91
|
/** Configuration accepted by a platform minip2p endpoint. */
|
|
106
92
|
export interface Minip2pConfig {
|
|
107
93
|
/** Raw 32-byte Ed25519 secret key. */
|
|
@@ -112,8 +98,12 @@ export interface Minip2pConfig {
|
|
|
112
98
|
readonly relays?: readonly string[];
|
|
113
99
|
/** AutoNAT server peer multiaddresses. */
|
|
114
100
|
readonly autonatServers?: readonly string[];
|
|
115
|
-
/**
|
|
116
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Listen multiaddresses; each address's shape selects its transport, e.g.
|
|
103
|
+
* `/ip4/0.0.0.0/udp/4001/quic-v1` or `/ip4/0.0.0.0/tcp/4001`. Omit for the
|
|
104
|
+
* native QUIC dual-stack defaults on ephemeral ports.
|
|
105
|
+
*/
|
|
106
|
+
readonly listen?: readonly [string, ...string[]];
|
|
117
107
|
/** Routes outbound connectivity through relays only. */
|
|
118
108
|
readonly forceRelay?: boolean;
|
|
119
109
|
/** Accepts unsigned pubsub messages. */
|
|
@@ -176,7 +166,11 @@ export interface InboundStreamMeta {
|
|
|
176
166
|
|
|
177
167
|
/** Payload types keyed by high-level SDK event name. */
|
|
178
168
|
export interface Minip2pNamedEventMap {
|
|
179
|
-
eventsDropped: {
|
|
169
|
+
eventsDropped: {
|
|
170
|
+
readonly dropped: number;
|
|
171
|
+
readonly totalDropped: number;
|
|
172
|
+
readonly terminalConnectIds: readonly number[];
|
|
173
|
+
};
|
|
180
174
|
driverFailed: {
|
|
181
175
|
readonly kind: DriverFailureKind;
|
|
182
176
|
readonly detail: string;
|
|
@@ -209,6 +203,7 @@ export interface Minip2pNamedEventMap {
|
|
|
209
203
|
pathEstablished: {
|
|
210
204
|
readonly connectId: number;
|
|
211
205
|
readonly peerId: string;
|
|
206
|
+
readonly connId: number;
|
|
212
207
|
readonly path: Path;
|
|
213
208
|
};
|
|
214
209
|
inboundPathEstablished: {
|
|
@@ -226,13 +221,16 @@ export interface Minip2pNamedEventMap {
|
|
|
226
221
|
readonly attempt: number;
|
|
227
222
|
readonly reason: string;
|
|
228
223
|
};
|
|
229
|
-
fellBackToRelay: { readonly connectId: number; readonly peerId: string };
|
|
230
224
|
connectFailed: {
|
|
231
225
|
readonly connectId: number;
|
|
232
226
|
readonly peerId: string;
|
|
233
227
|
readonly kind: NatErrorKind;
|
|
234
228
|
readonly detail: string;
|
|
235
229
|
};
|
|
230
|
+
connectCancelled: {
|
|
231
|
+
readonly connectId: number;
|
|
232
|
+
readonly peerId: string;
|
|
233
|
+
};
|
|
236
234
|
inboundDirectUpgrade: { readonly peerId: string };
|
|
237
235
|
message: {
|
|
238
236
|
readonly fromPeerId: string;
|
|
@@ -301,6 +299,41 @@ export interface OpOptions {
|
|
|
301
299
|
readonly signal?: AbortSignal;
|
|
302
300
|
}
|
|
303
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Where one Connection attempt goes:
|
|
304
|
+
*
|
|
305
|
+
* - a base58 peer ID, which applies the endpoint's discovery and relay policy;
|
|
306
|
+
* - one complete peer multiaddress ending in `/p2p/<peer>`, as advertised;
|
|
307
|
+
* - a non-empty list of complete peer multiaddresses that all name one peer.
|
|
308
|
+
*
|
|
309
|
+
* A string starting with `/` is an address; any other string is a peer ID.
|
|
310
|
+
* Address family and transport come from the addresses themselves.
|
|
311
|
+
*/
|
|
312
|
+
export type ConnectTarget = string | readonly [string, ...string[]];
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Wait controls for a Connection attempt.
|
|
316
|
+
*
|
|
317
|
+
* `timeoutMs` bounds only the local wait: the attempt keeps running, and a
|
|
318
|
+
* later {@link Minip2pBase.waitConnectResult} on its
|
|
319
|
+
* {@link Minip2pBase.startConnect} ID can still consume its terminal outcome.
|
|
320
|
+
* Aborting `signal` cancels the attempt, and the wait then settles from its
|
|
321
|
+
* terminal: `ConnectCancelledError`, or the real outcome if cancellation
|
|
322
|
+
* raced an attempt that had already settled.
|
|
323
|
+
*/
|
|
324
|
+
export interface ConnectOptions extends OpOptions {
|
|
325
|
+
/** Also cancel the attempt when `timeoutMs` elapses. Defaults to `false`. */
|
|
326
|
+
readonly cancelOnTimeout?: boolean;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** The transport connection currently selected for a peer. */
|
|
330
|
+
export interface ConnectionInfo {
|
|
331
|
+
/** Endpoint-local connection identifier, as carried by connection events. */
|
|
332
|
+
readonly connId: number;
|
|
333
|
+
/** Remote transport address, when known. */
|
|
334
|
+
readonly remoteAddr?: string;
|
|
335
|
+
}
|
|
336
|
+
|
|
304
337
|
/** Options accepted by {@link Minip2pBase.once}. */
|
|
305
338
|
export type OnceOptions = OpOptions;
|
|
306
339
|
|
|
@@ -353,6 +386,7 @@ export type PathKind =
|
|
|
353
386
|
|
|
354
387
|
/** Raw backend-only event tags. */
|
|
355
388
|
export const P2pEvent_Tags = {
|
|
389
|
+
ConnectCancelled: "ConnectCancelled",
|
|
356
390
|
ConnectFailed: "ConnectFailed",
|
|
357
391
|
ConnectionClosed: "ConnectionClosed",
|
|
358
392
|
ConnectionEstablished: "ConnectionEstablished",
|
|
@@ -361,7 +395,6 @@ export const P2pEvent_Tags = {
|
|
|
361
395
|
DriverFailed: "DriverFailed",
|
|
362
396
|
EndpointError: "EndpointError",
|
|
363
397
|
EventsDropped: "EventsDropped",
|
|
364
|
-
FellBackToRelay: "FellBackToRelay",
|
|
365
398
|
GossipsubOutboundFailure: "GossipsubOutboundFailure",
|
|
366
399
|
GossipsubProtocolViolation: "GossipsubProtocolViolation",
|
|
367
400
|
HolePunchFailed: "HolePunchFailed",
|
|
@@ -398,7 +431,11 @@ interface RawEvent<Tag extends P2pEventTag, Inner> {
|
|
|
398
431
|
export type P2pEvent =
|
|
399
432
|
| RawEvent<
|
|
400
433
|
typeof P2pEvent_Tags.EventsDropped,
|
|
401
|
-
{
|
|
434
|
+
{
|
|
435
|
+
dropped: number;
|
|
436
|
+
totalDropped: number;
|
|
437
|
+
terminalConnectIds: number[];
|
|
438
|
+
}
|
|
402
439
|
>
|
|
403
440
|
| RawEvent<
|
|
404
441
|
typeof P2pEvent_Tags.DriverFailed,
|
|
@@ -460,7 +497,7 @@ export type P2pEvent =
|
|
|
460
497
|
>
|
|
461
498
|
| RawEvent<
|
|
462
499
|
typeof P2pEvent_Tags.PathEstablished,
|
|
463
|
-
{ connectId: number; peerId: string; path: PathKind }
|
|
500
|
+
{ connectId: number; peerId: string; connId: number; path: PathKind }
|
|
464
501
|
>
|
|
465
502
|
| RawEvent<
|
|
466
503
|
typeof P2pEvent_Tags.InboundPathEstablished,
|
|
@@ -474,14 +511,14 @@ export type P2pEvent =
|
|
|
474
511
|
typeof P2pEvent_Tags.HolePunchFailed,
|
|
475
512
|
Minip2pNamedEventMap["holePunchFailed"]
|
|
476
513
|
>
|
|
477
|
-
| RawEvent<
|
|
478
|
-
typeof P2pEvent_Tags.FellBackToRelay,
|
|
479
|
-
Minip2pNamedEventMap["fellBackToRelay"]
|
|
480
|
-
>
|
|
481
514
|
| RawEvent<
|
|
482
515
|
typeof P2pEvent_Tags.ConnectFailed,
|
|
483
516
|
Minip2pNamedEventMap["connectFailed"]
|
|
484
517
|
>
|
|
518
|
+
| RawEvent<
|
|
519
|
+
typeof P2pEvent_Tags.ConnectCancelled,
|
|
520
|
+
Minip2pNamedEventMap["connectCancelled"]
|
|
521
|
+
>
|
|
485
522
|
| RawEvent<
|
|
486
523
|
typeof P2pEvent_Tags.InboundDirectUpgrade,
|
|
487
524
|
Minip2pNamedEventMap["inboundDirectUpgrade"]
|