@minip2p/core 0.1.0 → 0.3.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 +16 -3
- package/dist/backend.d.ts +53 -6
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +1 -1
- package/dist/backend.js.map +1 -1
- package/dist/errors.d.ts +61 -10
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +89 -11
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/sdk.d.ts +124 -60
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1018 -280
- package/dist/sdk.js.map +1 -1
- package/dist/types.d.ts +368 -231
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +84 -92
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
- package/src/backend.ts +62 -6
- package/src/errors.ts +120 -13
- package/src/index.ts +20 -11
- package/src/sdk.ts +1332 -345
- package/src/types.ts +413 -249
package/dist/types.d.ts
CHANGED
|
@@ -1,306 +1,443 @@
|
|
|
1
|
+
import type { DriverFailedError } from "./errors.js";
|
|
2
|
+
import type { Stream } from "./sdk.js";
|
|
1
3
|
/** Bytes accepted by the platform-neutral SDK. */
|
|
2
4
|
export type Bytes = ArrayBuffer | Uint8Array;
|
|
3
|
-
/** Signed-discovery settings. */
|
|
4
|
-
export interface
|
|
5
|
-
/**
|
|
5
|
+
/** Signed-discovery settings. The topic is intentionally application-scoped. */
|
|
6
|
+
export interface Minip2pDiscoveryOptions {
|
|
7
|
+
/** Application-scoped signed-beacon topic. */
|
|
6
8
|
readonly topic: string;
|
|
7
|
-
/**
|
|
8
|
-
readonly beaconIntervalMs
|
|
9
|
-
/**
|
|
10
|
-
readonly peerTtlMs
|
|
11
|
-
/** Whether
|
|
12
|
-
readonly autoDial
|
|
9
|
+
/** Beacon broadcast interval in milliseconds. */
|
|
10
|
+
readonly beaconIntervalMs?: number;
|
|
11
|
+
/** Time without observations before a peer expires. */
|
|
12
|
+
readonly peerTtlMs?: number;
|
|
13
|
+
/** Whether newly discovered peers should be dialed automatically. */
|
|
14
|
+
readonly autoDial?: boolean;
|
|
13
15
|
}
|
|
14
|
-
/** Local-link mDNS discovery settings. Omitted fields use
|
|
15
|
-
export interface
|
|
16
|
+
/** Local-link mDNS discovery settings. Omitted fields use native defaults. */
|
|
17
|
+
export interface Minip2pMdnsOptions {
|
|
18
|
+
/** Enables IPv6 multicast in addition to IPv4. */
|
|
16
19
|
readonly enableIpv6?: boolean;
|
|
20
|
+
/** TTL advertised in mDNS records. */
|
|
17
21
|
readonly ttlMs?: number;
|
|
22
|
+
/** Period between discovery queries. */
|
|
18
23
|
readonly queryIntervalMs?: number;
|
|
24
|
+
/** Maximum encoded DNS packet size. */
|
|
19
25
|
readonly maxPacketBytes?: number;
|
|
26
|
+
/** Maximum addresses advertised per response. */
|
|
20
27
|
readonly maxAnnouncedAddrs?: number;
|
|
28
|
+
/** Period between network-interface refreshes. */
|
|
21
29
|
readonly interfaceRefreshMs?: number;
|
|
30
|
+
/** Socket polling interval used by the native driver. */
|
|
22
31
|
readonly socketPollIntervalMs?: number;
|
|
32
|
+
/** Whether newly discovered peers should be dialed automatically. */
|
|
23
33
|
readonly autoDial?: boolean;
|
|
24
34
|
}
|
|
25
|
-
/**
|
|
26
|
-
export declare
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
35
|
+
/** Available pubsub routing strategies. */
|
|
36
|
+
export declare const PubsubRouter: {
|
|
37
|
+
readonly Floodsub: 1;
|
|
38
|
+
readonly Gossipsub: 0;
|
|
39
|
+
};
|
|
40
|
+
export type PubsubRouter = (typeof PubsubRouter)[keyof typeof PubsubRouter];
|
|
41
|
+
/** Coarse local reachability states. */
|
|
42
|
+
export declare const Reachability: {
|
|
43
|
+
readonly Private: 2;
|
|
44
|
+
readonly Public: 1;
|
|
45
|
+
readonly Unknown: 0;
|
|
46
|
+
};
|
|
47
|
+
export type Reachability = (typeof Reachability)[keyof typeof Reachability];
|
|
48
|
+
/** Sources contributing peer-discovery observations. */
|
|
49
|
+
export declare const DiscoverySource: {
|
|
50
|
+
readonly Mdns: 1;
|
|
51
|
+
readonly SignedBeacon: 0;
|
|
52
|
+
};
|
|
53
|
+
export type DiscoverySource = (typeof DiscoverySource)[keyof typeof DiscoverySource];
|
|
54
|
+
/** Fatal native-driver failure categories. */
|
|
55
|
+
export declare const DriverFailureKind: {
|
|
56
|
+
readonly Invariant: 2;
|
|
57
|
+
readonly Panic: 3;
|
|
58
|
+
readonly Swarm: 1;
|
|
59
|
+
readonly Transport: 0;
|
|
60
|
+
};
|
|
61
|
+
export type DriverFailureKind = (typeof DriverFailureKind)[keyof typeof DriverFailureKind];
|
|
62
|
+
/** Non-fatal endpoint runtime error categories. */
|
|
63
|
+
export declare const EndpointErrorKind: {
|
|
64
|
+
readonly Driver: 7;
|
|
65
|
+
readonly Identify: 2;
|
|
66
|
+
readonly IdentifyStreamRejected: 4;
|
|
67
|
+
readonly Multistream: 1;
|
|
68
|
+
readonly OpenStreamFailed: 5;
|
|
69
|
+
readonly Ping: 3;
|
|
70
|
+
readonly Transport: 0;
|
|
71
|
+
readonly UnsupportedProtocol: 6;
|
|
72
|
+
};
|
|
73
|
+
export type EndpointErrorKind = (typeof EndpointErrorKind)[keyof typeof EndpointErrorKind];
|
|
74
|
+
/** Terminal NAT connection failure categories. */
|
|
75
|
+
export declare const NatErrorKind: {
|
|
76
|
+
readonly DialFailed: 2;
|
|
77
|
+
readonly NoPathAvailable: 0;
|
|
78
|
+
readonly Protocol: 3;
|
|
79
|
+
readonly RelayRefused: 4;
|
|
80
|
+
readonly Timeout: 1;
|
|
81
|
+
};
|
|
82
|
+
export type NatErrorKind = (typeof NatErrorKind)[keyof typeof NatErrorKind];
|
|
30
83
|
/** Configuration accepted by a platform minip2p endpoint. */
|
|
31
|
-
export interface
|
|
32
|
-
/** Raw 32-byte Ed25519 secret key
|
|
84
|
+
export interface Minip2pConfig {
|
|
85
|
+
/** Raw 32-byte Ed25519 secret key. */
|
|
33
86
|
readonly secretKey: Bytes;
|
|
34
|
-
/**
|
|
87
|
+
/** Agent version advertised through Identify. */
|
|
35
88
|
readonly agentVersion?: string;
|
|
36
|
-
/** Direct QUIC relay peer
|
|
89
|
+
/** Direct QUIC relay peer multiaddresses. */
|
|
37
90
|
readonly relays?: readonly string[];
|
|
38
|
-
/**
|
|
91
|
+
/** AutoNAT server peer multiaddresses. */
|
|
39
92
|
readonly autonatServers?: readonly string[];
|
|
40
|
-
/** QUIC listen multiaddress
|
|
93
|
+
/** Local QUIC listen multiaddress; native defaults apply when omitted. */
|
|
41
94
|
readonly listenAddr?: string;
|
|
42
|
-
/**
|
|
95
|
+
/** Routes outbound connectivity through relays only. */
|
|
43
96
|
readonly forceRelay?: boolean;
|
|
44
|
-
/**
|
|
97
|
+
/** Accepts unsigned pubsub messages. */
|
|
45
98
|
readonly allowUnsigned?: boolean;
|
|
46
|
-
/** Pubsub router
|
|
99
|
+
/** Pubsub router to enable. */
|
|
47
100
|
readonly pubsubRouter?: PubsubRouter;
|
|
48
|
-
/**
|
|
101
|
+
/** Application protocol IDs accepted on inbound streams. */
|
|
49
102
|
readonly protocols?: readonly string[];
|
|
50
|
-
/** Signed-
|
|
51
|
-
readonly discovery?:
|
|
52
|
-
/** Enables mDNS with defaults
|
|
53
|
-
readonly mdns?: boolean |
|
|
103
|
+
/** Signed-beacon discovery configuration. */
|
|
104
|
+
readonly discovery?: Minip2pDiscoveryOptions;
|
|
105
|
+
/** Enables mDNS with defaults or explicit options. */
|
|
106
|
+
readonly mdns?: boolean | Minip2pMdnsOptions;
|
|
54
107
|
}
|
|
55
|
-
/**
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
108
|
+
/** Latest Identify information advertised by a remote peer. */
|
|
109
|
+
export interface IdentifyInfo {
|
|
110
|
+
/** Protobuf-encoded remote public key, when supplied. */
|
|
111
|
+
readonly publicKey?: ArrayBuffer;
|
|
112
|
+
/** Listen addresses advertised by the remote peer. */
|
|
113
|
+
readonly listenAddrs: readonly string[];
|
|
114
|
+
/** Protocols advertised by the remote peer. */
|
|
115
|
+
readonly protocols: readonly string[];
|
|
116
|
+
/** Address at which the remote observed this endpoint. */
|
|
117
|
+
readonly observedAddr?: string;
|
|
118
|
+
/** Remote libp2p protocol version. */
|
|
119
|
+
readonly protocolVersion?: string;
|
|
120
|
+
/** Remote agent version. */
|
|
121
|
+
readonly agentVersion?: string;
|
|
60
122
|
}
|
|
61
|
-
/**
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
|
|
123
|
+
/** Merged discovery information for one peer. */
|
|
124
|
+
export interface KnownPeerInfo {
|
|
125
|
+
readonly peerId: string;
|
|
126
|
+
readonly addrs: readonly string[];
|
|
127
|
+
readonly beaconAddrs: readonly string[];
|
|
128
|
+
readonly mdnsAddrs: readonly string[];
|
|
129
|
+
readonly beaconLastSeenAgeMs?: number;
|
|
130
|
+
readonly mdnsLastSeenAgeMs?: number;
|
|
131
|
+
readonly connected: boolean;
|
|
65
132
|
}
|
|
66
|
-
/**
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Invariant = 2,
|
|
71
|
-
Panic = 3
|
|
133
|
+
/** Active relay reservation metadata. */
|
|
134
|
+
export interface RelayReservationInfo {
|
|
135
|
+
readonly relayPeerId: string;
|
|
136
|
+
readonly expiresUnixSecs?: number;
|
|
72
137
|
}
|
|
73
|
-
/**
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
138
|
+
/** A usable NAT-orchestrated connection path. */
|
|
139
|
+
export type Path = {
|
|
140
|
+
readonly kind: "directDialed";
|
|
141
|
+
} | {
|
|
142
|
+
readonly kind: "directPunched";
|
|
143
|
+
} | {
|
|
144
|
+
readonly kind: "relayed";
|
|
145
|
+
readonly relayPeerId: string;
|
|
146
|
+
};
|
|
147
|
+
/** Serializable metadata for an inbound stream catch-all event. */
|
|
148
|
+
export interface InboundStreamMeta {
|
|
149
|
+
readonly peerId: string;
|
|
150
|
+
readonly protocolId: string;
|
|
151
|
+
readonly streamId: number;
|
|
152
|
+
readonly connId: number;
|
|
153
|
+
readonly initiatedLocally: boolean;
|
|
83
154
|
}
|
|
84
|
-
/**
|
|
85
|
-
export
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
155
|
+
/** Payload types keyed by high-level SDK event name. */
|
|
156
|
+
export interface Minip2pNamedEventMap {
|
|
157
|
+
eventsDropped: {
|
|
158
|
+
readonly dropped: number;
|
|
159
|
+
readonly totalDropped: number;
|
|
160
|
+
};
|
|
161
|
+
driverFailed: {
|
|
162
|
+
readonly kind: DriverFailureKind;
|
|
163
|
+
readonly detail: string;
|
|
164
|
+
};
|
|
165
|
+
connectionEstablished: {
|
|
166
|
+
readonly peerId: string;
|
|
167
|
+
readonly connId: number;
|
|
168
|
+
};
|
|
169
|
+
connectionClosed: {
|
|
170
|
+
readonly peerId: string;
|
|
171
|
+
readonly connId: number;
|
|
172
|
+
};
|
|
173
|
+
peerReady: {
|
|
174
|
+
readonly peerId: string;
|
|
175
|
+
readonly protocols: readonly string[];
|
|
176
|
+
};
|
|
177
|
+
identifyReceived: {
|
|
178
|
+
readonly peerId: string;
|
|
179
|
+
readonly info: IdentifyInfo;
|
|
180
|
+
};
|
|
181
|
+
pingRttMeasured: {
|
|
182
|
+
readonly peerId: string;
|
|
183
|
+
readonly rttMs: number;
|
|
184
|
+
};
|
|
185
|
+
pingTimeout: {
|
|
186
|
+
readonly peerId: string;
|
|
187
|
+
};
|
|
188
|
+
stream: Stream;
|
|
189
|
+
endpointError: {
|
|
190
|
+
readonly kind: EndpointErrorKind;
|
|
191
|
+
readonly peerId?: string;
|
|
192
|
+
readonly connId?: number;
|
|
193
|
+
readonly streamId?: number;
|
|
194
|
+
readonly detail: string;
|
|
195
|
+
};
|
|
196
|
+
reachabilityChanged: {
|
|
197
|
+
readonly previous: Reachability;
|
|
198
|
+
readonly current: Reachability;
|
|
199
|
+
readonly confirmedAddrs: readonly string[];
|
|
200
|
+
};
|
|
201
|
+
publicAddressesChanged: {
|
|
202
|
+
readonly addrs: readonly string[];
|
|
203
|
+
};
|
|
204
|
+
relayReserved: {
|
|
205
|
+
readonly relayPeerId: string;
|
|
206
|
+
readonly expiresUnixSecs?: number;
|
|
207
|
+
};
|
|
208
|
+
relayReservationLost: {
|
|
209
|
+
readonly relayPeerId: string;
|
|
210
|
+
};
|
|
211
|
+
pathEstablished: {
|
|
212
|
+
readonly connectId: number;
|
|
213
|
+
readonly peerId: string;
|
|
214
|
+
readonly path: Path;
|
|
215
|
+
};
|
|
216
|
+
pathUpgraded: {
|
|
217
|
+
readonly connectId: number;
|
|
218
|
+
readonly peerId: string;
|
|
219
|
+
readonly from: Path;
|
|
220
|
+
readonly to: Path;
|
|
221
|
+
};
|
|
222
|
+
holePunchFailed: {
|
|
223
|
+
readonly connectId: number;
|
|
224
|
+
readonly attempt: number;
|
|
225
|
+
readonly reason: string;
|
|
226
|
+
};
|
|
227
|
+
fellBackToRelay: {
|
|
228
|
+
readonly connectId: number;
|
|
229
|
+
readonly peerId: string;
|
|
230
|
+
};
|
|
231
|
+
connectFailed: {
|
|
232
|
+
readonly connectId: number;
|
|
233
|
+
readonly peerId: string;
|
|
234
|
+
readonly kind: NatErrorKind;
|
|
235
|
+
readonly detail: string;
|
|
236
|
+
};
|
|
237
|
+
inboundDirectUpgrade: {
|
|
238
|
+
readonly peerId: string;
|
|
239
|
+
};
|
|
240
|
+
message: {
|
|
241
|
+
readonly fromPeerId: string;
|
|
242
|
+
readonly topics: readonly string[];
|
|
243
|
+
readonly data: ArrayBuffer;
|
|
244
|
+
readonly seqno: ArrayBuffer;
|
|
245
|
+
readonly signed: boolean;
|
|
246
|
+
};
|
|
247
|
+
peerSubscribed: {
|
|
248
|
+
readonly peerId: string;
|
|
249
|
+
readonly topic: string;
|
|
250
|
+
};
|
|
251
|
+
peerUnsubscribed: {
|
|
252
|
+
readonly peerId: string;
|
|
253
|
+
readonly topic: string;
|
|
254
|
+
};
|
|
255
|
+
pubsubOutboundFailure: {
|
|
256
|
+
readonly peerId: string;
|
|
257
|
+
readonly reason: string;
|
|
258
|
+
};
|
|
259
|
+
pubsubProtocolViolation: {
|
|
260
|
+
readonly peerId: string;
|
|
261
|
+
readonly reason: string;
|
|
262
|
+
};
|
|
263
|
+
peerDiscovered: {
|
|
264
|
+
readonly peerId: string;
|
|
265
|
+
readonly addrs: readonly string[];
|
|
266
|
+
readonly source: DiscoverySource;
|
|
267
|
+
};
|
|
268
|
+
peerUpdated: {
|
|
269
|
+
readonly peerId: string;
|
|
270
|
+
readonly addrs: readonly string[];
|
|
271
|
+
readonly source: DiscoverySource;
|
|
272
|
+
};
|
|
273
|
+
peerExpired: {
|
|
274
|
+
readonly peerId: string;
|
|
275
|
+
};
|
|
276
|
+
discoveryDialFailed: {
|
|
277
|
+
readonly peerId: string;
|
|
278
|
+
readonly reason: string;
|
|
279
|
+
};
|
|
280
|
+
discoveryProtocolViolation: {
|
|
281
|
+
readonly peerId?: string;
|
|
282
|
+
readonly source: DiscoverySource;
|
|
283
|
+
readonly reason: string;
|
|
284
|
+
readonly suppressed: number;
|
|
285
|
+
};
|
|
286
|
+
queueOverflow: {
|
|
287
|
+
readonly dropped: number;
|
|
288
|
+
};
|
|
289
|
+
handlerError: {
|
|
290
|
+
readonly eventType: keyof Minip2pNamedEventMap | "inboundStream";
|
|
291
|
+
readonly metadata: Record<string, unknown>;
|
|
292
|
+
readonly error: unknown;
|
|
293
|
+
};
|
|
91
294
|
}
|
|
92
|
-
/**
|
|
93
|
-
export
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
295
|
+
/** Events available to the catch-all endpoint subscriber. */
|
|
296
|
+
export type Minip2pCatchAllEventMap = Omit<Minip2pNamedEventMap, "stream" | "handlerError"> & {
|
|
297
|
+
inboundStream: InboundStreamMeta;
|
|
298
|
+
handlerError: Minip2pNamedEventMap["handlerError"];
|
|
299
|
+
};
|
|
300
|
+
/** Discriminated union emitted to catch-all endpoint subscribers. */
|
|
301
|
+
export type Minip2pEvent = {
|
|
302
|
+
[Kind in keyof Minip2pCatchAllEventMap]: {
|
|
303
|
+
readonly type: Kind;
|
|
304
|
+
} & Minip2pCatchAllEventMap[Kind];
|
|
305
|
+
}[keyof Minip2pCatchAllEventMap];
|
|
306
|
+
/** Timeout and cancellation controls shared by Promise-based operations. */
|
|
307
|
+
export interface OpOptions {
|
|
308
|
+
/** Timeout in milliseconds; `0` disables the timeout. */
|
|
309
|
+
readonly timeoutMs?: number;
|
|
310
|
+
/** Abort signal that cancels only this caller's wait. */
|
|
311
|
+
readonly signal?: AbortSignal;
|
|
312
|
+
}
|
|
313
|
+
/** Options accepted by {@link Minip2pBase.once}. */
|
|
314
|
+
export type OnceOptions = OpOptions;
|
|
315
|
+
/** Options accepted by {@link Minip2pBase.waitFor}. */
|
|
316
|
+
export interface WaitForOptions<Event> extends OpOptions {
|
|
317
|
+
/** Optional filter applied before resolving the waiter. */
|
|
318
|
+
readonly predicate?: (event: Event) => boolean;
|
|
319
|
+
}
|
|
320
|
+
/** First usable path produced by a connection attempt. */
|
|
321
|
+
export interface ConnectResult {
|
|
322
|
+
readonly connectId: number;
|
|
323
|
+
readonly peerId: string;
|
|
324
|
+
readonly path: Path;
|
|
97
325
|
}
|
|
98
|
-
/**
|
|
326
|
+
/** Reason reported to endpoint close observers. */
|
|
327
|
+
export type CloseReason = {
|
|
328
|
+
readonly reason: "close";
|
|
329
|
+
} | {
|
|
330
|
+
readonly reason: "driverFailed";
|
|
331
|
+
readonly error: DriverFailedError;
|
|
332
|
+
};
|
|
333
|
+
/** Idempotent callback that removes a subscription. */
|
|
334
|
+
export type Unsubscribe = () => void;
|
|
335
|
+
/** Raw backend-only path tags. */
|
|
336
|
+
export declare const PathKind_Tags: {
|
|
337
|
+
readonly DirectDialed: "DirectDialed";
|
|
338
|
+
readonly DirectPunched: "DirectPunched";
|
|
339
|
+
readonly Relayed: "Relayed";
|
|
340
|
+
};
|
|
341
|
+
export type PathKindTag = (typeof PathKind_Tags)[keyof typeof PathKind_Tags];
|
|
99
342
|
export type PathKind = {
|
|
100
|
-
readonly tag: PathKind_Tags.DirectDialed;
|
|
343
|
+
readonly tag: typeof PathKind_Tags.DirectDialed;
|
|
101
344
|
} | {
|
|
102
|
-
readonly tag: PathKind_Tags.DirectPunched;
|
|
345
|
+
readonly tag: typeof PathKind_Tags.DirectPunched;
|
|
103
346
|
} | {
|
|
104
|
-
readonly tag: PathKind_Tags.Relayed;
|
|
347
|
+
readonly tag: typeof PathKind_Tags.Relayed;
|
|
105
348
|
readonly inner: {
|
|
106
349
|
readonly relayPeerId: string;
|
|
107
350
|
};
|
|
108
351
|
};
|
|
109
|
-
/**
|
|
110
|
-
export declare
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
ConnectionEstablished
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
352
|
+
/** Raw backend-only event tags. */
|
|
353
|
+
export declare const P2pEvent_Tags: {
|
|
354
|
+
readonly ConnectFailed: "ConnectFailed";
|
|
355
|
+
readonly ConnectionClosed: "ConnectionClosed";
|
|
356
|
+
readonly ConnectionEstablished: "ConnectionEstablished";
|
|
357
|
+
readonly DiscoveryDialFailed: "DiscoveryDialFailed";
|
|
358
|
+
readonly DiscoveryProtocolViolation: "DiscoveryProtocolViolation";
|
|
359
|
+
readonly DriverFailed: "DriverFailed";
|
|
360
|
+
readonly EndpointError: "EndpointError";
|
|
361
|
+
readonly EventsDropped: "EventsDropped";
|
|
362
|
+
readonly FellBackToRelay: "FellBackToRelay";
|
|
363
|
+
readonly HolePunchFailed: "HolePunchFailed";
|
|
364
|
+
readonly IdentifyReceived: "IdentifyReceived";
|
|
365
|
+
readonly InboundDirectUpgrade: "InboundDirectUpgrade";
|
|
366
|
+
readonly Message: "Message";
|
|
367
|
+
readonly PathEstablished: "PathEstablished";
|
|
368
|
+
readonly PathUpgraded: "PathUpgraded";
|
|
369
|
+
readonly PeerDiscovered: "PeerDiscovered";
|
|
370
|
+
readonly PeerExpired: "PeerExpired";
|
|
371
|
+
readonly PeerReady: "PeerReady";
|
|
372
|
+
readonly PeerSubscribed: "PeerSubscribed";
|
|
373
|
+
readonly PeerUnsubscribed: "PeerUnsubscribed";
|
|
374
|
+
readonly PeerUpdated: "PeerUpdated";
|
|
375
|
+
readonly PingRttMeasured: "PingRttMeasured";
|
|
376
|
+
readonly PingTimeout: "PingTimeout";
|
|
377
|
+
readonly PublicAddressesChanged: "PublicAddressesChanged";
|
|
378
|
+
readonly PubsubOutboundFailure: "PubsubOutboundFailure";
|
|
379
|
+
readonly PubsubProtocolViolation: "PubsubProtocolViolation";
|
|
380
|
+
readonly ReachabilityChanged: "ReachabilityChanged";
|
|
381
|
+
readonly RelayReservationLost: "RelayReservationLost";
|
|
382
|
+
readonly RelayReserved: "RelayReserved";
|
|
383
|
+
readonly StreamClosed: "StreamClosed";
|
|
384
|
+
readonly StreamData: "StreamData";
|
|
385
|
+
readonly StreamReady: "StreamReady";
|
|
386
|
+
readonly StreamRemoteWriteClosed: "StreamRemoteWriteClosed";
|
|
387
|
+
};
|
|
388
|
+
export type P2pEventTag = (typeof P2pEvent_Tags)[keyof typeof P2pEvent_Tags];
|
|
389
|
+
interface RawEvent<Tag extends P2pEventTag, Inner> {
|
|
146
390
|
readonly tag: Tag;
|
|
147
391
|
readonly inner: Readonly<Inner>;
|
|
148
392
|
}
|
|
149
|
-
|
|
150
|
-
export interface IdentifyInfo {
|
|
151
|
-
readonly publicKey?: ArrayBuffer;
|
|
152
|
-
readonly listenAddrs: readonly string[];
|
|
153
|
-
readonly protocols: readonly string[];
|
|
154
|
-
readonly observedAddr?: string;
|
|
155
|
-
readonly protocolVersion?: string;
|
|
156
|
-
readonly agentVersion?: string;
|
|
157
|
-
}
|
|
158
|
-
/** A platform-independent event emitted by the minip2p driver. */
|
|
159
|
-
export type P2pEvent = Event<P2pEvent_Tags.EventsDropped, {
|
|
393
|
+
export type P2pEvent = RawEvent<typeof P2pEvent_Tags.EventsDropped, {
|
|
160
394
|
dropped: number;
|
|
161
395
|
totalDropped: number;
|
|
162
|
-
}> |
|
|
396
|
+
}> | RawEvent<typeof P2pEvent_Tags.DriverFailed, {
|
|
163
397
|
kind: DriverFailureKind;
|
|
164
398
|
detail: string;
|
|
165
|
-
}> |
|
|
399
|
+
}> | RawEvent<typeof P2pEvent_Tags.ConnectionEstablished, {
|
|
166
400
|
peerId: string;
|
|
167
401
|
connId: number;
|
|
168
|
-
}> |
|
|
402
|
+
}> | RawEvent<typeof P2pEvent_Tags.ConnectionClosed, {
|
|
169
403
|
peerId: string;
|
|
170
404
|
connId: number;
|
|
171
|
-
}> |
|
|
405
|
+
}> | RawEvent<typeof P2pEvent_Tags.PeerReady, {
|
|
172
406
|
peerId: string;
|
|
173
407
|
protocols: readonly string[];
|
|
174
|
-
}> |
|
|
408
|
+
}> | RawEvent<typeof P2pEvent_Tags.IdentifyReceived, {
|
|
175
409
|
peerId: string;
|
|
176
410
|
info: IdentifyInfo;
|
|
177
|
-
}> |
|
|
411
|
+
}> | RawEvent<typeof P2pEvent_Tags.PingRttMeasured, {
|
|
178
412
|
peerId: string;
|
|
179
413
|
rttMs: number;
|
|
180
|
-
}> |
|
|
414
|
+
}> | RawEvent<typeof P2pEvent_Tags.PingTimeout, {
|
|
181
415
|
peerId: string;
|
|
182
|
-
}> |
|
|
183
|
-
peerId: string;
|
|
184
|
-
connId: number;
|
|
185
|
-
streamId: number;
|
|
186
|
-
protocolId: string;
|
|
187
|
-
initiatedLocally: boolean;
|
|
188
|
-
}> | Event<P2pEvent_Tags.StreamData, {
|
|
416
|
+
}> | RawEvent<typeof P2pEvent_Tags.StreamReady, InboundStreamMeta> | RawEvent<typeof P2pEvent_Tags.StreamData, {
|
|
189
417
|
peerId: string;
|
|
190
418
|
connId: number;
|
|
191
419
|
streamId: number;
|
|
192
420
|
data: ArrayBuffer;
|
|
193
|
-
}> |
|
|
421
|
+
}> | RawEvent<typeof P2pEvent_Tags.StreamRemoteWriteClosed, {
|
|
194
422
|
peerId: string;
|
|
195
423
|
connId: number;
|
|
196
424
|
streamId: number;
|
|
197
|
-
}> |
|
|
425
|
+
}> | RawEvent<typeof P2pEvent_Tags.StreamClosed, {
|
|
198
426
|
peerId: string;
|
|
199
427
|
connId: number;
|
|
200
428
|
streamId: number;
|
|
201
|
-
}> |
|
|
202
|
-
kind: EndpointErrorKind;
|
|
203
|
-
peerId?: string;
|
|
204
|
-
connId?: number;
|
|
205
|
-
detail: string;
|
|
206
|
-
}> | Event<P2pEvent_Tags.ReachabilityChanged, {
|
|
207
|
-
previous: Reachability;
|
|
208
|
-
current: Reachability;
|
|
209
|
-
confirmedAddrs: readonly string[];
|
|
210
|
-
}> | Event<P2pEvent_Tags.PublicAddressesChanged, {
|
|
211
|
-
addrs: readonly string[];
|
|
212
|
-
}> | Event<P2pEvent_Tags.RelayReserved, {
|
|
213
|
-
relayPeerId: string;
|
|
214
|
-
expiresUnixSecs?: number;
|
|
215
|
-
}> | Event<P2pEvent_Tags.RelayReservationLost, {
|
|
216
|
-
relayPeerId: string;
|
|
217
|
-
}> | Event<P2pEvent_Tags.PathEstablished, {
|
|
429
|
+
}> | RawEvent<typeof P2pEvent_Tags.EndpointError, Minip2pNamedEventMap["endpointError"]> | RawEvent<typeof P2pEvent_Tags.ReachabilityChanged, Minip2pNamedEventMap["reachabilityChanged"]> | RawEvent<typeof P2pEvent_Tags.PublicAddressesChanged, Minip2pNamedEventMap["publicAddressesChanged"]> | RawEvent<typeof P2pEvent_Tags.RelayReserved, Minip2pNamedEventMap["relayReserved"]> | RawEvent<typeof P2pEvent_Tags.RelayReservationLost, Minip2pNamedEventMap["relayReservationLost"]> | RawEvent<typeof P2pEvent_Tags.PathEstablished, {
|
|
218
430
|
connectId: number;
|
|
219
431
|
peerId: string;
|
|
220
432
|
path: PathKind;
|
|
221
|
-
}> |
|
|
433
|
+
}> | RawEvent<typeof P2pEvent_Tags.PathUpgraded, {
|
|
222
434
|
connectId: number;
|
|
223
435
|
peerId: string;
|
|
224
436
|
from: PathKind;
|
|
225
437
|
to: PathKind;
|
|
226
|
-
}> |
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
reason: string;
|
|
230
|
-
}> | Event<P2pEvent_Tags.FellBackToRelay, {
|
|
231
|
-
connectId: number;
|
|
232
|
-
peerId: string;
|
|
233
|
-
}> | Event<P2pEvent_Tags.ConnectFailed, {
|
|
234
|
-
connectId: number;
|
|
235
|
-
peerId: string;
|
|
236
|
-
kind: NatErrorKind;
|
|
237
|
-
detail: string;
|
|
238
|
-
}> | Event<P2pEvent_Tags.InboundDirectUpgrade, {
|
|
239
|
-
peerId: string;
|
|
240
|
-
}> | Event<P2pEvent_Tags.Message, {
|
|
241
|
-
fromPeerId: string;
|
|
242
|
-
topics: readonly string[];
|
|
243
|
-
data: ArrayBuffer;
|
|
244
|
-
seqno: ArrayBuffer;
|
|
245
|
-
signed: boolean;
|
|
246
|
-
}> | Event<P2pEvent_Tags.PeerSubscribed, {
|
|
247
|
-
peerId: string;
|
|
248
|
-
topic: string;
|
|
249
|
-
}> | Event<P2pEvent_Tags.PeerUnsubscribed, {
|
|
250
|
-
peerId: string;
|
|
251
|
-
topic: string;
|
|
252
|
-
}> | Event<P2pEvent_Tags.PubsubOutboundFailure, {
|
|
253
|
-
peerId: string;
|
|
254
|
-
reason: string;
|
|
255
|
-
}> | Event<P2pEvent_Tags.PubsubProtocolViolation, {
|
|
256
|
-
peerId: string;
|
|
257
|
-
reason: string;
|
|
258
|
-
}> | Event<P2pEvent_Tags.PeerDiscovered, {
|
|
259
|
-
peerId: string;
|
|
260
|
-
addrs: readonly string[];
|
|
261
|
-
source: DiscoverySource;
|
|
262
|
-
}> | Event<P2pEvent_Tags.PeerUpdated, {
|
|
263
|
-
peerId: string;
|
|
264
|
-
addrs: readonly string[];
|
|
265
|
-
source: DiscoverySource;
|
|
266
|
-
}> | Event<P2pEvent_Tags.PeerExpired, {
|
|
267
|
-
peerId: string;
|
|
268
|
-
}> | Event<P2pEvent_Tags.DiscoveryDialFailed, {
|
|
269
|
-
peerId: string;
|
|
270
|
-
reason: string;
|
|
271
|
-
}> | Event<P2pEvent_Tags.DiscoveryProtocolViolation, {
|
|
272
|
-
peerId?: string;
|
|
273
|
-
source: DiscoverySource;
|
|
274
|
-
reason: string;
|
|
275
|
-
suppressed: number;
|
|
276
|
-
}>;
|
|
277
|
-
/** Extracts one native event variant by its tag. */
|
|
278
|
-
export type P2pEventByTag<Tag extends P2pEvent_Tags> = Extract<P2pEvent, {
|
|
279
|
-
tag: Tag;
|
|
438
|
+
}> | RawEvent<typeof P2pEvent_Tags.HolePunchFailed, Minip2pNamedEventMap["holePunchFailed"]> | RawEvent<typeof P2pEvent_Tags.FellBackToRelay, Minip2pNamedEventMap["fellBackToRelay"]> | RawEvent<typeof P2pEvent_Tags.ConnectFailed, Minip2pNamedEventMap["connectFailed"]> | RawEvent<typeof P2pEvent_Tags.InboundDirectUpgrade, Minip2pNamedEventMap["inboundDirectUpgrade"]> | RawEvent<typeof P2pEvent_Tags.Message, Minip2pNamedEventMap["message"]> | RawEvent<typeof P2pEvent_Tags.PeerSubscribed, Minip2pNamedEventMap["peerSubscribed"]> | RawEvent<typeof P2pEvent_Tags.PeerUnsubscribed, Minip2pNamedEventMap["peerUnsubscribed"]> | RawEvent<typeof P2pEvent_Tags.PubsubOutboundFailure, Minip2pNamedEventMap["pubsubOutboundFailure"]> | RawEvent<typeof P2pEvent_Tags.PubsubProtocolViolation, Minip2pNamedEventMap["pubsubProtocolViolation"]> | RawEvent<typeof P2pEvent_Tags.PeerDiscovered, Minip2pNamedEventMap["peerDiscovered"]> | RawEvent<typeof P2pEvent_Tags.PeerUpdated, Minip2pNamedEventMap["peerUpdated"]> | RawEvent<typeof P2pEvent_Tags.PeerExpired, Minip2pNamedEventMap["peerExpired"]> | RawEvent<typeof P2pEvent_Tags.DiscoveryDialFailed, Minip2pNamedEventMap["discoveryDialFailed"]> | RawEvent<typeof P2pEvent_Tags.DiscoveryProtocolViolation, Minip2pNamedEventMap["discoveryProtocolViolation"]>;
|
|
439
|
+
export type P2pEventByTag<Tag extends P2pEventTag> = Extract<P2pEvent, {
|
|
440
|
+
readonly tag: Tag;
|
|
280
441
|
}>;
|
|
281
|
-
/** One peer in the shared discovery address book. */
|
|
282
|
-
export interface KnownPeerInfo {
|
|
283
|
-
readonly peerId: string;
|
|
284
|
-
readonly addrs: readonly string[];
|
|
285
|
-
readonly beaconAddrs: readonly string[];
|
|
286
|
-
readonly mdnsAddrs: readonly string[];
|
|
287
|
-
readonly beaconLastSeenAgeMs?: number;
|
|
288
|
-
readonly mdnsLastSeenAgeMs?: number;
|
|
289
|
-
readonly connected: boolean;
|
|
290
|
-
}
|
|
291
|
-
/** Snapshot of the active inbound relay reservation. */
|
|
292
|
-
export interface RelayReservationInfo {
|
|
293
|
-
readonly relayPeerId: string;
|
|
294
|
-
readonly expiresUnixSecs?: number;
|
|
295
|
-
}
|
|
296
|
-
/** Host-side notification that the TypeScript event queue discarded events. */
|
|
297
|
-
export interface QueueOverflowEvent {
|
|
298
|
-
readonly type: "queueOverflow";
|
|
299
|
-
readonly dropped: number;
|
|
300
|
-
}
|
|
301
|
-
/** An event emitted by the high-level SDK. */
|
|
302
|
-
export type MiniP2pEvent = P2pEvent | QueueOverflowEvent;
|
|
303
|
-
/** Removes an event subscription. */
|
|
304
|
-
export type Unsubscribe = () => void;
|
|
305
442
|
export {};
|
|
306
443
|
//# sourceMappingURL=types.d.ts.map
|