@minip2p/core 0.5.4 → 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 +2 -2
- 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 +182 -105
- package/dist/sdk.js.map +1 -1
- package/dist/types.d.ts +52 -32
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -8
- 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 -3
- package/src/sdk.ts +226 -151
- package/src/types.ts +76 -42
package/src/types.ts
CHANGED
|
@@ -38,13 +38,6 @@ export interface Minip2pMdnsOptions {
|
|
|
38
38
|
readonly autoDial?: boolean;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/** Available pubsub routing strategies. */
|
|
42
|
-
export const PubsubRouter = {
|
|
43
|
-
Floodsub: 1,
|
|
44
|
-
Gossipsub: 0,
|
|
45
|
-
} as const;
|
|
46
|
-
export type PubsubRouter = (typeof PubsubRouter)[keyof typeof PubsubRouter];
|
|
47
|
-
|
|
48
41
|
/** Coarse local reachability states. */
|
|
49
42
|
export const Reachability = {
|
|
50
43
|
Private: 2,
|
|
@@ -95,20 +88,6 @@ export const NatErrorKind = {
|
|
|
95
88
|
} as const;
|
|
96
89
|
export type NatErrorKind = (typeof NatErrorKind)[keyof typeof NatErrorKind];
|
|
97
90
|
|
|
98
|
-
/** Listen configuration for one enabled transport. */
|
|
99
|
-
export interface Minip2pTransportOptions {
|
|
100
|
-
/** Exact listen multiaddresses. Omit to listen on IPv4 and IPv6 defaults. */
|
|
101
|
-
readonly listen?: readonly [string, ...string[]];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Transports enabled by an endpoint. */
|
|
105
|
-
export interface Minip2pTransports {
|
|
106
|
-
/** Enables QUIC with defaults or explicit options. */
|
|
107
|
-
readonly quic?: true | Minip2pTransportOptions;
|
|
108
|
-
/** Enables TCP with defaults or explicit options. */
|
|
109
|
-
readonly tcp?: true | Minip2pTransportOptions;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
91
|
/** Configuration accepted by a platform minip2p endpoint. */
|
|
113
92
|
export interface Minip2pConfig {
|
|
114
93
|
/** Raw 32-byte Ed25519 secret key. */
|
|
@@ -119,14 +98,16 @@ export interface Minip2pConfig {
|
|
|
119
98
|
readonly relays?: readonly string[];
|
|
120
99
|
/** AutoNAT server peer multiaddresses. */
|
|
121
100
|
readonly autonatServers?: readonly string[];
|
|
122
|
-
/**
|
|
123
|
-
|
|
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[]];
|
|
124
107
|
/** Routes outbound connectivity through relays only. */
|
|
125
108
|
readonly forceRelay?: boolean;
|
|
126
109
|
/** Accepts unsigned pubsub messages. */
|
|
127
110
|
readonly allowUnsigned?: boolean;
|
|
128
|
-
/** Pubsub router to enable. */
|
|
129
|
-
readonly pubsubRouter?: PubsubRouter;
|
|
130
111
|
/** Application protocol IDs accepted on inbound streams. */
|
|
131
112
|
readonly protocols?: readonly string[];
|
|
132
113
|
/** Signed-beacon discovery configuration. */
|
|
@@ -185,7 +166,11 @@ export interface InboundStreamMeta {
|
|
|
185
166
|
|
|
186
167
|
/** Payload types keyed by high-level SDK event name. */
|
|
187
168
|
export interface Minip2pNamedEventMap {
|
|
188
|
-
eventsDropped: {
|
|
169
|
+
eventsDropped: {
|
|
170
|
+
readonly dropped: number;
|
|
171
|
+
readonly totalDropped: number;
|
|
172
|
+
readonly terminalConnectIds: readonly number[];
|
|
173
|
+
};
|
|
189
174
|
driverFailed: {
|
|
190
175
|
readonly kind: DriverFailureKind;
|
|
191
176
|
readonly detail: string;
|
|
@@ -218,6 +203,7 @@ export interface Minip2pNamedEventMap {
|
|
|
218
203
|
pathEstablished: {
|
|
219
204
|
readonly connectId: number;
|
|
220
205
|
readonly peerId: string;
|
|
206
|
+
readonly connId: number;
|
|
221
207
|
readonly path: Path;
|
|
222
208
|
};
|
|
223
209
|
inboundPathEstablished: {
|
|
@@ -235,13 +221,16 @@ export interface Minip2pNamedEventMap {
|
|
|
235
221
|
readonly attempt: number;
|
|
236
222
|
readonly reason: string;
|
|
237
223
|
};
|
|
238
|
-
fellBackToRelay: { readonly connectId: number; readonly peerId: string };
|
|
239
224
|
connectFailed: {
|
|
240
225
|
readonly connectId: number;
|
|
241
226
|
readonly peerId: string;
|
|
242
227
|
readonly kind: NatErrorKind;
|
|
243
228
|
readonly detail: string;
|
|
244
229
|
};
|
|
230
|
+
connectCancelled: {
|
|
231
|
+
readonly connectId: number;
|
|
232
|
+
readonly peerId: string;
|
|
233
|
+
};
|
|
245
234
|
inboundDirectUpgrade: { readonly peerId: string };
|
|
246
235
|
message: {
|
|
247
236
|
readonly fromPeerId: string;
|
|
@@ -252,8 +241,14 @@ export interface Minip2pNamedEventMap {
|
|
|
252
241
|
};
|
|
253
242
|
peerSubscribed: { readonly peerId: string; readonly topic: string };
|
|
254
243
|
peerUnsubscribed: { readonly peerId: string; readonly topic: string };
|
|
255
|
-
|
|
256
|
-
|
|
244
|
+
gossipsubOutboundFailure: {
|
|
245
|
+
readonly peerId: string;
|
|
246
|
+
readonly reason: string;
|
|
247
|
+
};
|
|
248
|
+
gossipsubProtocolViolation: {
|
|
249
|
+
readonly peerId: string;
|
|
250
|
+
readonly reason: string;
|
|
251
|
+
};
|
|
257
252
|
peerDiscovered: {
|
|
258
253
|
readonly peerId: string;
|
|
259
254
|
readonly addrs: readonly string[];
|
|
@@ -304,6 +299,41 @@ export interface OpOptions {
|
|
|
304
299
|
readonly signal?: AbortSignal;
|
|
305
300
|
}
|
|
306
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
|
+
|
|
307
337
|
/** Options accepted by {@link Minip2pBase.once}. */
|
|
308
338
|
export type OnceOptions = OpOptions;
|
|
309
339
|
|
|
@@ -356,6 +386,7 @@ export type PathKind =
|
|
|
356
386
|
|
|
357
387
|
/** Raw backend-only event tags. */
|
|
358
388
|
export const P2pEvent_Tags = {
|
|
389
|
+
ConnectCancelled: "ConnectCancelled",
|
|
359
390
|
ConnectFailed: "ConnectFailed",
|
|
360
391
|
ConnectionClosed: "ConnectionClosed",
|
|
361
392
|
ConnectionEstablished: "ConnectionEstablished",
|
|
@@ -364,7 +395,8 @@ export const P2pEvent_Tags = {
|
|
|
364
395
|
DriverFailed: "DriverFailed",
|
|
365
396
|
EndpointError: "EndpointError",
|
|
366
397
|
EventsDropped: "EventsDropped",
|
|
367
|
-
|
|
398
|
+
GossipsubOutboundFailure: "GossipsubOutboundFailure",
|
|
399
|
+
GossipsubProtocolViolation: "GossipsubProtocolViolation",
|
|
368
400
|
HolePunchFailed: "HolePunchFailed",
|
|
369
401
|
IdentifyReceived: "IdentifyReceived",
|
|
370
402
|
InboundDirectUpgrade: "InboundDirectUpgrade",
|
|
@@ -381,8 +413,6 @@ export const P2pEvent_Tags = {
|
|
|
381
413
|
PingRttMeasured: "PingRttMeasured",
|
|
382
414
|
PingTimeout: "PingTimeout",
|
|
383
415
|
PublicAddressesChanged: "PublicAddressesChanged",
|
|
384
|
-
PubsubOutboundFailure: "PubsubOutboundFailure",
|
|
385
|
-
PubsubProtocolViolation: "PubsubProtocolViolation",
|
|
386
416
|
ReachabilityChanged: "ReachabilityChanged",
|
|
387
417
|
RelayReservationLost: "RelayReservationLost",
|
|
388
418
|
RelayReserved: "RelayReserved",
|
|
@@ -401,7 +431,11 @@ interface RawEvent<Tag extends P2pEventTag, Inner> {
|
|
|
401
431
|
export type P2pEvent =
|
|
402
432
|
| RawEvent<
|
|
403
433
|
typeof P2pEvent_Tags.EventsDropped,
|
|
404
|
-
{
|
|
434
|
+
{
|
|
435
|
+
dropped: number;
|
|
436
|
+
totalDropped: number;
|
|
437
|
+
terminalConnectIds: number[];
|
|
438
|
+
}
|
|
405
439
|
>
|
|
406
440
|
| RawEvent<
|
|
407
441
|
typeof P2pEvent_Tags.DriverFailed,
|
|
@@ -463,7 +497,7 @@ export type P2pEvent =
|
|
|
463
497
|
>
|
|
464
498
|
| RawEvent<
|
|
465
499
|
typeof P2pEvent_Tags.PathEstablished,
|
|
466
|
-
{ connectId: number; peerId: string; path: PathKind }
|
|
500
|
+
{ connectId: number; peerId: string; connId: number; path: PathKind }
|
|
467
501
|
>
|
|
468
502
|
| RawEvent<
|
|
469
503
|
typeof P2pEvent_Tags.InboundPathEstablished,
|
|
@@ -477,14 +511,14 @@ export type P2pEvent =
|
|
|
477
511
|
typeof P2pEvent_Tags.HolePunchFailed,
|
|
478
512
|
Minip2pNamedEventMap["holePunchFailed"]
|
|
479
513
|
>
|
|
480
|
-
| RawEvent<
|
|
481
|
-
typeof P2pEvent_Tags.FellBackToRelay,
|
|
482
|
-
Minip2pNamedEventMap["fellBackToRelay"]
|
|
483
|
-
>
|
|
484
514
|
| RawEvent<
|
|
485
515
|
typeof P2pEvent_Tags.ConnectFailed,
|
|
486
516
|
Minip2pNamedEventMap["connectFailed"]
|
|
487
517
|
>
|
|
518
|
+
| RawEvent<
|
|
519
|
+
typeof P2pEvent_Tags.ConnectCancelled,
|
|
520
|
+
Minip2pNamedEventMap["connectCancelled"]
|
|
521
|
+
>
|
|
488
522
|
| RawEvent<
|
|
489
523
|
typeof P2pEvent_Tags.InboundDirectUpgrade,
|
|
490
524
|
Minip2pNamedEventMap["inboundDirectUpgrade"]
|
|
@@ -499,12 +533,12 @@ export type P2pEvent =
|
|
|
499
533
|
Minip2pNamedEventMap["peerUnsubscribed"]
|
|
500
534
|
>
|
|
501
535
|
| RawEvent<
|
|
502
|
-
typeof P2pEvent_Tags.
|
|
503
|
-
Minip2pNamedEventMap["
|
|
536
|
+
typeof P2pEvent_Tags.GossipsubOutboundFailure,
|
|
537
|
+
Minip2pNamedEventMap["gossipsubOutboundFailure"]
|
|
504
538
|
>
|
|
505
539
|
| RawEvent<
|
|
506
|
-
typeof P2pEvent_Tags.
|
|
507
|
-
Minip2pNamedEventMap["
|
|
540
|
+
typeof P2pEvent_Tags.GossipsubProtocolViolation,
|
|
541
|
+
Minip2pNamedEventMap["gossipsubProtocolViolation"]
|
|
508
542
|
>
|
|
509
543
|
| RawEvent<
|
|
510
544
|
typeof P2pEvent_Tags.PeerDiscovered,
|