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