@fkn/lib 0.9.63 → 0.9.65
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 +34 -0
- package/account-Bm7uIcQo.d.ts +39 -0
- package/account-Uh0-1Cbp.js +22 -0
- package/{account-generation-B0cJrpDx.cjs → account-generation-ACCBzaI-.cjs} +1 -1
- package/{account-generation-u31dhamM.js → account-generation-BKHNe-jL.js} +2 -3
- package/account-m2iCmNui.cjs +1 -0
- package/{account-storage-ZkzqZp3A.js → account-storage-BmCVutNL.js} +4 -5
- package/{account-storage-Co9IvkPr.d.ts → account-storage-UmSfF63A.d.ts} +1 -66
- package/{account-storage-BnohkyMJ.cjs → account-storage-dYWDpqsr.cjs} +1 -1
- package/account.cjs +1 -1
- package/account.d.ts +3 -40
- package/account.js +1 -23
- package/{api-xh6lzApn.d.ts → api-0Yp9uZcV.d.ts} +3 -7
- package/{api-Di2Ff3jS.js → api-DRglK7ft.js} +115 -156
- package/api-DrvhPN56.cjs +3 -0
- package/api.cjs +1 -1
- package/api.d.ts +2 -2
- package/api.js +1 -2
- package/attach-policy.d.ts +0 -4
- package/attach-policy.js +2 -3
- package/broker-frame-CF4-yXtj.cjs +9 -0
- package/broker-frame-vjSpBa8d.js +51 -0
- package/broker-frame.cjs +1 -0
- package/broker-frame.d.ts +12 -0
- package/broker-frame.js +1 -0
- package/{busy-DsMWrSzc.js → busy-C1JPjoZ_.js} +1 -2
- package/cloud/dgram.cjs +1 -1
- package/cloud/dgram.d.ts +1 -1
- package/cloud/dgram.js +1 -2
- package/cloud/dns.cjs +1 -1
- package/cloud/dns.d.ts +2 -2
- package/cloud/dns.js +1 -2
- package/cloud/fetch.cjs +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/fetch.js +1 -2
- package/cloud/fs/promises.cjs +1 -1
- package/cloud/fs/promises.d.ts +3 -5
- package/cloud/fs/promises.js +2 -3
- package/cloud/fs.cjs +1 -1
- package/cloud/fs.d.ts +4 -4
- package/cloud/fs.js +4 -34
- package/cloud/http.cjs +1 -1
- package/cloud/http.d.ts +1 -1
- package/cloud/http.js +1 -2
- package/cloud/net.cjs +1 -1
- package/cloud/net.d.ts +1 -1
- package/cloud/net.js +3 -3
- package/{cloud-CI7FFRMC.d.ts → cloud-BoH54gaM.d.ts} +7 -11
- package/{cloud-C6rG_aod.js → cloud-C7StNncS.js} +17 -17
- package/cloud-TN0eDUy3.cjs +1 -0
- package/cloud.cjs +1 -1
- package/cloud.d.ts +7 -7
- package/cloud.js +7 -7
- package/connect-button-2FmOM8ai.d.ts +2 -0
- package/{connect-button-DtsN3X1J.js → connect-button-C1wKkIhh.js} +1 -2
- package/{contract-BGMJVvTg.d.ts → contract-0rua6Wsh.d.ts} +11 -6
- package/contract.d.ts +3 -3
- package/contract.js +1 -2
- package/desktop-DOubT4ES.d.ts +57 -0
- package/desktop-vXKU4wEK.cjs +1 -0
- package/desktop-xTT7ciGX.js +50 -0
- package/desktop.cjs +1 -1
- package/desktop.d.ts +2 -58
- package/desktop.js +1 -51
- package/dgram-BBbLokVF.js +397 -0
- package/dgram-BYk-QDHW.d.ts +118 -0
- package/dgram-D9ljiUFh.cjs +1 -0
- package/dgram.cjs +1 -1
- package/dgram.d.ts +2 -119
- package/dgram.js +1 -410
- package/dns-2v96zoEh.cjs +1 -0
- package/dns-DyB4K2oE.d.ts +9 -0
- package/dns-o8DLFjP1.js +5 -0
- package/dns.cjs +1 -1
- package/dns.d.ts +3 -10
- package/dns.js +1 -6
- package/extension-BXBjpypy.cjs +1 -0
- package/{extension-C3_aJX7C.js → extension-D5UMnEmQ.js} +11 -12
- package/{extension-C1bcizcn.d.ts → extension-D98KM8W7.d.ts} +1 -27
- package/extension.cjs +1 -1
- package/extension.d.ts +2 -2
- package/extension.js +2 -2
- package/fs/promises.cjs +1 -1
- package/fs/promises.d.ts +2 -4
- package/fs/promises.js +2 -3
- package/fs--MLHvMW-.cjs +1 -0
- package/fs-BX_ghRy0.cjs +1 -0
- package/fs-BnWXGRik.js +33 -0
- package/{fs-DCJAYoYy.d.ts → fs-ChOYC6VD.d.ts} +3 -4
- package/{fs-DgdN2HPt.js → fs-Cw7CcUhx.js} +17 -41
- package/fs.cjs +1 -1
- package/fs.d.ts +4 -4
- package/fs.js +2 -2
- package/{hosts-t7CKGTRz.js → hosts-HUfgMimI.js} +1 -2
- package/http-BE3UBktN.cjs +9 -0
- package/http-CDhG4bUc.d.ts +187 -0
- package/http-DIDjdm08.js +523 -0
- package/http.cjs +1 -9
- package/http.d.ts +2 -188
- package/http.js +1 -542
- package/index-CUWTpQKP.d.ts +87 -0
- package/{index-BQgZVQl7.d.ts → index-CcVwh9yz.d.ts} +0 -2
- package/{index-C5DdoMGo.d.ts → index-Cu5EcdK0.d.ts} +0 -59
- package/{index-57lTXnoe.d.ts → index-D6GPJ4Ow.d.ts} +29 -26
- package/index.cjs +1 -1
- package/index.d.ts +17 -25
- package/index.js +22 -27
- package/lib-Bs-g5jyp.cjs +53 -0
- package/{lib-BrsqpUkv.js → lib-CtJaID_y.js} +7 -31
- package/{messages-AdPfdoLV.d.ts → messages-B9dOXntM.d.ts} +0 -2
- package/messages.d.ts +1 -1
- package/messages.js +1 -2
- package/net-COkJw8lV.js +286 -0
- package/net-Dk2kqtgE.cjs +1 -0
- package/{net-BpyIeQ8r.d.ts → net-mVAYXs8e.d.ts} +5 -7
- package/net.cjs +1 -1
- package/net.d.ts +1 -1
- package/net.js +3 -323
- package/{node-fs-DY2fO5zd.js → node-fs-B4pY08Kc.js} +3 -10
- package/node-fs-DN0ejGTL.cjs +1 -0
- package/opfs/promises.cjs +1 -1
- package/opfs/promises.d.ts +2 -4
- package/opfs/promises.js +2 -3
- package/{opfs-D0goLAQW.js → opfs-CzCfVam3.js} +2 -3
- package/opfs-D3pYzYRc.js +35 -0
- package/opfs-DuXvTgIl.cjs +1 -0
- package/opfs.cjs +1 -1
- package/opfs.d.ts +3 -88
- package/opfs.js +1 -36
- package/package.json +6 -1
- package/packages-BEadIy_h.d.ts +155 -0
- package/packages-Cws_rcgf.js +346 -0
- package/packages-DT8vPB5_.cjs +1 -0
- package/packages.cjs +1 -1
- package/packages.d.ts +3 -156
- package/packages.js +1 -347
- package/{proxy-tsVhjcl-.js → proxy-BBAQxJmP.js} +13 -13
- package/{proxy-Dz60YyYy.d.ts → proxy-BP40IXYD.d.ts} +2 -4
- package/proxy-DVgGp6A8.cjs +1 -0
- package/react.cjs +1 -1
- package/react.d.ts +16 -4
- package/react.js +96 -7
- package/{relay-choice-BGwXRC5d.js → relay-choice-Bb3oP2gw.js} +1 -2
- package/{relay-choice-5yUPI-tJ.d.ts → relay-choice-DOUttUnL.d.ts} +2 -4
- package/{rolldown-runtime-Dy4uBu1J.js → rolldown-runtime-CGnMp29N.js} +1 -2
- package/rooms-C6mbannC.d.ts +227 -0
- package/rooms-DHFS9cwA.cjs +1 -0
- package/rooms-DP5stTEr.js +300 -0
- package/rooms.cjs +1 -1
- package/rooms.d.ts +3 -228
- package/rooms.js +1 -301
- package/storage-BCjYihUO.cjs +1 -0
- package/storage-BhfImh_2.js +136 -0
- package/storage-DpCLksAa.d.ts +68 -0
- package/storage.cjs +1 -1
- package/storage.d.ts +3 -69
- package/storage.js +1 -137
- package/{utils-Cyq8uJiy.js → utils-DtWP-E9x.js} +1 -2
- package/{wire-Fk5pJaoy.d.ts → wire-DhmLnYEU.d.ts} +0 -2
- package/wire.d.ts +1 -1
- package/wire.js +1 -2
- package/api-BSk3dc_X.cjs +0 -3
- package/cloud-BoiHKoRZ.cjs +0 -1
- package/connect-button-Cp0NS95-.d.ts +0 -4
- package/extension-Crv4aUAm.cjs +0 -1
- package/fs-CjQTj3FA.cjs +0 -1
- package/lib-C_X3WR4G.cjs +0 -53
- package/node-fs-vsWuoMGa.cjs +0 -1
- package/proxy-BA92hkId.cjs +0 -1
package/desktop.d.ts
CHANGED
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
/** Typed placeholder for the planned desktop backend. Always false in this release. */
|
|
5
|
-
export declare const available: () => boolean;
|
|
6
|
-
/** Planned desktop fetch backend. Throws in this release. */
|
|
7
|
-
export declare const fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
8
|
-
/** Planned desktop DNS backend. Every method throws in this release. */
|
|
9
|
-
export declare const dns: {
|
|
10
|
-
lookup: (..._args: unknown[]) => never;
|
|
11
|
-
};
|
|
12
|
-
/** Planned desktop TCP backend. Every method throws in this release. */
|
|
13
|
-
export declare const net: {
|
|
14
|
-
connect: (..._args: unknown[]) => never;
|
|
15
|
-
createConnection: (..._args: unknown[]) => never;
|
|
16
|
-
createServer: (..._args: unknown[]) => never;
|
|
17
|
-
};
|
|
18
|
-
/** Planned desktop UDP backend. Every method throws in this release. */
|
|
19
|
-
export declare const dgram: {
|
|
20
|
-
createSocket: (..._args: unknown[]) => never;
|
|
21
|
-
};
|
|
22
|
-
/** Planned desktop storage backend. available() resolves false; storage operations throw. */
|
|
23
|
-
export declare const fs: {
|
|
24
|
-
available: () => Promise<boolean>;
|
|
25
|
-
readFile: (..._args: unknown[]) => never;
|
|
26
|
-
readFileSync: (..._args: unknown[]) => never;
|
|
27
|
-
writeFile: (..._args: unknown[]) => never;
|
|
28
|
-
writeFileSync: (..._args: unknown[]) => never;
|
|
29
|
-
appendFile: (..._args: unknown[]) => never;
|
|
30
|
-
appendFileSync: (..._args: unknown[]) => never;
|
|
31
|
-
existsSync: (..._args: unknown[]) => never;
|
|
32
|
-
stat: (..._args: unknown[]) => never;
|
|
33
|
-
statSync: (..._args: unknown[]) => never;
|
|
34
|
-
readdir: (..._args: unknown[]) => never;
|
|
35
|
-
readdirSync: (..._args: unknown[]) => never;
|
|
36
|
-
mkdir: (..._args: unknown[]) => never;
|
|
37
|
-
mkdirSync: (..._args: unknown[]) => never;
|
|
38
|
-
rm: (..._args: unknown[]) => never;
|
|
39
|
-
rmSync: (..._args: unknown[]) => never;
|
|
40
|
-
unlink: (..._args: unknown[]) => never;
|
|
41
|
-
unlinkSync: (..._args: unknown[]) => never;
|
|
42
|
-
rename: (..._args: unknown[]) => never;
|
|
43
|
-
renameSync: (..._args: unknown[]) => never;
|
|
44
|
-
mount: (..._args: unknown[]) => never;
|
|
45
|
-
flush: (..._args: unknown[]) => never;
|
|
46
|
-
promises: {
|
|
47
|
-
readFile: (..._args: unknown[]) => never;
|
|
48
|
-
writeFile: (..._args: unknown[]) => never;
|
|
49
|
-
unlink: (..._args: unknown[]) => never;
|
|
50
|
-
rename: (..._args: unknown[]) => never;
|
|
51
|
-
readdir: (..._args: unknown[]) => never;
|
|
52
|
-
mkdir: (..._args: unknown[]) => never;
|
|
53
|
-
rm: (..._args: unknown[]) => never;
|
|
54
|
-
stat: (..._args: unknown[]) => never;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
//#endregion
|
|
58
|
-
export { desktop_d_exports as t };
|
|
1
|
+
import { a as fetch, i as dns, o as fs, r as dgram, s as net, t as available } from "./desktop-DOubT4ES.js";
|
|
2
|
+
export { available, dgram, dns, fetch, fs, net };
|
package/desktop.js
CHANGED
|
@@ -1,51 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/desktop.ts
|
|
3
|
-
var t = /* @__PURE__ */ e({
|
|
4
|
-
available: () => n,
|
|
5
|
-
dgram: () => s,
|
|
6
|
-
dns: () => a,
|
|
7
|
-
fetch: () => i,
|
|
8
|
-
fs: () => c,
|
|
9
|
-
net: () => o
|
|
10
|
-
}), n = () => !1, r = (e) => (...t) => {
|
|
11
|
-
throw Error(`The FKN desktop app is not connected, desktop.${e} is unavailable`);
|
|
12
|
-
}, i = r("fetch"), a = { lookup: r("dns.lookup") }, o = {
|
|
13
|
-
connect: r("net.connect"),
|
|
14
|
-
createConnection: r("net.createConnection"),
|
|
15
|
-
createServer: r("net.createServer")
|
|
16
|
-
}, s = { createSocket: r("dgram.createSocket") }, c = {
|
|
17
|
-
available: async () => !1,
|
|
18
|
-
readFile: r("fs.readFile"),
|
|
19
|
-
readFileSync: r("fs.readFileSync"),
|
|
20
|
-
writeFile: r("fs.writeFile"),
|
|
21
|
-
writeFileSync: r("fs.writeFileSync"),
|
|
22
|
-
appendFile: r("fs.appendFile"),
|
|
23
|
-
appendFileSync: r("fs.appendFileSync"),
|
|
24
|
-
existsSync: r("fs.existsSync"),
|
|
25
|
-
stat: r("fs.stat"),
|
|
26
|
-
statSync: r("fs.statSync"),
|
|
27
|
-
readdir: r("fs.readdir"),
|
|
28
|
-
readdirSync: r("fs.readdirSync"),
|
|
29
|
-
mkdir: r("fs.mkdir"),
|
|
30
|
-
mkdirSync: r("fs.mkdirSync"),
|
|
31
|
-
rm: r("fs.rm"),
|
|
32
|
-
rmSync: r("fs.rmSync"),
|
|
33
|
-
unlink: r("fs.unlink"),
|
|
34
|
-
unlinkSync: r("fs.unlinkSync"),
|
|
35
|
-
rename: r("fs.rename"),
|
|
36
|
-
renameSync: r("fs.renameSync"),
|
|
37
|
-
mount: r("fs.mount"),
|
|
38
|
-
flush: r("fs.flush"),
|
|
39
|
-
promises: {
|
|
40
|
-
readFile: r("fs.promises.readFile"),
|
|
41
|
-
writeFile: r("fs.promises.writeFile"),
|
|
42
|
-
unlink: r("fs.promises.unlink"),
|
|
43
|
-
rename: r("fs.promises.rename"),
|
|
44
|
-
readdir: r("fs.promises.readdir"),
|
|
45
|
-
mkdir: r("fs.promises.mkdir"),
|
|
46
|
-
rm: r("fs.promises.rm"),
|
|
47
|
-
stat: r("fs.promises.stat")
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
//#endregion
|
|
51
|
-
export { n as available, s as dgram, a as dns, i as fetch, c as fs, o as net, t };
|
|
1
|
+
export { t as available, r as dgram, i as dns, a as fetch, o as fs, s as net } from "./desktop-xTT7ciGX.js";
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { t as e } from "./rolldown-runtime-CGnMp29N.js";
|
|
2
|
+
import { s as t } from "./api-DRglK7ft.js";
|
|
3
|
+
import { t as n } from "./busy-C1JPjoZ_.js";
|
|
4
|
+
import { t as r } from "./relay-choice-Bb3oP2gw.js";
|
|
5
|
+
import { a as i, i as a, s as o } from "./utils-DtWP-E9x.js";
|
|
6
|
+
import { UDP_PORT_ACK_TYPE as s } from "./wire.js";
|
|
7
|
+
import { Buffer as c } from "buffer";
|
|
8
|
+
import { EventEmitter as l } from "events";
|
|
9
|
+
import { Address4 as u, Address6 as d } from "ip-address";
|
|
10
|
+
// src/webvpn/dgram.ts
|
|
11
|
+
var f = /* @__PURE__ */ e({
|
|
12
|
+
Socket: () => p,
|
|
13
|
+
createSocket: () => y,
|
|
14
|
+
default: () => b
|
|
15
|
+
}), p = class extends l {
|
|
16
|
+
_type;
|
|
17
|
+
_localAddress;
|
|
18
|
+
_remoteAddress;
|
|
19
|
+
_connectedLocally;
|
|
20
|
+
_connectGeneration = 0;
|
|
21
|
+
_destroyed = !1;
|
|
22
|
+
_busyRelease;
|
|
23
|
+
_webVPNUdpSocketPromise;
|
|
24
|
+
_dataPort;
|
|
25
|
+
_socketId;
|
|
26
|
+
_sendQueue = [];
|
|
27
|
+
_sendQueueBytes = 0;
|
|
28
|
+
_sendFlushScheduled = !1;
|
|
29
|
+
_peerTailCache = /* @__PURE__ */ new Map();
|
|
30
|
+
_relayChoice;
|
|
31
|
+
_relay;
|
|
32
|
+
constructor(e) {
|
|
33
|
+
if (super(e), !e) throw Error("Missing options");
|
|
34
|
+
this._type = e.type, this._relayChoice = e.relay, e.connection && this.__webvpn_udp_socket_init__(e.connection);
|
|
35
|
+
}
|
|
36
|
+
_lastRecvBufferSize = 0;
|
|
37
|
+
_lastSendBufferSize = 0;
|
|
38
|
+
_lastTtl = 64;
|
|
39
|
+
_lastMulticastTtl = 1;
|
|
40
|
+
_lastMulticastLoopback = !0;
|
|
41
|
+
_setUdpOption(e) {
|
|
42
|
+
this._webVPNUdpSocketPromise ? this._webVPNUdpSocketPromise.then(async (t) => {
|
|
43
|
+
if (t) try {
|
|
44
|
+
await t.setOption(e);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
this.emit("error", e);
|
|
47
|
+
}
|
|
48
|
+
}) : this.emit("error", /* @__PURE__ */ Error("Cannot set socket option before bind"));
|
|
49
|
+
}
|
|
50
|
+
_dataPortAcks = !1;
|
|
51
|
+
_dataPortConsumedBytes = 0;
|
|
52
|
+
_dataPortAckedBytes = 0;
|
|
53
|
+
_ackDataPortBatch(e) {
|
|
54
|
+
if (!this._dataPortAcks || !this._dataPort || (this._dataPortConsumedBytes += e, this._dataPortAckedBytes !== 0 && this._dataPortConsumedBytes - this._dataPortAckedBytes < 524288)) return;
|
|
55
|
+
this._dataPortAckedBytes = this._dataPortConsumedBytes;
|
|
56
|
+
let t = {
|
|
57
|
+
type: s,
|
|
58
|
+
consumedBytes: this._dataPortConsumedBytes
|
|
59
|
+
};
|
|
60
|
+
this._dataPort.postMessage(t);
|
|
61
|
+
}
|
|
62
|
+
_onTransportClosed(e) {
|
|
63
|
+
this._destroyed || (this._destroyed = !0, this._busyRelease?.(), this._dataPort?.close(), this._dataPort = void 0, this.listenerCount("error") > 0 && this.emit("error", Error(e || "WebVPN session closed")), this.emit("close"));
|
|
64
|
+
}
|
|
65
|
+
_onDataPortBatch(e) {
|
|
66
|
+
let t = new DataView(e), n = !1, r, i = 0;
|
|
67
|
+
for (; i + 4 <= e.byteLength;) {
|
|
68
|
+
let a = t.getUint32(i);
|
|
69
|
+
i += 4;
|
|
70
|
+
let o = i + a;
|
|
71
|
+
if (o > e.byteLength) break;
|
|
72
|
+
let s = i + 4, l = t.getUint8(s);
|
|
73
|
+
s += 1;
|
|
74
|
+
let u, d, f;
|
|
75
|
+
if (l === 2) {
|
|
76
|
+
if (!this._remoteAddress) {
|
|
77
|
+
i = o;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
u = this._remoteAddress.address, d = this._remoteAddress.family, f = this._remoteAddress.port;
|
|
81
|
+
} else {
|
|
82
|
+
let n = new Uint8Array(e, s, l === 0 ? 4 : 16);
|
|
83
|
+
l === 0 ? (d = "IPv4", u = `${n[0]}.${n[1]}.${n[2]}.${n[3]}`) : (d = "IPv6", u = _(n)), s += n.byteLength, f = t.getUint16(s), s += 2;
|
|
84
|
+
}
|
|
85
|
+
let p = t.getUint32(s);
|
|
86
|
+
s += 4;
|
|
87
|
+
try {
|
|
88
|
+
this.emit("message", c.from(e.slice(s, s + p)), {
|
|
89
|
+
address: u,
|
|
90
|
+
family: d,
|
|
91
|
+
port: f,
|
|
92
|
+
size: p
|
|
93
|
+
});
|
|
94
|
+
} catch (e) {
|
|
95
|
+
n || (n = !0, r = e);
|
|
96
|
+
}
|
|
97
|
+
i = o;
|
|
98
|
+
}
|
|
99
|
+
if (n) throw r;
|
|
100
|
+
}
|
|
101
|
+
_peerTail(e, t) {
|
|
102
|
+
if (e === void 0 || t === void 0) return m;
|
|
103
|
+
let n = `${e}|${t}`, r = this._peerTailCache.get(n);
|
|
104
|
+
if (r) return r;
|
|
105
|
+
let i = u.isValid(e) ? g(e) : v(e), a = new Uint8Array(1 + i.byteLength + 2);
|
|
106
|
+
return a[0] = i.byteLength === 4 ? 0 : 1, a.set(i, 1), new DataView(a.buffer).setUint16(1 + i.byteLength, t), this._peerTailCache.size >= 4096 && this._peerTailCache.clear(), this._peerTailCache.set(n, a), a;
|
|
107
|
+
}
|
|
108
|
+
_portSend(e, t, n) {
|
|
109
|
+
let r = this._peerTail(t, n), i = new Uint8Array(8 + r.byteLength + 4 + e.byteLength), a = new DataView(i.buffer);
|
|
110
|
+
a.setUint32(0, i.byteLength - 4), a.setUint32(4, this._socketId), i.set(r, 8), a.setUint32(8 + r.byteLength, e.byteLength), i.set(e, 12 + r.byteLength), this._sendQueue.push(i), this._sendQueueBytes += i.byteLength, !this._sendFlushScheduled && (this._sendFlushScheduled = !0, queueMicrotask(() => {
|
|
111
|
+
this._sendFlushScheduled = !1;
|
|
112
|
+
let e = this._sendQueue, t = this._sendQueueBytes;
|
|
113
|
+
if (this._sendQueue = [], this._sendQueueBytes = 0, !e.length || !this._dataPort) return;
|
|
114
|
+
let n = new Uint8Array(t), r = 0;
|
|
115
|
+
for (let t of e) n.set(t, r), r += t.byteLength;
|
|
116
|
+
this._dataPort.postMessage(n.buffer, [n.buffer]);
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
addMembership(e, t) {
|
|
120
|
+
if (u.isValid(e)) {
|
|
121
|
+
let n = g(e), r = t && u.isValid(t) ? g(t) : new Uint8Array([
|
|
122
|
+
0,
|
|
123
|
+
0,
|
|
124
|
+
0,
|
|
125
|
+
0
|
|
126
|
+
]);
|
|
127
|
+
this._setUdpOption({
|
|
128
|
+
type: 5,
|
|
129
|
+
group: n,
|
|
130
|
+
interface: r
|
|
131
|
+
});
|
|
132
|
+
} else if (d.isValid(e)) {
|
|
133
|
+
let t = v(e);
|
|
134
|
+
this._setUdpOption({
|
|
135
|
+
type: 7,
|
|
136
|
+
group: t,
|
|
137
|
+
ifIndex: 0
|
|
138
|
+
});
|
|
139
|
+
} else this.emit("error", /* @__PURE__ */ Error(`Invalid multicast address: ${e}`));
|
|
140
|
+
}
|
|
141
|
+
address() {
|
|
142
|
+
if (!this._localAddress) throw Error("EBADF");
|
|
143
|
+
return this._localAddress;
|
|
144
|
+
}
|
|
145
|
+
bind(...e) {
|
|
146
|
+
let n = a(...e), i = this._type === "udp6" ? "::" : "0.0.0.0", o = this._relayChoice, s = this.__webvpn_udp_socket_init__(t("a udp socket").then((e) => (o !== void 0 && r(e, "dgram.createSocket"), e.cloud.webvpn.udpSocket({
|
|
147
|
+
type: this._type,
|
|
148
|
+
address: n.address ?? i,
|
|
149
|
+
port: n.port,
|
|
150
|
+
dataPort: !0,
|
|
151
|
+
relay: o
|
|
152
|
+
}))));
|
|
153
|
+
return n.callback && s.then((e) => {
|
|
154
|
+
e && n.callback.call(this);
|
|
155
|
+
}), this;
|
|
156
|
+
}
|
|
157
|
+
__webvpn_udp_socket_init__(e, t) {
|
|
158
|
+
return t && (this._localAddress = {
|
|
159
|
+
address: t.localAddress,
|
|
160
|
+
family: t.localFamily,
|
|
161
|
+
port: t.localPort
|
|
162
|
+
}), this._busyRelease ??= n("udp socket"), this._webVPNUdpSocketPromise = e.then((e) => {
|
|
163
|
+
if (e.dataPort) this._socketId = e.socketId, this._dataPort = e.dataPort, this._dataPortAcks = e.dataPortAcks === !0, this._dataPort.onmessage = (e) => {
|
|
164
|
+
try {
|
|
165
|
+
this._onDataPortBatch(e.data);
|
|
166
|
+
} finally {
|
|
167
|
+
this._ackDataPortBatch(e.data.byteLength);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
else {
|
|
171
|
+
let t = e.dataReadableStream.getReader();
|
|
172
|
+
(async () => {
|
|
173
|
+
for (;;) {
|
|
174
|
+
let { value: e, done: n } = await t.read();
|
|
175
|
+
if (n) return;
|
|
176
|
+
this.emit("message", c.from(e.data), {
|
|
177
|
+
address: e.address,
|
|
178
|
+
family: e.family,
|
|
179
|
+
port: e.port,
|
|
180
|
+
size: e.size
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
})().catch((e) => this._onTransportClosed(e instanceof Error ? e.message : void 0));
|
|
184
|
+
}
|
|
185
|
+
return e.closed?.then((e) => this._onTransportClosed(e?.reason)).catch(() => {}), this._relay = e.relay, this._localAddress = {
|
|
186
|
+
address: e.localAddress,
|
|
187
|
+
family: e.localFamily,
|
|
188
|
+
port: e.localPort
|
|
189
|
+
}, e;
|
|
190
|
+
}).catch((e) => {
|
|
191
|
+
this.emit("error", e);
|
|
192
|
+
}), this._webVPNUdpSocketPromise.then((e) => {
|
|
193
|
+
e ? this.emit("listening") : this._busyRelease?.();
|
|
194
|
+
}), this._webVPNUdpSocketPromise;
|
|
195
|
+
}
|
|
196
|
+
close(e) {
|
|
197
|
+
if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
|
|
198
|
+
return this._webVPNUdpSocketPromise.then(async (t) => {
|
|
199
|
+
if (!t) throw Error("Socket not bound");
|
|
200
|
+
let n = this._destroyed;
|
|
201
|
+
this._destroyed = !0, this._busyRelease?.(), this._dataPort?.close(), this._dataPort = void 0;
|
|
202
|
+
try {
|
|
203
|
+
await t.close();
|
|
204
|
+
} finally {
|
|
205
|
+
try {
|
|
206
|
+
e && e();
|
|
207
|
+
} finally {
|
|
208
|
+
n || this.emit("close");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}).catch(() => {}), this;
|
|
212
|
+
}
|
|
213
|
+
connect(...e) {
|
|
214
|
+
if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
|
|
215
|
+
this._webVPNUdpSocketPromise.then(async (t) => {
|
|
216
|
+
if (!t) throw Error("Socket not bound");
|
|
217
|
+
let n = e[0], r = this._type === "udp6" ? "::1" : "127.0.0.1", i = typeof e[1] == "string" ? e[1] : r, a = typeof e.at(-1) == "function" ? e.at(-1) : void 0, o = await t.connect({
|
|
218
|
+
remotePort: n,
|
|
219
|
+
remoteAddress: i
|
|
220
|
+
});
|
|
221
|
+
this._connectedLocally = o?.local === !0, this._remoteAddress = o?.address ? {
|
|
222
|
+
address: o.address,
|
|
223
|
+
family: o.family,
|
|
224
|
+
port: o.port
|
|
225
|
+
} : {
|
|
226
|
+
address: i,
|
|
227
|
+
family: this._type === "udp6" ? "IPv6" : "IPv4",
|
|
228
|
+
port: n
|
|
229
|
+
}, this._connectGeneration += 1, a && a();
|
|
230
|
+
}).catch((e) => {
|
|
231
|
+
this.emit("error", e);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
disconnect() {
|
|
235
|
+
if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
|
|
236
|
+
if (!this._remoteAddress) throw Error("ERR_SOCKET_DGRAM_NOT_CONNECTED");
|
|
237
|
+
let e = this._remoteAddress, t = this._connectedLocally, n = this._connectGeneration;
|
|
238
|
+
this._remoteAddress = void 0, this._connectedLocally = void 0, this._webVPNUdpSocketPromise.then((e) => e?.disconnect?.()).catch((r) => {
|
|
239
|
+
this._connectGeneration === n && (this._remoteAddress = e, this._connectedLocally = t), this.emit("error", r);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
dropMembership(e, t) {
|
|
243
|
+
if (u.isValid(e)) {
|
|
244
|
+
let n = g(e), r = t && u.isValid(t) ? g(t) : new Uint8Array([
|
|
245
|
+
0,
|
|
246
|
+
0,
|
|
247
|
+
0,
|
|
248
|
+
0
|
|
249
|
+
]);
|
|
250
|
+
this._setUdpOption({
|
|
251
|
+
type: 6,
|
|
252
|
+
group: n,
|
|
253
|
+
interface: r
|
|
254
|
+
});
|
|
255
|
+
} else if (d.isValid(e)) {
|
|
256
|
+
let t = v(e);
|
|
257
|
+
this._setUdpOption({
|
|
258
|
+
type: 8,
|
|
259
|
+
group: t,
|
|
260
|
+
ifIndex: 0
|
|
261
|
+
});
|
|
262
|
+
} else this.emit("error", /* @__PURE__ */ Error(`Invalid multicast address: ${e}`));
|
|
263
|
+
}
|
|
264
|
+
getRecvBufferSize() {
|
|
265
|
+
return this._lastRecvBufferSize;
|
|
266
|
+
}
|
|
267
|
+
getSendBufferSize() {
|
|
268
|
+
return this._lastSendBufferSize;
|
|
269
|
+
}
|
|
270
|
+
getSendQueueSize() {
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
getSendQueueCount() {
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
ref() {
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
remoteAddress() {
|
|
280
|
+
if (!this._remoteAddress) throw Error("ERR_SOCKET_DGRAM_NOT_CONNECTED");
|
|
281
|
+
return {
|
|
282
|
+
address: this._remoteAddress.address,
|
|
283
|
+
family: this._remoteAddress.family,
|
|
284
|
+
port: this._remoteAddress.port
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
send(...e) {
|
|
288
|
+
this._webVPNUdpSocketPromise || this.bind();
|
|
289
|
+
let t = i(...e), n = h(t.message), r = n;
|
|
290
|
+
if (t.hasRange) {
|
|
291
|
+
let { offset: e, length: i } = t;
|
|
292
|
+
if (!Number.isInteger(e) || e < 0 || e > n.byteLength) throw Object.assign(/* @__PURE__ */ RangeError("\"offset\" is outside of buffer bounds"), { code: "ERR_BUFFER_OUT_OF_BOUNDS" });
|
|
293
|
+
if (!Number.isInteger(i) || i < 0 || i > n.byteLength - e) throw Object.assign(/* @__PURE__ */ RangeError("\"length\" is outside of buffer bounds"), { code: "ERR_BUFFER_OUT_OF_BOUNDS" });
|
|
294
|
+
r = n.subarray(e, e + i);
|
|
295
|
+
}
|
|
296
|
+
let a = this._type === "udp6" ? "::1" : "127.0.0.1";
|
|
297
|
+
if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
|
|
298
|
+
this._webVPNUdpSocketPromise.then((e) => {
|
|
299
|
+
if (!e) throw Error("Socket not bound");
|
|
300
|
+
let n = t.callback, i = t.address ?? a, o = this._remoteAddress !== void 0 && t.address === void 0;
|
|
301
|
+
this._dataPort && (o || u.isValid(i) || d.isValid(i)) ? (this._portSend(r, o ? void 0 : i, o ? void 0 : t.port), n?.call(this, null, r.byteLength)) : e.send({
|
|
302
|
+
port: t.port,
|
|
303
|
+
address: i,
|
|
304
|
+
message: r.byteOffset === 0 && r.byteLength === r.buffer.byteLength ? r.buffer : r.buffer.slice(r.byteOffset, r.byteOffset + r.byteLength)
|
|
305
|
+
}).then(() => n?.call(this, null, r.byteLength), (e) => n ? n.call(this, e, 0) : this.emit("error", e));
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
setBroadcast(e) {
|
|
309
|
+
this._setUdpOption({
|
|
310
|
+
type: 0,
|
|
311
|
+
value: e
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
setMulticastInterface(e) {}
|
|
315
|
+
setMulticastLoopback(e) {
|
|
316
|
+
return this._setUdpOption({
|
|
317
|
+
type: 3,
|
|
318
|
+
value: e
|
|
319
|
+
}), this._setUdpOption({
|
|
320
|
+
type: 4,
|
|
321
|
+
value: e
|
|
322
|
+
}), this._lastMulticastLoopback = e, e;
|
|
323
|
+
}
|
|
324
|
+
setMulticastTTL(e) {
|
|
325
|
+
return this._setUdpOption({
|
|
326
|
+
type: 2,
|
|
327
|
+
value: e
|
|
328
|
+
}), this._lastMulticastTtl = e, e;
|
|
329
|
+
}
|
|
330
|
+
setRecvBufferSize(e) {
|
|
331
|
+
this._setUdpOption({
|
|
332
|
+
type: 10,
|
|
333
|
+
value: e
|
|
334
|
+
}), this._lastRecvBufferSize = e;
|
|
335
|
+
}
|
|
336
|
+
setSendBufferSize(e) {
|
|
337
|
+
this._setUdpOption({
|
|
338
|
+
type: 9,
|
|
339
|
+
value: e
|
|
340
|
+
}), this._lastSendBufferSize = e;
|
|
341
|
+
}
|
|
342
|
+
setTTL(e) {
|
|
343
|
+
return this._setUdpOption({
|
|
344
|
+
type: 1,
|
|
345
|
+
value: e
|
|
346
|
+
}), this._lastTtl = e, e;
|
|
347
|
+
}
|
|
348
|
+
unref() {
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
addSourceSpecificMembership(e, t, n) {}
|
|
352
|
+
dropSourceSpecificMembership(e, t, n) {}
|
|
353
|
+
async [Symbol.asyncDispose]() {
|
|
354
|
+
await new Promise((e) => {
|
|
355
|
+
this.close(e);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}, m = new Uint8Array([2]), h = (e) => {
|
|
359
|
+
if (typeof e == "string") return o.encode(e);
|
|
360
|
+
if (e instanceof Uint8Array) return e;
|
|
361
|
+
if (ArrayBuffer.isView(e)) return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
362
|
+
if (Array.isArray(e)) {
|
|
363
|
+
let t = e.map(h), n = new Uint8Array(t.reduce((e, t) => e + t.byteLength, 0)), r = 0;
|
|
364
|
+
for (let e of t) n.set(e, r), r += e.byteLength;
|
|
365
|
+
return n;
|
|
366
|
+
}
|
|
367
|
+
return new Uint8Array(e);
|
|
368
|
+
}, g = (e) => {
|
|
369
|
+
let t = e.split(".").map((e) => parseInt(e, 10));
|
|
370
|
+
if (t.length !== 4 || t.some((e) => Number.isNaN(e) || e < 0 || e > 255)) throw Error(`Invalid IPv4 address: ${e}`);
|
|
371
|
+
return new Uint8Array(t);
|
|
372
|
+
}, _ = (e) => {
|
|
373
|
+
let t = [];
|
|
374
|
+
for (let n = 0; n < 16; n += 2) t.push(e[n] << 8 | e[n + 1]);
|
|
375
|
+
let n = -1, r = 1;
|
|
376
|
+
for (let e = 0; e < 8;) {
|
|
377
|
+
if (t[e] !== 0) {
|
|
378
|
+
e++;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
let i = e;
|
|
382
|
+
for (; i < 8 && t[i] === 0;) i++;
|
|
383
|
+
i - e > r && (n = e, r = i - e), e = i;
|
|
384
|
+
}
|
|
385
|
+
return n === -1 ? t.map((e) => e.toString(16)).join(":") : `${t.slice(0, n).map((e) => e.toString(16)).join(":")}::${t.slice(n + r).map((e) => e.toString(16)).join(":")}`;
|
|
386
|
+
}, v = (e) => {
|
|
387
|
+
let t = new d(e).getBitsBase16(0, 128).match(/.{2}/g);
|
|
388
|
+
if (!t || t.length !== 16) throw Error(`Invalid IPv6 address: ${e}`);
|
|
389
|
+
return new Uint8Array(t.map((e) => parseInt(e, 16)));
|
|
390
|
+
}, y = (e, t) => {
|
|
391
|
+
let n = new p(typeof e == "string" ? { type: e } : e);
|
|
392
|
+
return t && n.on("message", t), n;
|
|
393
|
+
}, b = {
|
|
394
|
+
Socket: p,
|
|
395
|
+
createSocket: y
|
|
396
|
+
};
|
|
397
|
+
export { f as i, y as n, b as r, p as t };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { D as RelayChoice } from "./index-Cu5EcdK0.js";
|
|
2
|
+
import { Gt as UdpSocketResult, X as Resolvers } from "./contract-0rua6Wsh.js";
|
|
3
|
+
import { x as UdpSocketOption } from "./wire-DhmLnYEU.js";
|
|
4
|
+
import "./api-0Yp9uZcV.js";
|
|
5
|
+
import { t as RelayOption } from "./relay-choice-DOUttUnL.js";
|
|
6
|
+
import { Buffer } from "buffer";
|
|
7
|
+
import { AddressInfo } from "net";
|
|
8
|
+
import { BindOptions, RemoteInfo, Socket as Socket$1, SocketOptions, SocketType } from "dgram";
|
|
9
|
+
import { EventEmitter } from "events";
|
|
10
|
+
declare namespace dgram_d_exports {
|
|
11
|
+
export { Socket$2 as Socket, createSocket, _default as default };
|
|
12
|
+
}
|
|
13
|
+
type WebVpnUdpSocket = Resolvers['cloud']['webvpn']['udpSocket'];
|
|
14
|
+
interface EventEmitterOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Enables automatic capturing of promise rejection.
|
|
17
|
+
*/
|
|
18
|
+
captureRejections?: boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare class Socket$2 extends EventEmitter implements Socket$1 {
|
|
21
|
+
_type: 'udp4' | 'udp6';
|
|
22
|
+
_localAddress?: {
|
|
23
|
+
address: string;
|
|
24
|
+
family: string;
|
|
25
|
+
port: number;
|
|
26
|
+
};
|
|
27
|
+
_remoteAddress?: {
|
|
28
|
+
address: string;
|
|
29
|
+
family: string;
|
|
30
|
+
port: number;
|
|
31
|
+
};
|
|
32
|
+
_connectedLocally?: boolean;
|
|
33
|
+
_connectGeneration: number;
|
|
34
|
+
_destroyed: boolean;
|
|
35
|
+
_busyRelease?: () => void;
|
|
36
|
+
_webVPNUdpSocketPromise?: Promise<Awaited<ReturnType<WebVpnUdpSocket>> | undefined>;
|
|
37
|
+
_dataPort?: MessagePort;
|
|
38
|
+
_socketId?: number;
|
|
39
|
+
_sendQueue: Uint8Array[];
|
|
40
|
+
_sendQueueBytes: number;
|
|
41
|
+
_sendFlushScheduled: boolean;
|
|
42
|
+
_peerTailCache: Map<string, Uint8Array<ArrayBufferLike>>;
|
|
43
|
+
_relayChoice?: RelayChoice;
|
|
44
|
+
/** the relay serving this socket once it is bound, read through `relayOf` */
|
|
45
|
+
_relay?: string;
|
|
46
|
+
constructor(options: SocketOptions & EventEmitterOptions & RelayOption & {
|
|
47
|
+
connection?: ReturnType<WebVpnUdpSocket>;
|
|
48
|
+
});
|
|
49
|
+
_lastRecvBufferSize: number;
|
|
50
|
+
_lastSendBufferSize: number;
|
|
51
|
+
_lastTtl: number;
|
|
52
|
+
_lastMulticastTtl: number;
|
|
53
|
+
_lastMulticastLoopback: boolean;
|
|
54
|
+
_setUdpOption(option: UdpSocketOption): void;
|
|
55
|
+
_dataPortAcks: boolean;
|
|
56
|
+
_dataPortConsumedBytes: number;
|
|
57
|
+
_dataPortAckedBytes: number;
|
|
58
|
+
_ackDataPortBatch(batchBytes: number): void;
|
|
59
|
+
_onTransportClosed(reason?: string): void;
|
|
60
|
+
_onDataPortBatch(buffer: ArrayBuffer): void;
|
|
61
|
+
_peerTail(address: string | undefined, port: number | undefined): Uint8Array;
|
|
62
|
+
_portSend(message: Uint8Array, address: string | undefined, port: number | undefined): void;
|
|
63
|
+
addMembership(multicastAddress: string, multicastInterface?: string | undefined): void;
|
|
64
|
+
address(): AddressInfo;
|
|
65
|
+
bind(port?: number | undefined, address?: string | undefined, callback?: (() => void) | undefined): this;
|
|
66
|
+
bind(port?: number | undefined, callback?: (() => void) | undefined): this;
|
|
67
|
+
bind(callback?: (() => void) | undefined): this;
|
|
68
|
+
bind(options: BindOptions, callback?: (() => void) | undefined): this;
|
|
69
|
+
/**
|
|
70
|
+
* Wires the socket up from a connection already in hand and reports it as bound; also the seam a
|
|
71
|
+
* test uses to reach a refused bind without mocking the resolver. `endpoints` publishes the local
|
|
72
|
+
* address synchronously, as net.ts does: `address()` throws EBADF until the connection resolves,
|
|
73
|
+
* while Node fills an address in before reporting a socket bound.
|
|
74
|
+
*/
|
|
75
|
+
__webvpn_udp_socket_init__(connection: ReturnType<WebVpnUdpSocket>, endpoints?: Awaited<ReturnType<WebVpnUdpSocket>>): Promise<UdpSocketResult | undefined>;
|
|
76
|
+
close(callback?: (() => void) | undefined): this;
|
|
77
|
+
connect(port: number, address?: string, callback?: () => void): void;
|
|
78
|
+
connect(port: number, callback: () => void): void;
|
|
79
|
+
disconnect(): void;
|
|
80
|
+
dropMembership(multicastAddress: string, multicastInterface?: string | undefined): void;
|
|
81
|
+
getRecvBufferSize(): number;
|
|
82
|
+
getSendBufferSize(): number;
|
|
83
|
+
/** Queue measurements are not exposed by the browser transport. Always returns 0. */
|
|
84
|
+
getSendQueueSize(): number;
|
|
85
|
+
/** Queue measurements are not exposed by the browser transport. Always returns 0. */
|
|
86
|
+
getSendQueueCount(): number;
|
|
87
|
+
/** No-op in a browser, which has no Node process-liveness handle. */
|
|
88
|
+
ref(): this;
|
|
89
|
+
remoteAddress(): AddressInfo;
|
|
90
|
+
send(msg: string | readonly any[] | Uint8Array, port?: number | undefined, address?: string | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
91
|
+
send(msg: string | readonly any[] | Uint8Array, port?: number | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
92
|
+
send(msg: string | readonly any[] | Uint8Array, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
93
|
+
send(msg: string | Uint8Array, offset: number, length: number, port?: number | undefined, address?: string | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
94
|
+
send(msg: string | Uint8Array, offset: number, length: number, port?: number | undefined, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
95
|
+
send(msg: string | Uint8Array, offset: number, length: number, callback?: ((error: Error | null, bytes: number) => void) | undefined): void;
|
|
96
|
+
send(msg: unknown, offset?: unknown, length?: unknown, port?: unknown, address?: unknown, callback?: unknown): void;
|
|
97
|
+
setBroadcast(flag: boolean): void;
|
|
98
|
+
/** No-op. The browser transport does not expose an interface index or address. */
|
|
99
|
+
setMulticastInterface(multicastInterface: string): void;
|
|
100
|
+
setMulticastLoopback(flag: boolean): boolean;
|
|
101
|
+
setMulticastTTL(ttl: number): number;
|
|
102
|
+
setRecvBufferSize(size: number): void;
|
|
103
|
+
setSendBufferSize(size: number): void;
|
|
104
|
+
setTTL(ttl: number): number;
|
|
105
|
+
/** No-op in a browser, which has no Node process-liveness handle. */
|
|
106
|
+
unref(): this;
|
|
107
|
+
/** Not implemented by the browser transport. This method currently does nothing. */
|
|
108
|
+
addSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string | undefined): void;
|
|
109
|
+
/** Not implemented by the browser transport. This method currently does nothing. */
|
|
110
|
+
dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string | undefined): void;
|
|
111
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
declare const createSocket: (options: SocketType | (SocketOptions & RelayOption), callback?: (msg: Buffer, rinfo: RemoteInfo) => void) => Socket$2;
|
|
114
|
+
declare const _default: {
|
|
115
|
+
Socket: typeof Socket$2;
|
|
116
|
+
createSocket: typeof createSocket;
|
|
117
|
+
};
|
|
118
|
+
export { dgram_d_exports as i, _default as n, createSocket as r, Socket$2 as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-DrvhPN56.cjs"),n=require("./busy-BXbVH595.cjs"),r=require("./relay-choice-JC_JJY_M.cjs"),i=require("./utils-BpHmMkIR.cjs"),a=require("./wire.cjs");let o=require("buffer"),s=require("events"),c=require("ip-address");var l=e.t({Socket:()=>u,createSocket:()=>g,default:()=>_}),u=class extends s.EventEmitter{_type;_localAddress;_remoteAddress;_connectedLocally;_connectGeneration=0;_destroyed=!1;_busyRelease;_webVPNUdpSocketPromise;_dataPort;_socketId;_sendQueue=[];_sendQueueBytes=0;_sendFlushScheduled=!1;_peerTailCache=new Map;_relayChoice;_relay;constructor(e){if(super(e),!e)throw Error(`Missing options`);this._type=e.type,this._relayChoice=e.relay,e.connection&&this.__webvpn_udp_socket_init__(e.connection)}_lastRecvBufferSize=0;_lastSendBufferSize=0;_lastTtl=64;_lastMulticastTtl=1;_lastMulticastLoopback=!0;_setUdpOption(e){this._webVPNUdpSocketPromise?this._webVPNUdpSocketPromise.then(async t=>{if(t)try{await t.setOption(e)}catch(e){this.emit(`error`,e)}}):this.emit(`error`,Error(`Cannot set socket option before bind`))}_dataPortAcks=!1;_dataPortConsumedBytes=0;_dataPortAckedBytes=0;_ackDataPortBatch(e){if(!this._dataPortAcks||!this._dataPort||(this._dataPortConsumedBytes+=e,this._dataPortAckedBytes!==0&&this._dataPortConsumedBytes-this._dataPortAckedBytes<524288))return;this._dataPortAckedBytes=this._dataPortConsumedBytes;let t={type:a.UDP_PORT_ACK_TYPE,consumedBytes:this._dataPortConsumedBytes};this._dataPort.postMessage(t)}_onTransportClosed(e){this._destroyed||(this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0,this.listenerCount(`error`)>0&&this.emit(`error`,Error(e||`WebVPN session closed`)),this.emit(`close`))}_onDataPortBatch(e){let t=new DataView(e),n=!1,r,i=0;for(;i+4<=e.byteLength;){let a=t.getUint32(i);i+=4;let s=i+a;if(s>e.byteLength)break;let c=i+4,l=t.getUint8(c);c+=1;let u,d,f;if(l===2){if(!this._remoteAddress){i=s;continue}u=this._remoteAddress.address,d=this._remoteAddress.family,f=this._remoteAddress.port}else{let n=new Uint8Array(e,c,l===0?4:16);l===0?(d=`IPv4`,u=`${n[0]}.${n[1]}.${n[2]}.${n[3]}`):(d=`IPv6`,u=m(n)),c+=n.byteLength,f=t.getUint16(c),c+=2}let p=t.getUint32(c);c+=4;try{this.emit(`message`,o.Buffer.from(e.slice(c,c+p)),{address:u,family:d,port:f,size:p})}catch(e){n||(n=!0,r=e)}i=s}if(n)throw r}_peerTail(e,t){if(e===void 0||t===void 0)return d;let n=`${e}|${t}`,r=this._peerTailCache.get(n);if(r)return r;let i=c.Address4.isValid(e)?p(e):h(e),a=new Uint8Array(1+i.byteLength+2);return a[0]=i.byteLength===4?0:1,a.set(i,1),new DataView(a.buffer).setUint16(1+i.byteLength,t),this._peerTailCache.size>=4096&&this._peerTailCache.clear(),this._peerTailCache.set(n,a),a}_portSend(e,t,n){let r=this._peerTail(t,n),i=new Uint8Array(8+r.byteLength+4+e.byteLength),a=new DataView(i.buffer);a.setUint32(0,i.byteLength-4),a.setUint32(4,this._socketId),i.set(r,8),a.setUint32(8+r.byteLength,e.byteLength),i.set(e,12+r.byteLength),this._sendQueue.push(i),this._sendQueueBytes+=i.byteLength,!this._sendFlushScheduled&&(this._sendFlushScheduled=!0,queueMicrotask(()=>{this._sendFlushScheduled=!1;let e=this._sendQueue,t=this._sendQueueBytes;if(this._sendQueue=[],this._sendQueueBytes=0,!e.length||!this._dataPort)return;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;this._dataPort.postMessage(n.buffer,[n.buffer])}))}addMembership(e,t){if(c.Address4.isValid(e)){let n=p(e),r=t&&c.Address4.isValid(t)?p(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:5,group:n,interface:r})}else if(c.Address6.isValid(e)){let t=h(e);this._setUdpOption({type:7,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}address(){if(!this._localAddress)throw Error(`EBADF`);return this._localAddress}bind(...e){let n=i.i(...e),a=this._type===`udp6`?`::`:`0.0.0.0`,o=this._relayChoice,s=this.__webvpn_udp_socket_init__(t.s(`a udp socket`).then(e=>(o!==void 0&&r.t(e,`dgram.createSocket`),e.cloud.webvpn.udpSocket({type:this._type,address:n.address??a,port:n.port,dataPort:!0,relay:o}))));return n.callback&&s.then(e=>{e&&n.callback.call(this)}),this}__webvpn_udp_socket_init__(e,t){return t&&(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort}),this._busyRelease??=n.t(`udp socket`),this._webVPNUdpSocketPromise=e.then(e=>{if(e.dataPort)this._socketId=e.socketId,this._dataPort=e.dataPort,this._dataPortAcks=e.dataPortAcks===!0,this._dataPort.onmessage=e=>{try{this._onDataPortBatch(e.data)}finally{this._ackDataPortBatch(e.data.byteLength)}};else{let t=e.dataReadableStream.getReader();(async()=>{for(;;){let{value:e,done:n}=await t.read();if(n)return;this.emit(`message`,o.Buffer.from(e.data),{address:e.address,family:e.family,port:e.port,size:e.size})}})().catch(e=>this._onTransportClosed(e instanceof Error?e.message:void 0))}return e.closed?.then(e=>this._onTransportClosed(e?.reason)).catch(()=>{}),this._relay=e.relay,this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},e}).catch(e=>{this.emit(`error`,e)}),this._webVPNUdpSocketPromise.then(e=>{e?this.emit(`listening`):this._busyRelease?.()}),this._webVPNUdpSocketPromise}close(e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);return this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=this._destroyed;this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0;try{await t.close()}finally{try{e&&e()}finally{n||this.emit(`close`)}}}).catch(()=>{}),this}connect(...e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=e[0],r=this._type===`udp6`?`::1`:`127.0.0.1`,i=typeof e[1]==`string`?e[1]:r,a=typeof e.at(-1)==`function`?e.at(-1):void 0,o=await t.connect({remotePort:n,remoteAddress:i});this._connectedLocally=o?.local===!0,this._remoteAddress=o?.address?{address:o.address,family:o.family,port:o.port}:{address:i,family:this._type===`udp6`?`IPv6`:`IPv4`,port:n},this._connectGeneration+=1,a&&a()}).catch(e=>{this.emit(`error`,e)})}disconnect(){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);let e=this._remoteAddress,t=this._connectedLocally,n=this._connectGeneration;this._remoteAddress=void 0,this._connectedLocally=void 0,this._webVPNUdpSocketPromise.then(e=>e?.disconnect?.()).catch(r=>{this._connectGeneration===n&&(this._remoteAddress=e,this._connectedLocally=t),this.emit(`error`,r)})}dropMembership(e,t){if(c.Address4.isValid(e)){let n=p(e),r=t&&c.Address4.isValid(t)?p(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:6,group:n,interface:r})}else if(c.Address6.isValid(e)){let t=h(e);this._setUdpOption({type:8,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}getRecvBufferSize(){return this._lastRecvBufferSize}getSendBufferSize(){return this._lastSendBufferSize}getSendQueueSize(){return 0}getSendQueueCount(){return 0}ref(){return this}remoteAddress(){if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);return{address:this._remoteAddress.address,family:this._remoteAddress.family,port:this._remoteAddress.port}}send(...e){this._webVPNUdpSocketPromise||this.bind();let t=i.a(...e),n=f(t.message),r=n;if(t.hasRange){let{offset:e,length:i}=t;if(!Number.isInteger(e)||e<0||e>n.byteLength)throw Object.assign(RangeError(`"offset" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});if(!Number.isInteger(i)||i<0||i>n.byteLength-e)throw Object.assign(RangeError(`"length" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});r=n.subarray(e,e+i)}let a=this._type===`udp6`?`::1`:`127.0.0.1`;if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(e=>{if(!e)throw Error(`Socket not bound`);let n=t.callback,i=t.address??a,o=this._remoteAddress!==void 0&&t.address===void 0;this._dataPort&&(o||c.Address4.isValid(i)||c.Address6.isValid(i))?(this._portSend(r,o?void 0:i,o?void 0:t.port),n?.call(this,null,r.byteLength)):e.send({port:t.port,address:i,message:r.byteOffset===0&&r.byteLength===r.buffer.byteLength?r.buffer:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)}).then(()=>n?.call(this,null,r.byteLength),e=>n?n.call(this,e,0):this.emit(`error`,e))})}setBroadcast(e){this._setUdpOption({type:0,value:e})}setMulticastInterface(e){}setMulticastLoopback(e){return this._setUdpOption({type:3,value:e}),this._setUdpOption({type:4,value:e}),this._lastMulticastLoopback=e,e}setMulticastTTL(e){return this._setUdpOption({type:2,value:e}),this._lastMulticastTtl=e,e}setRecvBufferSize(e){this._setUdpOption({type:10,value:e}),this._lastRecvBufferSize=e}setSendBufferSize(e){this._setUdpOption({type:9,value:e}),this._lastSendBufferSize=e}setTTL(e){return this._setUdpOption({type:1,value:e}),this._lastTtl=e,e}unref(){return this}addSourceSpecificMembership(e,t,n){}dropSourceSpecificMembership(e,t,n){}async[Symbol.asyncDispose](){await new Promise(e=>{this.close(e)})}},d=new Uint8Array([2]),f=e=>{if(typeof e==`string`)return i.s.encode(e);if(e instanceof Uint8Array)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(Array.isArray(e)){let t=e.map(f),n=new Uint8Array(t.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let e of t)n.set(e,r),r+=e.byteLength;return n}return new Uint8Array(e)},p=e=>{let t=e.split(`.`).map(e=>parseInt(e,10));if(t.length!==4||t.some(e=>Number.isNaN(e)||e<0||e>255))throw Error(`Invalid IPv4 address: ${e}`);return new Uint8Array(t)},m=e=>{let t=[];for(let n=0;n<16;n+=2)t.push(e[n]<<8|e[n+1]);let n=-1,r=1;for(let e=0;e<8;){if(t[e]!==0){e++;continue}let i=e;for(;i<8&&t[i]===0;)i++;i-e>r&&(n=e,r=i-e),e=i}return n===-1?t.map(e=>e.toString(16)).join(`:`):`${t.slice(0,n).map(e=>e.toString(16)).join(`:`)}::${t.slice(n+r).map(e=>e.toString(16)).join(`:`)}`},h=e=>{let t=new c.Address6(e).getBitsBase16(0,128).match(/.{2}/g);if(!t||t.length!==16)throw Error(`Invalid IPv6 address: ${e}`);return new Uint8Array(t.map(e=>parseInt(e,16)))},g=(e,t)=>{let n=new u(typeof e==`string`?{type:e}:e);return t&&n.on(`message`,t),n},_={Socket:u,createSocket:g};Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return u}});
|
package/dgram.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-BSk3dc_X.cjs"),n=require("./busy-BXbVH595.cjs"),r=require("./relay-choice-JC_JJY_M.cjs"),i=require("./utils-BpHmMkIR.cjs"),a=require("./wire.cjs");let o=require("buffer"),s=require("events"),c=require("ip-address");var l=e.t({Socket:()=>u,createSocket:()=>g,default:()=>_}),u=class extends s.EventEmitter{_type;_localAddress;_remoteAddress;_connectedLocally;_connectGeneration=0;_destroyed=!1;_busyRelease;_webVPNUdpSocketPromise;_dataPort;_socketId;_sendQueue=[];_sendQueueBytes=0;_sendFlushScheduled=!1;_peerTailCache=new Map;_relayChoice;_relay;constructor(e){if(super(e),!e)throw Error(`Missing options`);this._type=e.type,this._relayChoice=e.relay,e.connection&&this.__webvpn_udp_socket_init__(e.connection)}_lastRecvBufferSize=0;_lastSendBufferSize=0;_lastTtl=64;_lastMulticastTtl=1;_lastMulticastLoopback=!0;_setUdpOption(e){if(!this._webVPNUdpSocketPromise){this.emit(`error`,Error(`Cannot set socket option before bind`));return}this._webVPNUdpSocketPromise.then(async t=>{if(t)try{await t.setOption(e)}catch(e){this.emit(`error`,e)}})}_dataPortAcks=!1;_dataPortConsumedBytes=0;_dataPortAckedBytes=0;_ackDataPortBatch(e){if(!this._dataPortAcks||!this._dataPort||(this._dataPortConsumedBytes+=e,this._dataPortAckedBytes!==0&&this._dataPortConsumedBytes-this._dataPortAckedBytes<524288))return;this._dataPortAckedBytes=this._dataPortConsumedBytes;let t={type:a.UDP_PORT_ACK_TYPE,consumedBytes:this._dataPortConsumedBytes};this._dataPort.postMessage(t)}_onTransportClosed(e){this._destroyed||(this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0,this.listenerCount(`error`)>0&&this.emit(`error`,Error(e||`WebVPN session closed`)),this.emit(`close`))}_onDataPortBatch(e){let t=new DataView(e),n=!1,r,i=0;for(;i+4<=e.byteLength;){let a=t.getUint32(i);i+=4;let s=i+a;if(s>e.byteLength)break;let c=i+4,l=t.getUint8(c);c+=1;let u,d,f;if(l===2){if(!this._remoteAddress){i=s;continue}u=this._remoteAddress.address,d=this._remoteAddress.family,f=this._remoteAddress.port}else{let n=new Uint8Array(e,c,l===0?4:16);l===0?(d=`IPv4`,u=`${n[0]}.${n[1]}.${n[2]}.${n[3]}`):(d=`IPv6`,u=m(n)),c+=n.byteLength,f=t.getUint16(c),c+=2}let p=t.getUint32(c);c+=4;try{this.emit(`message`,o.Buffer.from(e.slice(c,c+p)),{address:u,family:d,port:f,size:p})}catch(e){n||(n=!0,r=e)}i=s}if(n)throw r}_peerTail(e,t){if(e===void 0||t===void 0)return d;let n=`${e}|${t}`,r=this._peerTailCache.get(n);if(r)return r;let i=c.Address4.isValid(e)?p(e):h(e),a=new Uint8Array(1+i.byteLength+2);return a[0]=i.byteLength===4?0:1,a.set(i,1),new DataView(a.buffer).setUint16(1+i.byteLength,t),this._peerTailCache.size>=4096&&this._peerTailCache.clear(),this._peerTailCache.set(n,a),a}_portSend(e,t,n){let r=this._peerTail(t,n),i=new Uint8Array(8+r.byteLength+4+e.byteLength),a=new DataView(i.buffer);a.setUint32(0,i.byteLength-4),a.setUint32(4,this._socketId),i.set(r,8),a.setUint32(8+r.byteLength,e.byteLength),i.set(e,12+r.byteLength),this._sendQueue.push(i),this._sendQueueBytes+=i.byteLength,!this._sendFlushScheduled&&(this._sendFlushScheduled=!0,queueMicrotask(()=>{this._sendFlushScheduled=!1;let e=this._sendQueue,t=this._sendQueueBytes;if(this._sendQueue=[],this._sendQueueBytes=0,!e.length||!this._dataPort)return;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;this._dataPort.postMessage(n.buffer,[n.buffer])}))}addMembership(e,t){if(c.Address4.isValid(e)){let n=p(e),r=t&&c.Address4.isValid(t)?p(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:5,group:n,interface:r})}else if(c.Address6.isValid(e)){let t=h(e);this._setUdpOption({type:7,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}address(){if(!this._localAddress)throw Error(`EBADF`);return this._localAddress}bind(...e){let n=i.i(...e),a=this._type===`udp6`?`::`:`0.0.0.0`,o=this._relayChoice,s=this.__webvpn_udp_socket_init__(t.s(`a udp socket`).then(e=>(o!==void 0&&r.t(e,`dgram.createSocket`),e.cloud.webvpn.udpSocket({type:this._type,address:n.address??a,port:n.port,dataPort:!0,relay:o}))));return n.callback&&s.then(e=>{e&&n.callback.call(this)}),this}__webvpn_udp_socket_init__(e,t){return t&&(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort}),this._busyRelease??=n.t(`udp socket`),this._webVPNUdpSocketPromise=e.then(e=>{if(e.dataPort)this._socketId=e.socketId,this._dataPort=e.dataPort,this._dataPortAcks=e.dataPortAcks===!0,this._dataPort.onmessage=e=>{try{this._onDataPortBatch(e.data)}finally{this._ackDataPortBatch(e.data.byteLength)}};else{let t=e.dataReadableStream.getReader();(async()=>{for(;;){let{value:e,done:n}=await t.read();if(n)return;this.emit(`message`,o.Buffer.from(e.data),{address:e.address,family:e.family,port:e.port,size:e.size})}})().catch(e=>this._onTransportClosed(e instanceof Error?e.message:void 0))}return e.closed?.then(e=>this._onTransportClosed(e?.reason)).catch(()=>{}),this._relay=e.relay,this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},e}).catch(e=>{this.emit(`error`,e)}),this._webVPNUdpSocketPromise.then(e=>{if(!e){this._busyRelease?.();return}this.emit(`listening`)}),this._webVPNUdpSocketPromise}close(e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);return this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=this._destroyed;this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0;try{await t.close()}finally{try{e&&e()}finally{n||this.emit(`close`)}}}).catch(()=>{}),this}connect(...e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=e[0],r=this._type===`udp6`?`::1`:`127.0.0.1`,i=typeof e[1]==`string`?e[1]:r,a=typeof e.at(-1)==`function`?e.at(-1):void 0,o=await t.connect({remotePort:n,remoteAddress:i});this._connectedLocally=o?.local===!0,this._remoteAddress=o?.address?{address:o.address,family:o.family,port:o.port}:{address:i,family:this._type===`udp6`?`IPv6`:`IPv4`,port:n},this._connectGeneration+=1,a&&a()}).catch(e=>{this.emit(`error`,e)})}disconnect(){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);let e=this._remoteAddress,t=this._connectedLocally,n=this._connectGeneration;this._remoteAddress=void 0,this._connectedLocally=void 0,this._webVPNUdpSocketPromise.then(e=>e?.disconnect?.()).catch(r=>{this._connectGeneration===n&&(this._remoteAddress=e,this._connectedLocally=t),this.emit(`error`,r)})}dropMembership(e,t){if(c.Address4.isValid(e)){let n=p(e),r=t&&c.Address4.isValid(t)?p(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:6,group:n,interface:r})}else if(c.Address6.isValid(e)){let t=h(e);this._setUdpOption({type:8,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}getRecvBufferSize(){return this._lastRecvBufferSize}getSendBufferSize(){return this._lastSendBufferSize}getSendQueueSize(){return 0}getSendQueueCount(){return 0}ref(){return this}remoteAddress(){if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);return{address:this._remoteAddress.address,family:this._remoteAddress.family,port:this._remoteAddress.port}}send(...e){this._webVPNUdpSocketPromise||this.bind();let t=i.a(...e),n=f(t.message),r=n;if(t.hasRange){let{offset:e,length:i}=t;if(!Number.isInteger(e)||e<0||e>n.byteLength)throw Object.assign(RangeError(`"offset" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});if(!Number.isInteger(i)||i<0||i>n.byteLength-e)throw Object.assign(RangeError(`"length" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});r=n.subarray(e,e+i)}let a=this._type===`udp6`?`::1`:`127.0.0.1`;if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(e=>{if(!e)throw Error(`Socket not bound`);let n=t.callback,i=t.address??a,o=this._remoteAddress!==void 0&&t.address===void 0;if(this._dataPort&&(o||c.Address4.isValid(i)||c.Address6.isValid(i))){this._portSend(r,o?void 0:i,o?void 0:t.port),n?.call(this,null,r.byteLength);return}e.send({port:t.port,address:i,message:r.byteOffset===0&&r.byteLength===r.buffer.byteLength?r.buffer:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)}).then(()=>n?.call(this,null,r.byteLength),e=>n?n.call(this,e,0):this.emit(`error`,e))})}setBroadcast(e){this._setUdpOption({type:0,value:e})}setMulticastInterface(e){}setMulticastLoopback(e){return this._setUdpOption({type:3,value:e}),this._setUdpOption({type:4,value:e}),this._lastMulticastLoopback=e,e}setMulticastTTL(e){return this._setUdpOption({type:2,value:e}),this._lastMulticastTtl=e,e}setRecvBufferSize(e){this._setUdpOption({type:10,value:e}),this._lastRecvBufferSize=e}setSendBufferSize(e){this._setUdpOption({type:9,value:e}),this._lastSendBufferSize=e}setTTL(e){return this._setUdpOption({type:1,value:e}),this._lastTtl=e,e}unref(){return this}addSourceSpecificMembership(e,t,n){}dropSourceSpecificMembership(e,t,n){}async[Symbol.asyncDispose](){await new Promise(e=>{this.close(e)})}},d=new Uint8Array([2]),f=e=>{if(typeof e==`string`)return i.s.encode(e);if(e instanceof Uint8Array)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(Array.isArray(e)){let t=e.map(f),n=new Uint8Array(t.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let e of t)n.set(e,r),r+=e.byteLength;return n}return new Uint8Array(e)},p=e=>{let t=e.split(`.`).map(e=>parseInt(e,10));if(t.length!==4||t.some(e=>Number.isNaN(e)||e<0||e>255))throw Error(`Invalid IPv4 address: ${e}`);return new Uint8Array(t)},m=e=>{let t=[];for(let n=0;n<16;n+=2)t.push(e[n]<<8|e[n+1]);let n=-1,r=1;for(let e=0;e<8;){if(t[e]!==0){e++;continue}let i=e;for(;i<8&&t[i]===0;)i++;i-e>r&&(n=e,r=i-e),e=i}return n===-1?t.map(e=>e.toString(16)).join(`:`):`${t.slice(0,n).map(e=>e.toString(16)).join(`:`)}::${t.slice(n+r).map(e=>e.toString(16)).join(`:`)}`},h=e=>{let t=new c.Address6(e).getBitsBase16(0,128).match(/.{2}/g);if(!t||t.length!==16)throw Error(`Invalid IPv6 address: ${e}`);return new Uint8Array(t.map(e=>parseInt(e,16)))},g=(e,t)=>{let n=new u(typeof e==`string`?{type:e}:e);return t&&n.on(`message`,t),n},_={Socket:u,createSocket:g};exports.Socket=u,exports.createSocket=g,exports.default=_,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return l}});
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./dgram-D9ljiUFh.cjs");exports.Socket=e.t,exports.createSocket=e.n,exports.default=e.r;
|