weida 0.0.0-stage → 0.1.0-alpha.15
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/lib/errors.js +32 -0
- package/lib/index.d.ts +1211 -0
- package/lib/index.js +3354 -0
- package/lib/native.js +18 -0
- package/lib/wait.js +82 -0
- package/package.json +30 -4
- package/prebuilds/darwin-arm64/libweida.dylib +0 -0
- package/prebuilds/darwin-arm64/weida.node +0 -0
- package/prebuilds/linux-arm64/libweida.so +0 -0
- package/prebuilds/linux-arm64/weida.node +0 -0
- package/prebuilds/linux-x64/libweida.so +0 -0
- package/prebuilds/linux-x64/weida.node +0 -0
- package/prebuilds/win32-x64/weida.dll +0 -0
- package/prebuilds/win32-x64/weida.node +0 -0
- package/README.md +0 -3
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,1211 @@
|
|
|
1
|
+
// Declarations of lib/index.js (docs/libraries/weida-js.md).
|
|
2
|
+
|
|
3
|
+
import type { KeyObject, X509Certificate } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
/** The options every waiting method takes last. */
|
|
6
|
+
export interface WaitOptions {
|
|
7
|
+
/** Aborting it rejects the wait with `signal.reason` and cancels the
|
|
8
|
+
* operation; `AbortSignal.timeout(ms)` is the timeout. */
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Bytes in: a Uint8Array (a Buffer is one), or a string sent as UTF-8. */
|
|
13
|
+
export type Bytes = Uint8Array | string;
|
|
14
|
+
|
|
15
|
+
/** The library's version, e.g. "0.1.0-alpha.11-dev". */
|
|
16
|
+
export function version(): string;
|
|
17
|
+
|
|
18
|
+
/** The description of a status code, either sign; "unknown error" for one
|
|
19
|
+
* libweida does not define. */
|
|
20
|
+
export function strerror(code: number): string;
|
|
21
|
+
|
|
22
|
+
/** A fresh root trace context as W3C `traceparent` text. */
|
|
23
|
+
export function newTrace(): string;
|
|
24
|
+
|
|
25
|
+
/** A count, a duration in milliseconds or an optional number. */
|
|
26
|
+
export type Count = number | bigint;
|
|
27
|
+
|
|
28
|
+
/** How many layers a segment carries: 0 to 15. */
|
|
29
|
+
export const MAX_SEGMENT_LAYERS: number;
|
|
30
|
+
|
|
31
|
+
/** The first cursor level an application may name. */
|
|
32
|
+
export const CURSOR_LEVEL_APPLICATION_FLOOR: number;
|
|
33
|
+
|
|
34
|
+
/** The `datagramReceiveBytes` a profile with flows uses. */
|
|
35
|
+
export const DEFAULT_DATAGRAM_RECEIVE_BYTES: number;
|
|
36
|
+
|
|
37
|
+
/** The bytes of a blob id: a BLAKE3 hash. */
|
|
38
|
+
export const BLOB_ID_LEN: number;
|
|
39
|
+
|
|
40
|
+
/** The most pieces a blob has. */
|
|
41
|
+
export const MAX_PIECES: number;
|
|
42
|
+
|
|
43
|
+
/** The smallest piece size as its base-2 logarithm: 1 KiB. */
|
|
44
|
+
export const PIECE_SIZE_MIN_LOG2: number;
|
|
45
|
+
|
|
46
|
+
/** The largest piece size as its base-2 logarithm: 16 MiB. */
|
|
47
|
+
export const PIECE_SIZE_MAX_LOG2: number;
|
|
48
|
+
|
|
49
|
+
/** The default piece size as its base-2 logarithm: 1 MiB. */
|
|
50
|
+
export const PIECE_SIZE_DEFAULT_LOG2: number;
|
|
51
|
+
|
|
52
|
+
/** The id of `data`: its BLAKE3 hash, `BLOB_ID_LEN` bytes. */
|
|
53
|
+
export function blobIdOf(data: Bytes): Uint8Array;
|
|
54
|
+
|
|
55
|
+
/** What a swarm asks a seeder about one blob. */
|
|
56
|
+
export type AskKind = "WEIDA_ASK_LIST" | "WEIDA_ASK_HAVE" | "WEIDA_ASK_PIECE";
|
|
57
|
+
|
|
58
|
+
/** One order of a fetch: `index` is the piece of a PIECE, 0 otherwise. */
|
|
59
|
+
export interface Ask {
|
|
60
|
+
readonly kind: AskKind;
|
|
61
|
+
readonly index: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** One verified piece: its bytes are `Blob.span(index)` of the blob. */
|
|
65
|
+
export interface Piece {
|
|
66
|
+
readonly index: number;
|
|
67
|
+
readonly bytes: Uint8Array;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** How a fetch orders; an unknown field is a `TypeError`. */
|
|
71
|
+
export interface FetchOptions {
|
|
72
|
+
/** The piece list of an earlier fetch of the same blob, which spares the LIST order. */
|
|
73
|
+
list?: PieceList | null;
|
|
74
|
+
/** The fixed part of every answer's deadline. Default 30000. */
|
|
75
|
+
stallMs?: Count;
|
|
76
|
+
/** Bytes per second below which an answer is too slow. Default 65536; zero counts as one. */
|
|
77
|
+
minRate?: Count;
|
|
78
|
+
/** The most orders one seeder holds at once. Default 8; zero counts as one. */
|
|
79
|
+
perPeer?: Count;
|
|
80
|
+
/** Orders over all seeders at once. Default 32; zero counts as one. */
|
|
81
|
+
maxInflight?: Count;
|
|
82
|
+
/** The seeders a fetch takes pieces from. Default unbounded. */
|
|
83
|
+
maxPeers?: Count;
|
|
84
|
+
/** How long a seeder with nothing to take waits before it is asked HAVE again. Default 5000. */
|
|
85
|
+
haveRefreshMs?: Count;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Enumerations travel as the names of the weida.h constants.
|
|
89
|
+
export type Congestion = "WEIDA_CONGESTION_CUBIC" | "WEIDA_CONGESTION_NEW_RENO" | "WEIDA_CONGESTION_BBR";
|
|
90
|
+
export type Discovery = "WEIDA_DISCOVERY_AWARE" | "WEIDA_DISCOVERY_SINGLE";
|
|
91
|
+
export type OutboxFull = "WEIDA_OUTBOX_FULL_BLOCK" | "WEIDA_OUTBOX_FULL_DROP" | "WEIDA_OUTBOX_FULL_REJECT";
|
|
92
|
+
export type DeliveryLevel =
|
|
93
|
+
| "WEIDA_DELIVERY_LEVEL_BEST_EFFORT"
|
|
94
|
+
| "WEIDA_DELIVERY_LEVEL_AT_MOST_ONCE"
|
|
95
|
+
| "WEIDA_DELIVERY_LEVEL_AT_LEAST_ONCE";
|
|
96
|
+
export type Acknowledgement =
|
|
97
|
+
| "WEIDA_ACKNOWLEDGEMENT_NONE"
|
|
98
|
+
| "WEIDA_ACKNOWLEDGEMENT_TRANSPORT_RECEIPT"
|
|
99
|
+
| "WEIDA_ACKNOWLEDGEMENT_ACCEPTED"
|
|
100
|
+
| "WEIDA_ACKNOWLEDGEMENT_STORED"
|
|
101
|
+
| "WEIDA_ACKNOWLEDGEMENT_REPLICATED"
|
|
102
|
+
| "WEIDA_ACKNOWLEDGEMENT_PROCESSED";
|
|
103
|
+
export type Durability = "WEIDA_DURABILITY_WRITTEN" | "WEIDA_DURABILITY_FLUSHED";
|
|
104
|
+
export type OrderingMode =
|
|
105
|
+
| "WEIDA_ORDERING_MODE_NONE"
|
|
106
|
+
| "WEIDA_ORDERING_MODE_PER_PRODUCER_DETECT"
|
|
107
|
+
| "WEIDA_ORDERING_MODE_PER_PRODUCER_REASSEMBLE"
|
|
108
|
+
| "WEIDA_ORDERING_MODE_PER_KEY"
|
|
109
|
+
| "WEIDA_ORDERING_MODE_TOTAL";
|
|
110
|
+
export type Deduplication =
|
|
111
|
+
| "WEIDA_DEDUPLICATION_NONE"
|
|
112
|
+
| "WEIDA_DEDUPLICATION_BOUNDED"
|
|
113
|
+
| "WEIDA_DEDUPLICATION_DURABLE";
|
|
114
|
+
export type Backpressure =
|
|
115
|
+
| "WEIDA_BACKPRESSURE_BLOCK"
|
|
116
|
+
| "WEIDA_BACKPRESSURE_REJECT"
|
|
117
|
+
| "WEIDA_BACKPRESSURE_DROP"
|
|
118
|
+
| "WEIDA_BACKPRESSURE_SPILL"
|
|
119
|
+
| "WEIDA_BACKPRESSURE_COALESCE";
|
|
120
|
+
export type ProducerNaming = "WEIDA_PRODUCER_NAMING_FINGERPRINT" | "WEIDA_PRODUCER_NAMING_STABLE";
|
|
121
|
+
export type ReportMode = "WEIDA_REPORT_MODE_PROGRESS" | "WEIDA_REPORT_MODE_FINAL_ONLY";
|
|
122
|
+
/** A level in: a "WEIDA_ACKNOWLEDGEMENT_*" name or an application stage at
|
|
123
|
+
* or above CURSOR_LEVEL_APPLICATION_FLOOR. */
|
|
124
|
+
export type CursorLevel = Acknowledgement | number | bigint;
|
|
125
|
+
/** A level out: weida's own by name, an application stage as a bigint. */
|
|
126
|
+
export type ReportedLevel = Acknowledgement | bigint;
|
|
127
|
+
/** One reported level and how far it got. */
|
|
128
|
+
export interface CursorEntry {
|
|
129
|
+
readonly level: ReportedLevel;
|
|
130
|
+
readonly offset: bigint;
|
|
131
|
+
}
|
|
132
|
+
/** The newest offset per reported level, ascending by level. */
|
|
133
|
+
export type CursorSet = readonly CursorEntry[];
|
|
134
|
+
/** What an acceptor took. */
|
|
135
|
+
export type IncomingKind =
|
|
136
|
+
| "WEIDA_INCOMING_STREAM"
|
|
137
|
+
| "WEIDA_INCOMING_EXCHANGE"
|
|
138
|
+
| "WEIDA_INCOMING_SUBSCRIBED"
|
|
139
|
+
| "WEIDA_INCOMING_CREDIT"
|
|
140
|
+
| "WEIDA_INCOMING_UNSUBSCRIBED"
|
|
141
|
+
| "WEIDA_INCOMING_FLOW";
|
|
142
|
+
export type ErrorCode =
|
|
143
|
+
| "WEIDA_ERROR_CODE_UNKNOWN_ENDPOINT"
|
|
144
|
+
| "WEIDA_ERROR_CODE_REJECTED"
|
|
145
|
+
| "WEIDA_ERROR_CODE_UNSUPPORTED"
|
|
146
|
+
| "WEIDA_ERROR_CODE_INTERNAL"
|
|
147
|
+
| "WEIDA_ERROR_CODE_NO_REPLY";
|
|
148
|
+
export type LossCause =
|
|
149
|
+
| "WEIDA_LOSS_IDLE_TIMEOUT"
|
|
150
|
+
| "WEIDA_LOSS_PEER_CLOSED"
|
|
151
|
+
| "WEIDA_LOSS_PEER_RESTARTING"
|
|
152
|
+
| "WEIDA_LOSS_LOCALLY_CLOSED"
|
|
153
|
+
| "WEIDA_LOSS_RESET"
|
|
154
|
+
| "WEIDA_LOSS_TRANSPORT_ERROR";
|
|
155
|
+
export type PeerEventKind =
|
|
156
|
+
| "WEIDA_PEER_EVENT_CONNECTED"
|
|
157
|
+
| "WEIDA_PEER_EVENT_LOST"
|
|
158
|
+
| "WEIDA_PEER_EVENT_RETRYING"
|
|
159
|
+
| "WEIDA_PEER_EVENT_GAVE_UP"
|
|
160
|
+
| "WEIDA_PEER_EVENT_MISSED";
|
|
161
|
+
export type GiveUp = "WEIDA_GIVE_UP_POLICY" | "WEIDA_GIVE_UP_PEER_CHANGED" | "WEIDA_GIVE_UP_FAILED";
|
|
162
|
+
export type Alpn = "WEIDA_ALPN_WEIDA" | "WEIDA_ALPN_RAFT";
|
|
163
|
+
export type IdentityEventKind =
|
|
164
|
+
| "WEIDA_IDENTITY_EVENT_LOADED"
|
|
165
|
+
| "WEIDA_IDENTITY_EVENT_RENEWED"
|
|
166
|
+
| "WEIDA_IDENTITY_EVENT_KEY_CHANGED"
|
|
167
|
+
| "WEIDA_IDENTITY_EVENT_RENEWAL_FAILED"
|
|
168
|
+
| "WEIDA_IDENTITY_EVENT_HANDOFF_STOLEN"
|
|
169
|
+
| "WEIDA_IDENTITY_EVENT_TRUST_REFRESHED"
|
|
170
|
+
| "WEIDA_IDENTITY_EVENT_MISSED";
|
|
171
|
+
|
|
172
|
+
/** `weida::Limits`, the per-connection profile; unset fields keep weida's
|
|
173
|
+
* defaults. */
|
|
174
|
+
export interface LimitsFields {
|
|
175
|
+
maxHeaderBytes?: Count | null;
|
|
176
|
+
maxConcurrentUniStreams?: Count | null;
|
|
177
|
+
maxConcurrentBidiStreams?: Count | null;
|
|
178
|
+
streamReceiveWindow?: Count | null;
|
|
179
|
+
connectionReceiveWindow?: Count | null;
|
|
180
|
+
keepAliveMs?: Count | null;
|
|
181
|
+
idleTimeoutMs?: Count | null;
|
|
182
|
+
helloTimeoutMs?: Count | null;
|
|
183
|
+
maxSubscriptions?: Count | null;
|
|
184
|
+
subscriberBufferBytes?: Count | null;
|
|
185
|
+
maxSequenceScopes?: Count | null;
|
|
186
|
+
maxReorderHold?: Count | null;
|
|
187
|
+
maxLocalStreams?: Count | null;
|
|
188
|
+
maxParkedReverse?: Count | null;
|
|
189
|
+
maxDedupEntries?: Count | null;
|
|
190
|
+
datagramReceiveBytes?: Count | null;
|
|
191
|
+
datagramSendBytes?: Count | null;
|
|
192
|
+
pathReport?: boolean | null;
|
|
193
|
+
maxFlows?: Count | null;
|
|
194
|
+
flowQueueBytes?: Count | null;
|
|
195
|
+
flowEarlyBytes?: Count | null;
|
|
196
|
+
flowEarlyHoldMs?: Count | null;
|
|
197
|
+
congestion?: Congestion | null;
|
|
198
|
+
headerTimeoutMs?: Count | null;
|
|
199
|
+
maxHeaderStreams?: Count | null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** `weida::GuaranteeSet`, offered and required; unset dimensions are core. */
|
|
203
|
+
export interface GuaranteeSetFields {
|
|
204
|
+
delivery?: DeliveryLevel | null;
|
|
205
|
+
acknowledgement?: Acknowledgement | null;
|
|
206
|
+
durability?: Durability | null;
|
|
207
|
+
replicas?: Count | null;
|
|
208
|
+
ordering?: OrderingMode | null;
|
|
209
|
+
deduplication?: Deduplication | null;
|
|
210
|
+
dedupWindowMs?: Count | null;
|
|
211
|
+
backpressure?: Backpressure | null;
|
|
212
|
+
producerNaming?: ProducerNaming | null;
|
|
213
|
+
controlIsolated?: boolean | null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** `weida::ReconnectPolicy`; `never: true` starts from
|
|
217
|
+
* `ReconnectPolicy::never()` instead of the default. */
|
|
218
|
+
export interface ReconnectPolicyFields {
|
|
219
|
+
never?: boolean;
|
|
220
|
+
initialMs?: Count | null;
|
|
221
|
+
maxMs?: Count | null;
|
|
222
|
+
jitter?: boolean | null;
|
|
223
|
+
maxAttempts?: Count | null;
|
|
224
|
+
stopOnPeerClosed?: boolean | null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** One name lookup of a dial: the host the URL wrote, its port or null when
|
|
228
|
+
* it wrote none (the answer then chooses the ports), and the most addresses
|
|
229
|
+
* the answer may hold. */
|
|
230
|
+
export interface Lookup {
|
|
231
|
+
readonly name: string;
|
|
232
|
+
readonly port: number | null;
|
|
233
|
+
readonly maxAddresses: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Answers a lookup with `"ip:port"` strings in dial order; a throw or a
|
|
237
|
+
* rejection refuses it, and the dial rejects with WEIDA_EINVALID_ADDRESS. */
|
|
238
|
+
export type Resolver = (lookup: Lookup) => readonly string[] | Promise<readonly string[]>;
|
|
239
|
+
|
|
240
|
+
/** `weida::RuntimeConfig` but `network`. An unknown field throws a
|
|
241
|
+
* TypeError. */
|
|
242
|
+
export interface RuntimeConfigFields {
|
|
243
|
+
workerThreads?: Count | null;
|
|
244
|
+
shutdownTimeoutMs?: Count | null;
|
|
245
|
+
maxConnections?: Count | null;
|
|
246
|
+
maxConnectionsPerPeer?: Count | null;
|
|
247
|
+
endpointQueue?: Count | null;
|
|
248
|
+
maxResolvedAddresses?: Count | null;
|
|
249
|
+
connectAttemptTimeoutMs?: Count | null;
|
|
250
|
+
sendTimeoutMs?: Count | null;
|
|
251
|
+
outboxMessages?: Count | null;
|
|
252
|
+
outboxBytes?: Count | null;
|
|
253
|
+
outboxFull?: OutboxFull | null;
|
|
254
|
+
maxHandshakes?: Count | null;
|
|
255
|
+
retryAboveHandshakes?: Count | null;
|
|
256
|
+
discovery?: Discovery | null;
|
|
257
|
+
limits?: LimitsFields | null;
|
|
258
|
+
guarantees?: GuaranteeSetFields | null;
|
|
259
|
+
reconnect?: ReconnectPolicyFields | null;
|
|
260
|
+
/** Called on the JS thread for every lookup of the runtime's dials; never
|
|
261
|
+
* keeps the process alive. */
|
|
262
|
+
resolver?: Resolver | null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Every failure of libweida (docs/c/README.md R9). */
|
|
266
|
+
export class WeidaError extends Error {
|
|
267
|
+
/** The R9 constant name, e.g. "WEIDA_EUNTRUSTED". */
|
|
268
|
+
readonly code: string;
|
|
269
|
+
/** The positive status code. */
|
|
270
|
+
readonly errno: number;
|
|
271
|
+
/** "WEIDA_LOSS_*" for WEIDA_ECONNECTION_LOST, otherwise null. */
|
|
272
|
+
readonly lossCause: string | null;
|
|
273
|
+
/** The fingerprint the peer presented for WEIDA_EUNTRUSTED, otherwise null. */
|
|
274
|
+
readonly fingerprint: string | null;
|
|
275
|
+
/** The connection's largest payload for WEIDA_ETOO_LARGE, otherwise null. */
|
|
276
|
+
readonly max: number | null;
|
|
277
|
+
/** The raw OS error of WEIDA_EIO when it carried one, otherwise null. */
|
|
278
|
+
readonly osCode: number | null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** The local principal the kernel proved for the sender: its uid and gid on
|
|
282
|
+
* an `AF_UNIX` socket, its account SID on a named pipe. `pid` is null where
|
|
283
|
+
* the platform reports none, and an observation only: never authorize on it. */
|
|
284
|
+
export type PeerLocal =
|
|
285
|
+
| { readonly uid: number; readonly gid: number; readonly pid: number | null }
|
|
286
|
+
| { readonly sid: string; readonly pid: number | null };
|
|
287
|
+
|
|
288
|
+
/** What went missing before a transfer under per-producer ordering: the
|
|
289
|
+
* number expected next and the one that arrived; `seen - expected`
|
|
290
|
+
* transfers are missing. */
|
|
291
|
+
export interface Gap {
|
|
292
|
+
readonly expected: bigint;
|
|
293
|
+
readonly seen: bigint;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The metadata of an inbound transfer or request, copied out at once. */
|
|
297
|
+
export interface IncomingMeta {
|
|
298
|
+
readonly endpoint: string | null;
|
|
299
|
+
readonly contentType: string | null;
|
|
300
|
+
readonly topic: string | null;
|
|
301
|
+
readonly peerFingerprint: string | null;
|
|
302
|
+
/** The chain the sender presented, leaf first; null for an anonymous or
|
|
303
|
+
* local sender. */
|
|
304
|
+
readonly peerChain: readonly X509Certificate[] | null;
|
|
305
|
+
/** The local principal of a sender over a unix socket or a named pipe;
|
|
306
|
+
* null for any other sender. */
|
|
307
|
+
readonly peerLocal: PeerLocal | null;
|
|
308
|
+
readonly contentLen: bigint | null;
|
|
309
|
+
readonly sequence: bigint | null;
|
|
310
|
+
/** Null when nothing is missing or ordering is off. */
|
|
311
|
+
readonly gap: Gap | null;
|
|
312
|
+
/** The segment number of a RADIO stream segment. */
|
|
313
|
+
readonly segment: bigint | null;
|
|
314
|
+
/** The layer of a RADIO stream segment, present exactly when `segment` is. */
|
|
315
|
+
readonly layer: number | null;
|
|
316
|
+
/** The sender's trace context as `traceparent` text. */
|
|
317
|
+
readonly trace: string | null;
|
|
318
|
+
readonly tracestate: string | null;
|
|
319
|
+
/** The completion level the sender claimed for the message this answers. */
|
|
320
|
+
readonly achieved: Acknowledgement | null;
|
|
321
|
+
/** The cursor levels the sender ordered reported, ascending; empty when
|
|
322
|
+
* none. */
|
|
323
|
+
readonly report: readonly ReportedLevel[];
|
|
324
|
+
readonly reportMode: ReportMode;
|
|
325
|
+
/** Present exactly when levels were ordered. */
|
|
326
|
+
readonly reportId: bigint | null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** What a publisher dropped on one topic, by cause. */
|
|
330
|
+
export interface TopicDrops {
|
|
331
|
+
readonly topic: string;
|
|
332
|
+
readonly subscriberBudget: bigint;
|
|
333
|
+
readonly subscriberQueue: bigint;
|
|
334
|
+
readonly noParkedConnection: bigint;
|
|
335
|
+
readonly superseded: bigint;
|
|
336
|
+
readonly expired: bigint;
|
|
337
|
+
readonly tooLarge: bigint;
|
|
338
|
+
readonly noDatagrams: bigint;
|
|
339
|
+
readonly layersCut: bigint;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** What a radio dropped toward one joined dish connection, by cause. */
|
|
343
|
+
export interface DishDrops {
|
|
344
|
+
/** The key the dish proved; null when it proved none. */
|
|
345
|
+
readonly peerFingerprint: string | null;
|
|
346
|
+
readonly subscriberBudget: bigint;
|
|
347
|
+
readonly subscriberQueue: bigint;
|
|
348
|
+
readonly superseded: bigint;
|
|
349
|
+
readonly expired: bigint;
|
|
350
|
+
readonly tooLarge: bigint;
|
|
351
|
+
readonly noDatagrams: bigint;
|
|
352
|
+
readonly layersCut: bigint;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** A dish's terms for a join: its latency budget and its highest layer. */
|
|
356
|
+
export interface JoinTerms {
|
|
357
|
+
maxAgeMs?: Count | null;
|
|
358
|
+
/** 0 to 15; 16 to 255 reject the join with WEIDA_ELIMIT_EXCEEDED. */
|
|
359
|
+
maxLayer?: number | null;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** A segment's terms: its latency budget, its priority (an int16) and
|
|
363
|
+
* whether it relays an upstream still streaming. */
|
|
364
|
+
export interface SegmentTerms {
|
|
365
|
+
maxAgeMs?: Count | null;
|
|
366
|
+
priority?: number | null;
|
|
367
|
+
followsUpstream?: boolean | null;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** What a dish received: a stream segment, whose topic, number and layer
|
|
371
|
+
* are on `transfer.meta()`, or a datagram segment, whole. */
|
|
372
|
+
export type Received =
|
|
373
|
+
| { readonly kind: "WEIDA_RECEIVED_SEGMENT"; readonly transfer: IncomingTransfer }
|
|
374
|
+
| {
|
|
375
|
+
readonly kind: "WEIDA_RECEIVED_DATAGRAM";
|
|
376
|
+
readonly topic: string;
|
|
377
|
+
readonly segment: bigint;
|
|
378
|
+
readonly payload: Uint8Array;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/** What an acceptor took: a payload handed over, or the values of a credit
|
|
382
|
+
* grant or an unsubscription (`filter` null when the whole connection went
|
|
383
|
+
* away). */
|
|
384
|
+
export type Incoming =
|
|
385
|
+
| { readonly kind: "WEIDA_INCOMING_STREAM"; readonly transfer: IncomingTransfer }
|
|
386
|
+
| { readonly kind: "WEIDA_INCOMING_EXCHANGE"; readonly request: IncomingRequest }
|
|
387
|
+
| { readonly kind: "WEIDA_INCOMING_SUBSCRIBED"; readonly consumer: Consumer }
|
|
388
|
+
| {
|
|
389
|
+
readonly kind: "WEIDA_INCOMING_CREDIT";
|
|
390
|
+
readonly id: bigint;
|
|
391
|
+
readonly filter: string;
|
|
392
|
+
readonly limit: bigint;
|
|
393
|
+
}
|
|
394
|
+
| {
|
|
395
|
+
readonly kind: "WEIDA_INCOMING_UNSUBSCRIBED";
|
|
396
|
+
readonly id: bigint;
|
|
397
|
+
readonly filter: string | null;
|
|
398
|
+
}
|
|
399
|
+
| { readonly kind: "WEIDA_INCOMING_FLOW"; readonly flow: IncomingFlow };
|
|
400
|
+
|
|
401
|
+
/** What a sender attaches to a flow, once; a label is at most 256 bytes. */
|
|
402
|
+
export interface FlowMeta {
|
|
403
|
+
contentType?: string | null;
|
|
404
|
+
/** W3C version-00 `traceparent` text. */
|
|
405
|
+
trace?: string | null;
|
|
406
|
+
topic?: string | null;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** What the receiver learns about a flow when it arrives. */
|
|
410
|
+
export interface FlowInfo {
|
|
411
|
+
readonly endpoint: string;
|
|
412
|
+
readonly topic: string | null;
|
|
413
|
+
readonly contentType: string | null;
|
|
414
|
+
readonly trace: string | null;
|
|
415
|
+
readonly peerFingerprint: string | null;
|
|
416
|
+
readonly peerChain: readonly X509Certificate[] | null;
|
|
417
|
+
readonly peerLocal: PeerLocal | null;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** The sender's counters of one flow. */
|
|
421
|
+
export interface FlowStats {
|
|
422
|
+
readonly sent: bigint;
|
|
423
|
+
readonly tooLarge: bigint;
|
|
424
|
+
/** Local transports only. */
|
|
425
|
+
readonly discarded: bigint;
|
|
426
|
+
readonly notLive: bigint;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** The receiver's counters of one flow. */
|
|
430
|
+
export interface IncomingFlowStats {
|
|
431
|
+
readonly received: bigint;
|
|
432
|
+
readonly overflow: bigint;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** A collected payload and the metadata of its transfer. */
|
|
436
|
+
export interface Message {
|
|
437
|
+
readonly payload: Uint8Array;
|
|
438
|
+
readonly meta: IncomingMeta;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** The two halves of an exchange `Requester.open` started. */
|
|
442
|
+
export interface Exchange {
|
|
443
|
+
readonly body: OutgoingTransfer;
|
|
444
|
+
readonly reply: ReplyStream;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** UDP datagrams and the bytes inside them, in one direction. */
|
|
448
|
+
export interface UdpCounts {
|
|
449
|
+
readonly datagrams: bigint;
|
|
450
|
+
readonly bytes: bigint;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** The path under one QUIC connection; durations in microseconds. */
|
|
454
|
+
export interface PathStats {
|
|
455
|
+
readonly rttUs: bigint;
|
|
456
|
+
readonly minRttUs: bigint;
|
|
457
|
+
readonly cwnd: bigint;
|
|
458
|
+
readonly congestionEvents: bigint;
|
|
459
|
+
readonly lostPackets: bigint;
|
|
460
|
+
readonly lostBytes: bigint;
|
|
461
|
+
readonly sentPackets: bigint;
|
|
462
|
+
readonly currentMtu: bigint;
|
|
463
|
+
/** null when the peer accepts no datagram. */
|
|
464
|
+
readonly maxDatagramSize: bigint | null;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/** The transport's view of one QUIC connection. */
|
|
468
|
+
export interface TransportStats {
|
|
469
|
+
readonly path: PathStats;
|
|
470
|
+
readonly tx: UdpCounts;
|
|
471
|
+
readonly rx: UdpCounts;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** The peer's view of the path, from its latest record. */
|
|
475
|
+
export interface RemoteStats {
|
|
476
|
+
readonly rttUs: bigint;
|
|
477
|
+
readonly minRttUs: bigint;
|
|
478
|
+
readonly cwnd: bigint;
|
|
479
|
+
readonly congestionEvents: bigint;
|
|
480
|
+
readonly lostPackets: bigint;
|
|
481
|
+
readonly lostBytes: bigint;
|
|
482
|
+
readonly sentPackets: bigint;
|
|
483
|
+
readonly currentMtu: bigint;
|
|
484
|
+
/** How long ago the record arrived, in microseconds. */
|
|
485
|
+
readonly ageUs: bigint;
|
|
486
|
+
readonly tx: UdpCounts;
|
|
487
|
+
readonly rx: UdpCounts;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** One live connection of a requester, labelled by the URL it dialled. */
|
|
491
|
+
export interface ConnectionStats {
|
|
492
|
+
readonly url: string;
|
|
493
|
+
readonly ageUs: bigint;
|
|
494
|
+
readonly redials: bigint;
|
|
495
|
+
/** null on a local transport. */
|
|
496
|
+
readonly transport: TransportStats | null;
|
|
497
|
+
/** null until the peer's first record, on a local transport, or with
|
|
498
|
+
* `pathReport` off on either side. */
|
|
499
|
+
readonly remote: RemoteStats | null;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** One transition of one dialled address; a field of another kind is null. */
|
|
503
|
+
export interface PeerEvent {
|
|
504
|
+
readonly kind: PeerEventKind;
|
|
505
|
+
/** null for WEIDA_PEER_EVENT_MISSED. */
|
|
506
|
+
readonly url: string | null;
|
|
507
|
+
readonly peerFingerprint: string | null;
|
|
508
|
+
readonly cause: LossCause | null;
|
|
509
|
+
readonly attempt: number | null;
|
|
510
|
+
readonly delayUs: bigint | null;
|
|
511
|
+
readonly why: GiveUp | null;
|
|
512
|
+
readonly whyAttempts: number | null;
|
|
513
|
+
readonly whyPresented: string | null;
|
|
514
|
+
readonly whyMessage: string | null;
|
|
515
|
+
readonly missed: bigint | null;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** One transition of an identity or trust source; a field of another kind
|
|
519
|
+
* is null. */
|
|
520
|
+
export interface IdentityEvent {
|
|
521
|
+
readonly kind: IdentityEventKind;
|
|
522
|
+
/** LOADED, RENEWED: the key's fingerprint. */
|
|
523
|
+
readonly fingerprint: string | null;
|
|
524
|
+
/** KEY_CHANGED: the fingerprint that was. */
|
|
525
|
+
readonly from: string | null;
|
|
526
|
+
/** KEY_CHANGED: the fingerprint that is. */
|
|
527
|
+
readonly to: string | null;
|
|
528
|
+
/** RENEWAL_FAILED: why. */
|
|
529
|
+
readonly message: string | null;
|
|
530
|
+
/** MISSED: how many events this reader lost. */
|
|
531
|
+
readonly missed: bigint | null;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** How a file source watches its directory; an unknown field throws a
|
|
535
|
+
* TypeError. */
|
|
536
|
+
export interface FilesOptions {
|
|
537
|
+
/** Names the bootstrapped certificate is made for, when the directory is empty. */
|
|
538
|
+
names?: string[] | null;
|
|
539
|
+
/** How often the files' modification times are checked, at the next use; 0 checks at every use. */
|
|
540
|
+
pollMs?: Count | null;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** What one drain achieved, as counts of the transfers still
|
|
544
|
+
* unacknowledged when it started. */
|
|
545
|
+
export interface Drained {
|
|
546
|
+
/** Acknowledged by the peer's transport before the deadline. */
|
|
547
|
+
readonly delivered: bigint;
|
|
548
|
+
/** Unacknowledged at the deadline, refused by the peer, or lost with
|
|
549
|
+
* their connection; not an error. */
|
|
550
|
+
readonly outstanding: bigint;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/** The metadata an outgoing transfer carries. An unknown field throws a
|
|
554
|
+
* TypeError. */
|
|
555
|
+
export interface TransferMeta {
|
|
556
|
+
contentType?: string | null;
|
|
557
|
+
contentLen?: number | bigint | null;
|
|
558
|
+
/** A `traceparent`, from `newTrace()` or an inbound `IncomingMeta.trace`. */
|
|
559
|
+
trace?: string | null;
|
|
560
|
+
topic?: string | null;
|
|
561
|
+
achieved?: Acknowledgement | null;
|
|
562
|
+
/** The cursor levels the receiver should report; at most 16 distinct. */
|
|
563
|
+
report?: readonly CursorLevel[] | null;
|
|
564
|
+
reportMode?: ReportMode | null;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** Every class around a C handle. A dropped or consumed object throws
|
|
568
|
+
* WEIDA_ECLOSED without calling C. */
|
|
569
|
+
declare class Handle {
|
|
570
|
+
protected constructor();
|
|
571
|
+
/** Releases the handle now, ending its pending waits with WEIDA_ECLOSED. */
|
|
572
|
+
drop(): void;
|
|
573
|
+
[Symbol.dispose](): void;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export interface RuntimeConfig extends RuntimeConfigFields {}
|
|
577
|
+
export class RuntimeConfig {
|
|
578
|
+
constructor(fields?: RuntimeConfigFields);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export class Runtime extends Handle {
|
|
582
|
+
static owned(config?: RuntimeConfig | RuntimeConfigFields): Runtime;
|
|
583
|
+
listener(): Listener;
|
|
584
|
+
requester(clientTls: ClientTls): Requester;
|
|
585
|
+
pusher(clientTls: ClientTls): Pusher;
|
|
586
|
+
/** Two subscribers on one runtime collide on the path: use one runtime per subscriber of a path. */
|
|
587
|
+
subscriber(clientTls: ClientTls): Subscriber;
|
|
588
|
+
/** A dialling pair: one peer, dialled with `connect`. */
|
|
589
|
+
pair(clientTls: ClientTls): Paired;
|
|
590
|
+
surveyor(clientTls: ClientTls): Surveyor;
|
|
591
|
+
/** Two dishes on one runtime collide on the path: use one runtime per dish. */
|
|
592
|
+
dish(clientTls: ClientTls): Dish;
|
|
593
|
+
/** A raw peer that opens datagram flows. */
|
|
594
|
+
peer(clientTls: ClientTls): Peer;
|
|
595
|
+
/** A swarm: fetches one blob from every seeder it connected at once. */
|
|
596
|
+
swarm(clientTls: ClientTls): Swarm;
|
|
597
|
+
/** Duplicates discarded inside a negotiated deduplication window. */
|
|
598
|
+
suppressedDuplicates(): bigint;
|
|
599
|
+
/** Outgoing transfers reset because their deadline passed. */
|
|
600
|
+
expiredTransfers(): bigint;
|
|
601
|
+
/** Closes every endpoint and waits for the connections to go idle.
|
|
602
|
+
* Consumes the runtime. */
|
|
603
|
+
shutdown(options?: WaitOptions): Promise<void>;
|
|
604
|
+
/** Stops admitting work, waits up to `deadlineMs` for finished
|
|
605
|
+
* transfers to reach the peer's transport, then closes as `shutdown`
|
|
606
|
+
* does. Consumes the runtime. */
|
|
607
|
+
drain(deadlineMs: Count, options?: WaitOptions): Promise<Drained>;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export class Trust extends Handle {
|
|
611
|
+
constructor();
|
|
612
|
+
/** Pins a `sha256:` fingerprint; returns this trust. */
|
|
613
|
+
addPin(fingerprint: string): this;
|
|
614
|
+
/** Trusts the certificate authorities in `anchor` for a peer whose chain
|
|
615
|
+
* leads to one and names the dialled host; returns this trust. */
|
|
616
|
+
addAnchor(anchor: X509Certificate | Bytes): this;
|
|
617
|
+
/** Trusts the certificate authorities in a PEM file, read at each dial. */
|
|
618
|
+
addAnchorFile(path: string): this;
|
|
619
|
+
/** Whether the trust holds no pin and no anchor. */
|
|
620
|
+
isEmpty(): boolean;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export class Identity extends Handle {
|
|
624
|
+
static generate(): Identity;
|
|
625
|
+
/** A self-signed identity whose certificate names `names`. */
|
|
626
|
+
static generateFor(names: string[]): Identity;
|
|
627
|
+
static fromPem(cert: Bytes, key: Bytes): Identity;
|
|
628
|
+
/** From Node's types or PEM; a `KeyObject` is exported as PKCS#8. */
|
|
629
|
+
static from(parts: { cert: X509Certificate | X509Certificate[] | Bytes; key: KeyObject | Bytes }): Identity;
|
|
630
|
+
/** One PEM file with the chain and the key, read at first use. */
|
|
631
|
+
static fromPemFile(path: string): Identity;
|
|
632
|
+
/** A chain file and a key file, read at first use. */
|
|
633
|
+
static fromPemFiles(cert: string, key: string): Identity;
|
|
634
|
+
fingerprint(): string;
|
|
635
|
+
/** The certificate chain as PEM, without the key. */
|
|
636
|
+
certificatePem(): string;
|
|
637
|
+
/** The chain and the private key as one PEM document. Holds the private
|
|
638
|
+
* key; wipe it with `fill(0)` when done. */
|
|
639
|
+
toPem(): Uint8Array;
|
|
640
|
+
/** The certificate chain, leaf first. */
|
|
641
|
+
certificates(): X509Certificate[];
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export class ClientTls extends Handle {
|
|
645
|
+
/** Dials under `trust` (a `Trust` is copied, a `TrustSource` shared),
|
|
646
|
+
* presenting `identity` when given, asking for `alpn`. */
|
|
647
|
+
constructor(trust: Trust | TrustSource, options?: { identity?: Identity | IdentitySource; alpn?: Alpn });
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
export class ServerTls extends Handle {
|
|
651
|
+
/** Serves as `identity` (an `Identity` is copied, an `IdentitySource`
|
|
652
|
+
* shared); `requireClient` requires every client to present a key the
|
|
653
|
+
* trust accepts, or with "any-key" any key it proves; offers `alpn`. */
|
|
654
|
+
constructor(
|
|
655
|
+
identity: Identity | IdentitySource,
|
|
656
|
+
options?: { requireClient?: Trust | TrustSource | "any-key"; alpn?: Alpn },
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/** Where an identity comes from; shared by the TLS terms made from it. */
|
|
661
|
+
export class IdentitySource extends Handle {
|
|
662
|
+
static fromIdentity(identity: Identity): IdentitySource;
|
|
663
|
+
static ephemeral(names?: string[]): IdentitySource;
|
|
664
|
+
static external(identity: Identity): IdentitySource;
|
|
665
|
+
/** `cert.pem` and `key.pem` in `dir`, bootstrapped when empty, reloaded when changed. */
|
|
666
|
+
static files(dir: string, options?: FilesOptions | null): IdentitySource;
|
|
667
|
+
current(): Identity;
|
|
668
|
+
fingerprint(): string;
|
|
669
|
+
update(identity: Identity): void;
|
|
670
|
+
reportFailure(reason: string): void;
|
|
671
|
+
reportHandoffStolen(): void;
|
|
672
|
+
/** true when the files changed and were loaded. */
|
|
673
|
+
reload(): boolean;
|
|
674
|
+
/** A new reader of this source's events, from now on. */
|
|
675
|
+
events(): IdentityEvents;
|
|
676
|
+
downgrade(): WeakIdentitySource;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export class WeakIdentitySource extends Handle {
|
|
680
|
+
/** The source while anything holds it, else null. */
|
|
681
|
+
upgrade(): IdentitySource | null;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/** Whom a peer is accepted as, as a source; shared by the TLS terms made from it. */
|
|
685
|
+
export class TrustSource extends Handle {
|
|
686
|
+
static fromTrust(trust: Trust): TrustSource;
|
|
687
|
+
static external(trust: Trust): TrustSource;
|
|
688
|
+
/** A copy of the trust of the moment. */
|
|
689
|
+
current(): Trust;
|
|
690
|
+
update(trust: Trust): void;
|
|
691
|
+
reportFailure(reason: string): void;
|
|
692
|
+
isEmpty(): boolean;
|
|
693
|
+
/** A new reader of this source's events, from now on. */
|
|
694
|
+
events(): IdentityEvents;
|
|
695
|
+
downgrade(): WeakTrustSource;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export class WeakTrustSource extends Handle {
|
|
699
|
+
/** The source while anything holds it, else null. */
|
|
700
|
+
upgrade(): TrustSource | null;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export class Listener extends Handle {
|
|
704
|
+
bindQuic(addr: string, serverTls: ServerTls, options?: WaitOptions): Promise<Binding>;
|
|
705
|
+
/** Serves QUIC on an already bound socket's descriptor, libweida's once the call reaches it. */
|
|
706
|
+
bindQuicSocket(socket: number, serverTls: ServerTls, options?: WaitOptions): Promise<Binding>;
|
|
707
|
+
/** Serves this listener's endpoints through the relay at `relay`, registered under `via`'s key. */
|
|
708
|
+
bindRelay(relay: string, via: ClientTls, serverTls: ServerTls, options?: WaitOptions): Promise<Binding>;
|
|
709
|
+
bindInproc(bus: string): LocalBinding;
|
|
710
|
+
/** Throws WEIDA_EUNSUPPORTED on Windows. */
|
|
711
|
+
bindUnix(path: string): UnixBinding;
|
|
712
|
+
/** Throws WEIDA_EUNSUPPORTED off Windows. */
|
|
713
|
+
bindPipe(name: string): PipeBinding;
|
|
714
|
+
replier(path: string): Replier;
|
|
715
|
+
puller(path: string): Puller;
|
|
716
|
+
publisher(path: string): Publisher;
|
|
717
|
+
/** A bound pair, dialled by its one peer. */
|
|
718
|
+
pair(path: string): Paired;
|
|
719
|
+
respondent(path: string): Respondent;
|
|
720
|
+
/** A bus member accepting on `path` and dialling the others on `clientTls`. */
|
|
721
|
+
bus(path: string, clientTls: ClientTls): BusMember;
|
|
722
|
+
/** The radio serving `path`; dropping it releases the path. */
|
|
723
|
+
radio(path: string): Radio;
|
|
724
|
+
/** A raw acceptor: both stream kinds and flows on `path`, tagged. */
|
|
725
|
+
acceptor(path: string): Acceptor;
|
|
726
|
+
/** A seeder: hands each fetch's session to the application. */
|
|
727
|
+
seeder(path: string): Seeder;
|
|
728
|
+
/** Serves a relay on this listener's bindings. */
|
|
729
|
+
relay(): Relay;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
export class Binding extends Handle {
|
|
733
|
+
localAddr(): string | null;
|
|
734
|
+
/** Closes the binding's connections with SHUTDOWN; resolves once the port is free. */
|
|
735
|
+
close(options?: WaitOptions): Promise<void>;
|
|
736
|
+
/** Hands the socket over to a successor process. Consumes the binding. */
|
|
737
|
+
handOver(options?: WaitOptions): Promise<Handoff>;
|
|
738
|
+
/** Sends a predecessor's held close packets; resolves with how many were sent. */
|
|
739
|
+
takeOver(held: Uint8Array, options?: WaitOptions): Promise<number>;
|
|
740
|
+
/** Closes every connection from the peer with this key; how many it closed. */
|
|
741
|
+
disconnect(fingerprint: string): number;
|
|
742
|
+
/** A new reader of a relayed binding's registration events, or null when not relayed. */
|
|
743
|
+
relayEvents(): PeerEvents | null;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export class Handoff extends Handle {
|
|
747
|
+
/** How many close packets are held. */
|
|
748
|
+
held(): number;
|
|
749
|
+
/** The address the socket is bound to. */
|
|
750
|
+
localAddr(): string | null;
|
|
751
|
+
/** A copy of the held packets, for `Binding.takeOver`. */
|
|
752
|
+
bytes(): Uint8Array;
|
|
753
|
+
/** The socket's descriptor, the caller's from then on; once. */
|
|
754
|
+
takeSocket(): number;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
export class LocalBinding extends Handle {
|
|
758
|
+
bus(): string | null;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/** Dropping it ends the binding and removes the socket file. */
|
|
762
|
+
export class UnixBinding extends Handle {
|
|
763
|
+
path(): string | null;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/** Dropping it ends the binding and releases the name. */
|
|
767
|
+
export class PipeBinding extends Handle {
|
|
768
|
+
name(): string | null;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export class Requester extends Handle {
|
|
772
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
773
|
+
request(body: Bytes, options?: WaitOptions): Promise<IncomingTransfer>;
|
|
774
|
+
/** `request` with metadata, copied when the request starts. */
|
|
775
|
+
requestWith(meta: TransferMeta | null, body: Bytes, options?: WaitOptions): Promise<IncomingTransfer>;
|
|
776
|
+
/** Opens one exchange: the request body to write and the reply stream, independent of each other. */
|
|
777
|
+
open(meta?: TransferMeta | null, options?: WaitOptions): Promise<Exchange>;
|
|
778
|
+
/** One frozen record per live connection, in dial order. */
|
|
779
|
+
connectionStats(): readonly ConnectionStats[];
|
|
780
|
+
/** A new reader of this requester's peer events, from now on. */
|
|
781
|
+
events(): PeerEvents;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
export class ReplyStream extends Handle {
|
|
785
|
+
/** The reply as soon as its header arrives; consumes the stream. */
|
|
786
|
+
recv(options?: WaitOptions): Promise<IncomingTransfer>;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
export class PeerEvents extends Handle {
|
|
790
|
+
/** The next event, or null once the requester, or the relayed binding's registration, is gone. */
|
|
791
|
+
recv(options?: WaitOptions): Promise<PeerEvent | null>;
|
|
792
|
+
[Symbol.asyncIterator](): AsyncGenerator<PeerEvent, void, undefined>;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
export class IdentityEvents extends Handle {
|
|
796
|
+
/** The next event, or null once the source is gone. */
|
|
797
|
+
recv(options?: WaitOptions): Promise<IdentityEvent | null>;
|
|
798
|
+
[Symbol.asyncIterator](): AsyncGenerator<IdentityEvent, void, undefined>;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
export class Cursors extends Handle {
|
|
802
|
+
/** The newest set after a change, or null once no more cursors come. */
|
|
803
|
+
recv(options?: WaitOptions): Promise<CursorSet | null>;
|
|
804
|
+
[Symbol.asyncIterator](): AsyncGenerator<CursorSet, void, undefined>;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/** Dropping it without `finish` flushes nothing. */
|
|
808
|
+
export class Reporter extends Handle {
|
|
809
|
+
/** The levels the sender ordered, ascending. */
|
|
810
|
+
levels(): readonly ReportedLevel[];
|
|
811
|
+
mode(): ReportMode;
|
|
812
|
+
/** Progress records at `bytes` or `intervalMs`, whichever comes first;
|
|
813
|
+
* 0 and 0 write every report. */
|
|
814
|
+
setGranularity(bytes: Count, intervalMs: Count): void;
|
|
815
|
+
/** A level the sender did not order is ignored. */
|
|
816
|
+
report(level: CursorLevel, offset: Count, options?: WaitOptions): Promise<void>;
|
|
817
|
+
/** Flushes the newest offset per reported level. Consumes the reporter. */
|
|
818
|
+
finish(options?: WaitOptions): Promise<void>;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export class Peer extends Handle {
|
|
822
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
823
|
+
/** Whether the address was dialled. */
|
|
824
|
+
disconnect(url: string): boolean;
|
|
825
|
+
peerCount(): number;
|
|
826
|
+
connectionStats(): readonly ConnectionStats[];
|
|
827
|
+
events(): PeerEvents;
|
|
828
|
+
/** The bodies the outbox discarded. */
|
|
829
|
+
dropped(): bigint;
|
|
830
|
+
/** A one-way stream to the next peer. */
|
|
831
|
+
open(meta?: TransferMeta | null, options?: WaitOptions): Promise<OutgoingTransfer>;
|
|
832
|
+
/** An exchange with the next peer. */
|
|
833
|
+
openBi(meta?: TransferMeta | null, options?: WaitOptions): Promise<Exchange>;
|
|
834
|
+
/** Resolves once the body is written or held in the outbox. */
|
|
835
|
+
send(meta: TransferMeta | null, body: Bytes, options?: WaitOptions): Promise<void>;
|
|
836
|
+
/** Segment n+1 on `topic`; it supersedes this peer's segment n there. */
|
|
837
|
+
segment(topic: string, terms?: SegmentTerms | null, options?: WaitOptions): Promise<Segment>;
|
|
838
|
+
segmentDrops(topic: string): TopicDrops | null;
|
|
839
|
+
/** Resolves once the flow's header is written; a refusal arrives as a
|
|
840
|
+
* `send` that throws. */
|
|
841
|
+
openFlow(meta?: FlowMeta | null, options?: WaitOptions): Promise<Flow>;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
export class Acceptor extends Handle {
|
|
845
|
+
path(): string | null;
|
|
846
|
+
accept(options?: WaitOptions): Promise<Incoming>;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/** A consumer that subscribed on an acceptor's path; a queue delivers to it
|
|
850
|
+
* while its credit allows. */
|
|
851
|
+
export class Consumer extends Handle {
|
|
852
|
+
/** The number of its connection, shared by that connection's subscriptions. */
|
|
853
|
+
id(): bigint;
|
|
854
|
+
filter(): string | null;
|
|
855
|
+
path(): string | null;
|
|
856
|
+
open(meta?: TransferMeta | null, options?: WaitOptions): Promise<OutgoingTransfer>;
|
|
857
|
+
/** Resolves once the body is written and finished. */
|
|
858
|
+
deliver(meta: TransferMeta | null, body: Bytes, options?: WaitOptions): Promise<void>;
|
|
859
|
+
/** Closes the consumer's connection, ending every subscription it holds. */
|
|
860
|
+
close(code: Count, reason: string): void;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/** `drop()` closes the flow with FIN. */
|
|
864
|
+
export class Flow extends Handle {
|
|
865
|
+
/** Never waits; throws WEIDA_ETOO_LARGE above `maxPayload()`, and the
|
|
866
|
+
* error that ended the flow once it ended. */
|
|
867
|
+
send(payload: Bytes): void;
|
|
868
|
+
maxPayload(): number | null;
|
|
869
|
+
stats(): FlowStats;
|
|
870
|
+
/** null on a local transport. */
|
|
871
|
+
pathStats(): PathStats | null;
|
|
872
|
+
/** Resets the flow `CANCELED`. Consumes it. */
|
|
873
|
+
abort(): void;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** `drop()` stops the flow `CANCELED`. */
|
|
877
|
+
export class IncomingFlow extends Handle {
|
|
878
|
+
info(): FlowInfo;
|
|
879
|
+
/** The next datagram, or null once the flow ended and was drained. */
|
|
880
|
+
recv(options?: WaitOptions): Promise<Uint8Array | null>;
|
|
881
|
+
[Symbol.asyncIterator](): AsyncGenerator<Uint8Array, void, undefined>;
|
|
882
|
+
stats(): IncomingFlowStats;
|
|
883
|
+
/** null on a local transport. */
|
|
884
|
+
pathStats(): PathStats | null;
|
|
885
|
+
/** Stops the flow `REJECTED`. Consumes it. */
|
|
886
|
+
refuse(): void;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
export class Replier extends Handle {
|
|
890
|
+
path(): string | null;
|
|
891
|
+
accept(options?: WaitOptions): Promise<IncomingRequest>;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
export class Pusher extends Handle {
|
|
895
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
896
|
+
/** Whether the address was dialled. */
|
|
897
|
+
disconnect(url: string): boolean;
|
|
898
|
+
peerCount(): number;
|
|
899
|
+
connectionStats(): readonly ConnectionStats[];
|
|
900
|
+
events(): PeerEvents;
|
|
901
|
+
/** The bodies the outbox discarded. */
|
|
902
|
+
dropped(): bigint;
|
|
903
|
+
/** A one-way transfer to the next peer, whose `finish()` yields the delivery receipt. */
|
|
904
|
+
open(meta?: TransferMeta | null, options?: WaitOptions): Promise<OutgoingTransfer>;
|
|
905
|
+
/** Resolves once the body is written or held in the outbox. */
|
|
906
|
+
send(body: Bytes, options?: WaitOptions): Promise<void>;
|
|
907
|
+
sendWith(meta: TransferMeta | null, body: Bytes, options?: WaitOptions): Promise<void>;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
export class Puller extends Handle {
|
|
911
|
+
path(): string | null;
|
|
912
|
+
recv(options?: WaitOptions): Promise<IncomingTransfer>;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
export class Publisher extends Handle {
|
|
916
|
+
path(): string | null;
|
|
917
|
+
/** How many subscribers the payload was enqueued to; never waits on one. */
|
|
918
|
+
publish(topic: string, payload: Bytes): number;
|
|
919
|
+
publishWithTrace(topic: string, payload: Bytes, trace: string): number;
|
|
920
|
+
open(topic: string): FanOut;
|
|
921
|
+
openWithTrace(topic: string, trace: string): FanOut;
|
|
922
|
+
subscriberCount(): number;
|
|
923
|
+
filterCount(): number;
|
|
924
|
+
dropped(): bigint;
|
|
925
|
+
droppedOn(topic: string): TopicDrops | null;
|
|
926
|
+
drops(): readonly TopicDrops[];
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/** A publish in progress; dropping it without `finish()` aborts every copy. */
|
|
930
|
+
export class FanOut extends Handle {
|
|
931
|
+
topic(): string | null;
|
|
932
|
+
subscribers(): number;
|
|
933
|
+
/** The subscribers left; until it settles every other call throws WEIDA_EINVAL. */
|
|
934
|
+
writeWithin(chunk: Bytes, limitMs: Count, options?: WaitOptions): Promise<number>;
|
|
935
|
+
writeNow(chunk: Bytes): number;
|
|
936
|
+
/** The subscribers that received all of it; consumes the fan-out. */
|
|
937
|
+
finish(): number;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
export class Subscriber extends Handle {
|
|
941
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
942
|
+
disconnect(url: string): boolean;
|
|
943
|
+
peerCount(): number;
|
|
944
|
+
connectionStats(): readonly ConnectionStats[];
|
|
945
|
+
events(): PeerEvents;
|
|
946
|
+
/** Rejects with WEIDA_EPROTOCOL for a filter outside the grammar. */
|
|
947
|
+
subscribe(filter: string, options?: WaitOptions): Promise<void>;
|
|
948
|
+
unsubscribe(filter: string, options?: WaitOptions): Promise<void>;
|
|
949
|
+
grant(filter: string, limit: Count, options?: WaitOptions): Promise<void>;
|
|
950
|
+
filterCount(): number;
|
|
951
|
+
recv(options?: WaitOptions): Promise<IncomingTransfer>;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/** Either half of PAIR; a bound pair's first send or open waits until its peer has sent. */
|
|
955
|
+
export class Paired extends Handle {
|
|
956
|
+
/** "" on a dialling pair. */
|
|
957
|
+
path(): string | null;
|
|
958
|
+
/** Once: a second address rejects with WEIDA_ELIMIT_EXCEEDED, a bound pair with WEIDA_EUNSUPPORTED. */
|
|
959
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
960
|
+
peerCount(): number;
|
|
961
|
+
connectionStats(): readonly ConnectionStats[];
|
|
962
|
+
/** Null on a bound pair. */
|
|
963
|
+
events(): PeerEvents | null;
|
|
964
|
+
dropped(): bigint;
|
|
965
|
+
open(meta?: TransferMeta | null, options?: WaitOptions): Promise<OutgoingTransfer>;
|
|
966
|
+
send(body: Bytes, options?: WaitOptions): Promise<void>;
|
|
967
|
+
sendWith(meta: TransferMeta | null, body: Bytes, options?: WaitOptions): Promise<void>;
|
|
968
|
+
recv(options?: WaitOptions): Promise<IncomingTransfer>;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
export class Surveyor extends Handle {
|
|
972
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
973
|
+
peerCount(): number;
|
|
974
|
+
connectionStats(): readonly ConnectionStats[];
|
|
975
|
+
/** Asks every connected respondent; `deadlineMs` bounds the asking and the answers. */
|
|
976
|
+
survey(body: Bytes, deadlineMs: Count, options?: WaitOptions): Promise<SurveyRun>;
|
|
977
|
+
surveyWith(meta: TransferMeta | null, body: Bytes, deadlineMs: Count, options?: WaitOptions): Promise<SurveyRun>;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/** Dropping it resets every exchange not yet answered. */
|
|
981
|
+
export class SurveyRun extends Handle {
|
|
982
|
+
/** The next answer, or null once the run ended; a failed answer rejects and the run goes on. */
|
|
983
|
+
next(maxBytes: Count, options?: WaitOptions): Promise<Uint8Array | null>;
|
|
984
|
+
/** Answers that arrived after the deadline. */
|
|
985
|
+
late(): bigint;
|
|
986
|
+
respondents(): number;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
export class Respondent extends Handle {
|
|
990
|
+
path(): string | null;
|
|
991
|
+
accept(options?: WaitOptions): Promise<IncomingRequest>;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/** A blob: its root, size and piece size; WEIDA_EINVAL for a piece size out
|
|
995
|
+
* of range, more than `MAX_PIECES` pieces, or an empty blob whose root is
|
|
996
|
+
* not the hash of no bytes. */
|
|
997
|
+
export class Blob extends Handle {
|
|
998
|
+
constructor(root: Uint8Array, size: Count, pieceLog2?: number);
|
|
999
|
+
root(): Uint8Array;
|
|
1000
|
+
size(): bigint;
|
|
1001
|
+
pieceLog2(): number;
|
|
1002
|
+
count(): number;
|
|
1003
|
+
/** The byte range of piece `index`, end exclusive; null past the last piece. */
|
|
1004
|
+
span(index: number): { readonly start: bigint; readonly end: bigint } | null;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
export class PieceList extends Handle {
|
|
1008
|
+
static of(data: Bytes, pieceLog2?: number): PieceList;
|
|
1009
|
+
/** WEIDA_EINVAL unless the bytes hash to the blob's root. */
|
|
1010
|
+
static parse(blob: Blob, data: Uint8Array): PieceList;
|
|
1011
|
+
blob(): Blob;
|
|
1012
|
+
/** A copy; empty for a blob of at most one piece. */
|
|
1013
|
+
toBytes(): Uint8Array;
|
|
1014
|
+
check(index: number, piece: Bytes): boolean;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
export class TreeHasher extends Handle {
|
|
1018
|
+
constructor(pieceLog2?: number);
|
|
1019
|
+
update(data: Bytes): this;
|
|
1020
|
+
/** Consumes the hasher. */
|
|
1021
|
+
finish(): PieceList;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
export class Bits extends Handle {
|
|
1025
|
+
/** `len` bits, all clear. */
|
|
1026
|
+
constructor(len: number);
|
|
1027
|
+
static full(len: number): Bits;
|
|
1028
|
+
/** Bit `i` is bit `i % 8`, least significant first, of byte `i / 8`; padding bits clear. */
|
|
1029
|
+
static fromBytes(len: number, data: Uint8Array): Bits;
|
|
1030
|
+
/** A copy. */
|
|
1031
|
+
asBytes(): Uint8Array;
|
|
1032
|
+
len(): number;
|
|
1033
|
+
get(index: number): boolean;
|
|
1034
|
+
set(index: number, on: boolean): this;
|
|
1035
|
+
ones(): number;
|
|
1036
|
+
all(): boolean;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
export class Swarm extends Handle {
|
|
1040
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
1041
|
+
/** Whether the address was dialled. */
|
|
1042
|
+
disconnect(url: string): boolean;
|
|
1043
|
+
peerCount(): number;
|
|
1044
|
+
connectionStats(): readonly ConnectionStats[];
|
|
1045
|
+
events(): PeerEvents;
|
|
1046
|
+
/** Nothing is ordered before the first `next`; WEIDA_EINVAL for a `have`
|
|
1047
|
+
* without one bit per piece or a list of another blob. */
|
|
1048
|
+
fetch(blob: Blob, have: Bits, options?: FetchOptions | null): Fetch;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/** Dropping it aborts every order in flight. */
|
|
1052
|
+
export class Fetch extends Handle {
|
|
1053
|
+
blob(): Blob;
|
|
1054
|
+
/** WEIDA_EINVAL while a `next` is pending. */
|
|
1055
|
+
list(): PieceList | null;
|
|
1056
|
+
/** WEIDA_EINVAL while a `next` is pending. */
|
|
1057
|
+
delivered(): Bits;
|
|
1058
|
+
/** WEIDA_EINVAL while a `next` is pending. */
|
|
1059
|
+
inFlight(): Bits;
|
|
1060
|
+
/** The next verified piece, or null once every piece is held; rejects
|
|
1061
|
+
* with WEIDA_ENOT_CONNECTED when no seeder is left. */
|
|
1062
|
+
next(options?: WaitOptions): Promise<Piece | null>;
|
|
1063
|
+
/** Ends at null and leaves the fetch alive. */
|
|
1064
|
+
[Symbol.asyncIterator](): AsyncGenerator<Piece, void, undefined>;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
export class Seeder extends Handle {
|
|
1068
|
+
path(): string | null;
|
|
1069
|
+
accept(options?: WaitOptions): Promise<SeedSession>;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/** Its calls are one at a time; WEIDA_EINVAL otherwise. */
|
|
1073
|
+
export class SeedSession extends Handle {
|
|
1074
|
+
blob(): Blob;
|
|
1075
|
+
meta(): IncomingMeta;
|
|
1076
|
+
/** The number of the connection this session arrived on. */
|
|
1077
|
+
connection(): bigint;
|
|
1078
|
+
/** The next order, or null once the fetch finished its orders. */
|
|
1079
|
+
next(options?: WaitOptions): Promise<Ask | null>;
|
|
1080
|
+
answerList(list: PieceList, options?: WaitOptions): Promise<void>;
|
|
1081
|
+
answerHave(have: Bits, options?: WaitOptions): Promise<void>;
|
|
1082
|
+
answerPiece(data: Bytes, options?: WaitOptions): Promise<void>;
|
|
1083
|
+
/** Consumes the session. */
|
|
1084
|
+
decline(options?: WaitOptions): Promise<void>;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
export class BusMember extends Handle {
|
|
1088
|
+
path(): string | null;
|
|
1089
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
1090
|
+
peerCount(): number;
|
|
1091
|
+
connectionStats(): readonly ConnectionStats[];
|
|
1092
|
+
/** How many members the message reached. */
|
|
1093
|
+
send(body: Bytes, options?: WaitOptions): Promise<number>;
|
|
1094
|
+
sendWith(meta: TransferMeta | null, body: Bytes, options?: WaitOptions): Promise<number>;
|
|
1095
|
+
recv(options?: WaitOptions): Promise<IncomingTransfer>;
|
|
1096
|
+
/** The copies that never reached a member. */
|
|
1097
|
+
dropped(): bigint;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/** The sending half of RADIO/DISH; dropping it releases its path. */
|
|
1101
|
+
export class Radio extends Handle {
|
|
1102
|
+
path(): string | null;
|
|
1103
|
+
/** The topic's next segment to the dishes joined now; resets the previous one's unfinished layers. */
|
|
1104
|
+
segment(topic: string, terms?: SegmentTerms | null): Segment;
|
|
1105
|
+
/** How many dishes the datagram segment was handed to. */
|
|
1106
|
+
datagram(topic: string, payload: Bytes): number;
|
|
1107
|
+
dishCount(): number;
|
|
1108
|
+
dropped(): bigint;
|
|
1109
|
+
droppedOn(topic: string): TopicDrops | null;
|
|
1110
|
+
drops(): readonly TopicDrops[];
|
|
1111
|
+
/** How many joins on `filter` of the dishes whose key is `fingerprint` went. */
|
|
1112
|
+
evict(fingerprint: string, filter: string): number;
|
|
1113
|
+
dishDrops(): readonly DishDrops[];
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/** One open segment; dropping it without `finish()` resets every unfinished layer. */
|
|
1117
|
+
export class Segment extends Handle {
|
|
1118
|
+
number(): bigint;
|
|
1119
|
+
topic(): string | null;
|
|
1120
|
+
/** How many copies took the chunk on layer 0. */
|
|
1121
|
+
write(chunk: Bytes): number;
|
|
1122
|
+
/** How many copies took the chunk; a copy capped below `layer` is skipped. */
|
|
1123
|
+
writeLayer(layer: number, chunk: Bytes): number;
|
|
1124
|
+
finishLayer(layer: number): void;
|
|
1125
|
+
/** How many copies still hold layer 0; consumes the segment. */
|
|
1126
|
+
finish(): number;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/** The receiving half of RADIO/DISH. */
|
|
1130
|
+
export class Dish extends Handle {
|
|
1131
|
+
connect(url: string, options?: WaitOptions): Promise<void>;
|
|
1132
|
+
peerCount(): number;
|
|
1133
|
+
connectionStats(): readonly ConnectionStats[];
|
|
1134
|
+
events(): PeerEvents;
|
|
1135
|
+
/** Rejects with WEIDA_ELIMIT_EXCEEDED for a `maxLayer` of 16 or above, WEIDA_EPROTOCOL for a filter outside the grammar. */
|
|
1136
|
+
join(filter: string, terms?: JoinTerms | null, options?: WaitOptions): Promise<void>;
|
|
1137
|
+
leave(filter: string, options?: WaitOptions): Promise<void>;
|
|
1138
|
+
recv(options?: WaitOptions): Promise<Received>;
|
|
1139
|
+
/** Segments discarded because a newer one on their topic was already delivered. */
|
|
1140
|
+
stale(): bigint;
|
|
1141
|
+
/** Segments discarded because the receive queue was full. */
|
|
1142
|
+
overflow(): bigint;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
export class Relay extends Handle {
|
|
1146
|
+
/** The next registration or tunnel asking to be served. */
|
|
1147
|
+
accept(options?: WaitOptions): Promise<RelayRequest>;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
export class RelayRequest extends Handle {
|
|
1151
|
+
/** The key the asker proved, or null for an anonymous dialler. */
|
|
1152
|
+
peerFingerprint(): string | null;
|
|
1153
|
+
/** null for a registration; for a tunnel, the key of the peer it reaches. */
|
|
1154
|
+
target(): string | null;
|
|
1155
|
+
/** Serves it; consumes the request. */
|
|
1156
|
+
admit(options?: WaitOptions): Promise<void>;
|
|
1157
|
+
/** Refuses it with WEIDA_EREJECTED; consumes the request. */
|
|
1158
|
+
refuse(options?: WaitOptions): Promise<void>;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
export class IncomingRequest extends Handle {
|
|
1162
|
+
meta(): IncomingMeta;
|
|
1163
|
+
/** The number of the connection this request arrived on. */
|
|
1164
|
+
connection(): bigint;
|
|
1165
|
+
takeBody(): IncomingTransfer;
|
|
1166
|
+
/** Consumes the request. */
|
|
1167
|
+
reply(meta?: TransferMeta | null, options?: WaitOptions): Promise<OutgoingTransfer>;
|
|
1168
|
+
/** Refuses the exchange with `code`; consumes the request, an unknown name consumes nothing. */
|
|
1169
|
+
refuse(code: ErrorCode, options?: WaitOptions): Promise<void>;
|
|
1170
|
+
/** Resolves when the requester gave up; take it before `reply`, it outlives the request. */
|
|
1171
|
+
canceled(options?: WaitOptions): Promise<void>;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
export class IncomingTransfer extends Handle {
|
|
1175
|
+
meta(): IncomingMeta;
|
|
1176
|
+
/** The number of the connection this transfer arrived on. */
|
|
1177
|
+
connection(): bigint;
|
|
1178
|
+
/** A new reporter for the levels the sender ordered on every call; null
|
|
1179
|
+
* when it ordered none. Take it before `collect`, it outlives the
|
|
1180
|
+
* transfer. */
|
|
1181
|
+
reporter(): Reporter | null;
|
|
1182
|
+
/** Up to `cap` bytes (default 65536); empty at the end of the payload. */
|
|
1183
|
+
read(cap?: number, options?: WaitOptions): Promise<Uint8Array>;
|
|
1184
|
+
/** Consumes the transfer. */
|
|
1185
|
+
collect(maxBytes: number | bigint, options?: WaitOptions): Promise<Message>;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
export class OutgoingTransfer extends Handle {
|
|
1189
|
+
write(data: Bytes, options?: WaitOptions): Promise<number>;
|
|
1190
|
+
writeAll(data: Bytes, options?: WaitOptions): Promise<void>;
|
|
1191
|
+
/** The trace context propagated with this transfer; a reply inherits its
|
|
1192
|
+
* request's. */
|
|
1193
|
+
trace(): string | null;
|
|
1194
|
+
/** Higher is sent first among the streams of one connection; a no-op on
|
|
1195
|
+
* local transports. */
|
|
1196
|
+
setPriority(priority: number): void;
|
|
1197
|
+
/** A write or finish past the deadline throws WEIDA_EEXPIRED and the
|
|
1198
|
+
* reader sees WEIDA_ECANCELED. */
|
|
1199
|
+
expireAfterMs(ms: number | bigint): void;
|
|
1200
|
+
/** The queue of cursor sets the receiver reports, the first time; null
|
|
1201
|
+
* after that and when nothing was ordered. Take it before `finish`, it
|
|
1202
|
+
* outlives the transfer. */
|
|
1203
|
+
cursors(): Cursors | null;
|
|
1204
|
+
/** Consumes the transfer. */
|
|
1205
|
+
finish(): Delivery;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
export class Delivery extends Handle {
|
|
1209
|
+
/** Consumes the receipt. */
|
|
1210
|
+
delivered(options?: WaitOptions): Promise<void>;
|
|
1211
|
+
}
|