@cc-remote/iroh 1.0.0-rc.3
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/.yarnrc.yml +3 -0
- package/Cargo.toml +30 -0
- package/README.md +38 -0
- package/index.d.ts +478 -0
- package/index.js +603 -0
- package/package.json +66 -0
- package/src/endpoint.rs +1018 -0
- package/src/key.rs +173 -0
- package/src/lib.rs +59 -0
- package/src/net.rs +106 -0
- package/src/path.rs +167 -0
- package/src/relay.rs +194 -0
- package/src/services.rs +167 -0
- package/src/ticket.rs +46 -0
- package/src/watch.rs +111 -0
- package/test/endpoint.mjs +176 -0
- package/test/key.mjs +71 -0
- package/test/relay.mjs +40 -0
- package/test/services.mjs +47 -0
- package/tsconfig.json +11 -0
- package/typedoc.json +9 -0
package/.yarnrc.yml
ADDED
package/Cargo.toml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
edition = "2024"
|
|
3
|
+
name = "number0_iroh"
|
|
4
|
+
version = "1.0.0"
|
|
5
|
+
license = "MIT OR Apache-2.0"
|
|
6
|
+
authors = ["n0 team"]
|
|
7
|
+
repository = "https://github.com/n0-computer/iroh-ffi"
|
|
8
|
+
rust-version = "1.91"
|
|
9
|
+
|
|
10
|
+
[lib]
|
|
11
|
+
crate-type = ["cdylib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
napi = { version = "3", default-features = false, features = ["napi8", "error_anyhow", "async"] }
|
|
15
|
+
napi-derive = "3"
|
|
16
|
+
anyhow = "1.0.69"
|
|
17
|
+
iroh = "1.0.0"
|
|
18
|
+
iroh-base = "1.0.0"
|
|
19
|
+
iroh-metrics = "1.0.0"
|
|
20
|
+
iroh-relay = { version = "1.0.0", default-features = false }
|
|
21
|
+
iroh-services = { version = "1.0.0", default-features = false }
|
|
22
|
+
iroh-tickets = "1.0.0"
|
|
23
|
+
n0-future = "0.3"
|
|
24
|
+
tokio = "1.25.0"
|
|
25
|
+
url = "2.4"
|
|
26
|
+
tracing = "0.1.40"
|
|
27
|
+
tracing-subscriber = { version = "0.3.17" }
|
|
28
|
+
|
|
29
|
+
[build-dependencies]
|
|
30
|
+
napi-build = "2.2"
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# `@number0/iroh`
|
|
2
|
+
|
|
3
|
+
> A toolkit for building distributed applications
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
> npm i --save @number0/iroh
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Development
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
# debug build
|
|
16
|
+
> yarn build:debug
|
|
17
|
+
|
|
18
|
+
# run tests
|
|
19
|
+
> yarn test
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
This project is licensed under either of
|
|
26
|
+
|
|
27
|
+
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
28
|
+
http://www.apache.org/licenses/LICENSE-2.0)
|
|
29
|
+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
30
|
+
http://opensource.org/licenses/MIT)
|
|
31
|
+
|
|
32
|
+
at your option.
|
|
33
|
+
|
|
34
|
+
### Contribution
|
|
35
|
+
|
|
36
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted
|
|
37
|
+
for inclusion in this project by you, as defined in the Apache-2.0 license,
|
|
38
|
+
shall be dual licensed as above, without any additional terms or conditions.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/** A server-side handshake in progress. */
|
|
4
|
+
export declare class Accepting {
|
|
5
|
+
connect(): Promise<Connection>
|
|
6
|
+
alpn(): Promise<Array<number>>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** A bidirectional QUIC stream pair. */
|
|
10
|
+
export declare class BiStream {
|
|
11
|
+
get send(): SendStream
|
|
12
|
+
get recv(): RecvStream
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A client-side handshake in progress. */
|
|
16
|
+
export declare class Connecting {
|
|
17
|
+
connect(): Promise<Connection>
|
|
18
|
+
alpn(): Promise<Array<number>>
|
|
19
|
+
remoteId(): Promise<EndpointId>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** An active QUIC connection. */
|
|
23
|
+
export declare class Connection {
|
|
24
|
+
alpn(): Array<number>
|
|
25
|
+
remoteId(): EndpointId
|
|
26
|
+
side(): Side
|
|
27
|
+
openUni(): Promise<SendStream>
|
|
28
|
+
acceptUni(): Promise<RecvStream>
|
|
29
|
+
openBi(): Promise<BiStream>
|
|
30
|
+
acceptBi(): Promise<BiStream>
|
|
31
|
+
readDatagram(): Promise<Array<number>>
|
|
32
|
+
closed(): Promise<string>
|
|
33
|
+
closeReason(): string | null
|
|
34
|
+
close(errorCode: bigint, reason: Array<number>): void
|
|
35
|
+
sendDatagram(data: Array<number>): void
|
|
36
|
+
sendDatagramWait(data: Array<number>): Promise<void>
|
|
37
|
+
maxDatagramSize(): number | null
|
|
38
|
+
datagramSendBufferSpace(): number
|
|
39
|
+
stableId(): number
|
|
40
|
+
rtt(): number | null
|
|
41
|
+
stats(): ConnectionStats
|
|
42
|
+
paths(): Array<PathSnapshot>
|
|
43
|
+
watchPaths(callback: (paths: Array<PathSnapshot>) => void): WatchHandle
|
|
44
|
+
watchPathEvents(callback: (event: PathEvent) => void): WatchHandle
|
|
45
|
+
setMaxConcurrentUniStreams(count: bigint): void
|
|
46
|
+
setReceiveWindow(count: bigint): void
|
|
47
|
+
setMaxConcurrentBiStreams(count: bigint): void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** An iroh endpoint. */
|
|
51
|
+
export declare class Endpoint {
|
|
52
|
+
/** Create an endpoint builder (starts empty — apply a preset). */
|
|
53
|
+
static builder(): EndpointBuilder
|
|
54
|
+
/**
|
|
55
|
+
* Bind a new endpoint. Applies the n0 preset, then the given options.
|
|
56
|
+
* For a custom preset use [`Endpoint::builder`].
|
|
57
|
+
*/
|
|
58
|
+
static bind(options?: EndpointOptions | undefined | null, relayMode?: RelayMode | undefined | null): Promise<Endpoint>
|
|
59
|
+
/** This endpoint's id. */
|
|
60
|
+
id(): EndpointId
|
|
61
|
+
/** The [`EndpointAddr`] for this endpoint. */
|
|
62
|
+
addr(): EndpointAddr
|
|
63
|
+
/** Look up cached information about a remote endpoint, if any. */
|
|
64
|
+
remoteAddr(id: EndpointId): Promise<EndpointAddr | null>
|
|
65
|
+
/** Current statistics for this endpoint. */
|
|
66
|
+
stats(): Record<string, CounterStats>
|
|
67
|
+
/** The secret key backing this endpoint's identity. */
|
|
68
|
+
secretKey(): SecretKey
|
|
69
|
+
/** Replace the set of advertised ALPNs. */
|
|
70
|
+
setAlpns(alpns: Array<Array<number>>): void
|
|
71
|
+
/** Add an external (manually-known) socket address. */
|
|
72
|
+
addExternalAddr(addr: string): Promise<void>
|
|
73
|
+
/** Remove a previously-added external address. */
|
|
74
|
+
removeExternalAddr(addr: string): Promise<boolean>
|
|
75
|
+
/** The local socket addresses this endpoint is bound to. */
|
|
76
|
+
boundSockets(): Array<string>
|
|
77
|
+
/** Resolves once the endpoint has a usable home relay. */
|
|
78
|
+
online(): Promise<void>
|
|
79
|
+
/** Insert (or replace) a relay configuration at runtime. */
|
|
80
|
+
insertRelay(config: RelayConfig): Promise<void>
|
|
81
|
+
/** Remove a relay configuration at runtime. */
|
|
82
|
+
removeRelay(url: string): Promise<boolean>
|
|
83
|
+
/** Connect to a remote endpoint via the given ALPN. */
|
|
84
|
+
connect(addr: EndpointAddr, alpn: Array<number>): Promise<Connection>
|
|
85
|
+
/** Begin a connection attempt, returning the in-progress handle. */
|
|
86
|
+
connectPending(addr: EndpointAddr, alpn: Array<number>): Promise<Connecting>
|
|
87
|
+
/** Pull the next incoming connection attempt. */
|
|
88
|
+
acceptNext(): Promise<Incoming | null>
|
|
89
|
+
/** Watch for changes to this endpoint's address. */
|
|
90
|
+
watchAddr(callback: (addr: EndpointAddr) => void): WatchHandle
|
|
91
|
+
/** Watch for changes to the connected relays. */
|
|
92
|
+
watchHomeRelay(callback: (relayUrls: Array<string>) => void): WatchHandle
|
|
93
|
+
/** Watch for network-stack changes. */
|
|
94
|
+
watchNetworkChange(callback: () => void): WatchHandle
|
|
95
|
+
/** Close the endpoint. */
|
|
96
|
+
close(): Promise<void>
|
|
97
|
+
/** True if the endpoint is closed. */
|
|
98
|
+
isClosed(): boolean
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* An endpoint's id together with the network-level addresses where it can be
|
|
103
|
+
* reached. Mirrors the uniffi `EndpointAddr` object surface.
|
|
104
|
+
*/
|
|
105
|
+
export declare class EndpointAddr {
|
|
106
|
+
/** Create a new [`EndpointAddr`]. */
|
|
107
|
+
constructor(id: EndpointId, relayUrl?: string | undefined | null, addresses?: Array<string> | undefined | null)
|
|
108
|
+
/** The endpoint id. */
|
|
109
|
+
id(): EndpointId
|
|
110
|
+
/** The direct (ip:port) addresses of this peer. */
|
|
111
|
+
directAddresses(): Array<string>
|
|
112
|
+
/** The home relay URL for this peer, if known. */
|
|
113
|
+
relayUrl(): string | null
|
|
114
|
+
/** Returns true if both [`EndpointAddr`]s have the same values. */
|
|
115
|
+
equal(other: EndpointAddr): boolean
|
|
116
|
+
/** Clean string representation. */
|
|
117
|
+
toString(): string
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A mutable handle to an endpoint builder.
|
|
122
|
+
*
|
|
123
|
+
* Mirrors the uniffi `EndpointBuilder`. A "preset" in JS is simply any
|
|
124
|
+
* function `(builder: EndpointBuilder) => void` — call one of the built-in
|
|
125
|
+
* [`presetN0`] / [`presetMinimal`] / [`presetN0DisableRelay`] helpers (which
|
|
126
|
+
* install the crypto provider) and then layer on your own configuration.
|
|
127
|
+
*
|
|
128
|
+
* ```js
|
|
129
|
+
* const b = Endpoint.builder()
|
|
130
|
+
* presetMinimal(b)
|
|
131
|
+
* b.alpns([alpn])
|
|
132
|
+
* const ep = await b.bind()
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare class EndpointBuilder {
|
|
136
|
+
/** Replay the n0 production preset (relays + discovery + crypto provider). */
|
|
137
|
+
applyN0(): void
|
|
138
|
+
/** Replay the minimal preset (crypto provider only, no external deps). */
|
|
139
|
+
applyMinimal(): void
|
|
140
|
+
/** Replay the n0 preset with relays disabled. */
|
|
141
|
+
applyN0DisableRelay(): void
|
|
142
|
+
/** Set the endpoint secret key (32 bytes). */
|
|
143
|
+
secretKey(bytes: Array<number>): void
|
|
144
|
+
/** Set the advertised ALPNs. */
|
|
145
|
+
alpns(alpns: Array<Array<number>>): void
|
|
146
|
+
/** Set the relay mode. */
|
|
147
|
+
relayMode(mode: RelayMode): void
|
|
148
|
+
/**
|
|
149
|
+
* Remove all IP based transports, forcing all traffic over relays.
|
|
150
|
+
*
|
|
151
|
+
* This must be called *after* any preset (e.g. [`applyN0`]) that
|
|
152
|
+
* installs IP transports, otherwise the preset will re-add them.
|
|
153
|
+
*/
|
|
154
|
+
clearIpTransports(): void
|
|
155
|
+
/**
|
|
156
|
+
* Only publish relay addresses (no direct IPs) to discovery.
|
|
157
|
+
*
|
|
158
|
+
* Installs `AddrFilter::relay_only()` so the addresses published to
|
|
159
|
+
* discovery (pkarr/DNS) are limited to relay URLs.
|
|
160
|
+
*/
|
|
161
|
+
addrFilterRelayOnly(): void
|
|
162
|
+
/** Set the address the endpoint binds to (`host:port`). */
|
|
163
|
+
bindAddr(addr: string): void
|
|
164
|
+
/** Bind the endpoint. */
|
|
165
|
+
bind(): Promise<Endpoint>
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** An endpoint's identifier, a 32-byte ed25519 public key. */
|
|
169
|
+
export declare class EndpointId {
|
|
170
|
+
/** Returns true if both [`EndpointId`]s are equal. */
|
|
171
|
+
equals(other: EndpointId): boolean
|
|
172
|
+
/** Get the underlying 32 bytes. */
|
|
173
|
+
toBytes(): Array<number>
|
|
174
|
+
/** Parse an [`EndpointId`] from its base32 representation. */
|
|
175
|
+
static fromString(s: string): EndpointId
|
|
176
|
+
/** Construct an [`EndpointId`] from raw bytes (32 bytes). */
|
|
177
|
+
static fromBytes(bytes: Array<number>): EndpointId
|
|
178
|
+
/** Short base32 prefix. */
|
|
179
|
+
fmtShort(): string
|
|
180
|
+
/** Base32 string form. */
|
|
181
|
+
toString(): string
|
|
182
|
+
/** Verify a signature on `message` against this endpoint's key. */
|
|
183
|
+
verify(message: Array<number>, signature: Signature): void
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** A token containing information for establishing a connection to an endpoint. */
|
|
187
|
+
export declare class EndpointTicket {
|
|
188
|
+
/** Wrap an [`EndpointAddr`] into a ticket. */
|
|
189
|
+
static fromAddr(addr: EndpointAddr): EndpointTicket
|
|
190
|
+
/** Parse a ticket from its base32 string form. */
|
|
191
|
+
static fromString(s: string): EndpointTicket
|
|
192
|
+
/** The [`EndpointAddr`] embedded in this ticket. */
|
|
193
|
+
endpointAddr(): EndpointAddr
|
|
194
|
+
/** Base32 string form. */
|
|
195
|
+
toString(): string
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** An incoming connection that has not yet begun its server-side handshake. */
|
|
199
|
+
export declare class Incoming {
|
|
200
|
+
accept(): Promise<Accepting>
|
|
201
|
+
refuse(): Promise<void>
|
|
202
|
+
retry(): Promise<void>
|
|
203
|
+
ignore(): Promise<void>
|
|
204
|
+
localAddr(): Promise<IncomingLocalAddr>
|
|
205
|
+
remoteAddr(): Promise<IncomingAddr>
|
|
206
|
+
remoteAddrValidated(): Promise<boolean>
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The incoming half of a QUIC stream. */
|
|
210
|
+
export declare class RecvStream {
|
|
211
|
+
read(sizeLimit: number): Promise<Array<number>>
|
|
212
|
+
readExact(size: number): Promise<Array<number>>
|
|
213
|
+
readToEnd(sizeLimit: number): Promise<Array<number>>
|
|
214
|
+
id(): Promise<string>
|
|
215
|
+
bytesRead(): Promise<number>
|
|
216
|
+
stop(errorCode: bigint): Promise<void>
|
|
217
|
+
receivedReset(): Promise<number | null>
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** A collection of relay servers an endpoint should consider. */
|
|
221
|
+
export declare class RelayMap {
|
|
222
|
+
/** Create an empty relay map. */
|
|
223
|
+
static empty(): RelayMap
|
|
224
|
+
/** Build a relay map from a list of relay URLs. */
|
|
225
|
+
static fromUrls(urls: Array<string>): RelayMap
|
|
226
|
+
/** Insert a relay (replacing any prior entry for the same URL). */
|
|
227
|
+
insert(config: RelayConfig): void
|
|
228
|
+
/** Remove the entry for the given relay URL. Returns true if removed. */
|
|
229
|
+
remove(url: string): boolean
|
|
230
|
+
/** Check whether the given relay URL is in the map. */
|
|
231
|
+
contains(url: string): boolean
|
|
232
|
+
/** Look up the configuration for the given relay URL. */
|
|
233
|
+
get(url: string): RelayConfig | null
|
|
234
|
+
/** All relay URLs currently in the map. */
|
|
235
|
+
urls(): Array<string>
|
|
236
|
+
/** Number of relays in the map. */
|
|
237
|
+
len(): number
|
|
238
|
+
/** True if the map has no relays. */
|
|
239
|
+
isEmpty(): boolean
|
|
240
|
+
/** Clean string representation. */
|
|
241
|
+
toString(): string
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Configuration for which relay servers an endpoint uses. */
|
|
245
|
+
export declare class RelayMode {
|
|
246
|
+
/** No relays. */
|
|
247
|
+
static disabled(): RelayMode
|
|
248
|
+
/** Use the n0 production relay map. */
|
|
249
|
+
static defaultMode(): RelayMode
|
|
250
|
+
/** Use the n0 staging relay map. */
|
|
251
|
+
static staging(): RelayMode
|
|
252
|
+
/** Use a custom relay map. */
|
|
253
|
+
static custom(map: RelayMap): RelayMode
|
|
254
|
+
/** Build a custom relay mode from a list of relay URLs. */
|
|
255
|
+
static customFromUrls(urls: Array<string>): RelayMode
|
|
256
|
+
/** The relay map this mode resolves to. */
|
|
257
|
+
relayMap(): RelayMap
|
|
258
|
+
/** Clean string representation. */
|
|
259
|
+
toString(): string
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The secret key half of an endpoint identity. */
|
|
263
|
+
export declare class SecretKey {
|
|
264
|
+
/** Generate a new random secret key. */
|
|
265
|
+
static generate(): SecretKey
|
|
266
|
+
/** Construct from raw bytes (32 bytes). */
|
|
267
|
+
static fromBytes(bytes: Array<number>): SecretKey
|
|
268
|
+
/** Raw 32-byte form. */
|
|
269
|
+
toBytes(): Array<number>
|
|
270
|
+
/** The public [`EndpointId`] derived from this secret key. */
|
|
271
|
+
public(): EndpointId
|
|
272
|
+
/** Sign a message, producing an ed25519 signature. */
|
|
273
|
+
sign(message: Array<number>): Signature
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The outgoing half of a QUIC stream. */
|
|
277
|
+
export declare class SendStream {
|
|
278
|
+
write(buf: Array<number>): Promise<number>
|
|
279
|
+
writeAll(buf: Array<number>): Promise<void>
|
|
280
|
+
finish(): Promise<void>
|
|
281
|
+
reset(errorCode: bigint): Promise<void>
|
|
282
|
+
setPriority(p: number): Promise<void>
|
|
283
|
+
priority(): Promise<number>
|
|
284
|
+
stopped(): Promise<number | null>
|
|
285
|
+
id(): Promise<string>
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Client for services.iroh.computer. */
|
|
289
|
+
export declare class ServicesClient {
|
|
290
|
+
/** Build a new client bound to the given endpoint. */
|
|
291
|
+
static create(endpoint: Endpoint, options: ServicesOptions): Promise<ServicesClient>
|
|
292
|
+
/** Read the current endpoint name from the local client. */
|
|
293
|
+
name(): Promise<string | null>
|
|
294
|
+
/** Set the endpoint name cloud-side. */
|
|
295
|
+
setName(name: string): Promise<void>
|
|
296
|
+
/** Ping the remote service. */
|
|
297
|
+
ping(): Promise<void>
|
|
298
|
+
/** Force a metrics flush. */
|
|
299
|
+
pushMetrics(): Promise<void>
|
|
300
|
+
/** Run a network-diagnostics report, optionally submitting it. */
|
|
301
|
+
submitNetworkDiagnostics(send: boolean): Promise<DiagnosticsSummary>
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** An ed25519 signature over a message. */
|
|
305
|
+
export declare class Signature {
|
|
306
|
+
/** Construct from raw bytes (64 bytes). */
|
|
307
|
+
static fromBytes(bytes: Array<number>): Signature
|
|
308
|
+
/** Raw 64-byte form. */
|
|
309
|
+
toBytes(): Array<number>
|
|
310
|
+
/** Lowercase hex representation. */
|
|
311
|
+
toString(): string
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Handle to a running watcher task. Call `stop()` (or drop) to unregister. */
|
|
315
|
+
export declare class WatchHandle {
|
|
316
|
+
/** Stop the watcher, aborting the background task. */
|
|
317
|
+
stop(): Promise<void>
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Flat snapshot of headline connection statistics. */
|
|
321
|
+
export interface ConnectionStats {
|
|
322
|
+
udpTxDatagrams: number
|
|
323
|
+
udpTxBytes: number
|
|
324
|
+
udpRxDatagrams: number
|
|
325
|
+
udpRxBytes: number
|
|
326
|
+
lostPackets: number
|
|
327
|
+
lostBytes: number
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** A snapshot value for a single endpoint metric. */
|
|
331
|
+
export interface CounterStats {
|
|
332
|
+
value: number
|
|
333
|
+
description: string
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Flattened summary of an `iroh_services` diagnostics report. */
|
|
337
|
+
export interface DiagnosticsSummary {
|
|
338
|
+
endpointId: string
|
|
339
|
+
directAddrs: Array<string>
|
|
340
|
+
irohVersion: string
|
|
341
|
+
irohServicesVersion: string
|
|
342
|
+
hasNetReport: boolean
|
|
343
|
+
upnp?: boolean
|
|
344
|
+
pcp?: boolean
|
|
345
|
+
natPmp?: boolean
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Options passed to [`Endpoint::bind`].
|
|
350
|
+
*
|
|
351
|
+
* `bind` applies the n0 preset by default. For a custom preset use
|
|
352
|
+
* [`Endpoint::builder`] + the `EndpointBuilder` surface.
|
|
353
|
+
*/
|
|
354
|
+
export interface EndpointOptions {
|
|
355
|
+
bindAddr?: string
|
|
356
|
+
secretKey?: Array<number>
|
|
357
|
+
alpns?: Array<Array<number>>
|
|
358
|
+
/**
|
|
359
|
+
* Force all traffic over relays ("relay-only" mode).
|
|
360
|
+
*
|
|
361
|
+
* When `true`, removes all IP based transports (no direct connections or
|
|
362
|
+
* hole punching) and limits the addresses published to discovery to relay
|
|
363
|
+
* URLs only. Defaults to `false` (n0 preset behaviour unchanged).
|
|
364
|
+
*/
|
|
365
|
+
relayOnly?: boolean
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Where an incoming connection came from. */
|
|
369
|
+
export interface IncomingAddr {
|
|
370
|
+
/** One of "ip" | "relay" | "custom". */
|
|
371
|
+
kind: string
|
|
372
|
+
/** `ip:port` for ip, relay URL for relay. */
|
|
373
|
+
addr?: string
|
|
374
|
+
/** Remote endpoint id (relay only). */
|
|
375
|
+
endpointId?: string
|
|
376
|
+
/** Debug description (custom only). */
|
|
377
|
+
description?: string
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** The local address that received an incoming connection. */
|
|
381
|
+
export interface IncomingLocalAddr {
|
|
382
|
+
/** One of "ip" | "relay" | "custom". */
|
|
383
|
+
kind: string
|
|
384
|
+
addr?: string
|
|
385
|
+
description?: string
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** The logging level. See the rust (log crate)[https://docs.rs/log] for more information. */
|
|
389
|
+
export declare const enum LogLevel {
|
|
390
|
+
Trace = 'Trace',
|
|
391
|
+
Debug = 'Debug',
|
|
392
|
+
Info = 'Info',
|
|
393
|
+
Warn = 'Warn',
|
|
394
|
+
Error = 'Error',
|
|
395
|
+
Off = 'Off'
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** A path event with its associated data. */
|
|
399
|
+
export interface PathEvent {
|
|
400
|
+
kind: PathEventKind
|
|
401
|
+
id?: string
|
|
402
|
+
remoteAddr?: string
|
|
403
|
+
localAddr?: string
|
|
404
|
+
lastStats?: PathStatsRecord
|
|
405
|
+
missed?: number
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** An event from `Connection::watchPathEvents`. */
|
|
409
|
+
export declare const enum PathEventKind {
|
|
410
|
+
Opened = 'Opened',
|
|
411
|
+
Closed = 'Closed',
|
|
412
|
+
Selected = 'Selected',
|
|
413
|
+
Lagged = 'Lagged'
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** A flat snapshot of an open path's state. */
|
|
417
|
+
export interface PathSnapshot {
|
|
418
|
+
id: string
|
|
419
|
+
isSelected: boolean
|
|
420
|
+
remoteAddr: string
|
|
421
|
+
isIp: boolean
|
|
422
|
+
isRelay: boolean
|
|
423
|
+
rttMs: number
|
|
424
|
+
stats: PathStatsRecord
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Flattened headline numbers from `noq::PathStats`. */
|
|
428
|
+
export interface PathStatsRecord {
|
|
429
|
+
rttMs: number
|
|
430
|
+
udpTxDatagrams: number
|
|
431
|
+
udpTxBytes: number
|
|
432
|
+
udpRxDatagrams: number
|
|
433
|
+
udpRxBytes: number
|
|
434
|
+
cwnd: number
|
|
435
|
+
congestionEvents: number
|
|
436
|
+
lostPackets: number
|
|
437
|
+
lostBytes: number
|
|
438
|
+
currentMtu: number
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** The minimal preset (no external dependencies; good for tests / offline). */
|
|
442
|
+
export declare function presetMinimal(builder: EndpointBuilder): void
|
|
443
|
+
|
|
444
|
+
/** The n0 production preset (relays + discovery). */
|
|
445
|
+
export declare function presetN0(builder: EndpointBuilder): void
|
|
446
|
+
|
|
447
|
+
/** The n0 preset with relays disabled. */
|
|
448
|
+
export declare function presetN0DisableRelay(builder: EndpointBuilder): void
|
|
449
|
+
|
|
450
|
+
/** Config for a single relay server. */
|
|
451
|
+
export interface RelayConfig {
|
|
452
|
+
url: string
|
|
453
|
+
quicPort?: number
|
|
454
|
+
authToken?: string
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** Build options for [`ServicesClient`]. */
|
|
458
|
+
export interface ServicesOptions {
|
|
459
|
+
/** Encoded API secret string (`services1...`). */
|
|
460
|
+
apiSecret?: string
|
|
461
|
+
/** If true, read the API secret from `IROH_SERVICES_API_SECRET`. */
|
|
462
|
+
apiSecretFromEnv?: boolean
|
|
463
|
+
/** Unencrypted PEM-encoded OpenSSH ed25519 private key. */
|
|
464
|
+
sshKeyPem?: string
|
|
465
|
+
/** Optional endpoint name to register cloud-side. */
|
|
466
|
+
name?: string
|
|
467
|
+
/** Metrics push interval (ms). `0` disables interval pushes. */
|
|
468
|
+
metricsIntervalMs?: number
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Set the logging level. */
|
|
472
|
+
export declare function setLogLevel(level: LogLevel): void
|
|
473
|
+
|
|
474
|
+
/** Which side of a connection we are. */
|
|
475
|
+
export declare const enum Side {
|
|
476
|
+
Client = 'Client',
|
|
477
|
+
Server = 'Server'
|
|
478
|
+
}
|