/** * `.test` names for sandboxes. OrbStack only serves custom container domains * under `.local` (via mDNS), and nothing on the Mac resolves `.test`. With * `/etc/resolver/test` pointing here (see `dns-resolver.ts`), this forwarder * answers `.test` with the address of the sandbox at `.local` — so * `feature-x.my-app.test` reaches the same container as `feature-x.my-app.local`. * * No daemon: the Mac-side `orc start` of every sandbox runs a * {@link startDnsStandby}. One of them holds the port and serves all running * sandboxes; the others retry the bind and take over when it exits. * * Only names of running orckit sandboxes are answered; everything else under * `.test` is NXDOMAIN. That keeps `.test` meaning "a local sandbox" (never a * printer or other `.local` device on the LAN) and makes misses instant * instead of waiting out mDNS's 5 s timeout. */ export declare const DNS_SUFFIX = "test"; export declare const DEFAULT_DNS_PORT = 15353; /** * Always answered with {@link HEALTH_ADDRESS}, so `orc sandbox dns status` can * check the whole path (macOS resolver → `/etc/resolver/test` → this server) * through `getaddrinfo` without a running sandbox. The address is unusual on * purpose: a foreign wildcard `.test` resolver (Valet, puma-dev) answers * everything with 127.0.0.1 and must not pass for this one. */ export declare const HEALTH_NAME = "orckit-dns-check.test"; export declare const HEALTH_ADDRESS = "127.0.15.53"; export declare const RCODE: { readonly NOERROR: 0; readonly FORMERR: 1; readonly SERVFAIL: 2; readonly NXDOMAIN: 3; readonly REFUSED: 5; }; /** `.local` → `.test`; null for domains OrbStack serves under another suffix. */ export declare function testAlias(domain: string): string | null; export interface DnsQuery { id: number; /** Header flags of the query (opcode + RD are echoed back). */ flags: number; /** Lowercased, without the trailing dot. */ name: string; type: number; class: number; /** The question section as received (echoed verbatim, case included). */ question: Buffer; } /** * Parse a standard query with exactly one question. Returns null for anything * else (responses, other opcodes, compression pointers in the name, truncated * packets) — {@link handleQuery} answers those with FORMERR when it can. */ export declare function parseQuery(msg: Buffer): DnsQuery | null; /** * A response to `query`: the echoed question plus one A record per address. * NXDOMAIN and NODATA (NOERROR without addresses) get the zone's SOA in the * authority section — without one, resolvers cache the miss for as long as * they like. */ export declare function buildResponse(query: DnsQuery, rcode: number, addresses?: string[]): Buffer; export interface QueryDeps { /** Whether a `.local` name belongs to a running sandbox. */ isSandbox: (name: string) => Promise; /** IPv4 addresses for a `.local` name (the macOS resolver → OrbStack). */ lookup: (name: string) => Promise; } /** * Answer one query packet. Pure apart from `deps`; null means "don't reply" * (the packet wasn't a query at all). */ export declare function handleQuery(msg: Buffer, deps: QueryDeps): Promise; /** * Memoize the sandbox-domain list: reuse it for `maxAgeMs`, but on a miss * refresh once it is older than `missAgeMs`, so a sandbox that just started is * found on its first query. Concurrent refreshes share one call. */ export declare function domainCache(list: () => Promise, opts?: { maxAgeMs?: number; missAgeMs?: number; now?: () => number; }): (domain: string) => Promise; /** {@link QueryDeps.lookup} via `getaddrinfo` — the macOS resolver, so OrbStack's mDNS answers. */ export declare function systemLookup(name: string): Promise; export interface DnsForwarderHandle { readonly port: number; dispose(): Promise; } /** Serve {@link handleQuery} over UDP on 127.0.0.1 (only the Mac itself asks). */ export declare function startDnsForwarder(opts: { /** `.local` domains of the running sandboxes (OrbStack `dev.orbstack.domains`). */ sandboxDomains: () => Promise; lookup: QueryDeps['lookup']; port?: number; onError?: (err: Error) => void; }): Promise; export interface DnsStandbyHandle { /** True while this process holds the port and answers queries. */ serving(): boolean; dispose(): Promise; } type ForwarderOptions = Parameters[0]; /** * Serve on `port` if it's free; otherwise stand by and retry the bind every * `retryMs`, so when the `orc start` currently serving exits, another running * one takes over within about that long. Resolves once the first bind attempt * settled, so {@link DnsStandbyHandle.serving} is meaningful right away. * Bind errors other than EADDRINUSE are reported via `onError` and retried. */ export declare function startDnsStandby(opts: ForwarderOptions & { port: number; retryMs?: number; }): Promise; /** * Ask the forwarder on `port` for `name` (A). Resolves with the rcode and * addresses, or null when nothing answers within `timeoutMs`. */ export declare function queryDns(port: number, name: string, timeoutMs?: number): Promise<{ rcode: number; addresses: string[]; } | null>; export {}; //# sourceMappingURL=dns.d.ts.map