feat: answer CNAME, MX and TXT from the record set - #10
Merged
Conversation
The Pit publishes four record types. This bridge answered one of them: the
socket gated on A/AAAA and returned an honest empty NOERROR for everything
else, so an owner could publish an MX, see it listed on their names, and
get nothing back from `dig MX` — with no way to tell a record that is not
served from one they typed wrong.
Answered now, out of the `?records=1` the registry already exposes:
- TXT is split into 255-byte strings on BYTE boundaries. Long values are
normal rather than exceptional (a DKIM key never fits in one), and
splitting on characters cuts a multi-byte one in half so neither piece
decodes.
- MX carries its preference first, as the wire format requires.
- A record whose rdata will not encode is dropped rather than throwing.
This reads JSON over HTTP from a registry that may be a different
version than the bridge, and one bad row must not take down the
answers beside it.
- Oversized replies are trimmed to what fits in 512 bytes and marked
truncated, rather than dropping every answer: this bridge speaks UDP
only, so a client that retries over TCP finds nobody home.
A published CNAME now also answers the address question it was invisible
to. A name pointed at a hostname has no address to give, and targetAddress
returns null for one on purpose — the bridge does not do clearnet DNS — so
it was NODATA and looked exactly like a typo. Handing back the CNAME lets
the client chase it through its own resolver, which is the party that may.
That second lookup happens only when the name is here and has no address,
so a name that already resolves pays nothing for it.
`records` appears on a resolveName result only when it was asked for, so
every existing caller sees the shape it always did.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings this bridge level with the registry, which can now publish four record types (moshcoder/moshcode#241) and whose own resolver already answers them (moshcoder/moshcode#242).
What was wrong
The socket gated on
A/AAAAand returned an honest empty NOERROR for everything else. So an owner could publish an MX in the Pit, see it listed on their name, and get nothing fromdig MX— with no way to tell a record that isn't served from one they typed wrong.What changed
CNAME,MXandTXTare answered out of the?records=1the registry already exposes.targetAddressreturns null for one on purpose — this bridge does not do clearnet DNS), so it was NODATA and looked exactly like a typo. The extra round trip happens only when the name is here and has no address, so a name that already resolves pays nothing.Note the CNAME is answered only when one is actually published, not synthesized from any hostname target — that keeps the existing NODATA behaviour for a hostname or
:8080target exactly as its tests require.Compatibility
recordsappears on aresolveNameresult only when asked for, so every existing caller sees the shape it always did.buildResponse,answerPolicyandanswerForare untouched.This matters beyond this repo:
moshcodevendors this file assrc/dns.mjsand has a drift test that compares the two. Keeping these shapes stable is what lets that test stay meaningful.Tests
14 new in
test/dns-records.test.mjs, decoding rdata back off the wire rather than counting answers — an MX with its preference in the wrong order produces a reply of exactly the right shape that no client can use.Full suite: 82/82 pass (68 existing, unchanged).
Note on versions
package.jsonsaid0.2.1while npm has0.2.2published — the repo was behind what shipped. Bumped to0.3.0, which clears both. I have not published to npm; that's yours to run when you're happy with this.🤖 Generated with Claude Code