@jsprismarine/native-network 0.27.0 → 0.28.0-unstable-20261129155207
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/CHANGELOG.md +9 -0
- package/README.md +5 -0
- package/dist/Cfb8.d.ts +38 -0
- package/dist/Cfb8.d.ts.map +1 -0
- package/dist/Cfb8.js +99 -0
- package/dist/Cfb8.js.map +1 -0
- package/dist/NativeNetwork.d.ts +8 -1
- package/dist/NativeNetwork.d.ts.map +1 -1
- package/dist/NativeNetwork.js +32 -23
- package/dist/NativeNetwork.js.map +1 -1
- package/dist/ffi.d.ts +4 -0
- package/dist/ffi.d.ts.map +1 -1
- package/dist/ffi.js +18 -2
- package/dist/ffi.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @jsprismarine/native-network
|
|
2
2
|
|
|
3
|
+
## 0.28.0-unstable-20261129155207
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3974](https://github.com/JSPrismarine/JSPrismarine/pull/3974) [`89ae12e`](https://github.com/JSPrismarine/JSPrismarine/commit/89ae12e4bc77970f3f6233731659db7bb1b94454) Thanks [@filiphsps](https://github.com/filiphsps)! - The native networking library has `Cfb8`, AES-128 in CFB8 mode, the cipher a Java Edition connection runs after its login. It runs in the TLS library the library links, which uses the CPU's AES instructions where it has them. `Cfb8.create` returns `undefined` when no library for the machine loads, or the one that loads was built before the cipher. `openLibrary` binds the library and checks its interface without opening an event queue.
|
|
8
|
+
- Updated dependencies [[`89ae12e`](https://github.com/JSPrismarine/JSPrismarine/commit/89ae12e4bc77970f3f6233731659db7bb1b94454)]:
|
|
9
|
+
- @jsprismarine/errors@0.28.0-unstable-20261129155207
|
|
10
|
+
- @jsprismarine/native-library@0.28.0-unstable-20261129155207
|
|
11
|
+
|
|
3
12
|
## 0.27.0
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -13,6 +13,11 @@ TypeScript that binds it:
|
|
|
13
13
|
owns the socket, and the library sorts each datagram by its bytes before libjuice looks it up:
|
|
14
14
|
RakNet's datagrams go to RakNet through shared-memory rings, and WebRTC's stay in native code.
|
|
15
15
|
[ADR 0008](../../docs/adr/0008-shared-udp-port-in-native-code.md) has the design.
|
|
16
|
+
- `Cfb8`, AES-128 in CFB8 mode, the cipher a Java Edition connection runs after its login. It runs
|
|
17
|
+
in the linked TLS library, with the CPU's AES instructions where it has them. Bun's
|
|
18
|
+
`node:crypto` has no `aes-128-cfb8`, so a Bun server encrypts its Java players with this one.
|
|
19
|
+
`Cfb8.create` returns `undefined` when no library for the machine loads, or the one that loads
|
|
20
|
+
was built before the cipher.
|
|
16
21
|
|
|
17
22
|
## How it is called
|
|
18
23
|
|
package/dist/Cfb8.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One direction of an AES-128-CFB8 stream, Java Edition's connection cipher, run in the native
|
|
3
|
+
* library's TLS library. It exists for Bun, whose `node:crypto` has no `aes-128-cfb8`; Node.js
|
|
4
|
+
* has its own.
|
|
5
|
+
*
|
|
6
|
+
* The native cipher holds its key and register until {@link Cfb8.close}, so the owner closes it
|
|
7
|
+
* when the connection ends.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Cfb8 {
|
|
10
|
+
private readonly symbols;
|
|
11
|
+
private handle;
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Whether the native cipher is available: a build of the library for this machine loads and
|
|
15
|
+
* has it.
|
|
16
|
+
* @returns True when {@link Cfb8.create} returns a cipher.
|
|
17
|
+
*/
|
|
18
|
+
static available(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Starts one direction of a stream.
|
|
21
|
+
* @param direction - Which way the stream goes.
|
|
22
|
+
* @param key - The sixteen-byte AES-128 key.
|
|
23
|
+
* @param iv - The sixteen-byte initial register.
|
|
24
|
+
* @returns The cipher, or undefined when the library is missing or predates the cipher.
|
|
25
|
+
* @throws {NativeNetworkError} When the library refuses the key or the register.
|
|
26
|
+
*/
|
|
27
|
+
static create(direction: 'encrypt' | 'decrypt', key: Uint8Array, iv: Uint8Array): Cfb8 | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Runs the next bytes of the stream through the cipher.
|
|
30
|
+
* @param data - The bytes, which are left as they are.
|
|
31
|
+
* @returns The same number of bytes, encrypted or decrypted.
|
|
32
|
+
* @throws {NativeNetworkError} When the cipher was closed or the library fails.
|
|
33
|
+
*/
|
|
34
|
+
update(data: Uint8Array): Buffer;
|
|
35
|
+
/** Frees the native cipher. Closing it again does nothing. */
|
|
36
|
+
close(): void;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=Cfb8.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cfb8.d.ts","sources":["../src/Cfb8.ts"],"names":[],"mappings":"AAsCA;;;;;;;GAOG;AACH,qBAAa,IAAI;IAIT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH5B,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,eAKN;IAED;;;;OAIG;IACH,OAAc,SAAS,IAAI,OAAO,CAEjC;IAED;;;;;;;OAOG;IACH,OAAc,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,CASxG;IAED;;;;;OAKG;IACI,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAQtC;IAED,8DAA8D;IACvD,KAAK,IAAI,IAAI,CAInB;CACJ"}
|
package/dist/Cfb8.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { NativeNetwork, openLibrary } from "./NativeNetwork.js";
|
|
2
|
+
import { locateLibrary } from "./library.js";
|
|
3
|
+
import { NativeNetworkErrors } from "@jsprismarine/errors/native-network";
|
|
4
|
+
// src/Cfb8.ts
|
|
5
|
+
/** AES-128 takes a sixteen-byte key, and CFB8's register is one sixteen-byte block. */
|
|
6
|
+
var KEY_BYTES = 16;
|
|
7
|
+
/** The library's cipher calls once looked up: bound, or null when there is no library that has them. */
|
|
8
|
+
var bound;
|
|
9
|
+
/**
|
|
10
|
+
* The cipher calls of the library this thread already loaded, else of the installed build,
|
|
11
|
+
* bound once without opening an event queue, since a cipher needs none.
|
|
12
|
+
* @returns The calls, or undefined when no library loads or the one that does predates them.
|
|
13
|
+
*/
|
|
14
|
+
var cfb8Symbols = () => {
|
|
15
|
+
if (bound === void 0) {
|
|
16
|
+
let symbols = NativeNetwork.loaded()?.symbols;
|
|
17
|
+
if (symbols === void 0) try {
|
|
18
|
+
symbols = openLibrary(locateLibrary()).symbols;
|
|
19
|
+
} catch {}
|
|
20
|
+
const { jsp_cfb8_create: create, jsp_cfb8_update: update, jsp_cfb8_delete: remove } = symbols ?? {};
|
|
21
|
+
bound = create !== void 0 && update !== void 0 && remove !== void 0 ? {
|
|
22
|
+
jsp_cfb8_create: create,
|
|
23
|
+
jsp_cfb8_update: update,
|
|
24
|
+
jsp_cfb8_delete: remove
|
|
25
|
+
} : null;
|
|
26
|
+
}
|
|
27
|
+
return bound ?? void 0;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* One direction of an AES-128-CFB8 stream, Java Edition's connection cipher, run in the native
|
|
31
|
+
* library's TLS library. It exists for Bun, whose `node:crypto` has no `aes-128-cfb8`; Node.js
|
|
32
|
+
* has its own.
|
|
33
|
+
*
|
|
34
|
+
* The native cipher holds its key and register until {@link Cfb8.close}, so the owner closes it
|
|
35
|
+
* when the connection ends.
|
|
36
|
+
*/
|
|
37
|
+
var Cfb8 = class Cfb8 {
|
|
38
|
+
symbols;
|
|
39
|
+
handle;
|
|
40
|
+
constructor(symbols, handle) {
|
|
41
|
+
this.symbols = symbols;
|
|
42
|
+
this.handle = handle;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether the native cipher is available: a build of the library for this machine loads and
|
|
46
|
+
* has it.
|
|
47
|
+
* @returns True when {@link Cfb8.create} returns a cipher.
|
|
48
|
+
*/
|
|
49
|
+
static available() {
|
|
50
|
+
return cfb8Symbols() !== void 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Starts one direction of a stream.
|
|
54
|
+
* @param direction - Which way the stream goes.
|
|
55
|
+
* @param key - The sixteen-byte AES-128 key.
|
|
56
|
+
* @param iv - The sixteen-byte initial register.
|
|
57
|
+
* @returns The cipher, or undefined when the library is missing or predates the cipher.
|
|
58
|
+
* @throws {NativeNetworkError} When the library refuses the key or the register.
|
|
59
|
+
*/
|
|
60
|
+
static create(direction, key, iv) {
|
|
61
|
+
const symbols = cfb8Symbols();
|
|
62
|
+
if (symbols === void 0) return void 0;
|
|
63
|
+
if (key.byteLength !== KEY_BYTES || iv.byteLength !== KEY_BYTES) throw new NativeNetworkErrors.Cfb8Failed({
|
|
64
|
+
what: "take a key that is not sixteen bytes",
|
|
65
|
+
result: -1
|
|
66
|
+
});
|
|
67
|
+
const handle = symbols.jsp_cfb8_create(key, iv, direction === "encrypt" ? 1 : 0);
|
|
68
|
+
if (handle < 0) throw new NativeNetworkErrors.Cfb8Failed({
|
|
69
|
+
what: "start",
|
|
70
|
+
result: handle
|
|
71
|
+
});
|
|
72
|
+
return new Cfb8(symbols, handle);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Runs the next bytes of the stream through the cipher.
|
|
76
|
+
* @param data - The bytes, which are left as they are.
|
|
77
|
+
* @returns The same number of bytes, encrypted or decrypted.
|
|
78
|
+
* @throws {NativeNetworkError} When the cipher was closed or the library fails.
|
|
79
|
+
*/
|
|
80
|
+
update(data) {
|
|
81
|
+
const out = Buffer.from(data);
|
|
82
|
+
if (out.byteLength === 0) return out;
|
|
83
|
+
const result = this.symbols.jsp_cfb8_update(this.handle, out, out.byteLength);
|
|
84
|
+
if (result < 0) throw new NativeNetworkErrors.Cfb8Failed({
|
|
85
|
+
what: "update",
|
|
86
|
+
result
|
|
87
|
+
});
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/** Frees the native cipher. Closing it again does nothing. */
|
|
91
|
+
close() {
|
|
92
|
+
if (this.handle < 0) return;
|
|
93
|
+
this.symbols.jsp_cfb8_delete(this.handle);
|
|
94
|
+
this.handle = -1;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
export { Cfb8 };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=Cfb8.js.map
|
package/dist/Cfb8.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cfb8.js","names":[],"sources":["../src/Cfb8.ts"],"sourcesContent":["import { NativeNetwork, openLibrary } from './NativeNetwork';\nimport type { NativeSymbols } from './ffi';\nimport { locateLibrary } from './library';\nimport { NativeNetworkErrors } from '@jsprismarine/errors/native-network';\n\n/** AES-128 takes a sixteen-byte key, and CFB8's register is one sixteen-byte block. */\nconst KEY_BYTES = 16;\n\n/** The cipher's three calls, which a library built before them lacks. */\ntype Cfb8Symbols = Required<Pick<NativeSymbols, 'jsp_cfb8_create' | 'jsp_cfb8_update' | 'jsp_cfb8_delete'>>;\n\n/** The library's cipher calls once looked up: bound, or null when there is no library that has them. */\nlet bound: Cfb8Symbols | null | undefined;\n\n/**\n * The cipher calls of the library this thread already loaded, else of the installed build,\n * bound once without opening an event queue, since a cipher needs none.\n * @returns The calls, or undefined when no library loads or the one that does predates them.\n */\nconst cfb8Symbols = (): Cfb8Symbols | undefined => {\n if (bound === undefined) {\n let symbols: NativeSymbols | undefined = NativeNetwork.loaded()?.symbols;\n if (symbols === undefined) {\n try {\n symbols = openLibrary(locateLibrary()).symbols;\n } catch {\n // No build for this machine, or one that does not load: the caller falls back.\n }\n }\n const { jsp_cfb8_create: create, jsp_cfb8_update: update, jsp_cfb8_delete: remove } = symbols ?? {};\n bound =\n create !== undefined && update !== undefined && remove !== undefined\n ? { jsp_cfb8_create: create, jsp_cfb8_update: update, jsp_cfb8_delete: remove }\n : null;\n }\n return bound ?? undefined;\n};\n\n/**\n * One direction of an AES-128-CFB8 stream, Java Edition's connection cipher, run in the native\n * library's TLS library. It exists for Bun, whose `node:crypto` has no `aes-128-cfb8`; Node.js\n * has its own.\n *\n * The native cipher holds its key and register until {@link Cfb8.close}, so the owner closes it\n * when the connection ends.\n */\nexport class Cfb8 {\n private handle: number;\n\n private constructor(\n private readonly symbols: Cfb8Symbols,\n handle: number\n ) {\n this.handle = handle;\n }\n\n /**\n * Whether the native cipher is available: a build of the library for this machine loads and\n * has it.\n * @returns True when {@link Cfb8.create} returns a cipher.\n */\n public static available(): boolean {\n return cfb8Symbols() !== undefined;\n }\n\n /**\n * Starts one direction of a stream.\n * @param direction - Which way the stream goes.\n * @param key - The sixteen-byte AES-128 key.\n * @param iv - The sixteen-byte initial register.\n * @returns The cipher, or undefined when the library is missing or predates the cipher.\n * @throws {NativeNetworkError} When the library refuses the key or the register.\n */\n public static create(direction: 'encrypt' | 'decrypt', key: Uint8Array, iv: Uint8Array): Cfb8 | undefined {\n const symbols = cfb8Symbols();\n if (symbols === undefined) return undefined;\n // The library reads sixteen bytes from each and cannot see a shorter buffer's end.\n if (key.byteLength !== KEY_BYTES || iv.byteLength !== KEY_BYTES)\n throw new NativeNetworkErrors.Cfb8Failed({ what: 'take a key that is not sixteen bytes', result: -1 });\n const handle = symbols.jsp_cfb8_create(key, iv, direction === 'encrypt' ? 1 : 0);\n if (handle < 0) throw new NativeNetworkErrors.Cfb8Failed({ what: 'start', result: handle });\n return new Cfb8(symbols, handle);\n }\n\n /**\n * Runs the next bytes of the stream through the cipher.\n * @param data - The bytes, which are left as they are.\n * @returns The same number of bytes, encrypted or decrypted.\n * @throws {NativeNetworkError} When the cipher was closed or the library fails.\n */\n public update(data: Uint8Array): Buffer {\n // A copy, which the library rewrites in place, so the caller's bytes stay theirs.\n const out = Buffer.from(data);\n // An FFI may pass an empty buffer as a null pointer, which the library refuses.\n if (out.byteLength === 0) return out;\n const result = this.symbols.jsp_cfb8_update(this.handle, out, out.byteLength);\n if (result < 0) throw new NativeNetworkErrors.Cfb8Failed({ what: 'update', result });\n return out;\n }\n\n /** Frees the native cipher. Closing it again does nothing. */\n public close(): void {\n if (this.handle < 0) return;\n this.symbols.jsp_cfb8_delete(this.handle);\n this.handle = -1;\n }\n}\n"],"mappings":";;;;;AAMA,IAAM,YAAY;;AAMlB,IAAI;;;;;;AAOJ,IAAM,oBAA6C;CAC/C,IAAI,UAAU,KAAA,GAAW;EACrB,IAAI,UAAqC,cAAc,OAAO,CAAC,EAAE;EACjE,IAAI,YAAY,KAAA,GACZ,IAAI;GACA,UAAU,YAAY,cAAc,CAAC,CAAC,CAAC;EAC3C,QAAQ,CAER;EAEJ,MAAM,EAAE,iBAAiB,QAAQ,iBAAiB,QAAQ,iBAAiB,WAAW,WAAW,CAAC;EAClG,QACI,WAAW,KAAA,KAAa,WAAW,KAAA,KAAa,WAAW,KAAA,IACrD;GAAE,iBAAiB;GAAQ,iBAAiB;GAAQ,iBAAiB;EAAO,IAC5E;CACd;CACA,OAAO,SAAS,KAAA;AACpB;;;;;;;;;AAUA,IAAa,OAAb,MAAa,KAAK;CAIO;CAHb;CAEA,YACa,SACjB,QACF;EAFmB,KAAA,UAAA;EAGjB,KAAK,SAAS;CAClB;;;;;;CAOA,OAAc,YAAqB;EAC/B,OAAO,YAAY,MAAM,KAAA;CAC7B;;;;;;;;;CAUA,OAAc,OAAO,WAAkC,KAAiB,IAAkC;EACtG,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,GAAW,OAAO,KAAA;EAElC,IAAI,IAAI,eAAe,aAAa,GAAG,eAAe,WAClD,MAAM,IAAI,oBAAoB,WAAW;GAAE,MAAM;GAAwC,QAAQ;EAAG,CAAC;EACzG,MAAM,SAAS,QAAQ,gBAAgB,KAAK,IAAI,cAAc,YAAY,IAAI,CAAC;EAC/E,IAAI,SAAS,GAAG,MAAM,IAAI,oBAAoB,WAAW;GAAE,MAAM;GAAS,QAAQ;EAAO,CAAC;EAC1F,OAAO,IAAI,KAAK,SAAS,MAAM;CACnC;;;;;;;CAQO,OAAO,MAA0B;EAEpC,MAAM,MAAM,OAAO,KAAK,IAAI;EAE5B,IAAI,IAAI,eAAe,GAAG,OAAO;EACjC,MAAM,SAAS,KAAK,QAAQ,gBAAgB,KAAK,QAAQ,KAAK,IAAI,UAAU;EAC5E,IAAI,SAAS,GAAG,MAAM,IAAI,oBAAoB,WAAW;GAAE,MAAM;GAAU;EAAO,CAAC;EACnF,OAAO;CACX;;CAGO,QAAc;EACjB,IAAI,KAAK,SAAS,GAAG;EACrB,KAAK,QAAQ,gBAAgB,KAAK,MAAM;EACxC,KAAK,SAAS;CAClB;AACJ"}
|
package/dist/NativeNetwork.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NativeSymbols } from './ffi.js';
|
|
1
|
+
import type { BoundLibrary, NativeSymbols } from './ffi.js';
|
|
2
2
|
/** The interface version this binding speaks; it must equal the library's `JSP_ABI_VERSION`. */
|
|
3
3
|
export declare const ABI_VERSION = 1;
|
|
4
4
|
/** Event kinds, as `native/include/jsp_native_network.h` numbers them. */
|
|
@@ -33,6 +33,13 @@ export type NativeEventHandler = (event: NativeEventRecord) => void;
|
|
|
33
33
|
* @returns Its UTF-8 bytes and a trailing NUL.
|
|
34
34
|
*/
|
|
35
35
|
export declare const cString: (text: string) => Buffer;
|
|
36
|
+
/**
|
|
37
|
+
* Binds the library and checks that it speaks this binding's interface.
|
|
38
|
+
* @param path - The shared library's file.
|
|
39
|
+
* @returns The bound library.
|
|
40
|
+
* @throws {NativeLibraryError} When the library does not load or speaks another interface.
|
|
41
|
+
*/
|
|
42
|
+
export declare const openLibrary: (path: string) => BoundLibrary;
|
|
36
43
|
/**
|
|
37
44
|
* The native library, loaded once per thread, and that thread's event queue.
|
|
38
45
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeNetwork.d.ts","sources":["../src/NativeNetwork.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"NativeNetwork.d.ts","sources":["../src/NativeNetwork.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAKzD,gGAAgG;AAChG,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,0EAA0E;AAC1E,eAAO,MAAM,WAAW;aACpB,WAAW,EAAE,CAAC;aACd,SAAS,EAAE,CAAC;aACZ,KAAK,EAAE,CAAC;aACR,SAAS,EAAE,CAAC;aACZ,WAAW,EAAE,CAAC;aACd,IAAI,EAAE,CAAC;aACP,MAAM,EAAE,CAAC;aACT,KAAK,EAAE,CAAC;aACR,OAAO,EAAE,CAAC;aACV,WAAW,EAAE,EAAE;aACf,QAAQ,EAAE,EAAE;aACZ,GAAG,EAAE,EAAE;CACD,CAAC;AAEX,4CAA4C;AAC5C,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,uEAAuE;AACvE,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAQpE;;;;GAIG;AACH,eAAO,MAAM,OAAO,SAAU,MAAM,KAAG,MAA0C,CAAC;AAElF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,YAuB1C,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,aAAa;IAelB,OAAO,CAAC,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IAED,uFAAuF;IACvF,OAAO,CAAC,IAAI;IAuBZ;;;OAGG;IACI,KAAK,IAAI,IAAI,CAMnB;IAED,OAAO,CAAC,QAAQ;CAOnB"}
|
package/dist/NativeNetwork.js
CHANGED
|
@@ -32,6 +32,36 @@ var INITIAL_READ_BYTES = 262144;
|
|
|
32
32
|
*/
|
|
33
33
|
var cString = (text) => Buffer.from(`${text}\0`, "utf8");
|
|
34
34
|
/**
|
|
35
|
+
* Binds the library and checks that it speaks this binding's interface.
|
|
36
|
+
* @param path - The shared library's file.
|
|
37
|
+
* @returns The bound library.
|
|
38
|
+
* @throws {NativeLibraryError} When the library does not load or speaks another interface.
|
|
39
|
+
*/
|
|
40
|
+
var openLibrary = (path) => {
|
|
41
|
+
let library;
|
|
42
|
+
try {
|
|
43
|
+
library = bindLibrary(path);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error instanceof NativeLibraryError) throw error;
|
|
46
|
+
throw new NativeNetworkErrors.LibraryDoesNotLoad({
|
|
47
|
+
path,
|
|
48
|
+
platform: process.platform,
|
|
49
|
+
arch: process.arch,
|
|
50
|
+
value: error instanceof Error ? error.message : String(error)
|
|
51
|
+
}, { cause: error });
|
|
52
|
+
}
|
|
53
|
+
const version = library.symbols.jsp_abi_version();
|
|
54
|
+
if (version !== 1) {
|
|
55
|
+
library.close();
|
|
56
|
+
throw new NativeNetworkErrors.LibraryInterfaceMismatch({
|
|
57
|
+
path,
|
|
58
|
+
version,
|
|
59
|
+
abiVersion: 1
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return library;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
35
65
|
* The native library, loaded once per thread, and that thread's event queue.
|
|
36
66
|
*
|
|
37
67
|
* The library is mapped once per process, and each thread that loads it opens a queue of its
|
|
@@ -74,28 +104,7 @@ var NativeNetwork = class NativeNetwork {
|
|
|
74
104
|
*/
|
|
75
105
|
static async load(options = {}) {
|
|
76
106
|
if (NativeNetwork.instance !== void 0) return NativeNetwork.instance;
|
|
77
|
-
const
|
|
78
|
-
let library;
|
|
79
|
-
try {
|
|
80
|
-
library = bindLibrary(path);
|
|
81
|
-
} catch (error) {
|
|
82
|
-
if (error instanceof NativeLibraryError) throw error;
|
|
83
|
-
throw new NativeNetworkErrors.LibraryDoesNotLoad({
|
|
84
|
-
path,
|
|
85
|
-
platform: process.platform,
|
|
86
|
-
arch: process.arch,
|
|
87
|
-
value: error instanceof Error ? error.message : String(error)
|
|
88
|
-
}, { cause: error });
|
|
89
|
-
}
|
|
90
|
-
const version = library.symbols.jsp_abi_version();
|
|
91
|
-
if (version !== 1) {
|
|
92
|
-
library.close();
|
|
93
|
-
throw new NativeNetworkErrors.LibraryInterfaceMismatch({
|
|
94
|
-
path,
|
|
95
|
-
version,
|
|
96
|
-
abiVersion: 1
|
|
97
|
-
});
|
|
98
|
-
}
|
|
107
|
+
const library = openLibrary(options.path ?? locateLibrary());
|
|
99
108
|
const socket = dgram.createSocket("udp4");
|
|
100
109
|
await new Promise((resolve, reject) => {
|
|
101
110
|
socket.once("error", reject);
|
|
@@ -219,6 +228,6 @@ var NativeNetwork = class NativeNetwork {
|
|
|
219
228
|
this.handlers.get(event.id)?.(event);
|
|
220
229
|
}
|
|
221
230
|
};
|
|
222
|
-
export { ABI_VERSION, NativeEvent, NativeNetwork, cString };
|
|
231
|
+
export { ABI_VERSION, NativeEvent, NativeNetwork, cString, openLibrary };
|
|
223
232
|
|
|
224
233
|
//# sourceMappingURL=NativeNetwork.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeNetwork.js","names":[],"sources":["../src/NativeNetwork.ts"],"sourcesContent":["import dgram from 'node:dgram';\n\nimport { bindLibrary } from './ffi';\nimport type { BoundLibrary, NativeSymbols } from './ffi';\nimport { locateLibrary } from './library';\nimport { NativeLibraryError } from '@jsprismarine/errors/native-library';\nimport { NativeNetworkErrors } from '@jsprismarine/errors/native-network';\n\n/** The interface version this binding speaks; it must equal the library's `JSP_ABI_VERSION`. */\nexport const ABI_VERSION = 1;\n\n/** Event kinds, as `native/include/jsp_native_network.h` numbers them. */\nexport const NativeEvent = {\n description: 1,\n candidate: 2,\n state: 3,\n gathering: 4,\n dataChannel: 5,\n open: 6,\n closed: 7,\n error: 8,\n message: 9,\n bufferedLow: 10,\n iceState: 11,\n log: 12\n} as const;\n\n/** One event read from the native queue. */\nexport interface NativeEventRecord {\n readonly kind: number;\n /** The peer connection or data channel the event is about. */\n readonly id: number;\n readonly value: number;\n /** A copy of the payload; it stays valid after the next read. */\n readonly payload: Buffer;\n}\n\n/** What receives the events of one peer connection or data channel. */\nexport type NativeEventHandler = (event: NativeEventRecord) => void;\n\n/** libdatachannel's warning level, from `rtc.h`: the log level a load asks for unless told otherwise. */\nconst LOG_WARNING = 3;\n\nconst EVENT_HEADER_BYTES = 16;\nconst INITIAL_READ_BYTES = 256 * 1024;\n\n/**\n * Encodes a string for the C interface, NUL-terminated.\n * @param text - The string.\n * @returns Its UTF-8 bytes and a trailing NUL.\n */\nexport const cString = (text: string): Buffer => Buffer.from(`${text}\\0`, 'utf8');\n\n/**\n * The native library, loaded once per thread, and that thread's event queue.\n *\n * The library is mapped once per process, and each thread that loads it opens a queue of its\n * own, so a worker's peer connections report to the worker. libdatachannel's threads queue\n * events in native memory and send one datagram to a loopback socket here when the queue stops\n * being empty. The socket's handler drains the queue and\n * dispatches each event to the handler registered for its id, so every event reaches JavaScript\n * on the event loop, in order, with no call from a foreign thread.\n */\nexport class NativeNetwork {\n private static instance: NativeNetwork | undefined;\n\n /** Wake datagrams received; a burst of events costs one. */\n public wakes = 0;\n\n private readonly handlers = new Map<number, NativeEventHandler>();\n private readBuffer = Buffer.allocUnsafe(INITIAL_READ_BYTES);\n private logHandler: ((level: number, line: string) => void) | undefined;\n /** Events {@link NativeNetwork.flushLog} read but held back, in order, for the next drain. */\n private deferred: NativeEventRecord[] = [];\n /** Things that keep the process alive while they are open, such as a connection being made. */\n private holds = 0;\n\n private constructor(\n private readonly library: BoundLibrary,\n private readonly wakeSocket: dgram.Socket,\n /** The handle of this thread's event queue, which peer connections are created on. */\n public readonly queue: number\n ) {\n wakeSocket.on('message', () => {\n this.wakes++;\n this.drain();\n });\n wakeSocket.unref();\n }\n\n /**\n * Loads the library and opens this thread's event queue, the first time it is called on a thread.\n * @param options - The library file and log level; the defaults find the installed build and\n * log warnings and worse. libdatachannel takes the level once per process, from the first load.\n * @returns The loaded library.\n * @throws {NativeLibraryError} When the library cannot be found, loaded, or speaks another interface.\n */\n public static async load(options: { path?: string; logLevel?: number } = {}): Promise<NativeNetwork> {\n if (NativeNetwork.instance !== undefined) return NativeNetwork.instance;\n const path = options.path ?? locateLibrary();\n let library: BoundLibrary;\n try {\n library = bindLibrary(path);\n } catch (error: unknown) {\n // A runtime without an FFI already says what it needs.\n if (error instanceof NativeLibraryError) throw error;\n throw new NativeNetworkErrors.LibraryDoesNotLoad(\n {\n path,\n platform: process.platform,\n arch: process.arch,\n value: error instanceof Error ? error.message : String(error)\n },\n { cause: error }\n );\n }\n const version = library.symbols.jsp_abi_version();\n if (version !== ABI_VERSION) {\n library.close();\n throw new NativeNetworkErrors.LibraryInterfaceMismatch({\n path,\n version,\n abiVersion: ABI_VERSION\n });\n }\n\n const socket = dgram.createSocket('udp4');\n await new Promise<void>((resolve, reject) => {\n socket.once('error', reject);\n socket.bind(0, '127.0.0.1', () => {\n socket.off('error', reject);\n resolve();\n });\n });\n const opened = library.symbols.jsp_events_open(socket.address().port, options.logLevel ?? LOG_WARNING);\n if (opened < 0) {\n socket.close();\n library.close();\n throw new NativeNetworkErrors.EventQueueNotOpened({ opened });\n }\n NativeNetwork.instance = new NativeNetwork(library, socket, opened);\n return NativeNetwork.instance;\n }\n\n /** The loaded library, or undefined before {@link NativeNetwork.load}. */\n public static loaded(): NativeNetwork | undefined {\n return NativeNetwork.instance;\n }\n\n /** The bound C interface. */\n public get symbols(): NativeSymbols {\n return this.library.symbols;\n }\n\n /**\n * The address of shared memory, for an interface call that takes a pointer.\n * @param memory - The memory; it must outlive every native use of the pointer.\n * @returns The pointer.\n */\n public pointerOf(memory: SharedArrayBuffer): bigint | number {\n return this.library.pointerOf(memory);\n }\n\n /**\n * Sends the events of one id to a handler, until {@link NativeNetwork.unwatch}.\n * @param id - The peer connection or data channel.\n * @param handler - Receives its events in order.\n */\n public watch(id: number, handler: NativeEventHandler): void {\n this.handlers.set(id, handler);\n }\n\n /**\n * Stops sending an id's events anywhere.\n * @param id - The peer connection or data channel.\n */\n public unwatch(id: number): void {\n this.handlers.delete(id);\n }\n\n /**\n * Receives libdatachannel's log lines, when the library was loaded with a log level.\n * @param handler - Receives each line and its level.\n */\n public onLog(handler: (level: number, line: string) => void): void {\n this.logHandler = handler;\n }\n\n /** Keeps the process alive until the matching {@link NativeNetwork.release}. */\n public hold(): void {\n if (this.holds++ === 0) this.wakeSocket.ref();\n }\n\n /** Lets the process exit once nothing holds it. */\n public release(): void {\n if (this.holds > 0 && --this.holds === 0) this.wakeSocket.unref();\n }\n\n /** Reads every queued event and dispatches it; a read that finds the queue empty rearms the wake. */\n public drain(): void {\n for (const event of this.deferred.splice(0)) this.dispatch(event);\n this.read((event) => this.dispatch(event));\n }\n\n /**\n * Hands every queued log line to the log handler now, and keeps the other events, in order,\n * for the next turn of the event loop. A call that failed reads the lines it logged this way\n * without running another handler in the middle of its own failure.\n */\n public flushLog(): void {\n const waiting = this.deferred.length > 0;\n this.read((event) => {\n if (event.kind === NativeEvent.log) this.dispatch(event);\n else this.deferred.push(event);\n });\n if (!waiting && this.deferred.length > 0) setImmediate(() => this.drain());\n }\n\n /** Reads the queue until it is empty, which rearms the wake, passing each event on. */\n private read(receive: (event: NativeEventRecord) => void): void {\n for (;;) {\n const written = this.symbols.jsp_events_read(this.queue, this.readBuffer, this.readBuffer.byteLength);\n if (written === 0) return;\n if (written < 0) {\n this.readBuffer = Buffer.allocUnsafe(Math.max(-written, this.readBuffer.byteLength * 2));\n continue;\n }\n let offset = 0;\n while (offset < written) {\n const length = this.readBuffer.readUInt32LE(offset);\n const event: NativeEventRecord = {\n kind: this.readBuffer[offset + 4]!,\n id: this.readBuffer.readInt32LE(offset + 8),\n value: this.readBuffer.readInt32LE(offset + 12),\n payload: Buffer.from(this.readBuffer.subarray(offset + EVENT_HEADER_BYTES, offset + length))\n };\n offset += length;\n receive(event);\n }\n }\n }\n\n /**\n * Closes this thread's peer connections and its event queue. The library stays mapped, and\n * another thread's connections and the shared ports are not touched.\n */\n public close(): void {\n this.symbols.jsp_events_close(this.queue);\n this.handlers.clear();\n this.deferred = [];\n this.wakeSocket.close();\n NativeNetwork.instance = undefined;\n }\n\n private dispatch(event: NativeEventRecord): void {\n if (event.kind === NativeEvent.log) {\n this.logHandler?.(event.value, event.payload.toString('utf8'));\n return;\n }\n this.handlers.get(event.id)?.(event);\n }\n}\n"],"mappings":";;;;;;;AASA,IAAa,cAAc;;AAG3B,IAAa,cAAc;CACvB,aAAa;CACb,WAAW;CACX,OAAO;CACP,WAAW;CACX,aAAa;CACb,MAAM;CACN,QAAQ;CACR,OAAO;CACP,SAAS;CACT,aAAa;CACb,UAAU;CACV,KAAK;AACT;;AAgBA,IAAM,cAAc;AAEpB,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;;;;;;AAO3B,IAAa,WAAW,SAAyB,OAAO,KAAK,GAAG,KAAK,KAAK,MAAM;;;;;;;;;;;AAYhF,IAAa,gBAAb,MAAa,cAAc;CAeF;CACA;CAED;CAjBpB,OAAe;;CAGR,QAAQ;CAEE,2BAAW,IAAI,IAAgC;CACxD,aAAa,OAAO,YAAY,kBAAkB;CAClD;;CAEA,WAAgC,CAAC;;CAEjC,QAAQ;CAER,YACa,SACA,YAED,OAClB;EAJmB,KAAA,UAAA;EACA,KAAA,aAAA;EAED,KAAA,QAAA;EAEhB,WAAW,GAAG,iBAAiB;GAC3B,KAAK;GACL,KAAK,MAAM;EACf,CAAC;EACD,WAAW,MAAM;CACrB;;;;;;;;CASA,aAAoB,KAAK,UAAgD,CAA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MAAM,CAAC;IAC/F;IACA,UAAU;IACV,QAAQ,KAAK;GACjB;EACJ;CACJ;;;;;CAMO,QAAc;EACjB,KAAK,QAAQ,iBAAiB,KAAK,KAAK;EACxC,KAAK,SAAS,MAAM;EACpB,KAAK,WAAW,CAAC;EACjB,KAAK,WAAW,MAAM;EACtB,cAAc,WAAW,KAAA;CAC7B;CAEQ,SAAS,OAAgC;EAC7C,IAAI,MAAM,SAAS,YAAY,KAAK;GAChC,KAAK,aAAa,MAAM,OAAO,MAAM,QAAQ,SAAS,MAAM,CAAC;GAC7D;EACJ;EACA,KAAK,SAAS,IAAI,MAAM,EAAE,CAAC,GAAG,KAAK;CACvC;AACJ"}
|
|
1
|
+
{"version":3,"file":"NativeNetwork.js","names":[],"sources":["../src/NativeNetwork.ts"],"sourcesContent":["import dgram from 'node:dgram';\n\nimport { bindLibrary } from './ffi';\nimport type { BoundLibrary, NativeSymbols } from './ffi';\nimport { locateLibrary } from './library';\nimport { NativeLibraryError } from '@jsprismarine/errors/native-library';\nimport { NativeNetworkErrors } from '@jsprismarine/errors/native-network';\n\n/** The interface version this binding speaks; it must equal the library's `JSP_ABI_VERSION`. */\nexport const ABI_VERSION = 1;\n\n/** Event kinds, as `native/include/jsp_native_network.h` numbers them. */\nexport const NativeEvent = {\n description: 1,\n candidate: 2,\n state: 3,\n gathering: 4,\n dataChannel: 5,\n open: 6,\n closed: 7,\n error: 8,\n message: 9,\n bufferedLow: 10,\n iceState: 11,\n log: 12\n} as const;\n\n/** One event read from the native queue. */\nexport interface NativeEventRecord {\n readonly kind: number;\n /** The peer connection or data channel the event is about. */\n readonly id: number;\n readonly value: number;\n /** A copy of the payload; it stays valid after the next read. */\n readonly payload: Buffer;\n}\n\n/** What receives the events of one peer connection or data channel. */\nexport type NativeEventHandler = (event: NativeEventRecord) => void;\n\n/** libdatachannel's warning level, from `rtc.h`: the log level a load asks for unless told otherwise. */\nconst LOG_WARNING = 3;\n\nconst EVENT_HEADER_BYTES = 16;\nconst INITIAL_READ_BYTES = 256 * 1024;\n\n/**\n * Encodes a string for the C interface, NUL-terminated.\n * @param text - The string.\n * @returns Its UTF-8 bytes and a trailing NUL.\n */\nexport const cString = (text: string): Buffer => Buffer.from(`${text}\\0`, 'utf8');\n\n/**\n * Binds the library and checks that it speaks this binding's interface.\n * @param path - The shared library's file.\n * @returns The bound library.\n * @throws {NativeLibraryError} When the library does not load or speaks another interface.\n */\nexport const openLibrary = (path: string): BoundLibrary => {\n let library: BoundLibrary;\n try {\n library = bindLibrary(path);\n } catch (error: unknown) {\n // A runtime without an FFI already says what it needs.\n if (error instanceof NativeLibraryError) throw error;\n throw new NativeNetworkErrors.LibraryDoesNotLoad(\n {\n path,\n platform: process.platform,\n arch: process.arch,\n value: error instanceof Error ? error.message : String(error)\n },\n { cause: error }\n );\n }\n const version = library.symbols.jsp_abi_version();\n if (version !== ABI_VERSION) {\n library.close();\n throw new NativeNetworkErrors.LibraryInterfaceMismatch({ path, version, abiVersion: ABI_VERSION });\n }\n return library;\n};\n\n/**\n * The native library, loaded once per thread, and that thread's event queue.\n *\n * The library is mapped once per process, and each thread that loads it opens a queue of its\n * own, so a worker's peer connections report to the worker. libdatachannel's threads queue\n * events in native memory and send one datagram to a loopback socket here when the queue stops\n * being empty. The socket's handler drains the queue and\n * dispatches each event to the handler registered for its id, so every event reaches JavaScript\n * on the event loop, in order, with no call from a foreign thread.\n */\nexport class NativeNetwork {\n private static instance: NativeNetwork | undefined;\n\n /** Wake datagrams received; a burst of events costs one. */\n public wakes = 0;\n\n private readonly handlers = new Map<number, NativeEventHandler>();\n private readBuffer = Buffer.allocUnsafe(INITIAL_READ_BYTES);\n private logHandler: ((level: number, line: string) => void) | undefined;\n /** Events {@link NativeNetwork.flushLog} read but held back, in order, for the next drain. */\n private deferred: NativeEventRecord[] = [];\n /** Things that keep the process alive while they are open, such as a connection being made. */\n private holds = 0;\n\n private constructor(\n private readonly library: BoundLibrary,\n private readonly wakeSocket: dgram.Socket,\n /** The handle of this thread's event queue, which peer connections are created on. */\n public readonly queue: number\n ) {\n wakeSocket.on('message', () => {\n this.wakes++;\n this.drain();\n });\n wakeSocket.unref();\n }\n\n /**\n * Loads the library and opens this thread's event queue, the first time it is called on a thread.\n * @param options - The library file and log level; the defaults find the installed build and\n * log warnings and worse. libdatachannel takes the level once per process, from the first load.\n * @returns The loaded library.\n * @throws {NativeLibraryError} When the library cannot be found, loaded, or speaks another interface.\n */\n public static async load(options: { path?: string; logLevel?: number } = {}): Promise<NativeNetwork> {\n if (NativeNetwork.instance !== undefined) return NativeNetwork.instance;\n const path = options.path ?? locateLibrary();\n const library = openLibrary(path);\n\n const socket = dgram.createSocket('udp4');\n await new Promise<void>((resolve, reject) => {\n socket.once('error', reject);\n socket.bind(0, '127.0.0.1', () => {\n socket.off('error', reject);\n resolve();\n });\n });\n const opened = library.symbols.jsp_events_open(socket.address().port, options.logLevel ?? LOG_WARNING);\n if (opened < 0) {\n socket.close();\n library.close();\n throw new NativeNetworkErrors.EventQueueNotOpened({ opened });\n }\n NativeNetwork.instance = new NativeNetwork(library, socket, opened);\n return NativeNetwork.instance;\n }\n\n /** The loaded library, or undefined before {@link NativeNetwork.load}. */\n public static loaded(): NativeNetwork | undefined {\n return NativeNetwork.instance;\n }\n\n /** The bound C interface. */\n public get symbols(): NativeSymbols {\n return this.library.symbols;\n }\n\n /**\n * The address of shared memory, for an interface call that takes a pointer.\n * @param memory - The memory; it must outlive every native use of the pointer.\n * @returns The pointer.\n */\n public pointerOf(memory: SharedArrayBuffer): bigint | number {\n return this.library.pointerOf(memory);\n }\n\n /**\n * Sends the events of one id to a handler, until {@link NativeNetwork.unwatch}.\n * @param id - The peer connection or data channel.\n * @param handler - Receives its events in order.\n */\n public watch(id: number, handler: NativeEventHandler): void {\n this.handlers.set(id, handler);\n }\n\n /**\n * Stops sending an id's events anywhere.\n * @param id - The peer connection or data channel.\n */\n public unwatch(id: number): void {\n this.handlers.delete(id);\n }\n\n /**\n * Receives libdatachannel's log lines, when the library was loaded with a log level.\n * @param handler - Receives each line and its level.\n */\n public onLog(handler: (level: number, line: string) => void): void {\n this.logHandler = handler;\n }\n\n /** Keeps the process alive until the matching {@link NativeNetwork.release}. */\n public hold(): void {\n if (this.holds++ === 0) this.wakeSocket.ref();\n }\n\n /** Lets the process exit once nothing holds it. */\n public release(): void {\n if (this.holds > 0 && --this.holds === 0) this.wakeSocket.unref();\n }\n\n /** Reads every queued event and dispatches it; a read that finds the queue empty rearms the wake. */\n public drain(): void {\n for (const event of this.deferred.splice(0)) this.dispatch(event);\n this.read((event) => this.dispatch(event));\n }\n\n /**\n * Hands every queued log line to the log handler now, and keeps the other events, in order,\n * for the next turn of the event loop. A call that failed reads the lines it logged this way\n * without running another handler in the middle of its own failure.\n */\n public flushLog(): void {\n const waiting = this.deferred.length > 0;\n this.read((event) => {\n if (event.kind === NativeEvent.log) this.dispatch(event);\n else this.deferred.push(event);\n });\n if (!waiting && this.deferred.length > 0) setImmediate(() => this.drain());\n }\n\n /** Reads the queue until it is empty, which rearms the wake, passing each event on. */\n private read(receive: (event: NativeEventRecord) => void): void {\n for (;;) {\n const written = this.symbols.jsp_events_read(this.queue, this.readBuffer, this.readBuffer.byteLength);\n if (written === 0) return;\n if (written < 0) {\n this.readBuffer = Buffer.allocUnsafe(Math.max(-written, this.readBuffer.byteLength * 2));\n continue;\n }\n let offset = 0;\n while (offset < written) {\n const length = this.readBuffer.readUInt32LE(offset);\n const event: NativeEventRecord = {\n kind: this.readBuffer[offset + 4]!,\n id: this.readBuffer.readInt32LE(offset + 8),\n value: this.readBuffer.readInt32LE(offset + 12),\n payload: Buffer.from(this.readBuffer.subarray(offset + EVENT_HEADER_BYTES, offset + length))\n };\n offset += length;\n receive(event);\n }\n }\n }\n\n /**\n * Closes this thread's peer connections and its event queue. The library stays mapped, and\n * another thread's connections and the shared ports are not touched.\n */\n public close(): void {\n this.symbols.jsp_events_close(this.queue);\n this.handlers.clear();\n this.deferred = [];\n this.wakeSocket.close();\n NativeNetwork.instance = undefined;\n }\n\n private dispatch(event: NativeEventRecord): void {\n if (event.kind === NativeEvent.log) {\n this.logHandler?.(event.value, event.payload.toString('utf8'));\n return;\n }\n this.handlers.get(event.id)?.(event);\n }\n}\n"],"mappings":";;;;;;;AASA,IAAa,cAAc;;AAG3B,IAAa,cAAc;CACvB,aAAa;CACb,WAAW;CACX,OAAO;CACP,WAAW;CACX,aAAa;CACb,MAAM;CACN,QAAQ;CACR,OAAO;CACP,SAAS;CACT,aAAa;CACb,UAAU;CACV,KAAK;AACT;;AAgBA,IAAM,cAAc;AAEpB,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;;;;;;AAO3B,IAAa,WAAW,SAAyB,OAAO,KAAK,GAAG,KAAK,KAAK,MAAM;;;;;;;AAQhF,IAAa,eAAe,SAA+B;CACvD,IAAI;CACJ,IAAI;EACA,UAAU,YAAY,IAAI;CAC9B,SAAS,OAAgB;EAErB,IAAI,iBAAiB,oBAAoB,MAAM;EAC/C,MAAM,IAAI,oBAAoB,mBAC1B;GACI;GACA,UAAU,QAAQ;GAClB,MAAM,QAAQ;GACd,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAChE,GACA,EAAE,OAAO,MAAM,CACnB;CACJ;CACA,MAAM,UAAU,QAAQ,QAAQ,gBAAgB;CAChD,IAAI,YAAA,GAAyB;EACzB,QAAQ,MAAM;EACd,MAAM,IAAI,oBAAoB,yBAAyB;GAAE;GAAM;GAAS,YAAA;EAAwB,CAAC;CACrG;CACA,OAAO;AACX;;;;;;;;;;;AAYA,IAAa,gBAAb,MAAa,cAAc;CAeF;CACA;CAED;CAjBpB,OAAe;;CAGR,QAAQ;CAEE,2BAAW,IAAI,IAAgC;CACxD,aAAa,OAAO,YAAY,kBAAkB;CAClD;;CAEA,WAAgC,CAAC;;CAEjC,QAAQ;CAER,YACa,SACA,YAED,OAClB;EAJmB,KAAA,UAAA;EACA,KAAA,aAAA;EAED,KAAA,QAAA;EAEhB,WAAW,GAAG,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AAO,MAAM,QAAQ,SAAS,MAAM,CAAC;GAC7D;EACJ;EACA,KAAK,SAAS,IAAI,MAAM,EAAE,CAAC,GAAG,KAAK;CACvC;AACJ"}
|
package/dist/ffi.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export interface NativeSymbols {
|
|
|
34
34
|
jsp_mux_detach(handle: number, family: number): number;
|
|
35
35
|
jsp_mux_close(handle: number): number;
|
|
36
36
|
jsp_mux_stats(handle: number, out: Uint8Array, count: number): number;
|
|
37
|
+
/** The CFB8 cipher; missing from a library built before it, like `jsp_pc_round_trip_time`. */
|
|
38
|
+
jsp_cfb8_create?(key: Uint8Array, iv: Uint8Array, encrypt: number): number;
|
|
39
|
+
jsp_cfb8_update?(cipher: number, data: Uint8Array, size: number): number;
|
|
40
|
+
jsp_cfb8_delete?(cipher: number): number;
|
|
37
41
|
}
|
|
38
42
|
/** A bound library, and how to take a pointer to shared memory for it. */
|
|
39
43
|
export type BoundLibrary = BoundNative<NativeSymbols>;
|
package/dist/ffi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ffi.d.ts","sources":["../src/ffi.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAgB,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEjG,6FAA6F;AAC7F,MAAM,WAAW,aAAa;IAC1B,eAAe,IAAI,MAAM,CAAC;IAC1B,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5D,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACzE,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,WAAW,IAAI,IAAI,CAAC;IACpB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,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jsp_cfb8_create: ["i32", [
|
|
86
|
+
"buffer",
|
|
87
|
+
"buffer",
|
|
88
|
+
"i32"
|
|
89
|
+
]],
|
|
90
|
+
jsp_cfb8_update: ["i32", [
|
|
91
|
+
"i32",
|
|
92
|
+
"buffer",
|
|
93
|
+
"i32"
|
|
94
|
+
]],
|
|
95
|
+
jsp_cfb8_delete: ["i32", ["i32"]]
|
|
85
96
|
};
|
|
86
97
|
/**
|
|
87
98
|
* Symbols a library built from older sources lacks. Such a build stays loadable, because an
|
|
88
99
|
* install keeps the published one until the manifest points at a newer one, and the binding
|
|
89
100
|
* leaves each symbol it lacks undefined.
|
|
90
101
|
*/
|
|
91
|
-
var optionalSymbols = /* @__PURE__ */ new Set([
|
|
102
|
+
var optionalSymbols = /* @__PURE__ */ new Set([
|
|
103
|
+
"jsp_pc_round_trip_time",
|
|
104
|
+
"jsp_cfb8_create",
|
|
105
|
+
"jsp_cfb8_update",
|
|
106
|
+
"jsp_cfb8_delete"
|
|
107
|
+
]);
|
|
92
108
|
/**
|
|
93
109
|
* Opens the library with the running runtime's FFI.
|
|
94
110
|
* @param path - The shared library's file.
|
package/dist/ffi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ffi.js","names":[],"sources":["../src/ffi.ts"],"sourcesContent":["/**\n * Binds the library's flat C interface (`native/include/jsp_native_network.h`) through the\n * runtime's own FFI, `node:ffi` under Node.js and `bun:ffi` under Bun, with\n * `@jsprismarine/native-library`'s binder. Every call is synchronous and nothing calls back, so\n * neither FFI has to carry a call from a foreign thread.\n */\n\nimport { bindNative } from '@jsprismarine/native-library/ffi';\nimport type { BoundNative, FfiSignature, NativePointer } from '@jsprismarine/native-library/ffi';\n\n/** The C interface, one method per exported function. Strings are NUL-terminated buffers. */\nexport interface NativeSymbols {\n jsp_abi_version(): number;\n jsp_events_open(wakePort: number, logLevel: number): number;\n jsp_events_read(queue: number, buffer: Uint8Array, size: number): number;\n jsp_events_close(queue: number): void;\n jsp_cleanup(): void;\n jsp_classify(data: Uint8Array, size: number): number;\n jsp_pc_create(\n queue: number,\n bindAddress: Uint8Array,\n iceServers: Uint8Array,\n portBegin: number,\n portEnd: number,\n enableIceUdpMux: number,\n maxMessageSize: number\n ): number;\n jsp_pc_set_remote_description(pc: number, sdp: Uint8Array, type: Uint8Array): number;\n jsp_pc_set_local_description(pc: number, type: Uint8Array): number;\n jsp_pc_add_remote_candidate(pc: number, candidate: Uint8Array, mid: Uint8Array): number;\n jsp_pc_local_description(pc: number, buffer: Uint8Array, size: number): number;\n jsp_pc_selected_pair(pc: number, buffer: Uint8Array, size: number): number;\n /** Missing from a library built before it, which `bindLibrary` still loads. */\n jsp_pc_round_trip_time?(pc: number): number;\n jsp_pc_close(pc: number): number;\n jsp_pc_delete(pc: number): number;\n jsp_dc_create(pc: number, label: Uint8Array, unordered: number, maxRetransmits: number): number;\n jsp_dc_send(dc: number, data: Uint8Array, size: number): number;\n jsp_dc_buffered_amount(dc: number): number;\n jsp_dc_set_buffered_amount_low_threshold(dc: number, amount: number): number;\n jsp_dc_close(dc: number): number;\n jsp_dc_delete(dc: number): number;\n jsp_mux_open(bindAddress: Uint8Array, port: number): number;\n jsp_mux_attach(\n handle: number,\n family: number,\n inbound: NativePointer,\n inboundSize: number,\n outbound: NativePointer,\n outboundSize: number,\n wakePort: number\n ): number;\n jsp_mux_detach(handle: number, family: number): number;\n jsp_mux_close(handle: number): number;\n jsp_mux_stats(handle: number, out: Uint8Array, count: number): number;\n}\n\n/** A bound library, and how to take a pointer to shared memory for it. */\nexport type BoundLibrary = BoundNative<NativeSymbols>;\n\nconst signatures: { readonly [Name in keyof NativeSymbols]-?: FfiSignature } = {\n jsp_abi_version: ['i32', []],\n jsp_events_open: ['i32', ['i32', 'i32']],\n jsp_events_read: ['i32', ['i32', 'buffer', 'i32']],\n jsp_events_close: ['void', ['i32']],\n jsp_cleanup: ['void', []],\n jsp_classify: ['i32', ['buffer', 'i32']],\n jsp_pc_create: ['i32', ['i32', 'buffer', 'buffer', 'i32', 'i32', 'i32', 'i32']],\n jsp_pc_set_remote_description: ['i32', ['i32', 'buffer', 'buffer']],\n jsp_pc_set_local_description: ['i32', ['i32', 'buffer']],\n jsp_pc_add_remote_candidate: ['i32', ['i32', 'buffer', 'buffer']],\n jsp_pc_local_description: ['i32', ['i32', 'buffer', 'i32']],\n jsp_pc_selected_pair: ['i32', ['i32', 'buffer', 'i32']],\n jsp_pc_round_trip_time: ['i32', ['i32']],\n jsp_pc_close: ['i32', ['i32']],\n jsp_pc_delete: ['i32', ['i32']],\n jsp_dc_create: ['i32', ['i32', 'buffer', 'i32', 'i32']],\n jsp_dc_send: ['i32', ['i32', 'buffer', 'i32']],\n jsp_dc_buffered_amount: ['i32', ['i32']],\n jsp_dc_set_buffered_amount_low_threshold: ['i32', ['i32', 'i32']],\n jsp_dc_close: ['i32', ['i32']],\n jsp_dc_delete: ['i32', ['i32']],\n jsp_mux_open: ['i32', ['buffer', 'i32']],\n jsp_mux_attach: ['i32', ['i32', 'i32', 'pointer', 'i32', 'pointer', 'i32', 'i32']],\n jsp_mux_detach: ['i32', ['i32', 'i32']],\n jsp_mux_close: ['i32', ['i32']],\n jsp_mux_stats: ['i32', ['i32', 'buffer', 'i32']]\n};\n\n/**\n * Symbols a library built from older sources lacks. Such a build stays loadable, because an\n * install keeps the published one until the manifest points at a newer one, and the binding\n * leaves each symbol it lacks undefined.\n */\nconst optionalSymbols: ReadonlySet<string> = new Set(['jsp_pc_round_trip_time'] satisfies (keyof NativeSymbols)[]);\n\n/**\n * Opens the library with the running runtime's FFI.\n * @param path - The shared library's file.\n * @returns The bound library.\n * @throws {NativeLibraryError} When Node.js has no `node:ffi`.\n * @throws {Error} When the library does not load.\n */\nexport const bindLibrary = (path: string): BoundLibrary => bindNative<NativeSymbols>(path, signatures, optionalSymbols);\n"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"ffi.js","names":[],"sources":["../src/ffi.ts"],"sourcesContent":["/**\n * Binds the library's flat C interface (`native/include/jsp_native_network.h`) through the\n * runtime's own FFI, `node:ffi` under Node.js and `bun:ffi` under Bun, with\n * `@jsprismarine/native-library`'s binder. Every call is synchronous and nothing calls back, so\n * neither FFI has to carry a call from a foreign thread.\n */\n\nimport { bindNative } from '@jsprismarine/native-library/ffi';\nimport type { BoundNative, FfiSignature, NativePointer } from '@jsprismarine/native-library/ffi';\n\n/** The C interface, one method per exported function. Strings are NUL-terminated buffers. */\nexport interface NativeSymbols {\n jsp_abi_version(): number;\n jsp_events_open(wakePort: number, logLevel: number): number;\n jsp_events_read(queue: number, buffer: Uint8Array, size: number): number;\n jsp_events_close(queue: number): void;\n jsp_cleanup(): void;\n jsp_classify(data: Uint8Array, size: number): number;\n jsp_pc_create(\n queue: number,\n bindAddress: Uint8Array,\n iceServers: Uint8Array,\n portBegin: number,\n portEnd: number,\n enableIceUdpMux: number,\n maxMessageSize: number\n ): number;\n jsp_pc_set_remote_description(pc: number, sdp: Uint8Array, type: Uint8Array): number;\n jsp_pc_set_local_description(pc: number, type: Uint8Array): number;\n jsp_pc_add_remote_candidate(pc: number, candidate: Uint8Array, mid: Uint8Array): number;\n jsp_pc_local_description(pc: number, buffer: Uint8Array, size: number): number;\n jsp_pc_selected_pair(pc: number, buffer: Uint8Array, size: number): number;\n /** Missing from a library built before it, which `bindLibrary` still loads. */\n jsp_pc_round_trip_time?(pc: number): number;\n jsp_pc_close(pc: number): number;\n jsp_pc_delete(pc: number): number;\n jsp_dc_create(pc: number, label: Uint8Array, unordered: number, maxRetransmits: number): number;\n jsp_dc_send(dc: number, data: Uint8Array, size: number): number;\n jsp_dc_buffered_amount(dc: number): number;\n jsp_dc_set_buffered_amount_low_threshold(dc: number, amount: number): number;\n jsp_dc_close(dc: number): number;\n jsp_dc_delete(dc: number): number;\n jsp_mux_open(bindAddress: Uint8Array, port: number): number;\n jsp_mux_attach(\n handle: number,\n family: number,\n inbound: NativePointer,\n inboundSize: number,\n outbound: NativePointer,\n outboundSize: number,\n wakePort: number\n ): number;\n jsp_mux_detach(handle: number, family: number): number;\n jsp_mux_close(handle: number): number;\n jsp_mux_stats(handle: number, out: Uint8Array, count: number): number;\n /** The CFB8 cipher; missing from a library built before it, like `jsp_pc_round_trip_time`. */\n jsp_cfb8_create?(key: Uint8Array, iv: Uint8Array, encrypt: number): number;\n jsp_cfb8_update?(cipher: number, data: Uint8Array, size: number): number;\n jsp_cfb8_delete?(cipher: number): number;\n}\n\n/** A bound library, and how to take a pointer to shared memory for it. */\nexport type BoundLibrary = BoundNative<NativeSymbols>;\n\nconst signatures: { readonly [Name in keyof NativeSymbols]-?: FfiSignature } = {\n jsp_abi_version: ['i32', []],\n jsp_events_open: ['i32', ['i32', 'i32']],\n jsp_events_read: ['i32', ['i32', 'buffer', 'i32']],\n jsp_events_close: ['void', ['i32']],\n jsp_cleanup: ['void', []],\n jsp_classify: ['i32', ['buffer', 'i32']],\n jsp_pc_create: ['i32', ['i32', 'buffer', 'buffer', 'i32', 'i32', 'i32', 'i32']],\n jsp_pc_set_remote_description: ['i32', ['i32', 'buffer', 'buffer']],\n jsp_pc_set_local_description: ['i32', ['i32', 'buffer']],\n jsp_pc_add_remote_candidate: ['i32', ['i32', 'buffer', 'buffer']],\n jsp_pc_local_description: ['i32', ['i32', 'buffer', 'i32']],\n jsp_pc_selected_pair: ['i32', ['i32', 'buffer', 'i32']],\n jsp_pc_round_trip_time: ['i32', ['i32']],\n jsp_pc_close: ['i32', ['i32']],\n jsp_pc_delete: ['i32', ['i32']],\n jsp_dc_create: ['i32', ['i32', 'buffer', 'i32', 'i32']],\n jsp_dc_send: ['i32', ['i32', 'buffer', 'i32']],\n jsp_dc_buffered_amount: ['i32', ['i32']],\n jsp_dc_set_buffered_amount_low_threshold: ['i32', ['i32', 'i32']],\n jsp_dc_close: ['i32', ['i32']],\n jsp_dc_delete: ['i32', ['i32']],\n jsp_mux_open: ['i32', ['buffer', 'i32']],\n jsp_mux_attach: ['i32', ['i32', 'i32', 'pointer', 'i32', 'pointer', 'i32', 'i32']],\n jsp_mux_detach: ['i32', ['i32', 'i32']],\n jsp_mux_close: ['i32', ['i32']],\n jsp_mux_stats: ['i32', ['i32', 'buffer', 'i32']],\n jsp_cfb8_create: ['i32', ['buffer', 'buffer', 'i32']],\n jsp_cfb8_update: ['i32', ['i32', 'buffer', 'i32']],\n jsp_cfb8_delete: ['i32', ['i32']]\n};\n\n/**\n * Symbols a library built from older sources lacks. Such a build stays loadable, because an\n * install keeps the published one until the manifest points at a newer one, and the binding\n * leaves each symbol it lacks undefined.\n */\nconst optionalSymbols: ReadonlySet<string> = new Set([\n 'jsp_pc_round_trip_time',\n 'jsp_cfb8_create',\n 'jsp_cfb8_update',\n 'jsp_cfb8_delete'\n] satisfies (keyof NativeSymbols)[]);\n\n/**\n * Opens the library with the running runtime's FFI.\n * @param path - The shared library's file.\n * @returns The bound library.\n * @throws {NativeLibraryError} When Node.js has no `node:ffi`.\n * @throws {Error} When the library does not load.\n */\nexport const bindLibrary = (path: string): BoundLibrary => bindNative<NativeSymbols>(path, signatures, optionalSymbols);\n"],"mappings":";;;;;;;;AAgEA,IAAM,aAAyE;CAC3E,iBAAiB,CAAC,OAAO,CAAC,CAAC;CAC3B,iBAAiB,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC;CACvC,iBAAiB,CAAC,OAAO;EAAC;EAAO;EAAU;CAAK,CAAC;CACjD,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC;CAClC,aAAa,CAAC,QAAQ,CAAC,CAAC;CACxB,cAAc,CAAC,OAAO,CAAC,UAAU,KAAK,CAAC;CACvC,eAAe,CAAC,OAAO;EAAC;EAAO;EAAU;EAAU;EAAO;EAAO;EAAO;CAAK,CAAC;CAC9E,+BAA+B,CAAC,OAAO;EAAC;EAAO;EAAU;CAAQ,CAAC;CAClE,8BAA8B,CAAC,OAAO,CAAC,OAAO,QAAQ,CAAC;CACvD,6BAA6B,CAAC,OAAO;EAAC;EAAO;EAAU;CAAQ,CAAC;CAChE,0BAA0B,CAAC,OAAO;EAAC;EAAO;EAAU;CAAK,CAAC;CAC1D,sBAAsB,CAAC,OAAO;EAAC;EAAO;EAAU;CAAK,CAAC;CACtD,wBAAwB,CAAC,OAAO,CAAC,KAAK,CAAC;CACvC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;CAC7B,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC;CAC9B,eAAe,CAAC,OAAO;EAAC;EAAO;EAAU;EAAO;CAAK,CAAC;CACtD,aAAa,CAAC,OAAO;EAAC;EAAO;EAAU;CAAK,CAAC;CAC7C,wBAAwB,CAAC,OAAO,CAAC,KAAK,CAAC;CACvC,0CAA0C,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC;CAChE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;CAC7B,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC;CAC9B,cAAc,CAAC,OAAO,CAAC,UAAU,KAAK,CAAC;CACvC,gBAAgB,CAAC,OAAO;EAAC;EAAO;EAAO;EAAW;EAAO;EAAW;EAAO;CAAK,CAAC;CACjF,gBAAgB,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC;CACtC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC;CAC9B,eAAe,CAAC,OAAO;EAAC;EAAO;EAAU;CAAK,CAAC;CAC/C,iBAAiB,CAAC,OAAO;EAAC;EAAU;EAAU;CAAK,CAAC;CACpD,iBAAiB,CAAC,OAAO;EAAC;EAAO;EAAU;CAAK,CAAC;CACjD,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC;AACpC;;;;;;AAOA,IAAM,kCAAuC,IAAI,IAAI;CACjD;CACA;CACA;CACA;AACJ,CAAmC;;;;;;;;AASnC,IAAa,eAAe,SAA+B,WAA0B,MAAM,YAAY,eAAe"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export { operatingSystemOf, platformKey } from '@jsprismarine/native-library/pla
|
|
|
18
18
|
export type { NativeSymbols } from './ffi.js';
|
|
19
19
|
export type { LocateOptions } from '@jsprismarine/native-library';
|
|
20
20
|
export type { NativePointer } from '@jsprismarine/native-library/ffi';
|
|
21
|
+
export { Cfb8 } from './Cfb8.js';
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACnF,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,YAAY,EACR,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACjE,YAAY,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChG,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,E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E,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChG,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACpF,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACvF,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,4 +7,5 @@ import { libraryForPlatform, provideEmbeddedLibrary } from "./embed.js";
|
|
|
7
7
|
import { BASE_URL_ENV, SKIP_DOWNLOAD_ENV, installBuild, installedLibraryPath } from "./install.js";
|
|
8
8
|
import { parseManifest, readManifest } from "@jsprismarine/native-library/manifest";
|
|
9
9
|
import { operatingSystemOf, platformKey } from "@jsprismarine/native-library/platform";
|
|
10
|
-
|
|
10
|
+
import { Cfb8 } from "./Cfb8.js";
|
|
11
|
+
export { ABI_VERSION, BASE_URL_ENV, Cfb8, DATAGRAM_HEADER_BYTES, DataChannel, DatagramClass, LIBRARY_ENV, NativeEvent, NativeNetwork, PACKAGE_NAME, PeerConnection, RING_CONTROL_BYTES, SKIP_DOWNLOAD_ENV, SharedPort, approvalAdvice, bundledManifest, cString, classify, installBuild, installedLibraryPath, libraryForPlatform, locateLibrary, operatingSystemOf, parseManifest, platformKey, provideEmbeddedLibrary, readManifest, sharedLibraryName, staticLibraryName, verifyLibrary };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsprismarine/native-network",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Networking in native code for JSPrismarine: WebRTC peer connections on libdatachannel,
|
|
3
|
+
"version": "0.28.0-unstable-20261129155207",
|
|
4
|
+
"description": "Networking in native code for JSPrismarine: WebRTC peer connections on libdatachannel, a UDP port RakNet shares with NetherNet, and Java Edition's AES-CFB8 cipher",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"license": "(MIT OR MPL-2.0)",
|
|
41
41
|
"homepage": "https://github.com/JSPrismarine/JSPrismarine/tree/master/packages/native-network",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@jsprismarine/raknet": "0.
|
|
43
|
+
"@jsprismarine/raknet": "0.28.0-unstable-20261129155207",
|
|
44
44
|
"@types/node": "26.6.11",
|
|
45
45
|
"glob": "14.0.6",
|
|
46
46
|
"rimraf": "6.1.4",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"vitest": "5.1.2"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@jsprismarine/errors": "0.
|
|
54
|
-
"@jsprismarine/native-library": "0.
|
|
53
|
+
"@jsprismarine/errors": "0.28.0-unstable-20261129155207",
|
|
54
|
+
"@jsprismarine/native-library": "0.28.0-unstable-20261129155207"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"clean": "rimraf dist jsp *.tsbuildinfo vite.config.ts.timestamp-* .tsup .turbo",
|