@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/src/types.ts
CHANGED
|
@@ -1,336 +1,500 @@
|
|
|
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;
|
|
58
120
|
}
|
|
59
121
|
|
|
60
|
-
/**
|
|
61
|
-
export
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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;
|
|
65
136
|
}
|
|
66
137
|
|
|
67
|
-
/**
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
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;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Active relay reservation metadata. */
|
|
150
|
+
export interface RelayReservationInfo {
|
|
151
|
+
readonly relayPeerId: string;
|
|
152
|
+
readonly expiresUnixSecs?: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
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
|
+
pathUpgraded: {
|
|
208
|
+
readonly connectId: number;
|
|
209
|
+
readonly peerId: string;
|
|
210
|
+
readonly from: Path;
|
|
211
|
+
readonly to: Path;
|
|
212
|
+
};
|
|
213
|
+
holePunchFailed: {
|
|
214
|
+
readonly connectId: number;
|
|
215
|
+
readonly attempt: number;
|
|
216
|
+
readonly reason: string;
|
|
217
|
+
};
|
|
218
|
+
fellBackToRelay: { readonly connectId: number; readonly peerId: string };
|
|
219
|
+
connectFailed: {
|
|
220
|
+
readonly connectId: number;
|
|
221
|
+
readonly peerId: string;
|
|
222
|
+
readonly kind: NatErrorKind;
|
|
223
|
+
readonly detail: string;
|
|
224
|
+
};
|
|
225
|
+
inboundDirectUpgrade: { readonly peerId: string };
|
|
226
|
+
message: {
|
|
227
|
+
readonly fromPeerId: string;
|
|
228
|
+
readonly topics: readonly string[];
|
|
229
|
+
readonly data: ArrayBuffer;
|
|
230
|
+
readonly seqno: ArrayBuffer;
|
|
231
|
+
readonly signed: boolean;
|
|
232
|
+
};
|
|
233
|
+
peerSubscribed: { readonly peerId: string; readonly topic: string };
|
|
234
|
+
peerUnsubscribed: { readonly peerId: string; readonly topic: string };
|
|
235
|
+
pubsubOutboundFailure: { readonly peerId: string; readonly reason: string };
|
|
236
|
+
pubsubProtocolViolation: { readonly peerId: string; readonly reason: string };
|
|
237
|
+
peerDiscovered: {
|
|
238
|
+
readonly peerId: string;
|
|
239
|
+
readonly addrs: readonly string[];
|
|
240
|
+
readonly source: DiscoverySource;
|
|
241
|
+
};
|
|
242
|
+
peerUpdated: {
|
|
243
|
+
readonly peerId: string;
|
|
244
|
+
readonly addrs: readonly string[];
|
|
245
|
+
readonly source: DiscoverySource;
|
|
246
|
+
};
|
|
247
|
+
peerExpired: { readonly peerId: string };
|
|
248
|
+
discoveryDialFailed: { readonly peerId: string; readonly reason: string };
|
|
249
|
+
discoveryProtocolViolation: {
|
|
250
|
+
readonly peerId?: string;
|
|
251
|
+
readonly source: DiscoverySource;
|
|
252
|
+
readonly reason: string;
|
|
253
|
+
readonly suppressed: number;
|
|
254
|
+
};
|
|
255
|
+
queueOverflow: { readonly dropped: number };
|
|
256
|
+
handlerError: {
|
|
257
|
+
readonly eventType: keyof Minip2pNamedEventMap | "inboundStream";
|
|
258
|
+
readonly metadata: Record<string, unknown>;
|
|
259
|
+
readonly error: unknown;
|
|
260
|
+
};
|
|
79
261
|
}
|
|
80
262
|
|
|
81
|
-
/**
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
263
|
+
/** Events available to the catch-all endpoint subscriber. */
|
|
264
|
+
export type Minip2pCatchAllEventMap = Omit<
|
|
265
|
+
Minip2pNamedEventMap,
|
|
266
|
+
"stream" | "handlerError"
|
|
267
|
+
> & {
|
|
268
|
+
inboundStream: InboundStreamMeta;
|
|
269
|
+
handlerError: Minip2pNamedEventMap["handlerError"];
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/** Discriminated union emitted to catch-all endpoint subscribers. */
|
|
273
|
+
export type Minip2pEvent = {
|
|
274
|
+
[Kind in keyof Minip2pCatchAllEventMap]: {
|
|
275
|
+
readonly type: Kind;
|
|
276
|
+
} & Minip2pCatchAllEventMap[Kind];
|
|
277
|
+
}[keyof Minip2pCatchAllEventMap];
|
|
278
|
+
|
|
279
|
+
/** Timeout and cancellation controls shared by Promise-based operations. */
|
|
280
|
+
export interface OpOptions {
|
|
281
|
+
/** Timeout in milliseconds; `0` disables the timeout. */
|
|
282
|
+
readonly timeoutMs?: number;
|
|
283
|
+
/** Abort signal that cancels only this caller's wait. */
|
|
284
|
+
readonly signal?: AbortSignal;
|
|
91
285
|
}
|
|
92
286
|
|
|
93
|
-
/**
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
287
|
+
/** Options accepted by {@link Minip2pBase.once}. */
|
|
288
|
+
export type OnceOptions = OpOptions;
|
|
289
|
+
|
|
290
|
+
/** Options accepted by {@link Minip2pBase.waitFor}. */
|
|
291
|
+
export interface WaitForOptions<Event> extends OpOptions {
|
|
292
|
+
/** Optional filter applied before resolving the waiter. */
|
|
293
|
+
readonly predicate?: (event: Event) => boolean;
|
|
100
294
|
}
|
|
101
295
|
|
|
102
|
-
/**
|
|
103
|
-
export
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
296
|
+
/** First usable path produced by a connection attempt. */
|
|
297
|
+
export interface ConnectResult {
|
|
298
|
+
readonly connectId: number;
|
|
299
|
+
readonly peerId: string;
|
|
300
|
+
readonly path: Path;
|
|
107
301
|
}
|
|
108
302
|
|
|
109
|
-
/**
|
|
303
|
+
/** Reason reported to endpoint close observers. */
|
|
304
|
+
export type CloseReason =
|
|
305
|
+
| { readonly reason: "close" }
|
|
306
|
+
| {
|
|
307
|
+
readonly reason: "driverFailed";
|
|
308
|
+
readonly error: DriverFailedError;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/** Idempotent callback that removes a subscription. */
|
|
312
|
+
export type Unsubscribe = () => void;
|
|
313
|
+
|
|
314
|
+
/** Raw backend-only path tags. */
|
|
315
|
+
export const PathKind_Tags = {
|
|
316
|
+
DirectDialed: "DirectDialed",
|
|
317
|
+
DirectPunched: "DirectPunched",
|
|
318
|
+
Relayed: "Relayed",
|
|
319
|
+
} as const;
|
|
320
|
+
export type PathKindTag = (typeof PathKind_Tags)[keyof typeof PathKind_Tags];
|
|
110
321
|
export type PathKind =
|
|
111
|
-
| { readonly tag: PathKind_Tags.DirectDialed }
|
|
112
|
-
| { readonly tag: PathKind_Tags.DirectPunched }
|
|
322
|
+
| { readonly tag: typeof PathKind_Tags.DirectDialed }
|
|
323
|
+
| { readonly tag: typeof PathKind_Tags.DirectPunched }
|
|
113
324
|
| {
|
|
114
|
-
readonly tag: PathKind_Tags.Relayed;
|
|
325
|
+
readonly tag: typeof PathKind_Tags.Relayed;
|
|
115
326
|
readonly inner: { readonly relayPeerId: string };
|
|
116
327
|
};
|
|
117
328
|
|
|
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
|
-
}
|
|
329
|
+
/** Raw backend-only event tags. */
|
|
330
|
+
export const P2pEvent_Tags = {
|
|
331
|
+
ConnectFailed: "ConnectFailed",
|
|
332
|
+
ConnectionClosed: "ConnectionClosed",
|
|
333
|
+
ConnectionEstablished: "ConnectionEstablished",
|
|
334
|
+
DiscoveryDialFailed: "DiscoveryDialFailed",
|
|
335
|
+
DiscoveryProtocolViolation: "DiscoveryProtocolViolation",
|
|
336
|
+
DriverFailed: "DriverFailed",
|
|
337
|
+
EndpointError: "EndpointError",
|
|
338
|
+
EventsDropped: "EventsDropped",
|
|
339
|
+
FellBackToRelay: "FellBackToRelay",
|
|
340
|
+
HolePunchFailed: "HolePunchFailed",
|
|
341
|
+
IdentifyReceived: "IdentifyReceived",
|
|
342
|
+
InboundDirectUpgrade: "InboundDirectUpgrade",
|
|
343
|
+
Message: "Message",
|
|
344
|
+
PathEstablished: "PathEstablished",
|
|
345
|
+
PathUpgraded: "PathUpgraded",
|
|
346
|
+
PeerDiscovered: "PeerDiscovered",
|
|
347
|
+
PeerExpired: "PeerExpired",
|
|
348
|
+
PeerReady: "PeerReady",
|
|
349
|
+
PeerSubscribed: "PeerSubscribed",
|
|
350
|
+
PeerUnsubscribed: "PeerUnsubscribed",
|
|
351
|
+
PeerUpdated: "PeerUpdated",
|
|
352
|
+
PingRttMeasured: "PingRttMeasured",
|
|
353
|
+
PingTimeout: "PingTimeout",
|
|
354
|
+
PublicAddressesChanged: "PublicAddressesChanged",
|
|
355
|
+
PubsubOutboundFailure: "PubsubOutboundFailure",
|
|
356
|
+
PubsubProtocolViolation: "PubsubProtocolViolation",
|
|
357
|
+
ReachabilityChanged: "ReachabilityChanged",
|
|
358
|
+
RelayReservationLost: "RelayReservationLost",
|
|
359
|
+
RelayReserved: "RelayReserved",
|
|
360
|
+
StreamClosed: "StreamClosed",
|
|
361
|
+
StreamData: "StreamData",
|
|
362
|
+
StreamReady: "StreamReady",
|
|
363
|
+
StreamRemoteWriteClosed: "StreamRemoteWriteClosed",
|
|
364
|
+
} as const;
|
|
365
|
+
export type P2pEventTag = (typeof P2pEvent_Tags)[keyof typeof P2pEvent_Tags];
|
|
154
366
|
|
|
155
|
-
interface
|
|
367
|
+
interface RawEvent<Tag extends P2pEventTag, Inner> {
|
|
156
368
|
readonly tag: Tag;
|
|
157
369
|
readonly inner: Readonly<Inner>;
|
|
158
370
|
}
|
|
159
371
|
|
|
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
372
|
export type P2pEvent =
|
|
172
|
-
|
|
|
173
|
-
P2pEvent_Tags.EventsDropped,
|
|
373
|
+
| RawEvent<
|
|
374
|
+
typeof P2pEvent_Tags.EventsDropped,
|
|
174
375
|
{ dropped: number; totalDropped: number }
|
|
175
376
|
>
|
|
176
|
-
|
|
|
177
|
-
P2pEvent_Tags.DriverFailed,
|
|
377
|
+
| RawEvent<
|
|
378
|
+
typeof P2pEvent_Tags.DriverFailed,
|
|
178
379
|
{ kind: DriverFailureKind; detail: string }
|
|
179
380
|
>
|
|
180
|
-
|
|
|
181
|
-
P2pEvent_Tags.ConnectionEstablished,
|
|
381
|
+
| RawEvent<
|
|
382
|
+
typeof P2pEvent_Tags.ConnectionEstablished,
|
|
383
|
+
{ peerId: string; connId: number }
|
|
384
|
+
>
|
|
385
|
+
| RawEvent<
|
|
386
|
+
typeof P2pEvent_Tags.ConnectionClosed,
|
|
182
387
|
{ peerId: string; connId: number }
|
|
183
388
|
>
|
|
184
|
-
|
|
|
185
|
-
|
|
186
|
-
P2pEvent_Tags.PeerReady,
|
|
389
|
+
| RawEvent<
|
|
390
|
+
typeof P2pEvent_Tags.PeerReady,
|
|
187
391
|
{ peerId: string; protocols: readonly string[] }
|
|
188
392
|
>
|
|
189
|
-
|
|
|
190
|
-
P2pEvent_Tags.IdentifyReceived,
|
|
393
|
+
| RawEvent<
|
|
394
|
+
typeof P2pEvent_Tags.IdentifyReceived,
|
|
191
395
|
{ peerId: string; info: IdentifyInfo }
|
|
192
396
|
>
|
|
193
|
-
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
P2pEvent_Tags.StreamReady,
|
|
197
|
-
{
|
|
198
|
-
peerId: string;
|
|
199
|
-
connId: number;
|
|
200
|
-
streamId: number;
|
|
201
|
-
protocolId: string;
|
|
202
|
-
initiatedLocally: boolean;
|
|
203
|
-
}
|
|
397
|
+
| RawEvent<
|
|
398
|
+
typeof P2pEvent_Tags.PingRttMeasured,
|
|
399
|
+
{ peerId: string; rttMs: number }
|
|
204
400
|
>
|
|
205
|
-
|
|
|
206
|
-
|
|
401
|
+
| RawEvent<typeof P2pEvent_Tags.PingTimeout, { peerId: string }>
|
|
402
|
+
| RawEvent<typeof P2pEvent_Tags.StreamReady, InboundStreamMeta>
|
|
403
|
+
| RawEvent<
|
|
404
|
+
typeof P2pEvent_Tags.StreamData,
|
|
207
405
|
{ peerId: string; connId: number; streamId: number; data: ArrayBuffer }
|
|
208
406
|
>
|
|
209
|
-
|
|
|
210
|
-
P2pEvent_Tags.StreamRemoteWriteClosed,
|
|
407
|
+
| RawEvent<
|
|
408
|
+
typeof P2pEvent_Tags.StreamRemoteWriteClosed,
|
|
211
409
|
{ peerId: string; connId: number; streamId: number }
|
|
212
410
|
>
|
|
213
|
-
|
|
|
214
|
-
P2pEvent_Tags.StreamClosed,
|
|
411
|
+
| RawEvent<
|
|
412
|
+
typeof P2pEvent_Tags.StreamClosed,
|
|
215
413
|
{ peerId: string; connId: number; streamId: number }
|
|
216
414
|
>
|
|
217
|
-
|
|
|
218
|
-
P2pEvent_Tags.EndpointError,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
415
|
+
| RawEvent<
|
|
416
|
+
typeof P2pEvent_Tags.EndpointError,
|
|
417
|
+
Minip2pNamedEventMap["endpointError"]
|
|
418
|
+
>
|
|
419
|
+
| RawEvent<
|
|
420
|
+
typeof P2pEvent_Tags.ReachabilityChanged,
|
|
421
|
+
Minip2pNamedEventMap["reachabilityChanged"]
|
|
422
|
+
>
|
|
423
|
+
| RawEvent<
|
|
424
|
+
typeof P2pEvent_Tags.PublicAddressesChanged,
|
|
425
|
+
Minip2pNamedEventMap["publicAddressesChanged"]
|
|
225
426
|
>
|
|
226
|
-
|
|
|
227
|
-
P2pEvent_Tags.
|
|
228
|
-
|
|
229
|
-
previous: Reachability;
|
|
230
|
-
current: Reachability;
|
|
231
|
-
confirmedAddrs: readonly string[];
|
|
232
|
-
}
|
|
427
|
+
| RawEvent<
|
|
428
|
+
typeof P2pEvent_Tags.RelayReserved,
|
|
429
|
+
Minip2pNamedEventMap["relayReserved"]
|
|
233
430
|
>
|
|
234
|
-
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
{ relayPeerId: string; expiresUnixSecs?: number }
|
|
431
|
+
| RawEvent<
|
|
432
|
+
typeof P2pEvent_Tags.RelayReservationLost,
|
|
433
|
+
Minip2pNamedEventMap["relayReservationLost"]
|
|
238
434
|
>
|
|
239
|
-
|
|
|
240
|
-
|
|
241
|
-
P2pEvent_Tags.PathEstablished,
|
|
435
|
+
| RawEvent<
|
|
436
|
+
typeof P2pEvent_Tags.PathEstablished,
|
|
242
437
|
{ connectId: number; peerId: string; path: PathKind }
|
|
243
438
|
>
|
|
244
|
-
|
|
|
245
|
-
P2pEvent_Tags.PathUpgraded,
|
|
439
|
+
| RawEvent<
|
|
440
|
+
typeof P2pEvent_Tags.PathUpgraded,
|
|
246
441
|
{ connectId: number; peerId: string; from: PathKind; to: PathKind }
|
|
247
442
|
>
|
|
248
|
-
|
|
|
249
|
-
P2pEvent_Tags.HolePunchFailed,
|
|
250
|
-
|
|
443
|
+
| RawEvent<
|
|
444
|
+
typeof P2pEvent_Tags.HolePunchFailed,
|
|
445
|
+
Minip2pNamedEventMap["holePunchFailed"]
|
|
446
|
+
>
|
|
447
|
+
| RawEvent<
|
|
448
|
+
typeof P2pEvent_Tags.FellBackToRelay,
|
|
449
|
+
Minip2pNamedEventMap["fellBackToRelay"]
|
|
450
|
+
>
|
|
451
|
+
| RawEvent<
|
|
452
|
+
typeof P2pEvent_Tags.ConnectFailed,
|
|
453
|
+
Minip2pNamedEventMap["connectFailed"]
|
|
454
|
+
>
|
|
455
|
+
| RawEvent<
|
|
456
|
+
typeof P2pEvent_Tags.InboundDirectUpgrade,
|
|
457
|
+
Minip2pNamedEventMap["inboundDirectUpgrade"]
|
|
458
|
+
>
|
|
459
|
+
| RawEvent<typeof P2pEvent_Tags.Message, Minip2pNamedEventMap["message"]>
|
|
460
|
+
| RawEvent<
|
|
461
|
+
typeof P2pEvent_Tags.PeerSubscribed,
|
|
462
|
+
Minip2pNamedEventMap["peerSubscribed"]
|
|
463
|
+
>
|
|
464
|
+
| RawEvent<
|
|
465
|
+
typeof P2pEvent_Tags.PeerUnsubscribed,
|
|
466
|
+
Minip2pNamedEventMap["peerUnsubscribed"]
|
|
251
467
|
>
|
|
252
|
-
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
{
|
|
256
|
-
connectId: number;
|
|
257
|
-
peerId: string;
|
|
258
|
-
kind: NatErrorKind;
|
|
259
|
-
detail: string;
|
|
260
|
-
}
|
|
468
|
+
| RawEvent<
|
|
469
|
+
typeof P2pEvent_Tags.PubsubOutboundFailure,
|
|
470
|
+
Minip2pNamedEventMap["pubsubOutboundFailure"]
|
|
261
471
|
>
|
|
262
|
-
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
{
|
|
266
|
-
fromPeerId: string;
|
|
267
|
-
topics: readonly string[];
|
|
268
|
-
data: ArrayBuffer;
|
|
269
|
-
seqno: ArrayBuffer;
|
|
270
|
-
signed: boolean;
|
|
271
|
-
}
|
|
472
|
+
| RawEvent<
|
|
473
|
+
typeof P2pEvent_Tags.PubsubProtocolViolation,
|
|
474
|
+
Minip2pNamedEventMap["pubsubProtocolViolation"]
|
|
272
475
|
>
|
|
273
|
-
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
P2pEvent_Tags.PubsubOutboundFailure,
|
|
277
|
-
{ peerId: string; reason: string }
|
|
476
|
+
| RawEvent<
|
|
477
|
+
typeof P2pEvent_Tags.PeerDiscovered,
|
|
478
|
+
Minip2pNamedEventMap["peerDiscovered"]
|
|
278
479
|
>
|
|
279
|
-
|
|
|
280
|
-
P2pEvent_Tags.
|
|
281
|
-
|
|
480
|
+
| RawEvent<
|
|
481
|
+
typeof P2pEvent_Tags.PeerUpdated,
|
|
482
|
+
Minip2pNamedEventMap["peerUpdated"]
|
|
282
483
|
>
|
|
283
|
-
|
|
|
284
|
-
P2pEvent_Tags.
|
|
285
|
-
|
|
484
|
+
| RawEvent<
|
|
485
|
+
typeof P2pEvent_Tags.PeerExpired,
|
|
486
|
+
Minip2pNamedEventMap["peerExpired"]
|
|
286
487
|
>
|
|
287
|
-
|
|
|
288
|
-
P2pEvent_Tags.
|
|
289
|
-
|
|
488
|
+
| RawEvent<
|
|
489
|
+
typeof P2pEvent_Tags.DiscoveryDialFailed,
|
|
490
|
+
Minip2pNamedEventMap["discoveryDialFailed"]
|
|
290
491
|
>
|
|
291
|
-
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
P2pEvent_Tags.DiscoveryProtocolViolation,
|
|
295
|
-
{
|
|
296
|
-
peerId?: string;
|
|
297
|
-
source: DiscoverySource;
|
|
298
|
-
reason: string;
|
|
299
|
-
suppressed: number;
|
|
300
|
-
}
|
|
492
|
+
| RawEvent<
|
|
493
|
+
typeof P2pEvent_Tags.DiscoveryProtocolViolation,
|
|
494
|
+
Minip2pNamedEventMap["discoveryProtocolViolation"]
|
|
301
495
|
>;
|
|
302
496
|
|
|
303
|
-
|
|
304
|
-
export type P2pEventByTag<Tag extends P2pEvent_Tags> = Extract<
|
|
497
|
+
export type P2pEventByTag<Tag extends P2pEventTag> = Extract<
|
|
305
498
|
P2pEvent,
|
|
306
|
-
{ tag: Tag }
|
|
499
|
+
{ readonly tag: Tag }
|
|
307
500
|
>;
|
|
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;
|