opencharm 0.11.0 → 0.12.0
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 +1 -1
- package/dist/main.mjs +2908 -18
- package/package.json +1 -1
- package/sim/charm_sim.wasm +0 -0
package/dist/main.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { chmodSync, createWriteStream, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { homedir, hostname, platform, tmpdir } from "node:os";
|
|
5
5
|
import { dirname, extname, isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { createConnection, createServer } from "node:net";
|
|
@@ -15,6 +15,9 @@ import { pipeline } from "node:stream/promises";
|
|
|
15
15
|
import * as acp from "@agentclientprotocol/sdk";
|
|
16
16
|
import OpusScript from "opusscript";
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
18
|
+
//#region \0rolldown/runtime.js
|
|
19
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
20
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
18
21
|
//#endregion
|
|
19
22
|
//#region ../design/src/faces-data.ts
|
|
20
23
|
const facesData = {
|
|
@@ -870,6 +873,11 @@ const schema = z.object({
|
|
|
870
873
|
publicUrl: z.url().optional(),
|
|
871
874
|
maxConnections: z.number().int().min(1).max(1024).default(16),
|
|
872
875
|
allowInsecureRemote: z.boolean().default(false),
|
|
876
|
+
network: z.object({
|
|
877
|
+
host: z.string().min(1).default("0.0.0.0"),
|
|
878
|
+
port: z.number().int().min(0).max(65535).default(8787)
|
|
879
|
+
}).optional(),
|
|
880
|
+
discoverable: z.boolean().default(true),
|
|
873
881
|
voice: voiceSchema.default({ provider: "fake" }),
|
|
874
882
|
agent: agentSchema.default({ adapter: "fake" }),
|
|
875
883
|
turnTimeoutSeconds: z.number().int().min(5).max(600).default(60),
|
|
@@ -957,6 +965,7 @@ function parseConfig(input, baseDir) {
|
|
|
957
965
|
throw new Error(`Invalid charmd config: ${problems}`);
|
|
958
966
|
}
|
|
959
967
|
const config = result.data;
|
|
968
|
+
if (config.network && !config.allowInsecureRemote) throw new Error(`Invalid charmd config: "network" listens beyond this computer; set "allowInsecureRemote": true for a trusted home network`);
|
|
960
969
|
if (!LOOPBACK.has(config.listen.host) && !config.allowInsecureRemote) throw new Error(`Invalid charmd config: listen.host ${config.listen.host} is not loopback; put Caddy in front, or set "allowInsecureRemote": true for a trusted LAN`);
|
|
961
970
|
const statePath = baseDir && !isAbsolute(config.statePath) ? resolve(baseDir, config.statePath) : config.statePath;
|
|
962
971
|
const base = baseDir ?? process.cwd();
|
|
@@ -977,6 +986,9 @@ function loadConfig(path, options = {}) {
|
|
|
977
986
|
const found = (options.searchPaths ?? DEFAULT_SEARCH_PATHS).find((p) => existsSync(p));
|
|
978
987
|
return found ? parseConfig(JSON.parse(readFileSync(found, "utf8")), dirname(found)) : parseConfig({});
|
|
979
988
|
}
|
|
989
|
+
function isLoopback(host) {
|
|
990
|
+
return LOOPBACK.has(host);
|
|
991
|
+
}
|
|
980
992
|
//#endregion
|
|
981
993
|
//#region ../charmd/src/admin/admin-client.ts
|
|
982
994
|
const MAX_REPLY_BYTES = 262144;
|
|
@@ -1008,7 +1020,7 @@ function sendAdmin(socketPath, request) {
|
|
|
1008
1020
|
}
|
|
1009
1021
|
//#endregion
|
|
1010
1022
|
//#region package.json
|
|
1011
|
-
var version = "0.
|
|
1023
|
+
var version = "0.12.0";
|
|
1012
1024
|
function channelToCube(value) {
|
|
1013
1025
|
if (value < 48) return 0;
|
|
1014
1026
|
if (value < 115) return 1;
|
|
@@ -1175,12 +1187,23 @@ function fail$2(ctx, message) {
|
|
|
1175
1187
|
ctx.err.write(`${message}\n`);
|
|
1176
1188
|
process.exitCode = 1;
|
|
1177
1189
|
}
|
|
1178
|
-
async function
|
|
1179
|
-
const
|
|
1180
|
-
if (
|
|
1181
|
-
fail$2(ctx, "
|
|
1190
|
+
async function chooseWaiting(ctx, deps) {
|
|
1191
|
+
const charms = ((await deps.send(deps.socket, { cmd: "waiting" })).charms ?? []).filter((c) => /^\d{6}$/.test(c.code));
|
|
1192
|
+
if (charms.length === 0) {
|
|
1193
|
+
fail$2(ctx, "No charm is waiting to pair. Turn it on and connect it to this charmd: its screen shows a 6-digit code. Then: opencharm pair [code]");
|
|
1182
1194
|
return;
|
|
1183
1195
|
}
|
|
1196
|
+
ctx.out.write(`${charms.length === 1 ? "A charm is" : `${charms.length} charms are`} waiting to pair${charms.some((c) => c.kind) ? ` (${charms.map((c) => c.kind ?? "?").join(", ")})` : ""}.\n`);
|
|
1197
|
+
const typed = (await deps.prompt("Type the code on your charm's screen: ")).replace(/\s/g, "");
|
|
1198
|
+
if (!charms.some((c) => c.code === typed)) {
|
|
1199
|
+
fail$2(ctx, "That code isn't one of them. Nothing was changed.");
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
return typed;
|
|
1203
|
+
}
|
|
1204
|
+
async function pair(ctx, args, deps) {
|
|
1205
|
+
const code = firstPositional(args) ?? await chooseWaiting(ctx, deps);
|
|
1206
|
+
if (!code) return;
|
|
1184
1207
|
const pin = await deps.prompt("Choose a PIN for the charm (4-12 digits): ");
|
|
1185
1208
|
if (pin !== await deps.prompt("Type it again: ")) {
|
|
1186
1209
|
fail$2(ctx, "The PINs didn't match. Nothing was changed.");
|
|
@@ -1518,7 +1541,7 @@ function runHelp(ctx) {
|
|
|
1518
1541
|
opencharm serve start charmd [--config <file>]
|
|
1519
1542
|
opencharm sim the emulator, for developing the charm [--url <ws>] [--port <n>]
|
|
1520
1543
|
opencharm voice the local voice's models [install: download them now]
|
|
1521
|
-
opencharm pair
|
|
1544
|
+
opencharm pair [code] pair the charm showing [code]; no code: the charms waiting [--name <name>]
|
|
1522
1545
|
opencharm status paired charms and their state
|
|
1523
1546
|
opencharm lock <charm> lock a charm now
|
|
1524
1547
|
opencharm unlock <charm> clear a block and unlock
|
|
@@ -2015,6 +2038,14 @@ function createAdminActions({ store, pairing, sessions, look, agentCanChangeLook
|
|
|
2015
2038
|
return { speak };
|
|
2016
2039
|
});
|
|
2017
2040
|
},
|
|
2041
|
+
waiting() {
|
|
2042
|
+
const live = new Map([...sessions()].map((s) => [s.connectionId, s]));
|
|
2043
|
+
return { charms: pairing.waiting().filter((w) => live.get(w.connectionId)?.state === "unpaired").map((w) => ({
|
|
2044
|
+
code: w.code,
|
|
2045
|
+
kind: live.get(w.connectionId)?.build?.kind,
|
|
2046
|
+
expiresIn: w.expiresIn
|
|
2047
|
+
})) };
|
|
2048
|
+
},
|
|
2018
2049
|
status() {
|
|
2019
2050
|
return {
|
|
2020
2051
|
charmd: identity ?? "unknown",
|
|
@@ -2046,6 +2077,7 @@ const COMMANDS = [
|
|
|
2046
2077
|
"unlock",
|
|
2047
2078
|
"revoke",
|
|
2048
2079
|
"status",
|
|
2080
|
+
"waiting",
|
|
2049
2081
|
"devFace",
|
|
2050
2082
|
"devSay",
|
|
2051
2083
|
"devAsk",
|
|
@@ -2068,7 +2100,9 @@ function socketInUse(path) {
|
|
|
2068
2100
|
async function run$2(actions, request) {
|
|
2069
2101
|
const { cmd, ...args } = typeof request === "object" && request !== null ? request : {};
|
|
2070
2102
|
if (!isCommand(cmd)) throw new Error(`Unknown command ${JSON.stringify(cmd)}`);
|
|
2071
|
-
|
|
2103
|
+
if (cmd === "status") return actions.status();
|
|
2104
|
+
if (cmd === "waiting") return actions.waiting();
|
|
2105
|
+
return actions[cmd](args);
|
|
2072
2106
|
}
|
|
2073
2107
|
function handle(socket, actions) {
|
|
2074
2108
|
let buffer = "";
|
|
@@ -2205,11 +2239,2848 @@ var PairingRegistry = class {
|
|
|
2205
2239
|
this.#byCode.delete(code);
|
|
2206
2240
|
return pending.connectionId;
|
|
2207
2241
|
}
|
|
2242
|
+
waiting() {
|
|
2243
|
+
this.#prune();
|
|
2244
|
+
const now = this.#options.now();
|
|
2245
|
+
return [...this.#byCode.values()].map((p) => ({
|
|
2246
|
+
code: p.code,
|
|
2247
|
+
connectionId: p.connectionId,
|
|
2248
|
+
expiresIn: Math.max(0, Math.round((p.expiresAt - now) / 1e3))
|
|
2249
|
+
}));
|
|
2250
|
+
}
|
|
2208
2251
|
release(connectionId) {
|
|
2209
2252
|
for (const [code, pending] of this.#byCode) if (pending.connectionId === connectionId) this.#byCode.delete(code);
|
|
2210
2253
|
}
|
|
2211
2254
|
};
|
|
2212
2255
|
//#endregion
|
|
2256
|
+
//#region ../../node_modules/bonjour-service/dist/lib/utils/dns-equal.js
|
|
2257
|
+
var require_dns_equal = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2258
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2259
|
+
exports.default = dnsEqual;
|
|
2260
|
+
const capitalLetterRegex = /[A-Z]/g;
|
|
2261
|
+
function toLowerCase(input) {
|
|
2262
|
+
return input.toLowerCase();
|
|
2263
|
+
}
|
|
2264
|
+
function dnsEqual(a, b) {
|
|
2265
|
+
return a.replace(capitalLetterRegex, toLowerCase) === b.replace(capitalLetterRegex, toLowerCase);
|
|
2266
|
+
}
|
|
2267
|
+
}));
|
|
2268
|
+
//#endregion
|
|
2269
|
+
//#region ../../node_modules/bonjour-service/dist/lib/dns-txt.js
|
|
2270
|
+
var require_dns_txt = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2271
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2272
|
+
exports.DnsTxt = void 0;
|
|
2273
|
+
var DnsTxt = class {
|
|
2274
|
+
constructor(opts = {}) {
|
|
2275
|
+
this.binary = opts ? opts.binary : false;
|
|
2276
|
+
}
|
|
2277
|
+
encode(data = {}) {
|
|
2278
|
+
return Object.entries(data).map(([key, value]) => {
|
|
2279
|
+
let item = `${key}=${value}`;
|
|
2280
|
+
return Buffer.from(item);
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
decode(buffer) {
|
|
2284
|
+
var data = {};
|
|
2285
|
+
try {
|
|
2286
|
+
let parts = buffer.toString().split(/=(.+)/);
|
|
2287
|
+
let key = parts[0];
|
|
2288
|
+
data[key] = parts[1];
|
|
2289
|
+
} catch (_) {}
|
|
2290
|
+
return data;
|
|
2291
|
+
}
|
|
2292
|
+
decodeAll(buffer) {
|
|
2293
|
+
return buffer.filter((i) => i.length > 1).map((i) => this.decode(i)).reduce((prev, curr) => {
|
|
2294
|
+
var obj = prev;
|
|
2295
|
+
let [key] = Object.keys(curr);
|
|
2296
|
+
let [value] = Object.values(curr);
|
|
2297
|
+
obj[key] = value;
|
|
2298
|
+
return obj;
|
|
2299
|
+
}, {});
|
|
2300
|
+
}
|
|
2301
|
+
};
|
|
2302
|
+
exports.DnsTxt = DnsTxt;
|
|
2303
|
+
exports.default = DnsTxt;
|
|
2304
|
+
}));
|
|
2305
|
+
//#endregion
|
|
2306
|
+
//#region ../../node_modules/bonjour-service/dist/lib/service-types.js
|
|
2307
|
+
var require_service_types = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2308
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2309
|
+
exports.toType = exports.toString = void 0;
|
|
2310
|
+
const Prefix = (name) => {
|
|
2311
|
+
return "_" + name;
|
|
2312
|
+
};
|
|
2313
|
+
const AllowedProp = (key) => {
|
|
2314
|
+
return [
|
|
2315
|
+
"name",
|
|
2316
|
+
"protocol",
|
|
2317
|
+
"subtype"
|
|
2318
|
+
].includes(key);
|
|
2319
|
+
};
|
|
2320
|
+
const toString = (data) => {
|
|
2321
|
+
let formatted = {
|
|
2322
|
+
name: data.name,
|
|
2323
|
+
protocol: data.protocol,
|
|
2324
|
+
subtype: data.subtype
|
|
2325
|
+
};
|
|
2326
|
+
return Object.entries(formatted).filter(([key, val]) => AllowedProp(key) && val !== void 0).reduce((prev, [key, val]) => {
|
|
2327
|
+
switch (typeof val) {
|
|
2328
|
+
case "object":
|
|
2329
|
+
val.map((i) => prev.push(Prefix(i)));
|
|
2330
|
+
break;
|
|
2331
|
+
default: prev.push(Prefix(val));
|
|
2332
|
+
}
|
|
2333
|
+
return prev;
|
|
2334
|
+
}, []).join(".");
|
|
2335
|
+
};
|
|
2336
|
+
exports.toString = toString;
|
|
2337
|
+
const toType = (string) => {
|
|
2338
|
+
let parts = string.split(".");
|
|
2339
|
+
let subtype;
|
|
2340
|
+
for (let i in parts) {
|
|
2341
|
+
if (parts[i][0] !== "_") continue;
|
|
2342
|
+
parts[i] = parts[i].slice(1);
|
|
2343
|
+
}
|
|
2344
|
+
if (parts.includes("sub")) {
|
|
2345
|
+
subtype = parts.shift();
|
|
2346
|
+
parts.shift();
|
|
2347
|
+
}
|
|
2348
|
+
return {
|
|
2349
|
+
name: parts.shift(),
|
|
2350
|
+
protocol: parts.shift() || null,
|
|
2351
|
+
subtype
|
|
2352
|
+
};
|
|
2353
|
+
};
|
|
2354
|
+
exports.toType = toType;
|
|
2355
|
+
}));
|
|
2356
|
+
//#endregion
|
|
2357
|
+
//#region ../../node_modules/bonjour-service/dist/lib/service.js
|
|
2358
|
+
var require_service = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2359
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
2360
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
2361
|
+
};
|
|
2362
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2363
|
+
exports.Service = void 0;
|
|
2364
|
+
const os_1 = __importDefault(__require("os"));
|
|
2365
|
+
const dns_txt_1 = __importDefault(require_dns_txt());
|
|
2366
|
+
const events_1$1 = __require("events");
|
|
2367
|
+
const service_types_1 = require_service_types();
|
|
2368
|
+
const TLD = ".local";
|
|
2369
|
+
var Service = class extends events_1$1.EventEmitter {
|
|
2370
|
+
constructor(config, start, stop) {
|
|
2371
|
+
super();
|
|
2372
|
+
this.start = start;
|
|
2373
|
+
this.stop = stop;
|
|
2374
|
+
this.probe = true;
|
|
2375
|
+
this.published = false;
|
|
2376
|
+
this.activated = false;
|
|
2377
|
+
this.destroyed = false;
|
|
2378
|
+
this.txtService = new dns_txt_1.default();
|
|
2379
|
+
if (!config.name) throw new Error("ServiceConfig requires `name` property to be set");
|
|
2380
|
+
if (!config.type) throw new Error("ServiceConfig requires `type` property to be set");
|
|
2381
|
+
if (!config.port) throw new Error("ServiceConfig requires `port` property to be set");
|
|
2382
|
+
this.name = config.name.split(".").join("-");
|
|
2383
|
+
this.protocol = config.protocol || "tcp";
|
|
2384
|
+
this.type = (0, service_types_1.toString)({
|
|
2385
|
+
name: config.type,
|
|
2386
|
+
protocol: this.protocol
|
|
2387
|
+
});
|
|
2388
|
+
this.port = config.port;
|
|
2389
|
+
this.host = config.host || os_1.default.hostname();
|
|
2390
|
+
this.fqdn = `${this.name}.${this.type}${TLD}`;
|
|
2391
|
+
this.txt = config.txt;
|
|
2392
|
+
this.subtypes = config.subtypes;
|
|
2393
|
+
this.disableIPv6 = !!config.disableIPv6;
|
|
2394
|
+
}
|
|
2395
|
+
records() {
|
|
2396
|
+
var records = [
|
|
2397
|
+
this.RecordPTR(this),
|
|
2398
|
+
this.RecordSRV(this),
|
|
2399
|
+
this.RecordTXT(this),
|
|
2400
|
+
this.RecordServicePTR(this)
|
|
2401
|
+
];
|
|
2402
|
+
for (let subtype of this.subtypes || []) records.push(this.RecordSubtypePTR(this, subtype));
|
|
2403
|
+
let ifaces = Object.values(os_1.default.networkInterfaces());
|
|
2404
|
+
for (let iface of ifaces) {
|
|
2405
|
+
let addrs = iface;
|
|
2406
|
+
for (let addr of addrs) {
|
|
2407
|
+
if (addr.internal || addr.mac === "00:00:00:00:00:00") continue;
|
|
2408
|
+
switch (addr.family) {
|
|
2409
|
+
case "IPv4":
|
|
2410
|
+
records.push(this.RecordA(this, addr.address));
|
|
2411
|
+
break;
|
|
2412
|
+
case "IPv6":
|
|
2413
|
+
if (this.disableIPv6) break;
|
|
2414
|
+
records.push(this.RecordAAAA(this, addr.address));
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
return records;
|
|
2419
|
+
}
|
|
2420
|
+
RecordPTR(service) {
|
|
2421
|
+
return {
|
|
2422
|
+
name: `${service.type}${TLD}`,
|
|
2423
|
+
type: "PTR",
|
|
2424
|
+
ttl: 28800,
|
|
2425
|
+
data: service.fqdn
|
|
2426
|
+
};
|
|
2427
|
+
}
|
|
2428
|
+
RecordServicePTR(service) {
|
|
2429
|
+
return {
|
|
2430
|
+
name: `_services._dns-sd._udp${TLD}`,
|
|
2431
|
+
type: "PTR",
|
|
2432
|
+
ttl: 120,
|
|
2433
|
+
data: `${service.type}${TLD}`
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2436
|
+
RecordSubtypePTR(service, subtype) {
|
|
2437
|
+
return {
|
|
2438
|
+
name: `_${subtype}._sub.${service.type}${TLD}`,
|
|
2439
|
+
type: "PTR",
|
|
2440
|
+
ttl: 28800,
|
|
2441
|
+
data: `${service.name}.${service.type}${TLD}`
|
|
2442
|
+
};
|
|
2443
|
+
}
|
|
2444
|
+
RecordSRV(service) {
|
|
2445
|
+
return {
|
|
2446
|
+
name: service.fqdn,
|
|
2447
|
+
type: "SRV",
|
|
2448
|
+
ttl: 120,
|
|
2449
|
+
data: {
|
|
2450
|
+
port: service.port,
|
|
2451
|
+
target: service.host
|
|
2452
|
+
}
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
RecordTXT(service) {
|
|
2456
|
+
return {
|
|
2457
|
+
name: service.fqdn,
|
|
2458
|
+
type: "TXT",
|
|
2459
|
+
ttl: 4500,
|
|
2460
|
+
data: this.txtService.encode(service.txt)
|
|
2461
|
+
};
|
|
2462
|
+
}
|
|
2463
|
+
RecordA(service, ip) {
|
|
2464
|
+
return {
|
|
2465
|
+
name: service.host,
|
|
2466
|
+
type: "A",
|
|
2467
|
+
ttl: 120,
|
|
2468
|
+
data: ip
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
RecordAAAA(service, ip) {
|
|
2472
|
+
return {
|
|
2473
|
+
name: service.host,
|
|
2474
|
+
type: "AAAA",
|
|
2475
|
+
ttl: 120,
|
|
2476
|
+
data: ip
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
exports.Service = Service;
|
|
2481
|
+
exports.default = Service;
|
|
2482
|
+
}));
|
|
2483
|
+
//#endregion
|
|
2484
|
+
//#region ../../node_modules/bonjour-service/dist/lib/registry.js
|
|
2485
|
+
var require_registry = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2486
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
2487
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
2488
|
+
};
|
|
2489
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2490
|
+
exports.Registry = void 0;
|
|
2491
|
+
const dns_equal_1 = __importDefault(require_dns_equal());
|
|
2492
|
+
const service_1 = __importDefault(require_service());
|
|
2493
|
+
const REANNOUNCE_MAX_MS = 36e5;
|
|
2494
|
+
const REANNOUNCE_FACTOR = 3;
|
|
2495
|
+
const noop = function() {};
|
|
2496
|
+
var Registry = class {
|
|
2497
|
+
constructor(server) {
|
|
2498
|
+
this.services = [];
|
|
2499
|
+
this.server = server;
|
|
2500
|
+
}
|
|
2501
|
+
publish(config) {
|
|
2502
|
+
const configProbe = config.probe !== false;
|
|
2503
|
+
const service = new service_1.default(config, start.bind(null, this), stop.bind(null, this));
|
|
2504
|
+
function start(registry, { probe = configProbe } = {}) {
|
|
2505
|
+
if (service.activated) return;
|
|
2506
|
+
service.activated = true;
|
|
2507
|
+
registry.services.push(service);
|
|
2508
|
+
if (!(service instanceof service_1.default)) return;
|
|
2509
|
+
if (probe) registry.probe(registry.server.mdns, service, (exists) => {
|
|
2510
|
+
if (exists) {
|
|
2511
|
+
if (service.stop !== void 0) service.stop();
|
|
2512
|
+
console.log(/* @__PURE__ */ new Error("Service name is already in use on the network"));
|
|
2513
|
+
return;
|
|
2514
|
+
}
|
|
2515
|
+
registry.announce(registry.server, service);
|
|
2516
|
+
});
|
|
2517
|
+
else registry.announce(registry.server, service);
|
|
2518
|
+
}
|
|
2519
|
+
function stop(registry, callback) {
|
|
2520
|
+
if (!callback) callback = noop;
|
|
2521
|
+
if (!service.activated) return process.nextTick(callback);
|
|
2522
|
+
if (!(service instanceof service_1.default)) return process.nextTick(callback);
|
|
2523
|
+
registry.teardown(registry.server, service, callback);
|
|
2524
|
+
const index = registry.services.indexOf(service);
|
|
2525
|
+
if (index !== -1) registry.services.splice(index, 1);
|
|
2526
|
+
}
|
|
2527
|
+
service.start();
|
|
2528
|
+
return service;
|
|
2529
|
+
}
|
|
2530
|
+
unpublishAll(callback) {
|
|
2531
|
+
this.teardown(this.server, this.services, callback);
|
|
2532
|
+
this.services = [];
|
|
2533
|
+
}
|
|
2534
|
+
destroy() {
|
|
2535
|
+
this.services.map((service) => service.destroyed = true);
|
|
2536
|
+
}
|
|
2537
|
+
probe(mdns, service, callback) {
|
|
2538
|
+
var sent = false;
|
|
2539
|
+
var retries = 0;
|
|
2540
|
+
var timer;
|
|
2541
|
+
const send = () => {
|
|
2542
|
+
if (!service.activated || service.destroyed) return;
|
|
2543
|
+
mdns.query(service.fqdn, "ANY", function() {
|
|
2544
|
+
sent = true;
|
|
2545
|
+
timer = setTimeout(++retries < 3 ? send : done, 250);
|
|
2546
|
+
timer.unref();
|
|
2547
|
+
});
|
|
2548
|
+
};
|
|
2549
|
+
const onresponse = (packet) => {
|
|
2550
|
+
if (!sent) return;
|
|
2551
|
+
if (packet.answers.some(matchRR) || packet.additionals.some(matchRR)) done(true);
|
|
2552
|
+
};
|
|
2553
|
+
const matchRR = (rr) => {
|
|
2554
|
+
return (0, dns_equal_1.default)(rr.name, service.fqdn);
|
|
2555
|
+
};
|
|
2556
|
+
const done = (exists) => {
|
|
2557
|
+
mdns.removeListener("response", onresponse);
|
|
2558
|
+
clearTimeout(timer);
|
|
2559
|
+
callback(!!exists);
|
|
2560
|
+
};
|
|
2561
|
+
mdns.on("response", onresponse);
|
|
2562
|
+
setTimeout(send, Math.random() * 250);
|
|
2563
|
+
}
|
|
2564
|
+
announce(server, service) {
|
|
2565
|
+
var delay = 1e3;
|
|
2566
|
+
var packet = service.records();
|
|
2567
|
+
server.register(packet);
|
|
2568
|
+
const broadcast = () => {
|
|
2569
|
+
if (!service.activated || service.destroyed) return;
|
|
2570
|
+
server.mdns.respond(packet, function() {
|
|
2571
|
+
if (!service.published) {
|
|
2572
|
+
service.activated = true;
|
|
2573
|
+
service.published = true;
|
|
2574
|
+
service.emit("up");
|
|
2575
|
+
}
|
|
2576
|
+
delay = delay * REANNOUNCE_FACTOR;
|
|
2577
|
+
if (delay < REANNOUNCE_MAX_MS && !service.destroyed) setTimeout(broadcast, delay).unref();
|
|
2578
|
+
});
|
|
2579
|
+
};
|
|
2580
|
+
broadcast();
|
|
2581
|
+
}
|
|
2582
|
+
teardown(server, services, callback) {
|
|
2583
|
+
if (!Array.isArray(services)) services = [services];
|
|
2584
|
+
services = services.filter((service) => service.activated);
|
|
2585
|
+
var records = services.flatMap(function(service) {
|
|
2586
|
+
service.activated = false;
|
|
2587
|
+
var records = service.records();
|
|
2588
|
+
records.forEach((record) => {
|
|
2589
|
+
record.ttl = 0;
|
|
2590
|
+
});
|
|
2591
|
+
return records;
|
|
2592
|
+
});
|
|
2593
|
+
if (records.length === 0) return callback && process.nextTick(callback);
|
|
2594
|
+
server.unregister(records);
|
|
2595
|
+
server.mdns.respond(records, function() {
|
|
2596
|
+
services.forEach(function(service) {
|
|
2597
|
+
service.published = false;
|
|
2598
|
+
});
|
|
2599
|
+
if (typeof callback === "function") callback.apply(null, arguments);
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
exports.Registry = Registry;
|
|
2604
|
+
exports.default = Registry;
|
|
2605
|
+
}));
|
|
2606
|
+
//#endregion
|
|
2607
|
+
//#region ../../node_modules/dns-packet/types.js
|
|
2608
|
+
var require_types = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2609
|
+
exports.toString = function(type) {
|
|
2610
|
+
switch (type) {
|
|
2611
|
+
case 1: return "A";
|
|
2612
|
+
case 10: return "NULL";
|
|
2613
|
+
case 28: return "AAAA";
|
|
2614
|
+
case 18: return "AFSDB";
|
|
2615
|
+
case 42: return "APL";
|
|
2616
|
+
case 257: return "CAA";
|
|
2617
|
+
case 60: return "CDNSKEY";
|
|
2618
|
+
case 59: return "CDS";
|
|
2619
|
+
case 37: return "CERT";
|
|
2620
|
+
case 5: return "CNAME";
|
|
2621
|
+
case 49: return "DHCID";
|
|
2622
|
+
case 32769: return "DLV";
|
|
2623
|
+
case 39: return "DNAME";
|
|
2624
|
+
case 48: return "DNSKEY";
|
|
2625
|
+
case 43: return "DS";
|
|
2626
|
+
case 55: return "HIP";
|
|
2627
|
+
case 13: return "HINFO";
|
|
2628
|
+
case 45: return "IPSECKEY";
|
|
2629
|
+
case 25: return "KEY";
|
|
2630
|
+
case 36: return "KX";
|
|
2631
|
+
case 29: return "LOC";
|
|
2632
|
+
case 15: return "MX";
|
|
2633
|
+
case 35: return "NAPTR";
|
|
2634
|
+
case 2: return "NS";
|
|
2635
|
+
case 47: return "NSEC";
|
|
2636
|
+
case 50: return "NSEC3";
|
|
2637
|
+
case 51: return "NSEC3PARAM";
|
|
2638
|
+
case 12: return "PTR";
|
|
2639
|
+
case 46: return "RRSIG";
|
|
2640
|
+
case 17: return "RP";
|
|
2641
|
+
case 24: return "SIG";
|
|
2642
|
+
case 6: return "SOA";
|
|
2643
|
+
case 99: return "SPF";
|
|
2644
|
+
case 33: return "SRV";
|
|
2645
|
+
case 44: return "SSHFP";
|
|
2646
|
+
case 32768: return "TA";
|
|
2647
|
+
case 249: return "TKEY";
|
|
2648
|
+
case 52: return "TLSA";
|
|
2649
|
+
case 250: return "TSIG";
|
|
2650
|
+
case 16: return "TXT";
|
|
2651
|
+
case 252: return "AXFR";
|
|
2652
|
+
case 251: return "IXFR";
|
|
2653
|
+
case 41: return "OPT";
|
|
2654
|
+
case 255: return "ANY";
|
|
2655
|
+
}
|
|
2656
|
+
return "UNKNOWN_" + type;
|
|
2657
|
+
};
|
|
2658
|
+
exports.toType = function(name) {
|
|
2659
|
+
switch (name.toUpperCase()) {
|
|
2660
|
+
case "A": return 1;
|
|
2661
|
+
case "NULL": return 10;
|
|
2662
|
+
case "AAAA": return 28;
|
|
2663
|
+
case "AFSDB": return 18;
|
|
2664
|
+
case "APL": return 42;
|
|
2665
|
+
case "CAA": return 257;
|
|
2666
|
+
case "CDNSKEY": return 60;
|
|
2667
|
+
case "CDS": return 59;
|
|
2668
|
+
case "CERT": return 37;
|
|
2669
|
+
case "CNAME": return 5;
|
|
2670
|
+
case "DHCID": return 49;
|
|
2671
|
+
case "DLV": return 32769;
|
|
2672
|
+
case "DNAME": return 39;
|
|
2673
|
+
case "DNSKEY": return 48;
|
|
2674
|
+
case "DS": return 43;
|
|
2675
|
+
case "HIP": return 55;
|
|
2676
|
+
case "HINFO": return 13;
|
|
2677
|
+
case "IPSECKEY": return 45;
|
|
2678
|
+
case "KEY": return 25;
|
|
2679
|
+
case "KX": return 36;
|
|
2680
|
+
case "LOC": return 29;
|
|
2681
|
+
case "MX": return 15;
|
|
2682
|
+
case "NAPTR": return 35;
|
|
2683
|
+
case "NS": return 2;
|
|
2684
|
+
case "NSEC": return 47;
|
|
2685
|
+
case "NSEC3": return 50;
|
|
2686
|
+
case "NSEC3PARAM": return 51;
|
|
2687
|
+
case "PTR": return 12;
|
|
2688
|
+
case "RRSIG": return 46;
|
|
2689
|
+
case "RP": return 17;
|
|
2690
|
+
case "SIG": return 24;
|
|
2691
|
+
case "SOA": return 6;
|
|
2692
|
+
case "SPF": return 99;
|
|
2693
|
+
case "SRV": return 33;
|
|
2694
|
+
case "SSHFP": return 44;
|
|
2695
|
+
case "TA": return 32768;
|
|
2696
|
+
case "TKEY": return 249;
|
|
2697
|
+
case "TLSA": return 52;
|
|
2698
|
+
case "TSIG": return 250;
|
|
2699
|
+
case "TXT": return 16;
|
|
2700
|
+
case "AXFR": return 252;
|
|
2701
|
+
case "IXFR": return 251;
|
|
2702
|
+
case "OPT": return 41;
|
|
2703
|
+
case "ANY": return 255;
|
|
2704
|
+
case "*": return 255;
|
|
2705
|
+
}
|
|
2706
|
+
if (name.toUpperCase().startsWith("UNKNOWN_")) return parseInt(name.slice(8));
|
|
2707
|
+
return 0;
|
|
2708
|
+
};
|
|
2709
|
+
}));
|
|
2710
|
+
//#endregion
|
|
2711
|
+
//#region ../../node_modules/dns-packet/rcodes.js
|
|
2712
|
+
var require_rcodes = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2713
|
+
exports.toString = function(rcode) {
|
|
2714
|
+
switch (rcode) {
|
|
2715
|
+
case 0: return "NOERROR";
|
|
2716
|
+
case 1: return "FORMERR";
|
|
2717
|
+
case 2: return "SERVFAIL";
|
|
2718
|
+
case 3: return "NXDOMAIN";
|
|
2719
|
+
case 4: return "NOTIMP";
|
|
2720
|
+
case 5: return "REFUSED";
|
|
2721
|
+
case 6: return "YXDOMAIN";
|
|
2722
|
+
case 7: return "YXRRSET";
|
|
2723
|
+
case 8: return "NXRRSET";
|
|
2724
|
+
case 9: return "NOTAUTH";
|
|
2725
|
+
case 10: return "NOTZONE";
|
|
2726
|
+
case 11: return "RCODE_11";
|
|
2727
|
+
case 12: return "RCODE_12";
|
|
2728
|
+
case 13: return "RCODE_13";
|
|
2729
|
+
case 14: return "RCODE_14";
|
|
2730
|
+
case 15: return "RCODE_15";
|
|
2731
|
+
}
|
|
2732
|
+
return "RCODE_" + rcode;
|
|
2733
|
+
};
|
|
2734
|
+
exports.toRcode = function(code) {
|
|
2735
|
+
switch (code.toUpperCase()) {
|
|
2736
|
+
case "NOERROR": return 0;
|
|
2737
|
+
case "FORMERR": return 1;
|
|
2738
|
+
case "SERVFAIL": return 2;
|
|
2739
|
+
case "NXDOMAIN": return 3;
|
|
2740
|
+
case "NOTIMP": return 4;
|
|
2741
|
+
case "REFUSED": return 5;
|
|
2742
|
+
case "YXDOMAIN": return 6;
|
|
2743
|
+
case "YXRRSET": return 7;
|
|
2744
|
+
case "NXRRSET": return 8;
|
|
2745
|
+
case "NOTAUTH": return 9;
|
|
2746
|
+
case "NOTZONE": return 10;
|
|
2747
|
+
case "RCODE_11": return 11;
|
|
2748
|
+
case "RCODE_12": return 12;
|
|
2749
|
+
case "RCODE_13": return 13;
|
|
2750
|
+
case "RCODE_14": return 14;
|
|
2751
|
+
case "RCODE_15": return 15;
|
|
2752
|
+
}
|
|
2753
|
+
return 0;
|
|
2754
|
+
};
|
|
2755
|
+
}));
|
|
2756
|
+
//#endregion
|
|
2757
|
+
//#region ../../node_modules/dns-packet/opcodes.js
|
|
2758
|
+
var require_opcodes = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2759
|
+
exports.toString = function(opcode) {
|
|
2760
|
+
switch (opcode) {
|
|
2761
|
+
case 0: return "QUERY";
|
|
2762
|
+
case 1: return "IQUERY";
|
|
2763
|
+
case 2: return "STATUS";
|
|
2764
|
+
case 3: return "OPCODE_3";
|
|
2765
|
+
case 4: return "NOTIFY";
|
|
2766
|
+
case 5: return "UPDATE";
|
|
2767
|
+
case 6: return "OPCODE_6";
|
|
2768
|
+
case 7: return "OPCODE_7";
|
|
2769
|
+
case 8: return "OPCODE_8";
|
|
2770
|
+
case 9: return "OPCODE_9";
|
|
2771
|
+
case 10: return "OPCODE_10";
|
|
2772
|
+
case 11: return "OPCODE_11";
|
|
2773
|
+
case 12: return "OPCODE_12";
|
|
2774
|
+
case 13: return "OPCODE_13";
|
|
2775
|
+
case 14: return "OPCODE_14";
|
|
2776
|
+
case 15: return "OPCODE_15";
|
|
2777
|
+
}
|
|
2778
|
+
return "OPCODE_" + opcode;
|
|
2779
|
+
};
|
|
2780
|
+
exports.toOpcode = function(code) {
|
|
2781
|
+
switch (code.toUpperCase()) {
|
|
2782
|
+
case "QUERY": return 0;
|
|
2783
|
+
case "IQUERY": return 1;
|
|
2784
|
+
case "STATUS": return 2;
|
|
2785
|
+
case "OPCODE_3": return 3;
|
|
2786
|
+
case "NOTIFY": return 4;
|
|
2787
|
+
case "UPDATE": return 5;
|
|
2788
|
+
case "OPCODE_6": return 6;
|
|
2789
|
+
case "OPCODE_7": return 7;
|
|
2790
|
+
case "OPCODE_8": return 8;
|
|
2791
|
+
case "OPCODE_9": return 9;
|
|
2792
|
+
case "OPCODE_10": return 10;
|
|
2793
|
+
case "OPCODE_11": return 11;
|
|
2794
|
+
case "OPCODE_12": return 12;
|
|
2795
|
+
case "OPCODE_13": return 13;
|
|
2796
|
+
case "OPCODE_14": return 14;
|
|
2797
|
+
case "OPCODE_15": return 15;
|
|
2798
|
+
}
|
|
2799
|
+
return 0;
|
|
2800
|
+
};
|
|
2801
|
+
}));
|
|
2802
|
+
//#endregion
|
|
2803
|
+
//#region ../../node_modules/dns-packet/classes.js
|
|
2804
|
+
var require_classes = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2805
|
+
exports.toString = function(klass) {
|
|
2806
|
+
switch (klass) {
|
|
2807
|
+
case 1: return "IN";
|
|
2808
|
+
case 2: return "CS";
|
|
2809
|
+
case 3: return "CH";
|
|
2810
|
+
case 4: return "HS";
|
|
2811
|
+
case 255: return "ANY";
|
|
2812
|
+
}
|
|
2813
|
+
return "UNKNOWN_" + klass;
|
|
2814
|
+
};
|
|
2815
|
+
exports.toClass = function(name) {
|
|
2816
|
+
switch (name.toUpperCase()) {
|
|
2817
|
+
case "IN": return 1;
|
|
2818
|
+
case "CS": return 2;
|
|
2819
|
+
case "CH": return 3;
|
|
2820
|
+
case "HS": return 4;
|
|
2821
|
+
case "ANY": return 255;
|
|
2822
|
+
}
|
|
2823
|
+
return 0;
|
|
2824
|
+
};
|
|
2825
|
+
}));
|
|
2826
|
+
//#endregion
|
|
2827
|
+
//#region ../../node_modules/dns-packet/optioncodes.js
|
|
2828
|
+
var require_optioncodes = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2829
|
+
exports.toString = function(type) {
|
|
2830
|
+
switch (type) {
|
|
2831
|
+
case 1: return "LLQ";
|
|
2832
|
+
case 2: return "UL";
|
|
2833
|
+
case 3: return "NSID";
|
|
2834
|
+
case 5: return "DAU";
|
|
2835
|
+
case 6: return "DHU";
|
|
2836
|
+
case 7: return "N3U";
|
|
2837
|
+
case 8: return "CLIENT_SUBNET";
|
|
2838
|
+
case 9: return "EXPIRE";
|
|
2839
|
+
case 10: return "COOKIE";
|
|
2840
|
+
case 11: return "TCP_KEEPALIVE";
|
|
2841
|
+
case 12: return "PADDING";
|
|
2842
|
+
case 13: return "CHAIN";
|
|
2843
|
+
case 14: return "KEY_TAG";
|
|
2844
|
+
case 26946: return "DEVICEID";
|
|
2845
|
+
}
|
|
2846
|
+
if (type < 0) return null;
|
|
2847
|
+
return `OPTION_${type}`;
|
|
2848
|
+
};
|
|
2849
|
+
exports.toCode = function(name) {
|
|
2850
|
+
if (typeof name === "number") return name;
|
|
2851
|
+
if (!name) return -1;
|
|
2852
|
+
switch (name.toUpperCase()) {
|
|
2853
|
+
case "OPTION_0": return 0;
|
|
2854
|
+
case "LLQ": return 1;
|
|
2855
|
+
case "UL": return 2;
|
|
2856
|
+
case "NSID": return 3;
|
|
2857
|
+
case "OPTION_4": return 4;
|
|
2858
|
+
case "DAU": return 5;
|
|
2859
|
+
case "DHU": return 6;
|
|
2860
|
+
case "N3U": return 7;
|
|
2861
|
+
case "CLIENT_SUBNET": return 8;
|
|
2862
|
+
case "EXPIRE": return 9;
|
|
2863
|
+
case "COOKIE": return 10;
|
|
2864
|
+
case "TCP_KEEPALIVE": return 11;
|
|
2865
|
+
case "PADDING": return 12;
|
|
2866
|
+
case "CHAIN": return 13;
|
|
2867
|
+
case "KEY_TAG": return 14;
|
|
2868
|
+
case "DEVICEID": return 26946;
|
|
2869
|
+
case "OPTION_65535": return 65535;
|
|
2870
|
+
}
|
|
2871
|
+
const m = name.match(/_(\d+)$/);
|
|
2872
|
+
if (m) return parseInt(m[1], 10);
|
|
2873
|
+
return -1;
|
|
2874
|
+
};
|
|
2875
|
+
}));
|
|
2876
|
+
//#endregion
|
|
2877
|
+
//#region ../../node_modules/@leichtgewicht/ip-codec/index.cjs
|
|
2878
|
+
var require_ip_codec = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2879
|
+
var ipCodec = (function(exports$1) {
|
|
2880
|
+
"use strict";
|
|
2881
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
2882
|
+
exports$1.decode = decode;
|
|
2883
|
+
exports$1.encode = encode;
|
|
2884
|
+
exports$1.familyOf = familyOf;
|
|
2885
|
+
exports$1.name = void 0;
|
|
2886
|
+
exports$1.sizeOf = sizeOf;
|
|
2887
|
+
exports$1.v6 = exports$1.v4 = void 0;
|
|
2888
|
+
const v4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/;
|
|
2889
|
+
const v4Size = 4;
|
|
2890
|
+
const v6Regex = /^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;
|
|
2891
|
+
const v6Size = 16;
|
|
2892
|
+
const v4 = {
|
|
2893
|
+
name: "v4",
|
|
2894
|
+
size: v4Size,
|
|
2895
|
+
isFormat: (ip) => v4Regex.test(ip),
|
|
2896
|
+
encode(ip, buff, offset) {
|
|
2897
|
+
offset = ~~offset;
|
|
2898
|
+
buff = buff || new Uint8Array(offset + v4Size);
|
|
2899
|
+
const max = ip.length;
|
|
2900
|
+
let n = 0;
|
|
2901
|
+
for (let i = 0; i < max;) {
|
|
2902
|
+
const c = ip.charCodeAt(i++);
|
|
2903
|
+
if (c === 46) {
|
|
2904
|
+
buff[offset++] = n;
|
|
2905
|
+
n = 0;
|
|
2906
|
+
} else n = n * 10 + (c - 48);
|
|
2907
|
+
}
|
|
2908
|
+
buff[offset] = n;
|
|
2909
|
+
return buff;
|
|
2910
|
+
},
|
|
2911
|
+
decode(buff, offset) {
|
|
2912
|
+
offset = ~~offset;
|
|
2913
|
+
return `${buff[offset++]}.${buff[offset++]}.${buff[offset++]}.${buff[offset]}`;
|
|
2914
|
+
}
|
|
2915
|
+
};
|
|
2916
|
+
exports$1.v4 = v4;
|
|
2917
|
+
const v6 = {
|
|
2918
|
+
name: "v6",
|
|
2919
|
+
size: v6Size,
|
|
2920
|
+
isFormat: (ip) => ip.length > 0 && v6Regex.test(ip),
|
|
2921
|
+
encode(ip, buff, offset) {
|
|
2922
|
+
offset = ~~offset;
|
|
2923
|
+
let end = offset + v6Size;
|
|
2924
|
+
let fill = -1;
|
|
2925
|
+
let hexN = 0;
|
|
2926
|
+
let decN = 0;
|
|
2927
|
+
let prevColon = true;
|
|
2928
|
+
let useDec = false;
|
|
2929
|
+
buff = buff || new Uint8Array(offset + v6Size);
|
|
2930
|
+
for (let i = 0; i < ip.length; i++) {
|
|
2931
|
+
let c = ip.charCodeAt(i);
|
|
2932
|
+
if (c === 58) {
|
|
2933
|
+
if (prevColon) {
|
|
2934
|
+
if (fill !== -1) {
|
|
2935
|
+
if (offset < end) buff[offset] = 0;
|
|
2936
|
+
if (offset < end - 1) buff[offset + 1] = 0;
|
|
2937
|
+
offset += 2;
|
|
2938
|
+
} else if (offset < end) fill = offset;
|
|
2939
|
+
} else {
|
|
2940
|
+
if (useDec === true) {
|
|
2941
|
+
if (offset < end) buff[offset] = decN;
|
|
2942
|
+
offset++;
|
|
2943
|
+
} else {
|
|
2944
|
+
if (offset < end) buff[offset] = hexN >> 8;
|
|
2945
|
+
if (offset < end - 1) buff[offset + 1] = hexN & 255;
|
|
2946
|
+
offset += 2;
|
|
2947
|
+
}
|
|
2948
|
+
hexN = 0;
|
|
2949
|
+
decN = 0;
|
|
2950
|
+
}
|
|
2951
|
+
prevColon = true;
|
|
2952
|
+
useDec = false;
|
|
2953
|
+
} else if (c === 46) {
|
|
2954
|
+
if (offset < end) buff[offset] = decN;
|
|
2955
|
+
offset++;
|
|
2956
|
+
decN = 0;
|
|
2957
|
+
hexN = 0;
|
|
2958
|
+
prevColon = false;
|
|
2959
|
+
useDec = true;
|
|
2960
|
+
} else {
|
|
2961
|
+
prevColon = false;
|
|
2962
|
+
if (c >= 97) c -= 87;
|
|
2963
|
+
else if (c >= 65) c -= 55;
|
|
2964
|
+
else {
|
|
2965
|
+
c -= 48;
|
|
2966
|
+
decN = decN * 10 + c;
|
|
2967
|
+
}
|
|
2968
|
+
hexN = (hexN << 4) + c;
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
if (prevColon === false) {
|
|
2972
|
+
if (useDec === true) {
|
|
2973
|
+
if (offset < end) buff[offset] = decN;
|
|
2974
|
+
offset++;
|
|
2975
|
+
} else {
|
|
2976
|
+
if (offset < end) buff[offset] = hexN >> 8;
|
|
2977
|
+
if (offset < end - 1) buff[offset + 1] = hexN & 255;
|
|
2978
|
+
offset += 2;
|
|
2979
|
+
}
|
|
2980
|
+
} else if (fill === 0) {
|
|
2981
|
+
if (offset < end) buff[offset] = 0;
|
|
2982
|
+
if (offset < end - 1) buff[offset + 1] = 0;
|
|
2983
|
+
offset += 2;
|
|
2984
|
+
} else if (fill !== -1) {
|
|
2985
|
+
offset += 2;
|
|
2986
|
+
for (let i = Math.min(offset - 1, end - 1); i >= fill + 2; i--) buff[i] = buff[i - 2];
|
|
2987
|
+
buff[fill] = 0;
|
|
2988
|
+
buff[fill + 1] = 0;
|
|
2989
|
+
fill = offset;
|
|
2990
|
+
}
|
|
2991
|
+
if (fill !== offset && fill !== -1) {
|
|
2992
|
+
if (offset > end - 2) offset = end - 2;
|
|
2993
|
+
while (end > fill) buff[--end] = offset < end && offset > fill ? buff[--offset] : 0;
|
|
2994
|
+
} else while (offset < end) buff[offset++] = 0;
|
|
2995
|
+
return buff;
|
|
2996
|
+
},
|
|
2997
|
+
decode(buff, offset) {
|
|
2998
|
+
offset = ~~offset;
|
|
2999
|
+
let result = "";
|
|
3000
|
+
for (let i = 0; i < v6Size; i += 2) {
|
|
3001
|
+
if (i !== 0) result += ":";
|
|
3002
|
+
result += (buff[offset + i] << 8 | buff[offset + i + 1]).toString(16);
|
|
3003
|
+
}
|
|
3004
|
+
return result.replace(/(^|:)0(:0)*:0(:|$)/, "$1::$3").replace(/:{3,4}/, "::");
|
|
3005
|
+
}
|
|
3006
|
+
};
|
|
3007
|
+
exports$1.v6 = v6;
|
|
3008
|
+
exports$1.name = "ip";
|
|
3009
|
+
function sizeOf(ip) {
|
|
3010
|
+
if (v4.isFormat(ip)) return v4.size;
|
|
3011
|
+
if (v6.isFormat(ip)) return v6.size;
|
|
3012
|
+
throw Error(`Invalid ip address: ${ip}`);
|
|
3013
|
+
}
|
|
3014
|
+
function familyOf(string) {
|
|
3015
|
+
return sizeOf(string) === v4.size ? 1 : 2;
|
|
3016
|
+
}
|
|
3017
|
+
function encode(ip, buff, offset) {
|
|
3018
|
+
offset = ~~offset;
|
|
3019
|
+
const size = sizeOf(ip);
|
|
3020
|
+
if (typeof buff === "function") buff = buff(offset + size);
|
|
3021
|
+
if (size === v4.size) return v4.encode(ip, buff, offset);
|
|
3022
|
+
return v6.encode(ip, buff, offset);
|
|
3023
|
+
}
|
|
3024
|
+
function decode(buff, offset, length) {
|
|
3025
|
+
offset = ~~offset;
|
|
3026
|
+
length = length || buff.length - offset;
|
|
3027
|
+
if (length === v4.size) return v4.decode(buff, offset, length);
|
|
3028
|
+
if (length === v6.size) return v6.decode(buff, offset, length);
|
|
3029
|
+
throw Error(`Invalid buffer size needs to be ${v4.size} for v4 or ${v6.size} for v6.`);
|
|
3030
|
+
}
|
|
3031
|
+
return "default" in exports$1 ? exports$1.default : exports$1;
|
|
3032
|
+
})({});
|
|
3033
|
+
if (typeof define === "function" && define.amd) define([], function() {
|
|
3034
|
+
return ipCodec;
|
|
3035
|
+
});
|
|
3036
|
+
else if (typeof module === "object" && typeof exports === "object") module.exports = ipCodec;
|
|
3037
|
+
}));
|
|
3038
|
+
//#endregion
|
|
3039
|
+
//#region ../../node_modules/dns-packet/index.js
|
|
3040
|
+
var require_dns_packet = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
3041
|
+
const Buffer$1 = __require("buffer").Buffer;
|
|
3042
|
+
const types = require_types();
|
|
3043
|
+
const rcodes = require_rcodes();
|
|
3044
|
+
const opcodes = require_opcodes();
|
|
3045
|
+
const classes = require_classes();
|
|
3046
|
+
const optioncodes = require_optioncodes();
|
|
3047
|
+
const ip = require_ip_codec();
|
|
3048
|
+
const QUERY_FLAG = 0;
|
|
3049
|
+
const RESPONSE_FLAG = 32768;
|
|
3050
|
+
const FLUSH_MASK = 32768;
|
|
3051
|
+
const NOT_FLUSH_MASK = -32769;
|
|
3052
|
+
const QU_MASK = 32768;
|
|
3053
|
+
const NOT_QU_MASK = -32769;
|
|
3054
|
+
const name = exports.name = {};
|
|
3055
|
+
name.encode = function(str, buf, offset, { mail = false } = {}) {
|
|
3056
|
+
if (!buf) buf = Buffer$1.alloc(name.encodingLength(str));
|
|
3057
|
+
if (!offset) offset = 0;
|
|
3058
|
+
const oldOffset = offset;
|
|
3059
|
+
const n = str.replace(/^\.|\.$/gm, "");
|
|
3060
|
+
if (n.length) {
|
|
3061
|
+
let list = [];
|
|
3062
|
+
if (mail) {
|
|
3063
|
+
let localPart = "";
|
|
3064
|
+
n.split(".").forEach((label) => {
|
|
3065
|
+
if (label.endsWith("\\")) localPart += (localPart.length ? "." : "") + label.slice(0, -1);
|
|
3066
|
+
else if (list.length === 0 && localPart.length) list.push(localPart + "." + label);
|
|
3067
|
+
else list.push(label);
|
|
3068
|
+
});
|
|
3069
|
+
} else list = n.split(".");
|
|
3070
|
+
for (let i = 0; i < list.length; i++) {
|
|
3071
|
+
const len = buf.write(list[i], offset + 1);
|
|
3072
|
+
buf[offset] = len;
|
|
3073
|
+
offset += len + 1;
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
buf[offset++] = 0;
|
|
3077
|
+
name.encode.bytes = offset - oldOffset;
|
|
3078
|
+
return buf;
|
|
3079
|
+
};
|
|
3080
|
+
name.encode.bytes = 0;
|
|
3081
|
+
name.decode = function(buf, offset, { mail = false } = {}) {
|
|
3082
|
+
if (!offset) offset = 0;
|
|
3083
|
+
const list = [];
|
|
3084
|
+
let oldOffset = offset;
|
|
3085
|
+
let totalLength = 0;
|
|
3086
|
+
let consumedBytes = 0;
|
|
3087
|
+
let jumped = false;
|
|
3088
|
+
while (true) {
|
|
3089
|
+
if (offset >= buf.length) throw new Error("Cannot decode name (buffer overflow)");
|
|
3090
|
+
const len = buf[offset++];
|
|
3091
|
+
consumedBytes += jumped ? 0 : 1;
|
|
3092
|
+
if (len === 0) break;
|
|
3093
|
+
else if ((len & 192) === 0) {
|
|
3094
|
+
if (offset + len > buf.length) throw new Error("Cannot decode name (buffer overflow)");
|
|
3095
|
+
totalLength += len + 1;
|
|
3096
|
+
if (totalLength > 254) throw new Error("Cannot decode name (name too long)");
|
|
3097
|
+
let label = buf.toString("utf-8", offset, offset + len);
|
|
3098
|
+
if (mail) label = label.replace(/\./g, "\\.");
|
|
3099
|
+
list.push(label);
|
|
3100
|
+
offset += len;
|
|
3101
|
+
consumedBytes += jumped ? 0 : len;
|
|
3102
|
+
} else if ((len & 192) === 192) {
|
|
3103
|
+
if (offset + 1 > buf.length) throw new Error("Cannot decode name (buffer overflow)");
|
|
3104
|
+
const jumpOffset = buf.readUInt16BE(offset - 1) - 49152;
|
|
3105
|
+
if (jumpOffset >= oldOffset) throw new Error("Cannot decode name (bad pointer)");
|
|
3106
|
+
offset = jumpOffset;
|
|
3107
|
+
oldOffset = jumpOffset;
|
|
3108
|
+
consumedBytes += jumped ? 0 : 1;
|
|
3109
|
+
jumped = true;
|
|
3110
|
+
} else throw new Error("Cannot decode name (bad label)");
|
|
3111
|
+
}
|
|
3112
|
+
name.decode.bytes = consumedBytes;
|
|
3113
|
+
return list.length === 0 ? "." : list.join(".");
|
|
3114
|
+
};
|
|
3115
|
+
name.decode.bytes = 0;
|
|
3116
|
+
name.encodingLength = function(n) {
|
|
3117
|
+
if (n === "." || n === "..") return 1;
|
|
3118
|
+
return Buffer$1.byteLength(n.replace(/^\.|\.$/gm, "")) + 2;
|
|
3119
|
+
};
|
|
3120
|
+
const string = {};
|
|
3121
|
+
string.encode = function(s, buf, offset) {
|
|
3122
|
+
if (!buf) buf = Buffer$1.alloc(string.encodingLength(s));
|
|
3123
|
+
if (!offset) offset = 0;
|
|
3124
|
+
const len = buf.write(s, offset + 1);
|
|
3125
|
+
buf[offset] = len;
|
|
3126
|
+
string.encode.bytes = len + 1;
|
|
3127
|
+
return buf;
|
|
3128
|
+
};
|
|
3129
|
+
string.encode.bytes = 0;
|
|
3130
|
+
string.decode = function(buf, offset) {
|
|
3131
|
+
if (!offset) offset = 0;
|
|
3132
|
+
const len = buf[offset];
|
|
3133
|
+
const s = buf.toString("utf-8", offset + 1, offset + 1 + len);
|
|
3134
|
+
string.decode.bytes = len + 1;
|
|
3135
|
+
return s;
|
|
3136
|
+
};
|
|
3137
|
+
string.decode.bytes = 0;
|
|
3138
|
+
string.encodingLength = function(s) {
|
|
3139
|
+
return Buffer$1.byteLength(s) + 1;
|
|
3140
|
+
};
|
|
3141
|
+
const header = {};
|
|
3142
|
+
header.encode = function(h, buf, offset) {
|
|
3143
|
+
if (!buf) buf = header.encodingLength(h);
|
|
3144
|
+
if (!offset) offset = 0;
|
|
3145
|
+
const flags = (h.flags || 0) & 32767;
|
|
3146
|
+
const type = h.type === "response" ? RESPONSE_FLAG : QUERY_FLAG;
|
|
3147
|
+
buf.writeUInt16BE(h.id || 0, offset);
|
|
3148
|
+
buf.writeUInt16BE(flags | type, offset + 2);
|
|
3149
|
+
buf.writeUInt16BE(h.questions.length, offset + 4);
|
|
3150
|
+
buf.writeUInt16BE(h.answers.length, offset + 6);
|
|
3151
|
+
buf.writeUInt16BE(h.authorities.length, offset + 8);
|
|
3152
|
+
buf.writeUInt16BE(h.additionals.length, offset + 10);
|
|
3153
|
+
return buf;
|
|
3154
|
+
};
|
|
3155
|
+
header.encode.bytes = 12;
|
|
3156
|
+
header.decode = function(buf, offset) {
|
|
3157
|
+
if (!offset) offset = 0;
|
|
3158
|
+
if (buf.length < 12) throw new Error("Header must be 12 bytes");
|
|
3159
|
+
const flags = buf.readUInt16BE(offset + 2);
|
|
3160
|
+
return {
|
|
3161
|
+
id: buf.readUInt16BE(offset),
|
|
3162
|
+
type: flags & RESPONSE_FLAG ? "response" : "query",
|
|
3163
|
+
flags: flags & 32767,
|
|
3164
|
+
flag_qr: (flags >> 15 & 1) === 1,
|
|
3165
|
+
opcode: opcodes.toString(flags >> 11 & 15),
|
|
3166
|
+
flag_aa: (flags >> 10 & 1) === 1,
|
|
3167
|
+
flag_tc: (flags >> 9 & 1) === 1,
|
|
3168
|
+
flag_rd: (flags >> 8 & 1) === 1,
|
|
3169
|
+
flag_ra: (flags >> 7 & 1) === 1,
|
|
3170
|
+
flag_z: (flags >> 6 & 1) === 1,
|
|
3171
|
+
flag_ad: (flags >> 5 & 1) === 1,
|
|
3172
|
+
flag_cd: (flags >> 4 & 1) === 1,
|
|
3173
|
+
rcode: rcodes.toString(flags & 15),
|
|
3174
|
+
questions: new Array(buf.readUInt16BE(offset + 4)),
|
|
3175
|
+
answers: new Array(buf.readUInt16BE(offset + 6)),
|
|
3176
|
+
authorities: new Array(buf.readUInt16BE(offset + 8)),
|
|
3177
|
+
additionals: new Array(buf.readUInt16BE(offset + 10))
|
|
3178
|
+
};
|
|
3179
|
+
};
|
|
3180
|
+
header.decode.bytes = 12;
|
|
3181
|
+
header.encodingLength = function() {
|
|
3182
|
+
return 12;
|
|
3183
|
+
};
|
|
3184
|
+
const runknown = exports.unknown = {};
|
|
3185
|
+
runknown.encode = function(data, buf, offset) {
|
|
3186
|
+
if (!buf) buf = Buffer$1.alloc(runknown.encodingLength(data));
|
|
3187
|
+
if (!offset) offset = 0;
|
|
3188
|
+
buf.writeUInt16BE(data.length, offset);
|
|
3189
|
+
data.copy(buf, offset + 2);
|
|
3190
|
+
runknown.encode.bytes = data.length + 2;
|
|
3191
|
+
return buf;
|
|
3192
|
+
};
|
|
3193
|
+
runknown.encode.bytes = 0;
|
|
3194
|
+
runknown.decode = function(buf, offset) {
|
|
3195
|
+
if (!offset) offset = 0;
|
|
3196
|
+
const len = buf.readUInt16BE(offset);
|
|
3197
|
+
const data = buf.slice(offset + 2, offset + 2 + len);
|
|
3198
|
+
runknown.decode.bytes = len + 2;
|
|
3199
|
+
return data;
|
|
3200
|
+
};
|
|
3201
|
+
runknown.decode.bytes = 0;
|
|
3202
|
+
runknown.encodingLength = function(data) {
|
|
3203
|
+
return data.length + 2;
|
|
3204
|
+
};
|
|
3205
|
+
const rns = exports.ns = {};
|
|
3206
|
+
rns.encode = function(data, buf, offset) {
|
|
3207
|
+
if (!buf) buf = Buffer$1.alloc(rns.encodingLength(data));
|
|
3208
|
+
if (!offset) offset = 0;
|
|
3209
|
+
name.encode(data, buf, offset + 2);
|
|
3210
|
+
buf.writeUInt16BE(name.encode.bytes, offset);
|
|
3211
|
+
rns.encode.bytes = name.encode.bytes + 2;
|
|
3212
|
+
return buf;
|
|
3213
|
+
};
|
|
3214
|
+
rns.encode.bytes = 0;
|
|
3215
|
+
rns.decode = function(buf, offset) {
|
|
3216
|
+
if (!offset) offset = 0;
|
|
3217
|
+
const len = buf.readUInt16BE(offset);
|
|
3218
|
+
const dd = name.decode(buf, offset + 2);
|
|
3219
|
+
rns.decode.bytes = len + 2;
|
|
3220
|
+
return dd;
|
|
3221
|
+
};
|
|
3222
|
+
rns.decode.bytes = 0;
|
|
3223
|
+
rns.encodingLength = function(data) {
|
|
3224
|
+
return name.encodingLength(data) + 2;
|
|
3225
|
+
};
|
|
3226
|
+
const rsoa = exports.soa = {};
|
|
3227
|
+
rsoa.encode = function(data, buf, offset) {
|
|
3228
|
+
if (!buf) buf = Buffer$1.alloc(rsoa.encodingLength(data));
|
|
3229
|
+
if (!offset) offset = 0;
|
|
3230
|
+
const oldOffset = offset;
|
|
3231
|
+
offset += 2;
|
|
3232
|
+
name.encode(data.mname, buf, offset);
|
|
3233
|
+
offset += name.encode.bytes;
|
|
3234
|
+
name.encode(data.rname, buf, offset, { mail: true });
|
|
3235
|
+
offset += name.encode.bytes;
|
|
3236
|
+
buf.writeUInt32BE(data.serial || 0, offset);
|
|
3237
|
+
offset += 4;
|
|
3238
|
+
buf.writeUInt32BE(data.refresh || 0, offset);
|
|
3239
|
+
offset += 4;
|
|
3240
|
+
buf.writeUInt32BE(data.retry || 0, offset);
|
|
3241
|
+
offset += 4;
|
|
3242
|
+
buf.writeUInt32BE(data.expire || 0, offset);
|
|
3243
|
+
offset += 4;
|
|
3244
|
+
buf.writeUInt32BE(data.minimum || 0, offset);
|
|
3245
|
+
offset += 4;
|
|
3246
|
+
buf.writeUInt16BE(offset - oldOffset - 2, oldOffset);
|
|
3247
|
+
rsoa.encode.bytes = offset - oldOffset;
|
|
3248
|
+
return buf;
|
|
3249
|
+
};
|
|
3250
|
+
rsoa.encode.bytes = 0;
|
|
3251
|
+
rsoa.decode = function(buf, offset) {
|
|
3252
|
+
if (!offset) offset = 0;
|
|
3253
|
+
const oldOffset = offset;
|
|
3254
|
+
const data = {};
|
|
3255
|
+
offset += 2;
|
|
3256
|
+
data.mname = name.decode(buf, offset);
|
|
3257
|
+
offset += name.decode.bytes;
|
|
3258
|
+
data.rname = name.decode(buf, offset, { mail: true });
|
|
3259
|
+
offset += name.decode.bytes;
|
|
3260
|
+
data.serial = buf.readUInt32BE(offset);
|
|
3261
|
+
offset += 4;
|
|
3262
|
+
data.refresh = buf.readUInt32BE(offset);
|
|
3263
|
+
offset += 4;
|
|
3264
|
+
data.retry = buf.readUInt32BE(offset);
|
|
3265
|
+
offset += 4;
|
|
3266
|
+
data.expire = buf.readUInt32BE(offset);
|
|
3267
|
+
offset += 4;
|
|
3268
|
+
data.minimum = buf.readUInt32BE(offset);
|
|
3269
|
+
offset += 4;
|
|
3270
|
+
rsoa.decode.bytes = offset - oldOffset;
|
|
3271
|
+
return data;
|
|
3272
|
+
};
|
|
3273
|
+
rsoa.decode.bytes = 0;
|
|
3274
|
+
rsoa.encodingLength = function(data) {
|
|
3275
|
+
return 22 + name.encodingLength(data.mname) + name.encodingLength(data.rname);
|
|
3276
|
+
};
|
|
3277
|
+
const rtxt = exports.txt = {};
|
|
3278
|
+
rtxt.encode = function(data, buf, offset) {
|
|
3279
|
+
if (!Array.isArray(data)) data = [data];
|
|
3280
|
+
for (let i = 0; i < data.length; i++) {
|
|
3281
|
+
if (typeof data[i] === "string") data[i] = Buffer$1.from(data[i]);
|
|
3282
|
+
if (!Buffer$1.isBuffer(data[i])) throw new Error("Must be a Buffer");
|
|
3283
|
+
}
|
|
3284
|
+
if (!buf) buf = Buffer$1.alloc(rtxt.encodingLength(data));
|
|
3285
|
+
if (!offset) offset = 0;
|
|
3286
|
+
const oldOffset = offset;
|
|
3287
|
+
offset += 2;
|
|
3288
|
+
data.forEach(function(d) {
|
|
3289
|
+
buf[offset++] = d.length;
|
|
3290
|
+
d.copy(buf, offset, 0, d.length);
|
|
3291
|
+
offset += d.length;
|
|
3292
|
+
});
|
|
3293
|
+
buf.writeUInt16BE(offset - oldOffset - 2, oldOffset);
|
|
3294
|
+
rtxt.encode.bytes = offset - oldOffset;
|
|
3295
|
+
return buf;
|
|
3296
|
+
};
|
|
3297
|
+
rtxt.encode.bytes = 0;
|
|
3298
|
+
rtxt.decode = function(buf, offset) {
|
|
3299
|
+
if (!offset) offset = 0;
|
|
3300
|
+
const oldOffset = offset;
|
|
3301
|
+
let remaining = buf.readUInt16BE(offset);
|
|
3302
|
+
offset += 2;
|
|
3303
|
+
let data = [];
|
|
3304
|
+
while (remaining > 0) {
|
|
3305
|
+
const len = buf[offset++];
|
|
3306
|
+
--remaining;
|
|
3307
|
+
if (remaining < len) throw new Error("Buffer overflow");
|
|
3308
|
+
data.push(buf.slice(offset, offset + len));
|
|
3309
|
+
offset += len;
|
|
3310
|
+
remaining -= len;
|
|
3311
|
+
}
|
|
3312
|
+
rtxt.decode.bytes = offset - oldOffset;
|
|
3313
|
+
return data;
|
|
3314
|
+
};
|
|
3315
|
+
rtxt.decode.bytes = 0;
|
|
3316
|
+
rtxt.encodingLength = function(data) {
|
|
3317
|
+
if (!Array.isArray(data)) data = [data];
|
|
3318
|
+
let length = 2;
|
|
3319
|
+
data.forEach(function(buf) {
|
|
3320
|
+
if (typeof buf === "string") length += Buffer$1.byteLength(buf) + 1;
|
|
3321
|
+
else length += buf.length + 1;
|
|
3322
|
+
});
|
|
3323
|
+
return length;
|
|
3324
|
+
};
|
|
3325
|
+
const rnull = exports.null = {};
|
|
3326
|
+
rnull.encode = function(data, buf, offset) {
|
|
3327
|
+
if (!buf) buf = Buffer$1.alloc(rnull.encodingLength(data));
|
|
3328
|
+
if (!offset) offset = 0;
|
|
3329
|
+
if (typeof data === "string") data = Buffer$1.from(data);
|
|
3330
|
+
if (!data) data = Buffer$1.alloc(0);
|
|
3331
|
+
const oldOffset = offset;
|
|
3332
|
+
offset += 2;
|
|
3333
|
+
const len = data.length;
|
|
3334
|
+
data.copy(buf, offset, 0, len);
|
|
3335
|
+
offset += len;
|
|
3336
|
+
buf.writeUInt16BE(offset - oldOffset - 2, oldOffset);
|
|
3337
|
+
rnull.encode.bytes = offset - oldOffset;
|
|
3338
|
+
return buf;
|
|
3339
|
+
};
|
|
3340
|
+
rnull.encode.bytes = 0;
|
|
3341
|
+
rnull.decode = function(buf, offset) {
|
|
3342
|
+
if (!offset) offset = 0;
|
|
3343
|
+
const oldOffset = offset;
|
|
3344
|
+
const len = buf.readUInt16BE(offset);
|
|
3345
|
+
offset += 2;
|
|
3346
|
+
const data = buf.slice(offset, offset + len);
|
|
3347
|
+
offset += len;
|
|
3348
|
+
rnull.decode.bytes = offset - oldOffset;
|
|
3349
|
+
return data;
|
|
3350
|
+
};
|
|
3351
|
+
rnull.decode.bytes = 0;
|
|
3352
|
+
rnull.encodingLength = function(data) {
|
|
3353
|
+
if (!data) return 2;
|
|
3354
|
+
return (Buffer$1.isBuffer(data) ? data.length : Buffer$1.byteLength(data)) + 2;
|
|
3355
|
+
};
|
|
3356
|
+
const rhinfo = exports.hinfo = {};
|
|
3357
|
+
rhinfo.encode = function(data, buf, offset) {
|
|
3358
|
+
if (!buf) buf = Buffer$1.alloc(rhinfo.encodingLength(data));
|
|
3359
|
+
if (!offset) offset = 0;
|
|
3360
|
+
const oldOffset = offset;
|
|
3361
|
+
offset += 2;
|
|
3362
|
+
string.encode(data.cpu, buf, offset);
|
|
3363
|
+
offset += string.encode.bytes;
|
|
3364
|
+
string.encode(data.os, buf, offset);
|
|
3365
|
+
offset += string.encode.bytes;
|
|
3366
|
+
buf.writeUInt16BE(offset - oldOffset - 2, oldOffset);
|
|
3367
|
+
rhinfo.encode.bytes = offset - oldOffset;
|
|
3368
|
+
return buf;
|
|
3369
|
+
};
|
|
3370
|
+
rhinfo.encode.bytes = 0;
|
|
3371
|
+
rhinfo.decode = function(buf, offset) {
|
|
3372
|
+
if (!offset) offset = 0;
|
|
3373
|
+
const oldOffset = offset;
|
|
3374
|
+
const data = {};
|
|
3375
|
+
offset += 2;
|
|
3376
|
+
data.cpu = string.decode(buf, offset);
|
|
3377
|
+
offset += string.decode.bytes;
|
|
3378
|
+
data.os = string.decode(buf, offset);
|
|
3379
|
+
offset += string.decode.bytes;
|
|
3380
|
+
rhinfo.decode.bytes = offset - oldOffset;
|
|
3381
|
+
return data;
|
|
3382
|
+
};
|
|
3383
|
+
rhinfo.decode.bytes = 0;
|
|
3384
|
+
rhinfo.encodingLength = function(data) {
|
|
3385
|
+
return string.encodingLength(data.cpu) + string.encodingLength(data.os) + 2;
|
|
3386
|
+
};
|
|
3387
|
+
const rptr = exports.ptr = {};
|
|
3388
|
+
const rcname = exports.cname = rptr;
|
|
3389
|
+
const rdname = exports.dname = rptr;
|
|
3390
|
+
rptr.encode = function(data, buf, offset) {
|
|
3391
|
+
if (!buf) buf = Buffer$1.alloc(rptr.encodingLength(data));
|
|
3392
|
+
if (!offset) offset = 0;
|
|
3393
|
+
name.encode(data, buf, offset + 2);
|
|
3394
|
+
buf.writeUInt16BE(name.encode.bytes, offset);
|
|
3395
|
+
rptr.encode.bytes = name.encode.bytes + 2;
|
|
3396
|
+
return buf;
|
|
3397
|
+
};
|
|
3398
|
+
rptr.encode.bytes = 0;
|
|
3399
|
+
rptr.decode = function(buf, offset) {
|
|
3400
|
+
if (!offset) offset = 0;
|
|
3401
|
+
const data = name.decode(buf, offset + 2);
|
|
3402
|
+
rptr.decode.bytes = name.decode.bytes + 2;
|
|
3403
|
+
return data;
|
|
3404
|
+
};
|
|
3405
|
+
rptr.decode.bytes = 0;
|
|
3406
|
+
rptr.encodingLength = function(data) {
|
|
3407
|
+
return name.encodingLength(data) + 2;
|
|
3408
|
+
};
|
|
3409
|
+
const rsrv = exports.srv = {};
|
|
3410
|
+
rsrv.encode = function(data, buf, offset) {
|
|
3411
|
+
if (!buf) buf = Buffer$1.alloc(rsrv.encodingLength(data));
|
|
3412
|
+
if (!offset) offset = 0;
|
|
3413
|
+
buf.writeUInt16BE(data.priority || 0, offset + 2);
|
|
3414
|
+
buf.writeUInt16BE(data.weight || 0, offset + 4);
|
|
3415
|
+
buf.writeUInt16BE(data.port || 0, offset + 6);
|
|
3416
|
+
name.encode(data.target, buf, offset + 8);
|
|
3417
|
+
const len = name.encode.bytes + 6;
|
|
3418
|
+
buf.writeUInt16BE(len, offset);
|
|
3419
|
+
rsrv.encode.bytes = len + 2;
|
|
3420
|
+
return buf;
|
|
3421
|
+
};
|
|
3422
|
+
rsrv.encode.bytes = 0;
|
|
3423
|
+
rsrv.decode = function(buf, offset) {
|
|
3424
|
+
if (!offset) offset = 0;
|
|
3425
|
+
const len = buf.readUInt16BE(offset);
|
|
3426
|
+
const data = {};
|
|
3427
|
+
data.priority = buf.readUInt16BE(offset + 2);
|
|
3428
|
+
data.weight = buf.readUInt16BE(offset + 4);
|
|
3429
|
+
data.port = buf.readUInt16BE(offset + 6);
|
|
3430
|
+
data.target = name.decode(buf, offset + 8);
|
|
3431
|
+
rsrv.decode.bytes = len + 2;
|
|
3432
|
+
return data;
|
|
3433
|
+
};
|
|
3434
|
+
rsrv.decode.bytes = 0;
|
|
3435
|
+
rsrv.encodingLength = function(data) {
|
|
3436
|
+
return 8 + name.encodingLength(data.target);
|
|
3437
|
+
};
|
|
3438
|
+
const rcaa = exports.caa = {};
|
|
3439
|
+
rcaa.ISSUER_CRITICAL = 128;
|
|
3440
|
+
rcaa.encode = function(data, buf, offset) {
|
|
3441
|
+
const len = rcaa.encodingLength(data);
|
|
3442
|
+
if (!buf) buf = Buffer$1.alloc(rcaa.encodingLength(data));
|
|
3443
|
+
if (!offset) offset = 0;
|
|
3444
|
+
if (data.issuerCritical) data.flags = rcaa.ISSUER_CRITICAL;
|
|
3445
|
+
buf.writeUInt16BE(len - 2, offset);
|
|
3446
|
+
offset += 2;
|
|
3447
|
+
buf.writeUInt8(data.flags || 0, offset);
|
|
3448
|
+
offset += 1;
|
|
3449
|
+
string.encode(data.tag, buf, offset);
|
|
3450
|
+
offset += string.encode.bytes;
|
|
3451
|
+
buf.write(data.value, offset);
|
|
3452
|
+
offset += Buffer$1.byteLength(data.value);
|
|
3453
|
+
rcaa.encode.bytes = len;
|
|
3454
|
+
return buf;
|
|
3455
|
+
};
|
|
3456
|
+
rcaa.encode.bytes = 0;
|
|
3457
|
+
rcaa.decode = function(buf, offset) {
|
|
3458
|
+
if (!offset) offset = 0;
|
|
3459
|
+
const len = buf.readUInt16BE(offset);
|
|
3460
|
+
offset += 2;
|
|
3461
|
+
const oldOffset = offset;
|
|
3462
|
+
const data = {};
|
|
3463
|
+
data.flags = buf.readUInt8(offset);
|
|
3464
|
+
offset += 1;
|
|
3465
|
+
data.tag = string.decode(buf, offset);
|
|
3466
|
+
offset += string.decode.bytes;
|
|
3467
|
+
data.value = buf.toString("utf-8", offset, oldOffset + len);
|
|
3468
|
+
data.issuerCritical = !!(data.flags & rcaa.ISSUER_CRITICAL);
|
|
3469
|
+
rcaa.decode.bytes = len + 2;
|
|
3470
|
+
return data;
|
|
3471
|
+
};
|
|
3472
|
+
rcaa.decode.bytes = 0;
|
|
3473
|
+
rcaa.encodingLength = function(data) {
|
|
3474
|
+
return string.encodingLength(data.tag) + string.encodingLength(data.value) + 2;
|
|
3475
|
+
};
|
|
3476
|
+
const rmx = exports.mx = {};
|
|
3477
|
+
rmx.encode = function(data, buf, offset) {
|
|
3478
|
+
if (!buf) buf = Buffer$1.alloc(rmx.encodingLength(data));
|
|
3479
|
+
if (!offset) offset = 0;
|
|
3480
|
+
const oldOffset = offset;
|
|
3481
|
+
offset += 2;
|
|
3482
|
+
buf.writeUInt16BE(data.preference || 0, offset);
|
|
3483
|
+
offset += 2;
|
|
3484
|
+
name.encode(data.exchange, buf, offset);
|
|
3485
|
+
offset += name.encode.bytes;
|
|
3486
|
+
buf.writeUInt16BE(offset - oldOffset - 2, oldOffset);
|
|
3487
|
+
rmx.encode.bytes = offset - oldOffset;
|
|
3488
|
+
return buf;
|
|
3489
|
+
};
|
|
3490
|
+
rmx.encode.bytes = 0;
|
|
3491
|
+
rmx.decode = function(buf, offset) {
|
|
3492
|
+
if (!offset) offset = 0;
|
|
3493
|
+
const oldOffset = offset;
|
|
3494
|
+
const data = {};
|
|
3495
|
+
offset += 2;
|
|
3496
|
+
data.preference = buf.readUInt16BE(offset);
|
|
3497
|
+
offset += 2;
|
|
3498
|
+
data.exchange = name.decode(buf, offset);
|
|
3499
|
+
offset += name.decode.bytes;
|
|
3500
|
+
rmx.decode.bytes = offset - oldOffset;
|
|
3501
|
+
return data;
|
|
3502
|
+
};
|
|
3503
|
+
rmx.encodingLength = function(data) {
|
|
3504
|
+
return 4 + name.encodingLength(data.exchange);
|
|
3505
|
+
};
|
|
3506
|
+
const ra = exports.a = {};
|
|
3507
|
+
ra.encode = function(host, buf, offset) {
|
|
3508
|
+
if (!buf) buf = Buffer$1.alloc(ra.encodingLength(host));
|
|
3509
|
+
if (!offset) offset = 0;
|
|
3510
|
+
buf.writeUInt16BE(4, offset);
|
|
3511
|
+
offset += 2;
|
|
3512
|
+
ip.v4.encode(host, buf, offset);
|
|
3513
|
+
ra.encode.bytes = 6;
|
|
3514
|
+
return buf;
|
|
3515
|
+
};
|
|
3516
|
+
ra.encode.bytes = 0;
|
|
3517
|
+
ra.decode = function(buf, offset) {
|
|
3518
|
+
if (!offset) offset = 0;
|
|
3519
|
+
offset += 2;
|
|
3520
|
+
const host = ip.v4.decode(buf, offset);
|
|
3521
|
+
ra.decode.bytes = 6;
|
|
3522
|
+
return host;
|
|
3523
|
+
};
|
|
3524
|
+
ra.decode.bytes = 0;
|
|
3525
|
+
ra.encodingLength = function() {
|
|
3526
|
+
return 6;
|
|
3527
|
+
};
|
|
3528
|
+
const raaaa = exports.aaaa = {};
|
|
3529
|
+
raaaa.encode = function(host, buf, offset) {
|
|
3530
|
+
if (!buf) buf = Buffer$1.alloc(raaaa.encodingLength(host));
|
|
3531
|
+
if (!offset) offset = 0;
|
|
3532
|
+
buf.writeUInt16BE(16, offset);
|
|
3533
|
+
offset += 2;
|
|
3534
|
+
ip.v6.encode(host, buf, offset);
|
|
3535
|
+
raaaa.encode.bytes = 18;
|
|
3536
|
+
return buf;
|
|
3537
|
+
};
|
|
3538
|
+
raaaa.encode.bytes = 0;
|
|
3539
|
+
raaaa.decode = function(buf, offset) {
|
|
3540
|
+
if (!offset) offset = 0;
|
|
3541
|
+
offset += 2;
|
|
3542
|
+
const host = ip.v6.decode(buf, offset);
|
|
3543
|
+
raaaa.decode.bytes = 18;
|
|
3544
|
+
return host;
|
|
3545
|
+
};
|
|
3546
|
+
raaaa.decode.bytes = 0;
|
|
3547
|
+
raaaa.encodingLength = function() {
|
|
3548
|
+
return 18;
|
|
3549
|
+
};
|
|
3550
|
+
const roption = exports.option = {};
|
|
3551
|
+
roption.encode = function(option, buf, offset) {
|
|
3552
|
+
if (!buf) buf = Buffer$1.alloc(roption.encodingLength(option));
|
|
3553
|
+
if (!offset) offset = 0;
|
|
3554
|
+
const oldOffset = offset;
|
|
3555
|
+
const code = optioncodes.toCode(option.code);
|
|
3556
|
+
buf.writeUInt16BE(code, offset);
|
|
3557
|
+
offset += 2;
|
|
3558
|
+
if (option.data) {
|
|
3559
|
+
buf.writeUInt16BE(option.data.length, offset);
|
|
3560
|
+
offset += 2;
|
|
3561
|
+
option.data.copy(buf, offset);
|
|
3562
|
+
offset += option.data.length;
|
|
3563
|
+
} else switch (code) {
|
|
3564
|
+
case 8:
|
|
3565
|
+
const spl = option.sourcePrefixLength || 0;
|
|
3566
|
+
const fam = option.family || ip.familyOf(option.ip);
|
|
3567
|
+
const ipBuf = ip.encode(option.ip, Buffer$1.alloc);
|
|
3568
|
+
const ipLen = Math.ceil(spl / 8);
|
|
3569
|
+
buf.writeUInt16BE(ipLen + 4, offset);
|
|
3570
|
+
offset += 2;
|
|
3571
|
+
buf.writeUInt16BE(fam, offset);
|
|
3572
|
+
offset += 2;
|
|
3573
|
+
buf.writeUInt8(spl, offset++);
|
|
3574
|
+
buf.writeUInt8(option.scopePrefixLength || 0, offset++);
|
|
3575
|
+
ipBuf.copy(buf, offset, 0, ipLen);
|
|
3576
|
+
offset += ipLen;
|
|
3577
|
+
break;
|
|
3578
|
+
case 11:
|
|
3579
|
+
if (option.timeout) {
|
|
3580
|
+
buf.writeUInt16BE(2, offset);
|
|
3581
|
+
offset += 2;
|
|
3582
|
+
buf.writeUInt16BE(option.timeout, offset);
|
|
3583
|
+
offset += 2;
|
|
3584
|
+
} else {
|
|
3585
|
+
buf.writeUInt16BE(0, offset);
|
|
3586
|
+
offset += 2;
|
|
3587
|
+
}
|
|
3588
|
+
break;
|
|
3589
|
+
case 12:
|
|
3590
|
+
const len = option.length || 0;
|
|
3591
|
+
buf.writeUInt16BE(len, offset);
|
|
3592
|
+
offset += 2;
|
|
3593
|
+
buf.fill(0, offset, offset + len);
|
|
3594
|
+
offset += len;
|
|
3595
|
+
break;
|
|
3596
|
+
case 14:
|
|
3597
|
+
const tagsLen = option.tags.length * 2;
|
|
3598
|
+
buf.writeUInt16BE(tagsLen, offset);
|
|
3599
|
+
offset += 2;
|
|
3600
|
+
for (const tag of option.tags) {
|
|
3601
|
+
buf.writeUInt16BE(tag, offset);
|
|
3602
|
+
offset += 2;
|
|
3603
|
+
}
|
|
3604
|
+
break;
|
|
3605
|
+
default: throw new Error(`Unknown roption code: ${option.code}`);
|
|
3606
|
+
}
|
|
3607
|
+
roption.encode.bytes = offset - oldOffset;
|
|
3608
|
+
return buf;
|
|
3609
|
+
};
|
|
3610
|
+
roption.encode.bytes = 0;
|
|
3611
|
+
roption.decode = function(buf, offset) {
|
|
3612
|
+
if (!offset) offset = 0;
|
|
3613
|
+
const option = {};
|
|
3614
|
+
option.code = buf.readUInt16BE(offset);
|
|
3615
|
+
option.type = optioncodes.toString(option.code);
|
|
3616
|
+
offset += 2;
|
|
3617
|
+
const len = buf.readUInt16BE(offset);
|
|
3618
|
+
offset += 2;
|
|
3619
|
+
option.data = buf.slice(offset, offset + len);
|
|
3620
|
+
switch (option.code) {
|
|
3621
|
+
case 8:
|
|
3622
|
+
option.family = buf.readUInt16BE(offset);
|
|
3623
|
+
offset += 2;
|
|
3624
|
+
option.sourcePrefixLength = buf.readUInt8(offset++);
|
|
3625
|
+
option.scopePrefixLength = buf.readUInt8(offset++);
|
|
3626
|
+
const padded = Buffer$1.alloc(option.family === 1 ? 4 : 16);
|
|
3627
|
+
buf.copy(padded, 0, offset, offset + len - 4);
|
|
3628
|
+
option.ip = ip.decode(padded);
|
|
3629
|
+
break;
|
|
3630
|
+
case 11:
|
|
3631
|
+
if (len > 0) {
|
|
3632
|
+
option.timeout = buf.readUInt16BE(offset);
|
|
3633
|
+
offset += 2;
|
|
3634
|
+
}
|
|
3635
|
+
break;
|
|
3636
|
+
case 14:
|
|
3637
|
+
option.tags = [];
|
|
3638
|
+
for (let i = 0; i < len; i += 2) {
|
|
3639
|
+
option.tags.push(buf.readUInt16BE(offset));
|
|
3640
|
+
offset += 2;
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
roption.decode.bytes = len + 4;
|
|
3644
|
+
return option;
|
|
3645
|
+
};
|
|
3646
|
+
roption.decode.bytes = 0;
|
|
3647
|
+
roption.encodingLength = function(option) {
|
|
3648
|
+
if (option.data) return option.data.length + 4;
|
|
3649
|
+
switch (optioncodes.toCode(option.code)) {
|
|
3650
|
+
case 8:
|
|
3651
|
+
const spl = option.sourcePrefixLength || 0;
|
|
3652
|
+
return Math.ceil(spl / 8) + 8;
|
|
3653
|
+
case 11: return typeof option.timeout === "number" ? 6 : 4;
|
|
3654
|
+
case 12: return option.length + 4;
|
|
3655
|
+
case 14: return 4 + option.tags.length * 2;
|
|
3656
|
+
}
|
|
3657
|
+
throw new Error(`Unknown roption code: ${option.code}`);
|
|
3658
|
+
};
|
|
3659
|
+
const ropt = exports.opt = {};
|
|
3660
|
+
ropt.encode = function(options, buf, offset) {
|
|
3661
|
+
if (!buf) buf = Buffer$1.alloc(ropt.encodingLength(options));
|
|
3662
|
+
if (!offset) offset = 0;
|
|
3663
|
+
const oldOffset = offset;
|
|
3664
|
+
const rdlen = encodingLengthList(options, roption);
|
|
3665
|
+
buf.writeUInt16BE(rdlen, offset);
|
|
3666
|
+
offset = encodeList(options, roption, buf, offset + 2);
|
|
3667
|
+
ropt.encode.bytes = offset - oldOffset;
|
|
3668
|
+
return buf;
|
|
3669
|
+
};
|
|
3670
|
+
ropt.encode.bytes = 0;
|
|
3671
|
+
ropt.decode = function(buf, offset) {
|
|
3672
|
+
if (!offset) offset = 0;
|
|
3673
|
+
const oldOffset = offset;
|
|
3674
|
+
const options = [];
|
|
3675
|
+
let rdlen = buf.readUInt16BE(offset);
|
|
3676
|
+
offset += 2;
|
|
3677
|
+
let o = 0;
|
|
3678
|
+
while (rdlen > 0) {
|
|
3679
|
+
options[o++] = roption.decode(buf, offset);
|
|
3680
|
+
offset += roption.decode.bytes;
|
|
3681
|
+
rdlen -= roption.decode.bytes;
|
|
3682
|
+
}
|
|
3683
|
+
ropt.decode.bytes = offset - oldOffset;
|
|
3684
|
+
return options;
|
|
3685
|
+
};
|
|
3686
|
+
ropt.decode.bytes = 0;
|
|
3687
|
+
ropt.encodingLength = function(options) {
|
|
3688
|
+
return 2 + encodingLengthList(options || [], roption);
|
|
3689
|
+
};
|
|
3690
|
+
const rdnskey = exports.dnskey = {};
|
|
3691
|
+
rdnskey.PROTOCOL_DNSSEC = 3;
|
|
3692
|
+
rdnskey.ZONE_KEY = 128;
|
|
3693
|
+
rdnskey.SECURE_ENTRYPOINT = 32768;
|
|
3694
|
+
rdnskey.encode = function(key, buf, offset) {
|
|
3695
|
+
if (!buf) buf = Buffer$1.alloc(rdnskey.encodingLength(key));
|
|
3696
|
+
if (!offset) offset = 0;
|
|
3697
|
+
const oldOffset = offset;
|
|
3698
|
+
const keydata = key.key;
|
|
3699
|
+
if (!Buffer$1.isBuffer(keydata)) throw new Error("Key must be a Buffer");
|
|
3700
|
+
offset += 2;
|
|
3701
|
+
buf.writeUInt16BE(key.flags, offset);
|
|
3702
|
+
offset += 2;
|
|
3703
|
+
buf.writeUInt8(rdnskey.PROTOCOL_DNSSEC, offset);
|
|
3704
|
+
offset += 1;
|
|
3705
|
+
buf.writeUInt8(key.algorithm, offset);
|
|
3706
|
+
offset += 1;
|
|
3707
|
+
keydata.copy(buf, offset, 0, keydata.length);
|
|
3708
|
+
offset += keydata.length;
|
|
3709
|
+
rdnskey.encode.bytes = offset - oldOffset;
|
|
3710
|
+
buf.writeUInt16BE(rdnskey.encode.bytes - 2, oldOffset);
|
|
3711
|
+
return buf;
|
|
3712
|
+
};
|
|
3713
|
+
rdnskey.encode.bytes = 0;
|
|
3714
|
+
rdnskey.decode = function(buf, offset) {
|
|
3715
|
+
if (!offset) offset = 0;
|
|
3716
|
+
const oldOffset = offset;
|
|
3717
|
+
var key = {};
|
|
3718
|
+
var length = buf.readUInt16BE(offset);
|
|
3719
|
+
offset += 2;
|
|
3720
|
+
key.flags = buf.readUInt16BE(offset);
|
|
3721
|
+
offset += 2;
|
|
3722
|
+
if (buf.readUInt8(offset) !== rdnskey.PROTOCOL_DNSSEC) throw new Error("Protocol must be 3");
|
|
3723
|
+
offset += 1;
|
|
3724
|
+
key.algorithm = buf.readUInt8(offset);
|
|
3725
|
+
offset += 1;
|
|
3726
|
+
key.key = buf.slice(offset, oldOffset + length + 2);
|
|
3727
|
+
offset += key.key.length;
|
|
3728
|
+
rdnskey.decode.bytes = offset - oldOffset;
|
|
3729
|
+
return key;
|
|
3730
|
+
};
|
|
3731
|
+
rdnskey.decode.bytes = 0;
|
|
3732
|
+
rdnskey.encodingLength = function(key) {
|
|
3733
|
+
return 6 + Buffer$1.byteLength(key.key);
|
|
3734
|
+
};
|
|
3735
|
+
const rrrsig = exports.rrsig = {};
|
|
3736
|
+
rrrsig.encode = function(sig, buf, offset) {
|
|
3737
|
+
if (!buf) buf = Buffer$1.alloc(rrrsig.encodingLength(sig));
|
|
3738
|
+
if (!offset) offset = 0;
|
|
3739
|
+
const oldOffset = offset;
|
|
3740
|
+
const signature = sig.signature;
|
|
3741
|
+
if (!Buffer$1.isBuffer(signature)) throw new Error("Signature must be a Buffer");
|
|
3742
|
+
offset += 2;
|
|
3743
|
+
buf.writeUInt16BE(types.toType(sig.typeCovered), offset);
|
|
3744
|
+
offset += 2;
|
|
3745
|
+
buf.writeUInt8(sig.algorithm, offset);
|
|
3746
|
+
offset += 1;
|
|
3747
|
+
buf.writeUInt8(sig.labels, offset);
|
|
3748
|
+
offset += 1;
|
|
3749
|
+
buf.writeUInt32BE(sig.originalTTL, offset);
|
|
3750
|
+
offset += 4;
|
|
3751
|
+
buf.writeUInt32BE(sig.expiration, offset);
|
|
3752
|
+
offset += 4;
|
|
3753
|
+
buf.writeUInt32BE(sig.inception, offset);
|
|
3754
|
+
offset += 4;
|
|
3755
|
+
buf.writeUInt16BE(sig.keyTag, offset);
|
|
3756
|
+
offset += 2;
|
|
3757
|
+
name.encode(sig.signersName, buf, offset);
|
|
3758
|
+
offset += name.encode.bytes;
|
|
3759
|
+
signature.copy(buf, offset, 0, signature.length);
|
|
3760
|
+
offset += signature.length;
|
|
3761
|
+
rrrsig.encode.bytes = offset - oldOffset;
|
|
3762
|
+
buf.writeUInt16BE(rrrsig.encode.bytes - 2, oldOffset);
|
|
3763
|
+
return buf;
|
|
3764
|
+
};
|
|
3765
|
+
rrrsig.encode.bytes = 0;
|
|
3766
|
+
rrrsig.decode = function(buf, offset) {
|
|
3767
|
+
if (!offset) offset = 0;
|
|
3768
|
+
const oldOffset = offset;
|
|
3769
|
+
var sig = {};
|
|
3770
|
+
var length = buf.readUInt16BE(offset);
|
|
3771
|
+
offset += 2;
|
|
3772
|
+
sig.typeCovered = types.toString(buf.readUInt16BE(offset));
|
|
3773
|
+
offset += 2;
|
|
3774
|
+
sig.algorithm = buf.readUInt8(offset);
|
|
3775
|
+
offset += 1;
|
|
3776
|
+
sig.labels = buf.readUInt8(offset);
|
|
3777
|
+
offset += 1;
|
|
3778
|
+
sig.originalTTL = buf.readUInt32BE(offset);
|
|
3779
|
+
offset += 4;
|
|
3780
|
+
sig.expiration = buf.readUInt32BE(offset);
|
|
3781
|
+
offset += 4;
|
|
3782
|
+
sig.inception = buf.readUInt32BE(offset);
|
|
3783
|
+
offset += 4;
|
|
3784
|
+
sig.keyTag = buf.readUInt16BE(offset);
|
|
3785
|
+
offset += 2;
|
|
3786
|
+
sig.signersName = name.decode(buf, offset);
|
|
3787
|
+
offset += name.decode.bytes;
|
|
3788
|
+
sig.signature = buf.slice(offset, oldOffset + length + 2);
|
|
3789
|
+
offset += sig.signature.length;
|
|
3790
|
+
rrrsig.decode.bytes = offset - oldOffset;
|
|
3791
|
+
return sig;
|
|
3792
|
+
};
|
|
3793
|
+
rrrsig.decode.bytes = 0;
|
|
3794
|
+
rrrsig.encodingLength = function(sig) {
|
|
3795
|
+
return 20 + name.encodingLength(sig.signersName) + Buffer$1.byteLength(sig.signature);
|
|
3796
|
+
};
|
|
3797
|
+
const rrp = exports.rp = {};
|
|
3798
|
+
rrp.encode = function(data, buf, offset) {
|
|
3799
|
+
if (!buf) buf = Buffer$1.alloc(rrp.encodingLength(data));
|
|
3800
|
+
if (!offset) offset = 0;
|
|
3801
|
+
const oldOffset = offset;
|
|
3802
|
+
offset += 2;
|
|
3803
|
+
name.encode(data.mbox || ".", buf, offset, { mail: true });
|
|
3804
|
+
offset += name.encode.bytes;
|
|
3805
|
+
name.encode(data.txt || ".", buf, offset);
|
|
3806
|
+
offset += name.encode.bytes;
|
|
3807
|
+
rrp.encode.bytes = offset - oldOffset;
|
|
3808
|
+
buf.writeUInt16BE(rrp.encode.bytes - 2, oldOffset);
|
|
3809
|
+
return buf;
|
|
3810
|
+
};
|
|
3811
|
+
rrp.encode.bytes = 0;
|
|
3812
|
+
rrp.decode = function(buf, offset) {
|
|
3813
|
+
if (!offset) offset = 0;
|
|
3814
|
+
const oldOffset = offset;
|
|
3815
|
+
const data = {};
|
|
3816
|
+
offset += 2;
|
|
3817
|
+
data.mbox = name.decode(buf, offset, { mail: true }) || ".";
|
|
3818
|
+
offset += name.decode.bytes;
|
|
3819
|
+
data.txt = name.decode(buf, offset) || ".";
|
|
3820
|
+
offset += name.decode.bytes;
|
|
3821
|
+
rrp.decode.bytes = offset - oldOffset;
|
|
3822
|
+
return data;
|
|
3823
|
+
};
|
|
3824
|
+
rrp.decode.bytes = 0;
|
|
3825
|
+
rrp.encodingLength = function(data) {
|
|
3826
|
+
return 2 + name.encodingLength(data.mbox || ".") + name.encodingLength(data.txt || ".");
|
|
3827
|
+
};
|
|
3828
|
+
const typebitmap = {};
|
|
3829
|
+
typebitmap.encode = function(typelist, buf, offset) {
|
|
3830
|
+
if (!buf) buf = Buffer$1.alloc(typebitmap.encodingLength(typelist));
|
|
3831
|
+
if (!offset) offset = 0;
|
|
3832
|
+
const oldOffset = offset;
|
|
3833
|
+
var typesByWindow = [];
|
|
3834
|
+
for (var i = 0; i < typelist.length; i++) {
|
|
3835
|
+
var typeid = types.toType(typelist[i]);
|
|
3836
|
+
if (typesByWindow[typeid >> 8] === void 0) typesByWindow[typeid >> 8] = [];
|
|
3837
|
+
typesByWindow[typeid >> 8][typeid >> 3 & 31] |= 1 << 7 - (typeid & 7);
|
|
3838
|
+
}
|
|
3839
|
+
for (i = 0; i < typesByWindow.length; i++) if (typesByWindow[i] !== void 0) {
|
|
3840
|
+
var windowBuf = Buffer$1.from(typesByWindow[i]);
|
|
3841
|
+
buf.writeUInt8(i, offset);
|
|
3842
|
+
offset += 1;
|
|
3843
|
+
buf.writeUInt8(windowBuf.length, offset);
|
|
3844
|
+
offset += 1;
|
|
3845
|
+
windowBuf.copy(buf, offset);
|
|
3846
|
+
offset += windowBuf.length;
|
|
3847
|
+
}
|
|
3848
|
+
typebitmap.encode.bytes = offset - oldOffset;
|
|
3849
|
+
return buf;
|
|
3850
|
+
};
|
|
3851
|
+
typebitmap.encode.bytes = 0;
|
|
3852
|
+
typebitmap.decode = function(buf, offset, length) {
|
|
3853
|
+
if (!offset) offset = 0;
|
|
3854
|
+
const oldOffset = offset;
|
|
3855
|
+
var typelist = [];
|
|
3856
|
+
while (offset - oldOffset < length) {
|
|
3857
|
+
var window = buf.readUInt8(offset);
|
|
3858
|
+
offset += 1;
|
|
3859
|
+
var windowLength = buf.readUInt8(offset);
|
|
3860
|
+
offset += 1;
|
|
3861
|
+
for (var i = 0; i < windowLength; i++) {
|
|
3862
|
+
var b = buf.readUInt8(offset + i);
|
|
3863
|
+
for (var j = 0; j < 8; j++) if (b & 1 << 7 - j) {
|
|
3864
|
+
var typeid = types.toString(window << 8 | i << 3 | j);
|
|
3865
|
+
typelist.push(typeid);
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
offset += windowLength;
|
|
3869
|
+
}
|
|
3870
|
+
typebitmap.decode.bytes = offset - oldOffset;
|
|
3871
|
+
return typelist;
|
|
3872
|
+
};
|
|
3873
|
+
typebitmap.decode.bytes = 0;
|
|
3874
|
+
typebitmap.encodingLength = function(typelist) {
|
|
3875
|
+
var extents = [];
|
|
3876
|
+
for (var i = 0; i < typelist.length; i++) {
|
|
3877
|
+
var typeid = types.toType(typelist[i]);
|
|
3878
|
+
extents[typeid >> 8] = Math.max(extents[typeid >> 8] || 0, typeid & 255);
|
|
3879
|
+
}
|
|
3880
|
+
var len = 0;
|
|
3881
|
+
for (i = 0; i < extents.length; i++) if (extents[i] !== void 0) len += 2 + Math.ceil((extents[i] + 1) / 8);
|
|
3882
|
+
return len;
|
|
3883
|
+
};
|
|
3884
|
+
const rnsec = exports.nsec = {};
|
|
3885
|
+
rnsec.encode = function(record, buf, offset) {
|
|
3886
|
+
if (!buf) buf = Buffer$1.alloc(rnsec.encodingLength(record));
|
|
3887
|
+
if (!offset) offset = 0;
|
|
3888
|
+
const oldOffset = offset;
|
|
3889
|
+
offset += 2;
|
|
3890
|
+
name.encode(record.nextDomain, buf, offset);
|
|
3891
|
+
offset += name.encode.bytes;
|
|
3892
|
+
typebitmap.encode(record.rrtypes, buf, offset);
|
|
3893
|
+
offset += typebitmap.encode.bytes;
|
|
3894
|
+
rnsec.encode.bytes = offset - oldOffset;
|
|
3895
|
+
buf.writeUInt16BE(rnsec.encode.bytes - 2, oldOffset);
|
|
3896
|
+
return buf;
|
|
3897
|
+
};
|
|
3898
|
+
rnsec.encode.bytes = 0;
|
|
3899
|
+
rnsec.decode = function(buf, offset) {
|
|
3900
|
+
if (!offset) offset = 0;
|
|
3901
|
+
const oldOffset = offset;
|
|
3902
|
+
var record = {};
|
|
3903
|
+
var length = buf.readUInt16BE(offset);
|
|
3904
|
+
offset += 2;
|
|
3905
|
+
record.nextDomain = name.decode(buf, offset);
|
|
3906
|
+
offset += name.decode.bytes;
|
|
3907
|
+
record.rrtypes = typebitmap.decode(buf, offset, length - (offset - oldOffset));
|
|
3908
|
+
offset += typebitmap.decode.bytes;
|
|
3909
|
+
rnsec.decode.bytes = offset - oldOffset;
|
|
3910
|
+
return record;
|
|
3911
|
+
};
|
|
3912
|
+
rnsec.decode.bytes = 0;
|
|
3913
|
+
rnsec.encodingLength = function(record) {
|
|
3914
|
+
return 2 + name.encodingLength(record.nextDomain) + typebitmap.encodingLength(record.rrtypes);
|
|
3915
|
+
};
|
|
3916
|
+
const rnsec3 = exports.nsec3 = {};
|
|
3917
|
+
rnsec3.encode = function(record, buf, offset) {
|
|
3918
|
+
if (!buf) buf = Buffer$1.alloc(rnsec3.encodingLength(record));
|
|
3919
|
+
if (!offset) offset = 0;
|
|
3920
|
+
const oldOffset = offset;
|
|
3921
|
+
const salt = record.salt;
|
|
3922
|
+
if (!Buffer$1.isBuffer(salt)) throw new Error("salt must be a Buffer");
|
|
3923
|
+
const nextDomain = record.nextDomain;
|
|
3924
|
+
if (!Buffer$1.isBuffer(nextDomain)) throw new Error("nextDomain must be a Buffer");
|
|
3925
|
+
offset += 2;
|
|
3926
|
+
buf.writeUInt8(record.algorithm, offset);
|
|
3927
|
+
offset += 1;
|
|
3928
|
+
buf.writeUInt8(record.flags, offset);
|
|
3929
|
+
offset += 1;
|
|
3930
|
+
buf.writeUInt16BE(record.iterations, offset);
|
|
3931
|
+
offset += 2;
|
|
3932
|
+
buf.writeUInt8(salt.length, offset);
|
|
3933
|
+
offset += 1;
|
|
3934
|
+
salt.copy(buf, offset, 0, salt.length);
|
|
3935
|
+
offset += salt.length;
|
|
3936
|
+
buf.writeUInt8(nextDomain.length, offset);
|
|
3937
|
+
offset += 1;
|
|
3938
|
+
nextDomain.copy(buf, offset, 0, nextDomain.length);
|
|
3939
|
+
offset += nextDomain.length;
|
|
3940
|
+
typebitmap.encode(record.rrtypes, buf, offset);
|
|
3941
|
+
offset += typebitmap.encode.bytes;
|
|
3942
|
+
rnsec3.encode.bytes = offset - oldOffset;
|
|
3943
|
+
buf.writeUInt16BE(rnsec3.encode.bytes - 2, oldOffset);
|
|
3944
|
+
return buf;
|
|
3945
|
+
};
|
|
3946
|
+
rnsec3.encode.bytes = 0;
|
|
3947
|
+
rnsec3.decode = function(buf, offset) {
|
|
3948
|
+
if (!offset) offset = 0;
|
|
3949
|
+
const oldOffset = offset;
|
|
3950
|
+
var record = {};
|
|
3951
|
+
var length = buf.readUInt16BE(offset);
|
|
3952
|
+
offset += 2;
|
|
3953
|
+
record.algorithm = buf.readUInt8(offset);
|
|
3954
|
+
offset += 1;
|
|
3955
|
+
record.flags = buf.readUInt8(offset);
|
|
3956
|
+
offset += 1;
|
|
3957
|
+
record.iterations = buf.readUInt16BE(offset);
|
|
3958
|
+
offset += 2;
|
|
3959
|
+
const saltLength = buf.readUInt8(offset);
|
|
3960
|
+
offset += 1;
|
|
3961
|
+
record.salt = buf.slice(offset, offset + saltLength);
|
|
3962
|
+
offset += saltLength;
|
|
3963
|
+
const hashLength = buf.readUInt8(offset);
|
|
3964
|
+
offset += 1;
|
|
3965
|
+
record.nextDomain = buf.slice(offset, offset + hashLength);
|
|
3966
|
+
offset += hashLength;
|
|
3967
|
+
record.rrtypes = typebitmap.decode(buf, offset, length - (offset - oldOffset));
|
|
3968
|
+
offset += typebitmap.decode.bytes;
|
|
3969
|
+
rnsec3.decode.bytes = offset - oldOffset;
|
|
3970
|
+
return record;
|
|
3971
|
+
};
|
|
3972
|
+
rnsec3.decode.bytes = 0;
|
|
3973
|
+
rnsec3.encodingLength = function(record) {
|
|
3974
|
+
return 8 + record.salt.length + record.nextDomain.length + typebitmap.encodingLength(record.rrtypes);
|
|
3975
|
+
};
|
|
3976
|
+
const rds = exports.ds = {};
|
|
3977
|
+
rds.encode = function(digest, buf, offset) {
|
|
3978
|
+
if (!buf) buf = Buffer$1.alloc(rds.encodingLength(digest));
|
|
3979
|
+
if (!offset) offset = 0;
|
|
3980
|
+
const oldOffset = offset;
|
|
3981
|
+
const digestdata = digest.digest;
|
|
3982
|
+
if (!Buffer$1.isBuffer(digestdata)) throw new Error("Digest must be a Buffer");
|
|
3983
|
+
offset += 2;
|
|
3984
|
+
buf.writeUInt16BE(digest.keyTag, offset);
|
|
3985
|
+
offset += 2;
|
|
3986
|
+
buf.writeUInt8(digest.algorithm, offset);
|
|
3987
|
+
offset += 1;
|
|
3988
|
+
buf.writeUInt8(digest.digestType, offset);
|
|
3989
|
+
offset += 1;
|
|
3990
|
+
digestdata.copy(buf, offset, 0, digestdata.length);
|
|
3991
|
+
offset += digestdata.length;
|
|
3992
|
+
rds.encode.bytes = offset - oldOffset;
|
|
3993
|
+
buf.writeUInt16BE(rds.encode.bytes - 2, oldOffset);
|
|
3994
|
+
return buf;
|
|
3995
|
+
};
|
|
3996
|
+
rds.encode.bytes = 0;
|
|
3997
|
+
rds.decode = function(buf, offset) {
|
|
3998
|
+
if (!offset) offset = 0;
|
|
3999
|
+
const oldOffset = offset;
|
|
4000
|
+
var digest = {};
|
|
4001
|
+
var length = buf.readUInt16BE(offset);
|
|
4002
|
+
offset += 2;
|
|
4003
|
+
digest.keyTag = buf.readUInt16BE(offset);
|
|
4004
|
+
offset += 2;
|
|
4005
|
+
digest.algorithm = buf.readUInt8(offset);
|
|
4006
|
+
offset += 1;
|
|
4007
|
+
digest.digestType = buf.readUInt8(offset);
|
|
4008
|
+
offset += 1;
|
|
4009
|
+
digest.digest = buf.slice(offset, oldOffset + length + 2);
|
|
4010
|
+
offset += digest.digest.length;
|
|
4011
|
+
rds.decode.bytes = offset - oldOffset;
|
|
4012
|
+
return digest;
|
|
4013
|
+
};
|
|
4014
|
+
rds.decode.bytes = 0;
|
|
4015
|
+
rds.encodingLength = function(digest) {
|
|
4016
|
+
return 6 + Buffer$1.byteLength(digest.digest);
|
|
4017
|
+
};
|
|
4018
|
+
const rsshfp = exports.sshfp = {};
|
|
4019
|
+
rsshfp.getFingerprintLengthForHashType = function getFingerprintLengthForHashType(hashType) {
|
|
4020
|
+
switch (hashType) {
|
|
4021
|
+
case 1: return 20;
|
|
4022
|
+
case 2: return 32;
|
|
4023
|
+
}
|
|
4024
|
+
};
|
|
4025
|
+
rsshfp.encode = function encode(record, buf, offset) {
|
|
4026
|
+
if (!buf) buf = Buffer$1.alloc(rsshfp.encodingLength(record));
|
|
4027
|
+
if (!offset) offset = 0;
|
|
4028
|
+
const oldOffset = offset;
|
|
4029
|
+
offset += 2;
|
|
4030
|
+
buf[offset] = record.algorithm;
|
|
4031
|
+
offset += 1;
|
|
4032
|
+
buf[offset] = record.hash;
|
|
4033
|
+
offset += 1;
|
|
4034
|
+
const fingerprintBuf = Buffer$1.from(record.fingerprint.toUpperCase(), "hex");
|
|
4035
|
+
if (fingerprintBuf.length !== rsshfp.getFingerprintLengthForHashType(record.hash)) throw new Error("Invalid fingerprint length");
|
|
4036
|
+
fingerprintBuf.copy(buf, offset);
|
|
4037
|
+
offset += fingerprintBuf.byteLength;
|
|
4038
|
+
rsshfp.encode.bytes = offset - oldOffset;
|
|
4039
|
+
buf.writeUInt16BE(rsshfp.encode.bytes - 2, oldOffset);
|
|
4040
|
+
return buf;
|
|
4041
|
+
};
|
|
4042
|
+
rsshfp.encode.bytes = 0;
|
|
4043
|
+
rsshfp.decode = function decode(buf, offset) {
|
|
4044
|
+
if (!offset) offset = 0;
|
|
4045
|
+
const oldOffset = offset;
|
|
4046
|
+
const record = {};
|
|
4047
|
+
offset += 2;
|
|
4048
|
+
record.algorithm = buf[offset];
|
|
4049
|
+
offset += 1;
|
|
4050
|
+
record.hash = buf[offset];
|
|
4051
|
+
offset += 1;
|
|
4052
|
+
const fingerprintLength = rsshfp.getFingerprintLengthForHashType(record.hash);
|
|
4053
|
+
record.fingerprint = buf.slice(offset, offset + fingerprintLength).toString("hex").toUpperCase();
|
|
4054
|
+
offset += fingerprintLength;
|
|
4055
|
+
rsshfp.decode.bytes = offset - oldOffset;
|
|
4056
|
+
return record;
|
|
4057
|
+
};
|
|
4058
|
+
rsshfp.decode.bytes = 0;
|
|
4059
|
+
rsshfp.encodingLength = function(record) {
|
|
4060
|
+
return 4 + Buffer$1.from(record.fingerprint, "hex").byteLength;
|
|
4061
|
+
};
|
|
4062
|
+
const rnaptr = exports.naptr = {};
|
|
4063
|
+
rnaptr.encode = function(data, buf, offset) {
|
|
4064
|
+
if (!buf) buf = Buffer$1.alloc(rnaptr.encodingLength(data));
|
|
4065
|
+
if (!offset) offset = 0;
|
|
4066
|
+
const oldOffset = offset;
|
|
4067
|
+
offset += 2;
|
|
4068
|
+
buf.writeUInt16BE(data.order || 0, offset);
|
|
4069
|
+
offset += 2;
|
|
4070
|
+
buf.writeUInt16BE(data.preference || 0, offset);
|
|
4071
|
+
offset += 2;
|
|
4072
|
+
string.encode(data.flags, buf, offset);
|
|
4073
|
+
offset += string.encode.bytes;
|
|
4074
|
+
string.encode(data.services, buf, offset);
|
|
4075
|
+
offset += string.encode.bytes;
|
|
4076
|
+
string.encode(data.regexp, buf, offset);
|
|
4077
|
+
offset += string.encode.bytes;
|
|
4078
|
+
name.encode(data.replacement, buf, offset);
|
|
4079
|
+
offset += name.encode.bytes;
|
|
4080
|
+
rnaptr.encode.bytes = offset - oldOffset;
|
|
4081
|
+
buf.writeUInt16BE(rnaptr.encode.bytes - 2, oldOffset);
|
|
4082
|
+
return buf;
|
|
4083
|
+
};
|
|
4084
|
+
rnaptr.encode.bytes = 0;
|
|
4085
|
+
rnaptr.decode = function(buf, offset) {
|
|
4086
|
+
if (!offset) offset = 0;
|
|
4087
|
+
const oldOffset = offset;
|
|
4088
|
+
const data = {};
|
|
4089
|
+
offset += 2;
|
|
4090
|
+
data.order = buf.readUInt16BE(offset);
|
|
4091
|
+
offset += 2;
|
|
4092
|
+
data.preference = buf.readUInt16BE(offset);
|
|
4093
|
+
offset += 2;
|
|
4094
|
+
data.flags = string.decode(buf, offset);
|
|
4095
|
+
offset += string.decode.bytes;
|
|
4096
|
+
data.services = string.decode(buf, offset);
|
|
4097
|
+
offset += string.decode.bytes;
|
|
4098
|
+
data.regexp = string.decode(buf, offset);
|
|
4099
|
+
offset += string.decode.bytes;
|
|
4100
|
+
data.replacement = name.decode(buf, offset);
|
|
4101
|
+
offset += name.decode.bytes;
|
|
4102
|
+
rnaptr.decode.bytes = offset - oldOffset;
|
|
4103
|
+
return data;
|
|
4104
|
+
};
|
|
4105
|
+
rnaptr.decode.bytes = 0;
|
|
4106
|
+
rnaptr.encodingLength = function(data) {
|
|
4107
|
+
return string.encodingLength(data.flags) + string.encodingLength(data.services) + string.encodingLength(data.regexp) + name.encodingLength(data.replacement) + 6;
|
|
4108
|
+
};
|
|
4109
|
+
const rtlsa = exports.tlsa = {};
|
|
4110
|
+
rtlsa.encode = function(cert, buf, offset) {
|
|
4111
|
+
if (!buf) buf = Buffer$1.alloc(rtlsa.encodingLength(cert));
|
|
4112
|
+
if (!offset) offset = 0;
|
|
4113
|
+
const oldOffset = offset;
|
|
4114
|
+
const certdata = cert.certificate;
|
|
4115
|
+
if (!Buffer$1.isBuffer(certdata)) throw new Error("Certificate must be a Buffer");
|
|
4116
|
+
offset += 2;
|
|
4117
|
+
buf.writeUInt8(cert.usage, offset);
|
|
4118
|
+
offset += 1;
|
|
4119
|
+
buf.writeUInt8(cert.selector, offset);
|
|
4120
|
+
offset += 1;
|
|
4121
|
+
buf.writeUInt8(cert.matchingType, offset);
|
|
4122
|
+
offset += 1;
|
|
4123
|
+
certdata.copy(buf, offset, 0, certdata.length);
|
|
4124
|
+
offset += certdata.length;
|
|
4125
|
+
rtlsa.encode.bytes = offset - oldOffset;
|
|
4126
|
+
buf.writeUInt16BE(rtlsa.encode.bytes - 2, oldOffset);
|
|
4127
|
+
return buf;
|
|
4128
|
+
};
|
|
4129
|
+
rtlsa.encode.bytes = 0;
|
|
4130
|
+
rtlsa.decode = function(buf, offset) {
|
|
4131
|
+
if (!offset) offset = 0;
|
|
4132
|
+
const oldOffset = offset;
|
|
4133
|
+
const cert = {};
|
|
4134
|
+
const length = buf.readUInt16BE(offset);
|
|
4135
|
+
offset += 2;
|
|
4136
|
+
cert.usage = buf.readUInt8(offset);
|
|
4137
|
+
offset += 1;
|
|
4138
|
+
cert.selector = buf.readUInt8(offset);
|
|
4139
|
+
offset += 1;
|
|
4140
|
+
cert.matchingType = buf.readUInt8(offset);
|
|
4141
|
+
offset += 1;
|
|
4142
|
+
cert.certificate = buf.slice(offset, oldOffset + length + 2);
|
|
4143
|
+
offset += cert.certificate.length;
|
|
4144
|
+
rtlsa.decode.bytes = offset - oldOffset;
|
|
4145
|
+
return cert;
|
|
4146
|
+
};
|
|
4147
|
+
rtlsa.decode.bytes = 0;
|
|
4148
|
+
rtlsa.encodingLength = function(cert) {
|
|
4149
|
+
return 5 + Buffer$1.byteLength(cert.certificate);
|
|
4150
|
+
};
|
|
4151
|
+
const renc = exports.record = function(type) {
|
|
4152
|
+
switch (type.toUpperCase()) {
|
|
4153
|
+
case "A": return ra;
|
|
4154
|
+
case "PTR": return rptr;
|
|
4155
|
+
case "CNAME": return rcname;
|
|
4156
|
+
case "DNAME": return rdname;
|
|
4157
|
+
case "TXT": return rtxt;
|
|
4158
|
+
case "NULL": return rnull;
|
|
4159
|
+
case "AAAA": return raaaa;
|
|
4160
|
+
case "SRV": return rsrv;
|
|
4161
|
+
case "HINFO": return rhinfo;
|
|
4162
|
+
case "CAA": return rcaa;
|
|
4163
|
+
case "NS": return rns;
|
|
4164
|
+
case "SOA": return rsoa;
|
|
4165
|
+
case "MX": return rmx;
|
|
4166
|
+
case "OPT": return ropt;
|
|
4167
|
+
case "DNSKEY": return rdnskey;
|
|
4168
|
+
case "RRSIG": return rrrsig;
|
|
4169
|
+
case "RP": return rrp;
|
|
4170
|
+
case "NSEC": return rnsec;
|
|
4171
|
+
case "NSEC3": return rnsec3;
|
|
4172
|
+
case "SSHFP": return rsshfp;
|
|
4173
|
+
case "DS": return rds;
|
|
4174
|
+
case "NAPTR": return rnaptr;
|
|
4175
|
+
case "TLSA": return rtlsa;
|
|
4176
|
+
}
|
|
4177
|
+
return runknown;
|
|
4178
|
+
};
|
|
4179
|
+
const answer = exports.answer = {};
|
|
4180
|
+
answer.encode = function(a, buf, offset) {
|
|
4181
|
+
if (!buf) buf = Buffer$1.alloc(answer.encodingLength(a));
|
|
4182
|
+
if (!offset) offset = 0;
|
|
4183
|
+
const oldOffset = offset;
|
|
4184
|
+
name.encode(a.name, buf, offset);
|
|
4185
|
+
offset += name.encode.bytes;
|
|
4186
|
+
buf.writeUInt16BE(types.toType(a.type), offset);
|
|
4187
|
+
if (a.type.toUpperCase() === "OPT") {
|
|
4188
|
+
if (a.name !== ".") throw new Error("OPT name must be root.");
|
|
4189
|
+
buf.writeUInt16BE(a.udpPayloadSize || 4096, offset + 2);
|
|
4190
|
+
buf.writeUInt8(a.extendedRcode || 0, offset + 4);
|
|
4191
|
+
buf.writeUInt8(a.ednsVersion || 0, offset + 5);
|
|
4192
|
+
buf.writeUInt16BE(a.flags || 0, offset + 6);
|
|
4193
|
+
offset += 8;
|
|
4194
|
+
ropt.encode(a.options || [], buf, offset);
|
|
4195
|
+
offset += ropt.encode.bytes;
|
|
4196
|
+
} else {
|
|
4197
|
+
let klass = classes.toClass(a.class === void 0 ? "IN" : a.class);
|
|
4198
|
+
if (a.flush) klass |= FLUSH_MASK;
|
|
4199
|
+
buf.writeUInt16BE(klass, offset + 2);
|
|
4200
|
+
buf.writeUInt32BE(a.ttl || 0, offset + 4);
|
|
4201
|
+
offset += 8;
|
|
4202
|
+
const enc = renc(a.type);
|
|
4203
|
+
enc.encode(a.data, buf, offset);
|
|
4204
|
+
offset += enc.encode.bytes;
|
|
4205
|
+
}
|
|
4206
|
+
answer.encode.bytes = offset - oldOffset;
|
|
4207
|
+
return buf;
|
|
4208
|
+
};
|
|
4209
|
+
answer.encode.bytes = 0;
|
|
4210
|
+
answer.decode = function(buf, offset) {
|
|
4211
|
+
if (!offset) offset = 0;
|
|
4212
|
+
const a = {};
|
|
4213
|
+
const oldOffset = offset;
|
|
4214
|
+
a.name = name.decode(buf, offset);
|
|
4215
|
+
offset += name.decode.bytes;
|
|
4216
|
+
a.type = types.toString(buf.readUInt16BE(offset));
|
|
4217
|
+
if (a.type === "OPT") {
|
|
4218
|
+
a.udpPayloadSize = buf.readUInt16BE(offset + 2);
|
|
4219
|
+
a.extendedRcode = buf.readUInt8(offset + 4);
|
|
4220
|
+
a.ednsVersion = buf.readUInt8(offset + 5);
|
|
4221
|
+
a.flags = buf.readUInt16BE(offset + 6);
|
|
4222
|
+
a.flag_do = (a.flags >> 15 & 1) === 1;
|
|
4223
|
+
a.options = ropt.decode(buf, offset + 8);
|
|
4224
|
+
offset += 8 + ropt.decode.bytes;
|
|
4225
|
+
} else {
|
|
4226
|
+
const klass = buf.readUInt16BE(offset + 2);
|
|
4227
|
+
a.ttl = buf.readUInt32BE(offset + 4);
|
|
4228
|
+
a.class = classes.toString(klass & NOT_FLUSH_MASK);
|
|
4229
|
+
a.flush = !!(klass & FLUSH_MASK);
|
|
4230
|
+
const enc = renc(a.type);
|
|
4231
|
+
a.data = enc.decode(buf, offset + 8);
|
|
4232
|
+
offset += 8 + enc.decode.bytes;
|
|
4233
|
+
}
|
|
4234
|
+
answer.decode.bytes = offset - oldOffset;
|
|
4235
|
+
return a;
|
|
4236
|
+
};
|
|
4237
|
+
answer.decode.bytes = 0;
|
|
4238
|
+
answer.encodingLength = function(a) {
|
|
4239
|
+
const data = a.data !== null && a.data !== void 0 ? a.data : a.options;
|
|
4240
|
+
return name.encodingLength(a.name) + 8 + renc(a.type).encodingLength(data);
|
|
4241
|
+
};
|
|
4242
|
+
const question = exports.question = {};
|
|
4243
|
+
question.encode = function(q, buf, offset) {
|
|
4244
|
+
if (!buf) buf = Buffer$1.alloc(question.encodingLength(q));
|
|
4245
|
+
if (!offset) offset = 0;
|
|
4246
|
+
const oldOffset = offset;
|
|
4247
|
+
name.encode(q.name, buf, offset);
|
|
4248
|
+
offset += name.encode.bytes;
|
|
4249
|
+
buf.writeUInt16BE(types.toType(q.type), offset);
|
|
4250
|
+
offset += 2;
|
|
4251
|
+
buf.writeUInt16BE(classes.toClass(q.class === void 0 ? "IN" : q.class), offset);
|
|
4252
|
+
offset += 2;
|
|
4253
|
+
question.encode.bytes = offset - oldOffset;
|
|
4254
|
+
return q;
|
|
4255
|
+
};
|
|
4256
|
+
question.encode.bytes = 0;
|
|
4257
|
+
question.decode = function(buf, offset) {
|
|
4258
|
+
if (!offset) offset = 0;
|
|
4259
|
+
const oldOffset = offset;
|
|
4260
|
+
const q = {};
|
|
4261
|
+
q.name = name.decode(buf, offset);
|
|
4262
|
+
offset += name.decode.bytes;
|
|
4263
|
+
q.type = types.toString(buf.readUInt16BE(offset));
|
|
4264
|
+
offset += 2;
|
|
4265
|
+
q.class = classes.toString(buf.readUInt16BE(offset));
|
|
4266
|
+
offset += 2;
|
|
4267
|
+
if (!!(q.class & QU_MASK)) q.class &= NOT_QU_MASK;
|
|
4268
|
+
question.decode.bytes = offset - oldOffset;
|
|
4269
|
+
return q;
|
|
4270
|
+
};
|
|
4271
|
+
question.decode.bytes = 0;
|
|
4272
|
+
question.encodingLength = function(q) {
|
|
4273
|
+
return name.encodingLength(q.name) + 4;
|
|
4274
|
+
};
|
|
4275
|
+
exports.AUTHORITATIVE_ANSWER = 1024;
|
|
4276
|
+
exports.TRUNCATED_RESPONSE = 512;
|
|
4277
|
+
exports.RECURSION_DESIRED = 256;
|
|
4278
|
+
exports.RECURSION_AVAILABLE = 128;
|
|
4279
|
+
exports.AUTHENTIC_DATA = 32;
|
|
4280
|
+
exports.CHECKING_DISABLED = 16;
|
|
4281
|
+
exports.DNSSEC_OK = 32768;
|
|
4282
|
+
exports.encode = function(result, buf, offset) {
|
|
4283
|
+
const allocing = !buf;
|
|
4284
|
+
if (allocing) buf = Buffer$1.alloc(exports.encodingLength(result));
|
|
4285
|
+
if (!offset) offset = 0;
|
|
4286
|
+
const oldOffset = offset;
|
|
4287
|
+
if (!result.questions) result.questions = [];
|
|
4288
|
+
if (!result.answers) result.answers = [];
|
|
4289
|
+
if (!result.authorities) result.authorities = [];
|
|
4290
|
+
if (!result.additionals) result.additionals = [];
|
|
4291
|
+
header.encode(result, buf, offset);
|
|
4292
|
+
offset += header.encode.bytes;
|
|
4293
|
+
offset = encodeList(result.questions, question, buf, offset);
|
|
4294
|
+
offset = encodeList(result.answers, answer, buf, offset);
|
|
4295
|
+
offset = encodeList(result.authorities, answer, buf, offset);
|
|
4296
|
+
offset = encodeList(result.additionals, answer, buf, offset);
|
|
4297
|
+
exports.encode.bytes = offset - oldOffset;
|
|
4298
|
+
if (allocing && exports.encode.bytes !== buf.length) return buf.slice(0, exports.encode.bytes);
|
|
4299
|
+
return buf;
|
|
4300
|
+
};
|
|
4301
|
+
exports.encode.bytes = 0;
|
|
4302
|
+
exports.decode = function(buf, offset) {
|
|
4303
|
+
if (!offset) offset = 0;
|
|
4304
|
+
const oldOffset = offset;
|
|
4305
|
+
const result = header.decode(buf, offset);
|
|
4306
|
+
offset += header.decode.bytes;
|
|
4307
|
+
offset = decodeList(result.questions, question, buf, offset);
|
|
4308
|
+
offset = decodeList(result.answers, answer, buf, offset);
|
|
4309
|
+
offset = decodeList(result.authorities, answer, buf, offset);
|
|
4310
|
+
offset = decodeList(result.additionals, answer, buf, offset);
|
|
4311
|
+
exports.decode.bytes = offset - oldOffset;
|
|
4312
|
+
return result;
|
|
4313
|
+
};
|
|
4314
|
+
exports.decode.bytes = 0;
|
|
4315
|
+
exports.encodingLength = function(result) {
|
|
4316
|
+
return header.encodingLength(result) + encodingLengthList(result.questions || [], question) + encodingLengthList(result.answers || [], answer) + encodingLengthList(result.authorities || [], answer) + encodingLengthList(result.additionals || [], answer);
|
|
4317
|
+
};
|
|
4318
|
+
exports.streamEncode = function(result) {
|
|
4319
|
+
const buf = exports.encode(result);
|
|
4320
|
+
const sbuf = Buffer$1.alloc(2);
|
|
4321
|
+
sbuf.writeUInt16BE(buf.byteLength);
|
|
4322
|
+
const combine = Buffer$1.concat([sbuf, buf]);
|
|
4323
|
+
exports.streamEncode.bytes = combine.byteLength;
|
|
4324
|
+
return combine;
|
|
4325
|
+
};
|
|
4326
|
+
exports.streamEncode.bytes = 0;
|
|
4327
|
+
exports.streamDecode = function(sbuf) {
|
|
4328
|
+
const len = sbuf.readUInt16BE(0);
|
|
4329
|
+
if (sbuf.byteLength < len + 2) return null;
|
|
4330
|
+
const result = exports.decode(sbuf.slice(2));
|
|
4331
|
+
exports.streamDecode.bytes = exports.decode.bytes;
|
|
4332
|
+
return result;
|
|
4333
|
+
};
|
|
4334
|
+
exports.streamDecode.bytes = 0;
|
|
4335
|
+
function encodingLengthList(list, enc) {
|
|
4336
|
+
let len = 0;
|
|
4337
|
+
for (let i = 0; i < list.length; i++) len += enc.encodingLength(list[i]);
|
|
4338
|
+
return len;
|
|
4339
|
+
}
|
|
4340
|
+
function encodeList(list, enc, buf, offset) {
|
|
4341
|
+
for (let i = 0; i < list.length; i++) {
|
|
4342
|
+
enc.encode(list[i], buf, offset);
|
|
4343
|
+
offset += enc.encode.bytes;
|
|
4344
|
+
}
|
|
4345
|
+
return offset;
|
|
4346
|
+
}
|
|
4347
|
+
function decodeList(list, enc, buf, offset) {
|
|
4348
|
+
for (let i = 0; i < list.length; i++) {
|
|
4349
|
+
list[i] = enc.decode(buf, offset);
|
|
4350
|
+
offset += enc.decode.bytes;
|
|
4351
|
+
}
|
|
4352
|
+
return offset;
|
|
4353
|
+
}
|
|
4354
|
+
}));
|
|
4355
|
+
//#endregion
|
|
4356
|
+
//#region ../../node_modules/thunky/index.js
|
|
4357
|
+
var require_thunky = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4358
|
+
var nextTick = nextTickArgs;
|
|
4359
|
+
process.nextTick(upgrade, 42);
|
|
4360
|
+
module.exports = thunky;
|
|
4361
|
+
function thunky(fn) {
|
|
4362
|
+
var state = run;
|
|
4363
|
+
return thunk;
|
|
4364
|
+
function thunk(callback) {
|
|
4365
|
+
state(callback || noop);
|
|
4366
|
+
}
|
|
4367
|
+
function run(callback) {
|
|
4368
|
+
var stack = [callback];
|
|
4369
|
+
state = wait;
|
|
4370
|
+
fn(done);
|
|
4371
|
+
function wait(callback) {
|
|
4372
|
+
stack.push(callback);
|
|
4373
|
+
}
|
|
4374
|
+
function done(err) {
|
|
4375
|
+
var args = arguments;
|
|
4376
|
+
state = isError(err) ? run : finished;
|
|
4377
|
+
while (stack.length) finished(stack.shift());
|
|
4378
|
+
function finished(callback) {
|
|
4379
|
+
nextTick(apply, callback, args);
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
function isError(err) {
|
|
4385
|
+
return Object.prototype.toString.call(err) === "[object Error]";
|
|
4386
|
+
}
|
|
4387
|
+
function noop() {}
|
|
4388
|
+
function apply(callback, args) {
|
|
4389
|
+
callback.apply(null, args);
|
|
4390
|
+
}
|
|
4391
|
+
function upgrade(val) {
|
|
4392
|
+
if (val === 42) nextTick = process.nextTick;
|
|
4393
|
+
}
|
|
4394
|
+
function nextTickArgs(fn, a, b) {
|
|
4395
|
+
process.nextTick(function() {
|
|
4396
|
+
fn(a, b);
|
|
4397
|
+
});
|
|
4398
|
+
}
|
|
4399
|
+
}));
|
|
4400
|
+
//#endregion
|
|
4401
|
+
//#region ../../node_modules/multicast-dns/index.js
|
|
4402
|
+
var require_multicast_dns = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4403
|
+
var packet = require_dns_packet();
|
|
4404
|
+
var dgram = __require("dgram");
|
|
4405
|
+
var thunky = require_thunky();
|
|
4406
|
+
var events = __require("events");
|
|
4407
|
+
var os = __require("os");
|
|
4408
|
+
var noop = function() {};
|
|
4409
|
+
module.exports = function(opts) {
|
|
4410
|
+
if (!opts) opts = {};
|
|
4411
|
+
var that = new events.EventEmitter();
|
|
4412
|
+
var port = typeof opts.port === "number" ? opts.port : 5353;
|
|
4413
|
+
var type = opts.type || "udp4";
|
|
4414
|
+
var ip = opts.ip || opts.host || (type === "udp4" ? "224.0.0.251" : null);
|
|
4415
|
+
var me = {
|
|
4416
|
+
address: ip,
|
|
4417
|
+
port
|
|
4418
|
+
};
|
|
4419
|
+
var memberships = {};
|
|
4420
|
+
var destroyed = false;
|
|
4421
|
+
var interval = null;
|
|
4422
|
+
if (type === "udp6" && (!ip || !opts.interface)) throw new Error("For IPv6 multicast you must specify `ip` and `interface`");
|
|
4423
|
+
var socket = opts.socket || dgram.createSocket({
|
|
4424
|
+
type,
|
|
4425
|
+
reuseAddr: opts.reuseAddr !== false,
|
|
4426
|
+
toString: function() {
|
|
4427
|
+
return type;
|
|
4428
|
+
}
|
|
4429
|
+
});
|
|
4430
|
+
socket.on("error", function(err) {
|
|
4431
|
+
if (err.code === "EACCES" || err.code === "EADDRINUSE") that.emit("error", err);
|
|
4432
|
+
else that.emit("warning", err);
|
|
4433
|
+
});
|
|
4434
|
+
socket.on("message", function(message, rinfo) {
|
|
4435
|
+
try {
|
|
4436
|
+
message = packet.decode(message);
|
|
4437
|
+
} catch (err) {
|
|
4438
|
+
that.emit("warning", err);
|
|
4439
|
+
return;
|
|
4440
|
+
}
|
|
4441
|
+
that.emit("packet", message, rinfo);
|
|
4442
|
+
if (message.type === "query") that.emit("query", message, rinfo);
|
|
4443
|
+
if (message.type === "response") that.emit("response", message, rinfo);
|
|
4444
|
+
});
|
|
4445
|
+
socket.on("listening", function() {
|
|
4446
|
+
if (!port) port = me.port = socket.address().port;
|
|
4447
|
+
if (opts.multicast !== false) {
|
|
4448
|
+
that.update();
|
|
4449
|
+
interval = setInterval(that.update, 5e3);
|
|
4450
|
+
socket.setMulticastTTL(opts.ttl || 255);
|
|
4451
|
+
socket.setMulticastLoopback(opts.loopback !== false);
|
|
4452
|
+
}
|
|
4453
|
+
});
|
|
4454
|
+
var bind = thunky(function(cb) {
|
|
4455
|
+
if (!port || opts.bind === false) return cb(null);
|
|
4456
|
+
socket.once("error", cb);
|
|
4457
|
+
socket.bind(port, opts.bind || opts.interface, function() {
|
|
4458
|
+
socket.removeListener("error", cb);
|
|
4459
|
+
cb(null);
|
|
4460
|
+
});
|
|
4461
|
+
});
|
|
4462
|
+
bind(function(err) {
|
|
4463
|
+
if (err) return that.emit("error", err);
|
|
4464
|
+
that.emit("ready");
|
|
4465
|
+
});
|
|
4466
|
+
that.send = function(value, rinfo, cb) {
|
|
4467
|
+
if (typeof rinfo === "function") return that.send(value, null, rinfo);
|
|
4468
|
+
if (!cb) cb = noop;
|
|
4469
|
+
if (!rinfo) rinfo = me;
|
|
4470
|
+
else if (!rinfo.host && !rinfo.address) rinfo.address = me.address;
|
|
4471
|
+
bind(onbind);
|
|
4472
|
+
function onbind(err) {
|
|
4473
|
+
if (destroyed) return cb();
|
|
4474
|
+
if (err) return cb(err);
|
|
4475
|
+
var message = packet.encode(value);
|
|
4476
|
+
socket.send(message, 0, message.length, rinfo.port, rinfo.address || rinfo.host, cb);
|
|
4477
|
+
}
|
|
4478
|
+
};
|
|
4479
|
+
that.response = that.respond = function(res, rinfo, cb) {
|
|
4480
|
+
if (Array.isArray(res)) res = { answers: res };
|
|
4481
|
+
res.type = "response";
|
|
4482
|
+
res.flags = (res.flags || 0) | packet.AUTHORITATIVE_ANSWER;
|
|
4483
|
+
that.send(res, rinfo, cb);
|
|
4484
|
+
};
|
|
4485
|
+
that.query = function(q, type, rinfo, cb) {
|
|
4486
|
+
if (typeof type === "function") return that.query(q, null, null, type);
|
|
4487
|
+
if (typeof type === "object" && type && type.port) return that.query(q, null, type, rinfo);
|
|
4488
|
+
if (typeof rinfo === "function") return that.query(q, type, null, rinfo);
|
|
4489
|
+
if (!cb) cb = noop;
|
|
4490
|
+
if (typeof q === "string") q = [{
|
|
4491
|
+
name: q,
|
|
4492
|
+
type: type || "ANY"
|
|
4493
|
+
}];
|
|
4494
|
+
if (Array.isArray(q)) q = {
|
|
4495
|
+
type: "query",
|
|
4496
|
+
questions: q
|
|
4497
|
+
};
|
|
4498
|
+
q.type = "query";
|
|
4499
|
+
that.send(q, rinfo, cb);
|
|
4500
|
+
};
|
|
4501
|
+
that.destroy = function(cb) {
|
|
4502
|
+
if (!cb) cb = noop;
|
|
4503
|
+
if (destroyed) return process.nextTick(cb);
|
|
4504
|
+
destroyed = true;
|
|
4505
|
+
clearInterval(interval);
|
|
4506
|
+
for (var iface in memberships) try {
|
|
4507
|
+
socket.dropMembership(ip, iface);
|
|
4508
|
+
} catch (e) {}
|
|
4509
|
+
memberships = {};
|
|
4510
|
+
socket.close(cb);
|
|
4511
|
+
};
|
|
4512
|
+
that.update = function() {
|
|
4513
|
+
var ifaces = opts.interface ? [].concat(opts.interface) : allInterfaces();
|
|
4514
|
+
var updated = false;
|
|
4515
|
+
for (var i = 0; i < ifaces.length; i++) {
|
|
4516
|
+
var addr = ifaces[i];
|
|
4517
|
+
if (memberships[addr]) continue;
|
|
4518
|
+
try {
|
|
4519
|
+
socket.addMembership(ip, addr);
|
|
4520
|
+
memberships[addr] = true;
|
|
4521
|
+
updated = true;
|
|
4522
|
+
} catch (err) {
|
|
4523
|
+
that.emit("warning", err);
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
if (updated) {
|
|
4527
|
+
if (socket.setMulticastInterface) try {
|
|
4528
|
+
socket.setMulticastInterface(opts.interface || defaultInterface());
|
|
4529
|
+
} catch (err) {
|
|
4530
|
+
that.emit("warning", err);
|
|
4531
|
+
}
|
|
4532
|
+
that.emit("networkInterface");
|
|
4533
|
+
}
|
|
4534
|
+
};
|
|
4535
|
+
return that;
|
|
4536
|
+
};
|
|
4537
|
+
function defaultInterface() {
|
|
4538
|
+
var networks = os.networkInterfaces();
|
|
4539
|
+
var names = Object.keys(networks);
|
|
4540
|
+
for (var i = 0; i < names.length; i++) {
|
|
4541
|
+
var net = networks[names[i]];
|
|
4542
|
+
for (var j = 0; j < net.length; j++) {
|
|
4543
|
+
var iface = net[j];
|
|
4544
|
+
if (isIPv4(iface.family) && !iface.internal) {
|
|
4545
|
+
if (os.platform() === "darwin" && names[i] === "en0") return iface.address;
|
|
4546
|
+
return "0.0.0.0";
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4549
|
+
}
|
|
4550
|
+
return "127.0.0.1";
|
|
4551
|
+
}
|
|
4552
|
+
function allInterfaces() {
|
|
4553
|
+
var networks = os.networkInterfaces();
|
|
4554
|
+
var names = Object.keys(networks);
|
|
4555
|
+
var res = [];
|
|
4556
|
+
for (var i = 0; i < names.length; i++) {
|
|
4557
|
+
var net = networks[names[i]];
|
|
4558
|
+
for (var j = 0; j < net.length; j++) {
|
|
4559
|
+
var iface = net[j];
|
|
4560
|
+
if (isIPv4(iface.family)) {
|
|
4561
|
+
res.push(iface.address);
|
|
4562
|
+
break;
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
}
|
|
4566
|
+
return res;
|
|
4567
|
+
}
|
|
4568
|
+
function isIPv4(family) {
|
|
4569
|
+
return family === 4 || family === "IPv4";
|
|
4570
|
+
}
|
|
4571
|
+
}));
|
|
4572
|
+
//#endregion
|
|
4573
|
+
//#region ../../node_modules/fast-deep-equal/es6/index.js
|
|
4574
|
+
var require_es6 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4575
|
+
module.exports = function equal(a, b) {
|
|
4576
|
+
if (a === b) return true;
|
|
4577
|
+
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
4578
|
+
if (a.constructor !== b.constructor) return false;
|
|
4579
|
+
var length, i, keys;
|
|
4580
|
+
if (Array.isArray(a)) {
|
|
4581
|
+
length = a.length;
|
|
4582
|
+
if (length != b.length) return false;
|
|
4583
|
+
for (i = length; i-- !== 0;) if (!equal(a[i], b[i])) return false;
|
|
4584
|
+
return true;
|
|
4585
|
+
}
|
|
4586
|
+
if (a instanceof Map && b instanceof Map) {
|
|
4587
|
+
if (a.size !== b.size) return false;
|
|
4588
|
+
for (i of a.entries()) if (!b.has(i[0])) return false;
|
|
4589
|
+
for (i of a.entries()) if (!equal(i[1], b.get(i[0]))) return false;
|
|
4590
|
+
return true;
|
|
4591
|
+
}
|
|
4592
|
+
if (a instanceof Set && b instanceof Set) {
|
|
4593
|
+
if (a.size !== b.size) return false;
|
|
4594
|
+
for (i of a.entries()) if (!b.has(i[0])) return false;
|
|
4595
|
+
return true;
|
|
4596
|
+
}
|
|
4597
|
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
4598
|
+
length = a.length;
|
|
4599
|
+
if (length != b.length) return false;
|
|
4600
|
+
for (i = length; i-- !== 0;) if (a[i] !== b[i]) return false;
|
|
4601
|
+
return true;
|
|
4602
|
+
}
|
|
4603
|
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
4604
|
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
4605
|
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
4606
|
+
keys = Object.keys(a);
|
|
4607
|
+
length = keys.length;
|
|
4608
|
+
if (length !== Object.keys(b).length) return false;
|
|
4609
|
+
for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
4610
|
+
for (i = length; i-- !== 0;) {
|
|
4611
|
+
var key = keys[i];
|
|
4612
|
+
if (!equal(a[key], b[key])) return false;
|
|
4613
|
+
}
|
|
4614
|
+
return true;
|
|
4615
|
+
}
|
|
4616
|
+
return a !== a && b !== b;
|
|
4617
|
+
};
|
|
4618
|
+
}));
|
|
4619
|
+
//#endregion
|
|
4620
|
+
//#region ../../node_modules/bonjour-service/dist/lib/mdns-server.js
|
|
4621
|
+
var require_mdns_server = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4622
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
4623
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
4624
|
+
};
|
|
4625
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4626
|
+
exports.Server = void 0;
|
|
4627
|
+
const multicast_dns_1 = __importDefault(require_multicast_dns());
|
|
4628
|
+
const es6_1 = __importDefault(require_es6());
|
|
4629
|
+
const dns_equal_1 = __importDefault(require_dns_equal());
|
|
4630
|
+
var Server = class {
|
|
4631
|
+
constructor(opts, errorCallback) {
|
|
4632
|
+
this.registry = {};
|
|
4633
|
+
this.mdns = (0, multicast_dns_1.default)(opts);
|
|
4634
|
+
this.mdns.setMaxListeners(0);
|
|
4635
|
+
this.mdns.on("query", this.respondToQuery.bind(this));
|
|
4636
|
+
this.errorCallback = errorCallback !== null && errorCallback !== void 0 ? errorCallback : function(err) {
|
|
4637
|
+
throw err;
|
|
4638
|
+
};
|
|
4639
|
+
}
|
|
4640
|
+
register(records) {
|
|
4641
|
+
const shouldRegister = (record) => {
|
|
4642
|
+
var subRegistry = this.registry[record.type];
|
|
4643
|
+
if (!subRegistry) subRegistry = this.registry[record.type] = [];
|
|
4644
|
+
else if (subRegistry.some(this.isDuplicateRecord(record))) return;
|
|
4645
|
+
subRegistry.push(record);
|
|
4646
|
+
};
|
|
4647
|
+
if (Array.isArray(records)) records.forEach(shouldRegister);
|
|
4648
|
+
else shouldRegister(records);
|
|
4649
|
+
}
|
|
4650
|
+
unregister(records) {
|
|
4651
|
+
const shouldUnregister = (record) => {
|
|
4652
|
+
let type = record.type;
|
|
4653
|
+
if (!(type in this.registry)) return;
|
|
4654
|
+
this.registry[type] = this.registry[type].filter((i) => i.name !== record.name);
|
|
4655
|
+
};
|
|
4656
|
+
if (Array.isArray(records)) records.forEach(shouldUnregister);
|
|
4657
|
+
else shouldUnregister(records);
|
|
4658
|
+
}
|
|
4659
|
+
respondToQuery(query) {
|
|
4660
|
+
let self = this;
|
|
4661
|
+
query.questions.forEach((question) => {
|
|
4662
|
+
var type = question.type;
|
|
4663
|
+
var name = question.name;
|
|
4664
|
+
var answers = type === "ANY" ? Object.keys(self.registry).map(self.recordsFor.bind(self, name)).flat(1) : self.recordsFor(name, type);
|
|
4665
|
+
if (answers.length === 0) return;
|
|
4666
|
+
var additionals = [];
|
|
4667
|
+
if (type !== "ANY") {
|
|
4668
|
+
answers.forEach((answer) => {
|
|
4669
|
+
if (answer.type !== "PTR") return;
|
|
4670
|
+
additionals = additionals.concat(self.recordsFor(answer.data, "SRV")).concat(self.recordsFor(answer.data, "TXT"));
|
|
4671
|
+
});
|
|
4672
|
+
additionals.filter(function(record) {
|
|
4673
|
+
return record.type === "SRV";
|
|
4674
|
+
}).map(function(record) {
|
|
4675
|
+
return record.data.target;
|
|
4676
|
+
}).filter(this.unique()).forEach(function(target) {
|
|
4677
|
+
additionals = additionals.concat(self.recordsFor(target, "A")).concat(self.recordsFor(target, "AAAA"));
|
|
4678
|
+
});
|
|
4679
|
+
}
|
|
4680
|
+
self.mdns.respond({
|
|
4681
|
+
answers,
|
|
4682
|
+
additionals
|
|
4683
|
+
}, (err) => {
|
|
4684
|
+
if (err) this.errorCallback(err);
|
|
4685
|
+
});
|
|
4686
|
+
});
|
|
4687
|
+
}
|
|
4688
|
+
recordsFor(name, type) {
|
|
4689
|
+
if (!(type in this.registry)) return [];
|
|
4690
|
+
return this.registry[type].filter((record) => {
|
|
4691
|
+
var _name = ~name.indexOf(".") ? record.name : record.name.split(".")[0];
|
|
4692
|
+
return (0, dns_equal_1.default)(_name, name);
|
|
4693
|
+
});
|
|
4694
|
+
}
|
|
4695
|
+
isDuplicateRecord(a) {
|
|
4696
|
+
return (b) => {
|
|
4697
|
+
return a.type === b.type && a.name === b.name && (0, es6_1.default)(a.data, b.data);
|
|
4698
|
+
};
|
|
4699
|
+
}
|
|
4700
|
+
unique() {
|
|
4701
|
+
var set = [];
|
|
4702
|
+
return (obj) => {
|
|
4703
|
+
if (~set.indexOf(obj)) return false;
|
|
4704
|
+
set.push(obj);
|
|
4705
|
+
return true;
|
|
4706
|
+
};
|
|
4707
|
+
}
|
|
4708
|
+
};
|
|
4709
|
+
exports.Server = Server;
|
|
4710
|
+
exports.default = Server;
|
|
4711
|
+
}));
|
|
4712
|
+
//#endregion
|
|
4713
|
+
//#region ../../node_modules/bonjour-service/dist/lib/utils/filter-service.js
|
|
4714
|
+
var require_filter_service = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4715
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4716
|
+
exports.default = (service, txtQuery) => {
|
|
4717
|
+
if (txtQuery === void 0) return true;
|
|
4718
|
+
let serviceTxt = service.txt;
|
|
4719
|
+
let query = Object.entries(txtQuery).map(([key, value]) => {
|
|
4720
|
+
let queryValue = serviceTxt[key];
|
|
4721
|
+
if (queryValue === void 0) return false;
|
|
4722
|
+
if (value != queryValue) return false;
|
|
4723
|
+
return true;
|
|
4724
|
+
});
|
|
4725
|
+
if (query.length == 0) return true;
|
|
4726
|
+
if (query.includes(false)) return false;
|
|
4727
|
+
return true;
|
|
4728
|
+
};
|
|
4729
|
+
}));
|
|
4730
|
+
//#endregion
|
|
4731
|
+
//#region ../../node_modules/bonjour-service/dist/lib/utils/filter-txt.js
|
|
4732
|
+
var require_filter_txt = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4733
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4734
|
+
exports.default = (data) => Object.keys(data).filter((key) => !key.includes("binary")).reduce((cur, key) => {
|
|
4735
|
+
return Object.assign(cur, { [key]: data[key] });
|
|
4736
|
+
}, {});
|
|
4737
|
+
}));
|
|
4738
|
+
//#endregion
|
|
4739
|
+
//#region ../../node_modules/bonjour-service/dist/lib/utils/equal-txt.js
|
|
4740
|
+
var require_equal_txt = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4741
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4742
|
+
exports.default = equalTxt;
|
|
4743
|
+
function equalTxt(a, b) {
|
|
4744
|
+
if (a === void 0 || b === void 0) return false;
|
|
4745
|
+
let aKeys = Object.keys(a);
|
|
4746
|
+
let bKeys = Object.keys(b);
|
|
4747
|
+
if (aKeys.length != bKeys.length) return false;
|
|
4748
|
+
for (let key of aKeys) if (a[key] != b[key]) return false;
|
|
4749
|
+
return true;
|
|
4750
|
+
}
|
|
4751
|
+
}));
|
|
4752
|
+
//#endregion
|
|
4753
|
+
//#region ../../node_modules/bonjour-service/dist/lib/browser.js
|
|
4754
|
+
var require_browser = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4755
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
4756
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
4757
|
+
};
|
|
4758
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4759
|
+
exports.Browser = void 0;
|
|
4760
|
+
const dns_txt_1 = __importDefault(require_dns_txt());
|
|
4761
|
+
const dns_equal_1 = __importDefault(require_dns_equal());
|
|
4762
|
+
const events_1 = __require("events");
|
|
4763
|
+
const service_types_1 = require_service_types();
|
|
4764
|
+
const filter_service_1 = __importDefault(require_filter_service());
|
|
4765
|
+
const filter_txt_1 = __importDefault(require_filter_txt());
|
|
4766
|
+
const equal_txt_1 = __importDefault(require_equal_txt());
|
|
4767
|
+
const TLD = ".local";
|
|
4768
|
+
const WILDCARD = "_services._dns-sd._udp" + TLD;
|
|
4769
|
+
var Browser = class Browser extends events_1.EventEmitter {
|
|
4770
|
+
constructor(mdns, opts, onup) {
|
|
4771
|
+
super();
|
|
4772
|
+
this.onresponse = void 0;
|
|
4773
|
+
this.serviceMap = {};
|
|
4774
|
+
this.wildcard = false;
|
|
4775
|
+
this._services = [];
|
|
4776
|
+
if (typeof opts === "function") return new Browser(mdns, null, opts);
|
|
4777
|
+
this.mdns = mdns;
|
|
4778
|
+
this.txt = new dns_txt_1.default(opts !== null && opts.txt != null ? opts.txt : void 0);
|
|
4779
|
+
if (opts === null || opts.type === void 0) {
|
|
4780
|
+
this.name = WILDCARD;
|
|
4781
|
+
this.wildcard = true;
|
|
4782
|
+
} else {
|
|
4783
|
+
this.name = (0, service_types_1.toString)({
|
|
4784
|
+
name: opts.type,
|
|
4785
|
+
protocol: opts.protocol || "tcp"
|
|
4786
|
+
}) + TLD;
|
|
4787
|
+
if (opts.name) this.name = opts.name + "." + this.name;
|
|
4788
|
+
this.wildcard = false;
|
|
4789
|
+
}
|
|
4790
|
+
if (opts != null && opts.txt !== void 0) this.txtQuery = (0, filter_txt_1.default)(opts.txt);
|
|
4791
|
+
if (onup) this.on("up", onup);
|
|
4792
|
+
this.start();
|
|
4793
|
+
}
|
|
4794
|
+
start() {
|
|
4795
|
+
if (this.onresponse || this.name === void 0) return;
|
|
4796
|
+
var self = this;
|
|
4797
|
+
var nameMap = {};
|
|
4798
|
+
if (!this.wildcard) nameMap[this.name] = true;
|
|
4799
|
+
this.onresponse = (packet, rinfo) => {
|
|
4800
|
+
if (self.wildcard) packet.answers.forEach((answer) => {
|
|
4801
|
+
if (answer.type !== "PTR" || answer.name !== self.name || answer.name in nameMap) return;
|
|
4802
|
+
nameMap[answer.data] = true;
|
|
4803
|
+
self.mdns.query(answer.data, "PTR");
|
|
4804
|
+
});
|
|
4805
|
+
const receiveTime = Date.now();
|
|
4806
|
+
Object.keys(nameMap).forEach(function(name) {
|
|
4807
|
+
self.goodbyes(name, packet).forEach(self.removeService.bind(self));
|
|
4808
|
+
var matches = self.buildServicesFor(name, packet, self.txt, rinfo, receiveTime);
|
|
4809
|
+
if (matches.length === 0) return;
|
|
4810
|
+
matches.forEach((service) => {
|
|
4811
|
+
const existingService = self._services.find((s) => (0, dns_equal_1.default)(s.fqdn, service.fqdn));
|
|
4812
|
+
if (existingService) {
|
|
4813
|
+
self.updateServiceSrv(existingService, service);
|
|
4814
|
+
self.updateServiceTxt(existingService, service);
|
|
4815
|
+
return;
|
|
4816
|
+
}
|
|
4817
|
+
self.addService(service);
|
|
4818
|
+
});
|
|
4819
|
+
});
|
|
4820
|
+
};
|
|
4821
|
+
this.mdns.on("response", this.onresponse);
|
|
4822
|
+
this.update();
|
|
4823
|
+
}
|
|
4824
|
+
stop() {
|
|
4825
|
+
if (!this.onresponse) return;
|
|
4826
|
+
this.mdns.removeListener("response", this.onresponse);
|
|
4827
|
+
this.onresponse = void 0;
|
|
4828
|
+
}
|
|
4829
|
+
update() {
|
|
4830
|
+
this.mdns.query(this.name, "PTR");
|
|
4831
|
+
}
|
|
4832
|
+
expire() {
|
|
4833
|
+
const currentTime = Date.now();
|
|
4834
|
+
this._services = this._services.filter((service) => {
|
|
4835
|
+
if (!service.ttl || service.lastSeen === void 0) return true;
|
|
4836
|
+
if (service.lastSeen + service.ttl * 1e3 < currentTime) {
|
|
4837
|
+
this.emit("down", service);
|
|
4838
|
+
return false;
|
|
4839
|
+
}
|
|
4840
|
+
return true;
|
|
4841
|
+
});
|
|
4842
|
+
}
|
|
4843
|
+
get services() {
|
|
4844
|
+
return this._services;
|
|
4845
|
+
}
|
|
4846
|
+
addService(service) {
|
|
4847
|
+
if ((0, filter_service_1.default)(service, this.txtQuery) === false) return;
|
|
4848
|
+
this._services.push(service);
|
|
4849
|
+
this.serviceMap[service.fqdn] = true;
|
|
4850
|
+
this.emit("up", service);
|
|
4851
|
+
}
|
|
4852
|
+
updateServiceSrv(existingService, newService) {
|
|
4853
|
+
if (existingService.name !== newService.name || existingService.host !== newService.host || existingService.port !== newService.port || existingService.type !== newService.type || existingService.protocol !== newService.protocol) {
|
|
4854
|
+
this.replaceService(newService);
|
|
4855
|
+
this.emit("srv-update", newService, existingService);
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
updateServiceTxt(existingService, service) {
|
|
4859
|
+
if ((0, equal_txt_1.default)(service.txt, (existingService === null || existingService === void 0 ? void 0 : existingService.txt) || {})) return;
|
|
4860
|
+
if (!(0, filter_service_1.default)(service, this.txtQuery)) {
|
|
4861
|
+
this.removeService(service.fqdn);
|
|
4862
|
+
return;
|
|
4863
|
+
}
|
|
4864
|
+
this.replaceService(service);
|
|
4865
|
+
this.emit("txt-update", service, existingService);
|
|
4866
|
+
}
|
|
4867
|
+
replaceService(service) {
|
|
4868
|
+
this._services = this._services.map((s) => {
|
|
4869
|
+
if (!(0, dns_equal_1.default)(s.fqdn, service.fqdn)) return s;
|
|
4870
|
+
return service;
|
|
4871
|
+
});
|
|
4872
|
+
}
|
|
4873
|
+
removeService(fqdn) {
|
|
4874
|
+
var service, index;
|
|
4875
|
+
this._services.some(function(s, i) {
|
|
4876
|
+
if ((0, dns_equal_1.default)(s.fqdn, fqdn)) {
|
|
4877
|
+
service = s;
|
|
4878
|
+
index = i;
|
|
4879
|
+
return true;
|
|
4880
|
+
}
|
|
4881
|
+
});
|
|
4882
|
+
if (!service || index === void 0) return;
|
|
4883
|
+
this._services.splice(index, 1);
|
|
4884
|
+
delete this.serviceMap[fqdn];
|
|
4885
|
+
this.emit("down", service);
|
|
4886
|
+
}
|
|
4887
|
+
goodbyes(name, packet) {
|
|
4888
|
+
return packet.answers.concat(packet.additionals).filter((rr) => rr.type === "PTR" && rr.ttl === 0 && (0, dns_equal_1.default)(rr.name, name)).map((rr) => rr.data);
|
|
4889
|
+
}
|
|
4890
|
+
buildServicesFor(name, packet, txt, referer, receiveTime) {
|
|
4891
|
+
var records = packet.answers.concat(packet.additionals).filter((rr) => rr.ttl > 0);
|
|
4892
|
+
return records.filter((rr) => rr.type === "PTR" && (0, dns_equal_1.default)(rr.name, name)).map((ptr) => {
|
|
4893
|
+
const service = {
|
|
4894
|
+
addresses: [],
|
|
4895
|
+
subtypes: [],
|
|
4896
|
+
ttl: ptr.ttl,
|
|
4897
|
+
lastSeen: receiveTime
|
|
4898
|
+
};
|
|
4899
|
+
records.filter((rr) => {
|
|
4900
|
+
return rr.type === "PTR" && (0, dns_equal_1.default)(rr.data, ptr.data) && rr.name.includes("._sub");
|
|
4901
|
+
}).forEach((rr) => {
|
|
4902
|
+
const types = (0, service_types_1.toType)(rr.name);
|
|
4903
|
+
service.subtypes.push(types.subtype);
|
|
4904
|
+
});
|
|
4905
|
+
records.filter((rr) => {
|
|
4906
|
+
return (rr.type === "SRV" || rr.type === "TXT") && (0, dns_equal_1.default)(rr.name, ptr.data);
|
|
4907
|
+
}).forEach((rr) => {
|
|
4908
|
+
if (rr.type === "SRV") {
|
|
4909
|
+
var parts = rr.name.split(".");
|
|
4910
|
+
var name = parts[0];
|
|
4911
|
+
var types = (0, service_types_1.toType)(parts.slice(1, -1).join("."));
|
|
4912
|
+
service.name = name;
|
|
4913
|
+
service.fqdn = rr.name;
|
|
4914
|
+
service.host = rr.data.target;
|
|
4915
|
+
service.referer = referer;
|
|
4916
|
+
service.port = rr.data.port;
|
|
4917
|
+
service.type = types.name;
|
|
4918
|
+
service.protocol = types.protocol;
|
|
4919
|
+
} else if (rr.type === "TXT") {
|
|
4920
|
+
service.rawTxt = rr.data;
|
|
4921
|
+
service.txt = this.txt.decodeAll(rr.data);
|
|
4922
|
+
}
|
|
4923
|
+
});
|
|
4924
|
+
if (!service.name) return;
|
|
4925
|
+
records.filter((rr) => (rr.type === "A" || rr.type === "AAAA") && (0, dns_equal_1.default)(rr.name, service.host)).forEach((rr) => service.addresses.push(rr.data));
|
|
4926
|
+
return service;
|
|
4927
|
+
}).filter((rr) => !!rr);
|
|
4928
|
+
}
|
|
4929
|
+
};
|
|
4930
|
+
exports.Browser = Browser;
|
|
4931
|
+
exports.default = Browser;
|
|
4932
|
+
}));
|
|
4933
|
+
//#endregion
|
|
4934
|
+
//#region ../../node_modules/bonjour-service/dist/lib/bonjour.js
|
|
4935
|
+
var require_bonjour = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4936
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
4937
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
4938
|
+
};
|
|
4939
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4940
|
+
exports.Browser = exports.Service = void 0;
|
|
4941
|
+
const registry_1 = __importDefault(require_registry());
|
|
4942
|
+
const mdns_server_1 = __importDefault(require_mdns_server());
|
|
4943
|
+
const browser_1 = __importDefault(require_browser());
|
|
4944
|
+
exports.Browser = browser_1.default;
|
|
4945
|
+
exports.Service = __importDefault(require_service()).default;
|
|
4946
|
+
var Bonjour = class {
|
|
4947
|
+
constructor(opts = {}, errorCallback) {
|
|
4948
|
+
this.server = new mdns_server_1.default(opts, errorCallback);
|
|
4949
|
+
this.registry = new registry_1.default(this.server);
|
|
4950
|
+
}
|
|
4951
|
+
publish(opts) {
|
|
4952
|
+
return this.registry.publish(opts);
|
|
4953
|
+
}
|
|
4954
|
+
unpublishAll(callback) {
|
|
4955
|
+
return this.registry.unpublishAll(callback);
|
|
4956
|
+
}
|
|
4957
|
+
find(opts = null, onup) {
|
|
4958
|
+
return new browser_1.default(this.server.mdns, opts, onup);
|
|
4959
|
+
}
|
|
4960
|
+
findOne(opts = null, timeout = 1e4, callback) {
|
|
4961
|
+
const browser = new browser_1.default(this.server.mdns, opts);
|
|
4962
|
+
var timer;
|
|
4963
|
+
browser.once("up", (service) => {
|
|
4964
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
4965
|
+
browser.stop();
|
|
4966
|
+
if (callback) callback(service);
|
|
4967
|
+
});
|
|
4968
|
+
timer = setTimeout(() => {
|
|
4969
|
+
browser.stop();
|
|
4970
|
+
if (callback) callback(null);
|
|
4971
|
+
}, timeout);
|
|
4972
|
+
return browser;
|
|
4973
|
+
}
|
|
4974
|
+
destroy(callback) {
|
|
4975
|
+
this.registry.destroy();
|
|
4976
|
+
this.server.mdns.destroy(callback);
|
|
4977
|
+
}
|
|
4978
|
+
};
|
|
4979
|
+
exports.default = Bonjour;
|
|
4980
|
+
}));
|
|
4981
|
+
//#endregion
|
|
4982
|
+
//#region ../charmd/src/device/announce.ts
|
|
4983
|
+
var import_dist = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4984
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
4985
|
+
if (k2 === void 0) k2 = k;
|
|
4986
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4987
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
4988
|
+
enumerable: true,
|
|
4989
|
+
get: function() {
|
|
4990
|
+
return m[k];
|
|
4991
|
+
}
|
|
4992
|
+
};
|
|
4993
|
+
Object.defineProperty(o, k2, desc);
|
|
4994
|
+
}) : (function(o, m, k, k2) {
|
|
4995
|
+
if (k2 === void 0) k2 = k;
|
|
4996
|
+
o[k2] = m[k];
|
|
4997
|
+
}));
|
|
4998
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
4999
|
+
Object.defineProperty(o, "default", {
|
|
5000
|
+
enumerable: true,
|
|
5001
|
+
value: v
|
|
5002
|
+
});
|
|
5003
|
+
}) : function(o, v) {
|
|
5004
|
+
o["default"] = v;
|
|
5005
|
+
});
|
|
5006
|
+
var __importStar = exports && exports.__importStar || (function() {
|
|
5007
|
+
var ownKeys = function(o) {
|
|
5008
|
+
ownKeys = Object.getOwnPropertyNames || function(o) {
|
|
5009
|
+
var ar = [];
|
|
5010
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
5011
|
+
return ar;
|
|
5012
|
+
};
|
|
5013
|
+
return ownKeys(o);
|
|
5014
|
+
};
|
|
5015
|
+
return function(mod) {
|
|
5016
|
+
if (mod && mod.__esModule) return mod;
|
|
5017
|
+
var result = {};
|
|
5018
|
+
if (mod != null) {
|
|
5019
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
5020
|
+
}
|
|
5021
|
+
__setModuleDefault(result, mod);
|
|
5022
|
+
return result;
|
|
5023
|
+
};
|
|
5024
|
+
})();
|
|
5025
|
+
const bonjour_1 = (exports && exports.__importDefault || function(mod) {
|
|
5026
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
5027
|
+
})(require_bonjour());
|
|
5028
|
+
const imported = __importStar(require_bonjour());
|
|
5029
|
+
var Bonjour = class extends bonjour_1.default {};
|
|
5030
|
+
var BonjourClass = Bonjour;
|
|
5031
|
+
(function(Bonjour) {
|
|
5032
|
+
Bonjour.Bonjour = BonjourClass;
|
|
5033
|
+
Bonjour.Service = imported.Service;
|
|
5034
|
+
Bonjour.Browser = imported.Browser;
|
|
5035
|
+
})(Bonjour || (Bonjour = {}));
|
|
5036
|
+
Object.defineProperty(Bonjour, "default", {
|
|
5037
|
+
enumerable: true,
|
|
5038
|
+
value: Bonjour
|
|
5039
|
+
});
|
|
5040
|
+
module.exports.Bonjour = Bonjour;
|
|
5041
|
+
module.exports.Service = imported.Service;
|
|
5042
|
+
module.exports.Browser = imported.Browser;
|
|
5043
|
+
module.exports.default = Bonjour;
|
|
5044
|
+
module.exports = Bonjour;
|
|
5045
|
+
})))();
|
|
5046
|
+
function localHost() {
|
|
5047
|
+
let label = "";
|
|
5048
|
+
if (platform() === "darwin") try {
|
|
5049
|
+
label = execFileSync("scutil", ["--get", "LocalHostName"], {
|
|
5050
|
+
encoding: "utf8",
|
|
5051
|
+
timeout: 2e3
|
|
5052
|
+
}).trim();
|
|
5053
|
+
} catch {
|
|
5054
|
+
label = "";
|
|
5055
|
+
}
|
|
5056
|
+
if (!/^[A-Za-z0-9-]{1,63}$/.test(label)) label = hostname().split(".")[0] ?? "";
|
|
5057
|
+
return `${label}.local`;
|
|
5058
|
+
}
|
|
5059
|
+
const announceOnNetwork = (port) => {
|
|
5060
|
+
let warned = false;
|
|
5061
|
+
const bonjour = new import_dist.Bonjour({}, (error) => {
|
|
5062
|
+
if (warned) return;
|
|
5063
|
+
warned = true;
|
|
5064
|
+
console.error(`charmd: mDNS: ${String(error)}`);
|
|
5065
|
+
});
|
|
5066
|
+
const computer = hostname().replace(/\.local$/, "");
|
|
5067
|
+
bonjour.publish({
|
|
5068
|
+
name: `OpenCharm on ${computer}`,
|
|
5069
|
+
host: localHost(),
|
|
5070
|
+
type: "opencharm",
|
|
5071
|
+
port,
|
|
5072
|
+
txt: { path: "/charm" }
|
|
5073
|
+
}).on("error", (error) => {
|
|
5074
|
+
console.error(`charmd: couldn't announce itself on the network: ${String(error)}`);
|
|
5075
|
+
});
|
|
5076
|
+
return () => new Promise((resolve) => {
|
|
5077
|
+
bonjour.unpublishAll(() => {
|
|
5078
|
+
bonjour.destroy();
|
|
5079
|
+
resolve();
|
|
5080
|
+
});
|
|
5081
|
+
});
|
|
5082
|
+
};
|
|
5083
|
+
//#endregion
|
|
2213
5084
|
//#region ../charmd/src/device/ota.ts
|
|
2214
5085
|
function handleOta(res, websocketUrl) {
|
|
2215
5086
|
res.writeHead(200, { "content-type": "application/json" });
|
|
@@ -4966,20 +7837,29 @@ async function startDaemon(config, options = {}) {
|
|
|
4966
7837
|
});
|
|
4967
7838
|
const adminServer = await startAdminServer(config.adminSocket, admin);
|
|
4968
7839
|
let websocketUrl = config.publicUrl ?? "";
|
|
4969
|
-
const
|
|
7840
|
+
const answerHttp = (onNetwork) => (req, res) => {
|
|
4970
7841
|
if (isOtaRequest(req)) {
|
|
4971
|
-
|
|
7842
|
+
const host = req.headers.host ?? "";
|
|
7843
|
+
handleOta(res, onNetwork && !config.publicUrl && /^[A-Za-z0-9.:[\]-]{1,255}$/.test(host) ? `ws://${host}/charm` : websocketUrl);
|
|
4972
7844
|
return;
|
|
4973
7845
|
}
|
|
4974
7846
|
res.writeHead(404).end();
|
|
4975
|
-
}
|
|
7847
|
+
};
|
|
7848
|
+
const http = createServer$1(answerHttp(false));
|
|
7849
|
+
const network = config.network ? createServer$1(answerHttp(true)) : void 0;
|
|
4976
7850
|
const wss = new WebSocketServer({
|
|
4977
|
-
|
|
4978
|
-
path: "/charm",
|
|
7851
|
+
noServer: true,
|
|
4979
7852
|
maxPayload: LIMITS.maxJsonBytes,
|
|
4980
7853
|
handleProtocols: (protocols) => protocols.has("opencharm") ? SUBPROTOCOL : false
|
|
4981
7854
|
});
|
|
4982
7855
|
wss.on("error", () => void 0);
|
|
7856
|
+
for (const server of [http, network]) server?.on("upgrade", (req, socket, head) => {
|
|
7857
|
+
if ((req.url ?? "").split("?")[0] !== "/charm") {
|
|
7858
|
+
socket.destroy();
|
|
7859
|
+
return;
|
|
7860
|
+
}
|
|
7861
|
+
wss.handleUpgrade(req, socket, head, (ws) => wss.emit("connection", ws, req));
|
|
7862
|
+
});
|
|
4983
7863
|
const answered = /* @__PURE__ */ new WeakSet();
|
|
4984
7864
|
const heartbeat = setInterval(() => {
|
|
4985
7865
|
for (const client of wss.clients) {
|
|
@@ -5037,18 +7917,25 @@ async function startDaemon(config, options = {}) {
|
|
|
5037
7917
|
});
|
|
5038
7918
|
ws.on("error", () => ws.terminate());
|
|
5039
7919
|
});
|
|
7920
|
+
const listen = (server, port, host) => new Promise((resolve, reject) => {
|
|
7921
|
+
server.once("error", reject);
|
|
7922
|
+
server.listen(port, host, resolve);
|
|
7923
|
+
});
|
|
5040
7924
|
try {
|
|
5041
|
-
await
|
|
5042
|
-
|
|
5043
|
-
http.listen(config.listen.port, config.listen.host, resolve);
|
|
5044
|
-
});
|
|
7925
|
+
await listen(http, config.listen.port, config.listen.host);
|
|
7926
|
+
if (network && config.network) await listen(network, config.network.port, config.network.host);
|
|
5045
7927
|
} catch (error) {
|
|
7928
|
+
http.close();
|
|
7929
|
+
network?.close();
|
|
5046
7930
|
clearInterval(heartbeat);
|
|
5047
7931
|
await new Promise((resolve) => adminServer.close(() => resolve()));
|
|
5048
7932
|
throw error;
|
|
5049
7933
|
}
|
|
5050
7934
|
const { port } = http.address();
|
|
5051
7935
|
const url = `ws://${config.listen.host.includes(":") ? `[${config.listen.host}]` : config.listen.host}:${port}/charm`;
|
|
7936
|
+
const networkPort = network ? network.address().port : void 0;
|
|
7937
|
+
const announced = networkPort ?? (isLoopback(config.listen.host) ? void 0 : port);
|
|
7938
|
+
const stopAnnouncing = config.discoverable && announced !== void 0 ? (options.announce ?? announceOnNetwork)(announced) : void 0;
|
|
5052
7939
|
websocketUrl = config.publicUrl ?? url;
|
|
5053
7940
|
if (!options.quiet) console.log([
|
|
5054
7941
|
"charmd",
|
|
@@ -5056,15 +7943,18 @@ async function startDaemon(config, options = {}) {
|
|
|
5056
7943
|
"listening on",
|
|
5057
7944
|
url
|
|
5058
7945
|
].filter(Boolean).join(" "));
|
|
7946
|
+
if (!options.quiet && networkPort !== void 0 && config.network) console.log(`Charms on this network: ws://${config.network.host}:${networkPort}/charm`);
|
|
5059
7947
|
return {
|
|
5060
7948
|
url,
|
|
5061
7949
|
admin,
|
|
5062
7950
|
close: async () => {
|
|
5063
7951
|
clearInterval(heartbeat);
|
|
7952
|
+
await stopAnnouncing?.();
|
|
5064
7953
|
for (const client of wss.clients) client.terminate();
|
|
5065
7954
|
agent.dispose?.();
|
|
5066
7955
|
await new Promise((resolve) => wss.close(() => resolve()));
|
|
5067
7956
|
await new Promise((resolve) => http.close(() => resolve()));
|
|
7957
|
+
if (network) await new Promise((resolve) => network.close(() => resolve()));
|
|
5068
7958
|
await new Promise((resolve) => adminServer.close(() => resolve()));
|
|
5069
7959
|
}
|
|
5070
7960
|
};
|
|
@@ -5096,7 +7986,7 @@ function formatIdentity(unit, version, commit) {
|
|
|
5096
7986
|
let cached;
|
|
5097
7987
|
function identity() {
|
|
5098
7988
|
if (cached) return cached;
|
|
5099
|
-
const commit = "
|
|
7989
|
+
const commit = "fe3cd5f";
|
|
5100
7990
|
cached = {
|
|
5101
7991
|
version: `cli@${version}`,
|
|
5102
7992
|
commit,
|