22 lines
1.1 KiB
JavaScript
22 lines
1.1 KiB
JavaScript
|
|
// Daemon decision logic (favor-BCNR, detect ICANN conflict), tested against the
|
||
|
|
// real chain + real ICANN DNS. This is what bnsd.js would run per query.
|
||
|
|
import WebSocket from "ws";
|
||
|
|
import { resolveName } from "../../Argus/src/lib/resolver-web.js";
|
||
|
|
import { Resolver } from "node:dns/promises";
|
||
|
|
const icann = new Resolver(); icann.setServers(["1.1.1.1"]); // bypass local NRPT
|
||
|
|
async function decide(name) {
|
||
|
|
const [bcnr, ip] = await Promise.all([
|
||
|
|
resolveName(name, { WebSocket }).catch(() => null),
|
||
|
|
icann.resolve4(name).then(a => a[0]).catch(() => null),
|
||
|
|
]);
|
||
|
|
let d;
|
||
|
|
if (bcnr && ip) d = "CONFLICT → ask user (BCNR vs ICANN)";
|
||
|
|
else if (bcnr) d = "serve BCNR (favored; no ICANN entry)";
|
||
|
|
else if (ip) d = `forward ICANN (${ip})`;
|
||
|
|
else d = "NXDOMAIN (neither root has it)";
|
||
|
|
console.log(`${name.padEnd(16)} BCNR=${bcnr ? "yes[" + Object.keys(bcnr.records) + "]" : "no ".padEnd(3)} ICANN=${(ip||"no").padEnd(15)} -> ${d}`);
|
||
|
|
}
|
||
|
|
const names = process.argv.slice(2).length ? process.argv.slice(2) : ["syskypo.de","google.de","go.dev","nothing-xyz.de"];
|
||
|
|
for (const n of names) await decide(n);
|
||
|
|
process.exit(0);
|