From 8eda860b6d250f90389e2c6bf65f2ca62453a2db Mon Sep 17 00:00:00 2001 From: f Date: Wed, 30 Oct 2024 16:42:37 -0300 Subject: [PATCH 1/2] feat: always answer with the NS record in the authority section if we don't do this, we're never going to see the resource record being found, because resolvers would recurse into the nameserver as the authority for this, even if intermediate nameservers know it. --- dns/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dns/index.ts b/dns/index.ts index 480caa7..3a17e77 100644 --- a/dns/index.ts +++ b/dns/index.ts @@ -12,6 +12,15 @@ export async function initDnsServer (port: number, store: SiteConfigStore, logge const [{ name }] = request.questions logger?.info(`[dns] ${rinfo.address}:${rinfo.port} asked for ${name}`) + // TODO: Pass server from config + response.authorities.push({ + name, + type: dns2.Packet.TYPE.NS, + class: dns2.Packet.CLASS.IN, + ttl: TTL, + ns: 'api.distributed.press.' + }) + const cleanedName = name.toLowerCase().replace('_dnslink.', '') store.get(cleanedName) .then(({ links }) => { @@ -33,6 +42,7 @@ export async function initDnsServer (port: number, store: SiteConfigStore, logge data: `dnslink=${links.hyper.dnslink}` }) } + send(response) }) .catch((error) => { From 148f403a15c43529852b6de92fff3375c3db9d61 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 31 Oct 2024 16:37:05 -0300 Subject: [PATCH 2/2] feat: customize the dns server --- api/index.ts | 2 +- dns/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/index.ts b/api/index.ts index dff86ea..eba7156 100644 --- a/api/index.ts +++ b/api/index.ts @@ -70,7 +70,7 @@ async function apiBuilder (cfg: APIConfig): Promise { const store = new Store(cfg, db, protocols) server.log.info('Initializing DNS server') - const dns = await initDnsServer(cfg.dnsport, store.sites, server.log) + const dns = await initDnsServer(cfg.dnsport, store.sites, server.log, cfg.host) server.log.info('Done') await registerAuth(cfg, server, store) diff --git a/dns/index.ts b/dns/index.ts index 3a17e77..db7390a 100644 --- a/dns/index.ts +++ b/dns/index.ts @@ -4,7 +4,7 @@ import { SiteConfigStore } from '../config/sites.js' const TTL = 604800 // 7 days ttl -export async function initDnsServer (port: number, store: SiteConfigStore, logger?: FastifyBaseLogger): Promise> { +export async function initDnsServer (port: number, store: SiteConfigStore, logger?: FastifyBaseLogger, host?: string = 'api.distributed.press'): Promise> { const server = dns2.createServer({ udp: true, handle: (request, send, rinfo) => { @@ -18,7 +18,7 @@ export async function initDnsServer (port: number, store: SiteConfigStore, logge type: dns2.Packet.TYPE.NS, class: dns2.Packet.CLASS.IN, ttl: TTL, - ns: 'api.distributed.press.' + ns: `${host}.` }) const cleanedName = name.toLowerCase().replace('_dnslink.', '')