opendht 0.0.0-stage → 4.4.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -2
- package/crypto.js +56 -0
- package/examples/dhtnode.js +176 -0
- package/examples/dhtnode.ts +171 -0
- package/index.d.ts +120 -0
- package/index.js +187 -0
- package/package.json +57 -5
- package/prebuilds/darwin-arm64/libargon2.1.dylib +0 -0
- package/prebuilds/darwin-arm64/libcrypto.3.dylib +0 -0
- package/prebuilds/darwin-arm64/libfmt.12.2.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libgmp.10.dylib +0 -0
- package/prebuilds/darwin-arm64/libgnutls.30.dylib +0 -0
- package/prebuilds/darwin-arm64/libhogweed.7.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libidn2.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libintl.8.dylib +0 -0
- package/prebuilds/darwin-arm64/libjsoncpp.27.dylib +0 -0
- package/prebuilds/darwin-arm64/libllhttp.9.4.3.dylib +0 -0
- package/prebuilds/darwin-arm64/libnettle.9.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libopendht.4.4.99.dylib +0 -0
- package/prebuilds/darwin-arm64/libp11-kit.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libsimdutf.35.0.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libssl.3.dylib +0 -0
- package/prebuilds/darwin-arm64/libtasn1.6.dylib +0 -0
- package/prebuilds/darwin-arm64/libunistring.5.dylib +0 -0
- package/prebuilds/darwin-arm64/licenses/OpenDHT-LICENSE.txt +7 -0
- package/prebuilds/darwin-arm64/licenses/argon2-LICENSE.txt +314 -0
- package/prebuilds/darwin-arm64/licenses/fmt-LICENSE.txt +20 -0
- package/prebuilds/darwin-arm64/licenses/gettext-COPYING.txt +674 -0
- package/prebuilds/darwin-arm64/licenses/gmp-COPYING.LESSERv3.txt +165 -0
- package/prebuilds/darwin-arm64/licenses/gmp-COPYING.txt +674 -0
- package/prebuilds/darwin-arm64/licenses/gnutls-COPYING.LESSERv2.txt +501 -0
- package/prebuilds/darwin-arm64/licenses/gnutls-COPYING.txt +674 -0
- package/prebuilds/darwin-arm64/licenses/jsoncpp-LICENSE.txt +55 -0
- package/prebuilds/darwin-arm64/licenses/libidn2-COPYING.LESSERv3.txt +165 -0
- package/prebuilds/darwin-arm64/licenses/libidn2-COPYING.txt +674 -0
- package/prebuilds/darwin-arm64/licenses/libidn2-COPYING.unicode.txt +91 -0
- package/prebuilds/darwin-arm64/licenses/libtasn1-COPYING.LESSERv2.txt +501 -0
- package/prebuilds/darwin-arm64/licenses/libtasn1-COPYING.txt +674 -0
- package/prebuilds/darwin-arm64/licenses/libunistring-COPYING.LIB.txt +165 -0
- package/prebuilds/darwin-arm64/licenses/libunistring-COPYING.txt +674 -0
- package/prebuilds/darwin-arm64/licenses/llhttp-LICENSE-MIT.txt +22 -0
- package/prebuilds/darwin-arm64/licenses/llhttp-LICENSE.txt +22 -0
- package/prebuilds/darwin-arm64/licenses/nettle-COPYING.LESSERv3.txt +165 -0
- package/prebuilds/darwin-arm64/licenses/openssl@3-LICENSE.txt.txt +177 -0
- package/prebuilds/darwin-arm64/licenses/p11-kit-COPYING.txt +27 -0
- package/prebuilds/darwin-arm64/licenses/simdutf-LICENSE-APACHE.txt +201 -0
- package/prebuilds/darwin-arm64/licenses/simdutf-LICENSE-MIT.txt +18 -0
- package/prebuilds/darwin-arm64/manifest.json +25 -0
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/darwin-x64/libargon2.1.dylib +0 -0
- package/prebuilds/darwin-x64/libcrypto.3.dylib +0 -0
- package/prebuilds/darwin-x64/libfmt.12.2.0.dylib +0 -0
- package/prebuilds/darwin-x64/libgmp.10.dylib +0 -0
- package/prebuilds/darwin-x64/libgnutls.30.dylib +0 -0
- package/prebuilds/darwin-x64/libhogweed.7.0.dylib +0 -0
- package/prebuilds/darwin-x64/libidn2.0.dylib +0 -0
- package/prebuilds/darwin-x64/libintl.8.dylib +0 -0
- package/prebuilds/darwin-x64/libjsoncpp.27.dylib +0 -0
- package/prebuilds/darwin-x64/libllhttp.9.4.3.dylib +0 -0
- package/prebuilds/darwin-x64/libnettle.9.0.dylib +0 -0
- package/prebuilds/darwin-x64/libopendht.4.4.99.dylib +0 -0
- package/prebuilds/darwin-x64/libp11-kit.0.dylib +0 -0
- package/prebuilds/darwin-x64/libsimdutf.35.0.0.dylib +0 -0
- package/prebuilds/darwin-x64/libssl.3.dylib +0 -0
- package/prebuilds/darwin-x64/libtasn1.6.dylib +0 -0
- package/prebuilds/darwin-x64/libunistring.5.dylib +0 -0
- package/prebuilds/darwin-x64/licenses/OpenDHT-LICENSE.txt +7 -0
- package/prebuilds/darwin-x64/licenses/argon2-LICENSE.txt +314 -0
- package/prebuilds/darwin-x64/licenses/fmt-LICENSE.txt +20 -0
- package/prebuilds/darwin-x64/licenses/gettext-COPYING.txt +674 -0
- package/prebuilds/darwin-x64/licenses/gmp-COPYING.LESSERv3.txt +165 -0
- package/prebuilds/darwin-x64/licenses/gmp-COPYING.txt +674 -0
- package/prebuilds/darwin-x64/licenses/gnutls-COPYING.LESSERv2.txt +501 -0
- package/prebuilds/darwin-x64/licenses/gnutls-COPYING.txt +674 -0
- package/prebuilds/darwin-x64/licenses/jsoncpp-LICENSE.txt +55 -0
- package/prebuilds/darwin-x64/licenses/libidn2-COPYING.LESSERv3.txt +165 -0
- package/prebuilds/darwin-x64/licenses/libidn2-COPYING.txt +674 -0
- package/prebuilds/darwin-x64/licenses/libidn2-COPYING.unicode.txt +91 -0
- package/prebuilds/darwin-x64/licenses/libtasn1-COPYING.LESSERv2.txt +501 -0
- package/prebuilds/darwin-x64/licenses/libtasn1-COPYING.txt +674 -0
- package/prebuilds/darwin-x64/licenses/libunistring-COPYING.LIB.txt +165 -0
- package/prebuilds/darwin-x64/licenses/libunistring-COPYING.txt +674 -0
- package/prebuilds/darwin-x64/licenses/llhttp-LICENSE-MIT.txt +22 -0
- package/prebuilds/darwin-x64/licenses/llhttp-LICENSE.txt +22 -0
- package/prebuilds/darwin-x64/licenses/nettle-COPYING.LESSERv3.txt +165 -0
- package/prebuilds/darwin-x64/licenses/openssl@3-LICENSE.txt.txt +177 -0
- package/prebuilds/darwin-x64/licenses/p11-kit-COPYING.txt +27 -0
- package/prebuilds/darwin-x64/licenses/simdutf-LICENSE-APACHE.txt +201 -0
- package/prebuilds/darwin-x64/licenses/simdutf-LICENSE-MIT.txt +18 -0
- package/prebuilds/darwin-x64/manifest.json +25 -0
- package/prebuilds/darwin-x64/node.napi.node +0 -0
- package/prebuilds/linux-x64/libargon2.so.1 +0 -0
- package/prebuilds/linux-x64/libcrypto.so.3 +0 -0
- package/prebuilds/linux-x64/libffi.so.8 +0 -0
- package/prebuilds/linux-x64/libfmt.so.9 +0 -0
- package/prebuilds/linux-x64/libgmp.so.10 +0 -0
- package/prebuilds/linux-x64/libgnutls.so.30 +0 -0
- package/prebuilds/linux-x64/libhogweed.so.6 +0 -0
- package/prebuilds/linux-x64/libidn2.so.0 +0 -0
- package/prebuilds/linux-x64/libjsoncpp.so.25 +0 -0
- package/prebuilds/linux-x64/libllhttp.so.9.2 +0 -0
- package/prebuilds/linux-x64/libnettle.so.8 +0 -0
- package/prebuilds/linux-x64/libopendht.so.4 +0 -0
- package/prebuilds/linux-x64/libp11-kit.so.0 +0 -0
- package/prebuilds/linux-x64/libssl.so.3 +0 -0
- package/prebuilds/linux-x64/libtasn1.so.6 +0 -0
- package/prebuilds/linux-x64/libunistring.so.5 +0 -0
- package/prebuilds/linux-x64/licenses/OpenDHT-LICENSE.txt +7 -0
- package/prebuilds/linux-x64/licenses/libargon2-1-copyright.txt +167 -0
- package/prebuilds/linux-x64/licenses/libffi8-copyright.txt +225 -0
- package/prebuilds/linux-x64/licenses/libfmt9-copyright.txt +411 -0
- package/prebuilds/linux-x64/licenses/libgmp10-copyright.txt +94 -0
- package/prebuilds/linux-x64/licenses/libgnutls30t64-copyright.txt +1248 -0
- package/prebuilds/linux-x64/licenses/libhogweed6t64-copyright.txt +723 -0
- package/prebuilds/linux-x64/licenses/libidn2-0-copyright.txt +113 -0
- package/prebuilds/linux-x64/licenses/libjsoncpp25-copyright.txt +84 -0
- package/prebuilds/linux-x64/licenses/libnettle8t64-copyright.txt +723 -0
- package/prebuilds/linux-x64/licenses/libp11-kit0-copyright.txt +493 -0
- package/prebuilds/linux-x64/licenses/libssl3t64-copyright.txt +70 -0
- package/prebuilds/linux-x64/licenses/libtasn1-6-copyright.txt +83 -0
- package/prebuilds/linux-x64/licenses/libunistring5-copyright.txt +152 -0
- package/prebuilds/linux-x64/licenses/llhttp-llhttp-LICENSE-MIT.txt +22 -0
- package/prebuilds/linux-x64/licenses/simdutf/LICENSE-APACHE +201 -0
- package/prebuilds/linux-x64/licenses/simdutf/LICENSE-MIT +18 -0
- package/prebuilds/linux-x64/manifest.json +24 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/win32-x64/argon2.dll +0 -0
- package/prebuilds/win32-x64/fmt.dll +0 -0
- package/prebuilds/win32-x64/gmp-10.dll +0 -0
- package/prebuilds/win32-x64/gnutls.dll +0 -0
- package/prebuilds/win32-x64/hogweed-7.dll +0 -0
- package/prebuilds/win32-x64/jsoncpp.dll +0 -0
- package/prebuilds/win32-x64/libcrypto-3-x64.dll +0 -0
- package/prebuilds/win32-x64/libssl-3-x64.dll +0 -0
- package/prebuilds/win32-x64/licenses/OpenDHT-LICENSE.txt +7 -0
- package/prebuilds/win32-x64/manifest.json +20 -0
- package/prebuilds/win32-x64/nettle-9.dll +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/prebuilds/win32-x64/opendht.dll +0 -0
- package/prebuilds/win32-x64/simdutf.dll +0 -0
- package/prebuilds/win32-x64/tasn1-6.dll +0 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
|
|
4
|
+
export const version: string;
|
|
5
|
+
export function hash(data: string | Uint8Array): string;
|
|
6
|
+
|
|
7
|
+
export interface KeyOptions {
|
|
8
|
+
algorithm?: 'ec' | 'rsa';
|
|
9
|
+
bits?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class PublicKey {
|
|
13
|
+
constructor(data: Uint8Array);
|
|
14
|
+
serialize(): Buffer;
|
|
15
|
+
getId(): string;
|
|
16
|
+
getLongId(): string;
|
|
17
|
+
checkSignature(data: Uint8Array, signature: Uint8Array): boolean;
|
|
18
|
+
encrypt(data: Uint8Array): Buffer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class PrivateKey {
|
|
22
|
+
constructor(data: Uint8Array, password?: string);
|
|
23
|
+
static generate(options?: KeyOptions): Promise<PrivateKey>;
|
|
24
|
+
serialize(password?: string): Buffer;
|
|
25
|
+
getPublicKey(): PublicKey;
|
|
26
|
+
sign(data: Uint8Array): Buffer;
|
|
27
|
+
decrypt(data: Uint8Array): Buffer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Certificate {
|
|
31
|
+
constructor(data: Uint8Array);
|
|
32
|
+
serialize(): Buffer;
|
|
33
|
+
getPublicKey(): PublicKey;
|
|
34
|
+
getId(): string;
|
|
35
|
+
getLongId(): string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class Identity {
|
|
39
|
+
constructor(privateKey: PrivateKey, certificate: Certificate);
|
|
40
|
+
static generate(name?: string, options?: KeyOptions): Promise<Identity>;
|
|
41
|
+
readonly privateKey: PrivateKey;
|
|
42
|
+
readonly certificate: Certificate;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface RunOptions {
|
|
46
|
+
port?: number;
|
|
47
|
+
ipv4?: string;
|
|
48
|
+
ipv6?: string;
|
|
49
|
+
network?: number;
|
|
50
|
+
persistPath?: string;
|
|
51
|
+
identity?: Identity;
|
|
52
|
+
proxyServer?: string;
|
|
53
|
+
proxyUserAgent?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface PutOptions {
|
|
57
|
+
id?: bigint;
|
|
58
|
+
type?: number;
|
|
59
|
+
userType?: string;
|
|
60
|
+
permanent?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Value {
|
|
64
|
+
id: bigint;
|
|
65
|
+
type: number;
|
|
66
|
+
seq: number;
|
|
67
|
+
data: Buffer;
|
|
68
|
+
userType: string;
|
|
69
|
+
owner: string | null;
|
|
70
|
+
isSigned: boolean;
|
|
71
|
+
isEncrypted: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Listener {
|
|
75
|
+
cancel(): void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ListenEvent {
|
|
79
|
+
value: Value;
|
|
80
|
+
expired: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ValueIterator<T> extends AsyncIterableIterator<T, undefined>, Listener, AsyncDisposable {
|
|
84
|
+
return(): Promise<IteratorResult<T, undefined>>;
|
|
85
|
+
throw(error?: unknown): Promise<IteratorResult<T, undefined>>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ListenerIterator extends ValueIterator<ListenEvent> { }
|
|
89
|
+
|
|
90
|
+
export type NodeStatus = 'disconnected' | 'connecting' | 'connected';
|
|
91
|
+
|
|
92
|
+
export interface ConnectivityStatus {
|
|
93
|
+
ipv4: NodeStatus;
|
|
94
|
+
ipv6: NodeStatus;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface RunnerEvents {
|
|
98
|
+
statusChanged: [status: ConnectivityStatus];
|
|
99
|
+
error: [error: Error];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class DhtRunner extends EventEmitter<RunnerEvents> implements AsyncDisposable {
|
|
103
|
+
run(options?: RunOptions): void;
|
|
104
|
+
isRunning(): boolean;
|
|
105
|
+
getBoundPort(family?: 4 | 6): number;
|
|
106
|
+
getNodeId(): string;
|
|
107
|
+
getStatus(): ConnectivityStatus;
|
|
108
|
+
bootstrap(host: string, port: number): void;
|
|
109
|
+
get(key: string): ValueIterator<Value>;
|
|
110
|
+
getAll(key: string): Promise<Value[]>;
|
|
111
|
+
put(key: string, data: Uint8Array, options?: PutOptions): Promise<boolean>;
|
|
112
|
+
putSigned(key: string, data: Uint8Array, options?: PutOptions): Promise<boolean>;
|
|
113
|
+
putEncrypted(key: string, data: Uint8Array, recipient: PublicKey, options?: PutOptions): Promise<boolean>;
|
|
114
|
+
listen(key: string): ListenerIterator;
|
|
115
|
+
listen(key: string, callback: (value: Value, expired: boolean) => void): Listener;
|
|
116
|
+
close(): Promise<void>;
|
|
117
|
+
ref(): this;
|
|
118
|
+
unref(): this;
|
|
119
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
120
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { constants } from 'node:os';
|
|
3
|
+
import { dlopen } from 'node:process';
|
|
4
|
+
import load from 'node-gyp-build';
|
|
5
|
+
import createCrypto from './crypto.js';
|
|
6
|
+
|
|
7
|
+
const binding = { exports: {} };
|
|
8
|
+
const flags = process.platform === 'linux'
|
|
9
|
+
? constants.dlopen.RTLD_LAZY | constants.dlopen.RTLD_DEEPBIND
|
|
10
|
+
: undefined;
|
|
11
|
+
dlopen(binding, process.env.OPENDHT_NODE_BINDING || load.path(import.meta.dirname),
|
|
12
|
+
flags);
|
|
13
|
+
const native = binding.exports;
|
|
14
|
+
const { PublicKey, PrivateKey, Certificate, Identity, handle } = createCrypto(native);
|
|
15
|
+
|
|
16
|
+
function eventReporter(owner, event) {
|
|
17
|
+
return value => { owner.deref()?.emit(event, value); };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class DhtRunner extends EventEmitter {
|
|
21
|
+
#native;
|
|
22
|
+
#closing;
|
|
23
|
+
#listeners = 0;
|
|
24
|
+
#pending = 0;
|
|
25
|
+
#iterators = new Set();
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
const owner = new WeakRef(this);
|
|
30
|
+
this.#native = new native.NativeRunner(eventReporter(owner, 'statusChanged'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#updateOwner() {
|
|
34
|
+
this.#native.setOwner(this.#listeners || this.#pending || this.listenerCount('statusChanged') ? this : null);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#track(operation) {
|
|
38
|
+
this.#pending++;
|
|
39
|
+
this.#updateOwner();
|
|
40
|
+
return operation.finally(() => {
|
|
41
|
+
this.#pending--;
|
|
42
|
+
this.#updateOwner();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
on(event, listener) { super.on(event, listener); this.#updateOwner(); return this; }
|
|
47
|
+
addListener(event, listener) { return this.on(event, listener); }
|
|
48
|
+
prependListener(event, listener) { super.prependListener(event, listener); this.#updateOwner(); return this; }
|
|
49
|
+
removeListener(event, listener) { super.removeListener(event, listener); this.#updateOwner(); return this; }
|
|
50
|
+
off(event, listener) { return this.removeListener(event, listener); }
|
|
51
|
+
removeAllListeners(...args) { super.removeAllListeners(...args); this.#updateOwner(); return this; }
|
|
52
|
+
|
|
53
|
+
run(options) {
|
|
54
|
+
if (typeof options?.proxyServer === 'string' && options.proxyServer) {
|
|
55
|
+
const proxy = new URL(options.proxyServer);
|
|
56
|
+
if (proxy.protocol !== 'http:' && proxy.protocol !== 'https:')
|
|
57
|
+
throw new TypeError('proxyServer must be an HTTP(S) URL');
|
|
58
|
+
}
|
|
59
|
+
if (options?.identity !== undefined) options = { ...options, identity: handle(options.identity, Identity) };
|
|
60
|
+
this.#native.run(options);
|
|
61
|
+
}
|
|
62
|
+
isRunning() { return this.#native.isRunning(); }
|
|
63
|
+
getBoundPort(family = 4) { return this.#native.getBoundPort(family); }
|
|
64
|
+
getNodeId() { return this.#native.getNodeId(); }
|
|
65
|
+
getStatus() { return this.#native.getStatus(); }
|
|
66
|
+
bootstrap(host, port) { this.#native.bootstrap(host, port); }
|
|
67
|
+
get(key) {
|
|
68
|
+
return this.#iterate((push, finish) => {
|
|
69
|
+
const operation = this.#native.get(key, push);
|
|
70
|
+
this.#track(operation.done).then(() => finish(), finish);
|
|
71
|
+
return () => this.#native.cancelGet(operation.token);
|
|
72
|
+
}, true);
|
|
73
|
+
}
|
|
74
|
+
getAll(key) { return this.#track(this.#native.getAll(key)); }
|
|
75
|
+
put(key, data, options) { return this.#track(this.#native.put(key, data, options)); }
|
|
76
|
+
putSigned(key, data, options) { return this.#track(this.#native.putSigned(key, data, options)); }
|
|
77
|
+
putEncrypted(key, data, recipient, options) {
|
|
78
|
+
return this.#track(this.#native.putEncrypted(key, data, options, handle(recipient, PublicKey)));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
listen(key, callback) {
|
|
82
|
+
if (callback === undefined) {
|
|
83
|
+
return this.#iterate(push => {
|
|
84
|
+
const subscription = this.listen(key, (value, expired) => push({ value, expired }));
|
|
85
|
+
return () => subscription.cancel();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const token = this.#native.listen(key, callback);
|
|
89
|
+
this.#listeners++;
|
|
90
|
+
this.#updateOwner();
|
|
91
|
+
let cancelled = false;
|
|
92
|
+
return {
|
|
93
|
+
cancel: () => {
|
|
94
|
+
if (cancelled) return;
|
|
95
|
+
this.#native.cancelListen(token);
|
|
96
|
+
cancelled = true;
|
|
97
|
+
this.#listeners--;
|
|
98
|
+
this.#updateOwner();
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#iterate(subscribe, rejectOnClose = false) {
|
|
104
|
+
let values = [];
|
|
105
|
+
let offset = 0;
|
|
106
|
+
const pending = [];
|
|
107
|
+
let done = false;
|
|
108
|
+
let failure;
|
|
109
|
+
const finish = error => {
|
|
110
|
+
if (done) return;
|
|
111
|
+
done = true;
|
|
112
|
+
failure = error;
|
|
113
|
+
unsubscribe();
|
|
114
|
+
this.#iterators.delete(onClose);
|
|
115
|
+
if (failure) {
|
|
116
|
+
values = [];
|
|
117
|
+
offset = 0;
|
|
118
|
+
}
|
|
119
|
+
for (const { resolve, reject } of pending.splice(0)) {
|
|
120
|
+
if (failure) reject(failure);
|
|
121
|
+
else resolve({ value: undefined, done: true });
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const cancel = () => {
|
|
125
|
+
values = [];
|
|
126
|
+
offset = 0;
|
|
127
|
+
failure = undefined;
|
|
128
|
+
finish();
|
|
129
|
+
};
|
|
130
|
+
const onClose = () => {
|
|
131
|
+
if (rejectOnClose) {
|
|
132
|
+
const error = new Error('DHT runner is closed');
|
|
133
|
+
error.code = 'ERR_DHT_CLOSED';
|
|
134
|
+
finish(error);
|
|
135
|
+
} else cancel();
|
|
136
|
+
};
|
|
137
|
+
const unsubscribe = subscribe(value => {
|
|
138
|
+
if (done) return;
|
|
139
|
+
const waiter = pending.shift();
|
|
140
|
+
if (waiter) waiter.resolve({ value, done: false });
|
|
141
|
+
else values.push(value);
|
|
142
|
+
}, finish);
|
|
143
|
+
this.#iterators.add(onClose);
|
|
144
|
+
return {
|
|
145
|
+
next() {
|
|
146
|
+
if (failure) return Promise.reject(failure);
|
|
147
|
+
if (offset < values.length) {
|
|
148
|
+
const value = values[offset];
|
|
149
|
+
values[offset++] = undefined;
|
|
150
|
+
if (offset === values.length) {
|
|
151
|
+
values = [];
|
|
152
|
+
offset = 0;
|
|
153
|
+
}
|
|
154
|
+
return Promise.resolve({ value, done: false });
|
|
155
|
+
}
|
|
156
|
+
if (done) return Promise.resolve({ value: undefined, done: true });
|
|
157
|
+
return new Promise((resolve, reject) => pending.push({ resolve, reject }));
|
|
158
|
+
},
|
|
159
|
+
return() {
|
|
160
|
+
cancel();
|
|
161
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
162
|
+
},
|
|
163
|
+
throw(error) {
|
|
164
|
+
cancel();
|
|
165
|
+
return Promise.reject(error);
|
|
166
|
+
},
|
|
167
|
+
cancel,
|
|
168
|
+
[Symbol.asyncIterator]() { return this; },
|
|
169
|
+
[Symbol.asyncDispose]() { cancel(); return Promise.resolve(); },
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
close() {
|
|
174
|
+
if (!this.#closing) {
|
|
175
|
+
this.#closing = this.#native.close();
|
|
176
|
+
for (const cancel of this.#iterators) cancel();
|
|
177
|
+
}
|
|
178
|
+
return this.#closing;
|
|
179
|
+
}
|
|
180
|
+
ref() { this.#native.ref(); return this; }
|
|
181
|
+
unref() { this.#native.unref(); return this; }
|
|
182
|
+
[Symbol.asyncDispose]() { return this.close(); }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export { DhtRunner, PublicKey, PrivateKey, Certificate, Identity };
|
|
186
|
+
export const hash = native.hash;
|
|
187
|
+
export const version = native.version;
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "opendht",
|
|
3
|
+
"version": "4.4.101",
|
|
4
|
+
"description": "Distributed hash table for Node.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/savoirfairelinux/opendht.git",
|
|
9
|
+
"directory": "nodejs"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"types": "index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"import": "./index.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"index.js",
|
|
27
|
+
"index.d.ts",
|
|
28
|
+
"crypto.js",
|
|
29
|
+
"README.md",
|
|
30
|
+
"examples/dhtnode.js",
|
|
31
|
+
"examples/dhtnode.ts",
|
|
32
|
+
"prebuilds/"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22.9.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "cmake-js compile",
|
|
39
|
+
"postbuild": "npm run build:examples",
|
|
40
|
+
"build:examples": "tsc --strict --types node --target es2024 --module Node16 --moduleResolution Node16 --rootDir examples --outDir examples examples/dhtnode.ts",
|
|
41
|
+
"dhtnode": "node examples/dhtnode.js",
|
|
42
|
+
"prepack": "npm run build:examples",
|
|
43
|
+
"bundle": "node scripts/bundle.js",
|
|
44
|
+
"package": "npm run bundle && npm pack --pack-destination dist",
|
|
45
|
+
"test:package": "node scripts/test-package.js",
|
|
46
|
+
"test": "node --test test/*.test.js",
|
|
47
|
+
"typecheck": "tsc --noEmit --strict --types node --target es2024 --module Node16 --moduleResolution Node16 test/types.ts examples/dhtnode.ts"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"node-gyp-build": "^4.8.4"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.20.5",
|
|
54
|
+
"cmake-js": "^8.0.0",
|
|
55
|
+
"node-addon-api": "^8.8.0",
|
|
56
|
+
"typescript": "^7.0.2"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2014-2026 Savoir-faire Linux Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|