Minimal DNS message codec (RFC 1035).
libp2p performs the UDP transport itself (see dnsresolver), so this module only deals with the wire format: building a query and decoding the answer records we care about (A, AAAA, TXT). It is pure bytes-in/bytes-out and raises only ValueError on malformed input.
Types
DnsAnswer = object kind*: DnsRecordKind value*: string ## IPv4/IPv6 textual form, or concatenated TXT strings
- Source Edit
DnsRecordKind = enum A = 1, TXT = 16, AAAA = 28
- Source Edit
Procs
proc encodeQuery(id: uint16; name: string; kind: DnsRecordKind): seq[byte] {. ...raises: [ValueError], raises: [], tags: [], forbids: [].}
- Builds a standard recursive query for name/kind. Raises ValueError on an illegal name (empty/oversized label or a name whose encoded form exceeds 255 bytes). Source Edit
proc parseAnswers(data: openArray[byte]; expectedId: uint16): seq[DnsAnswer] {. ...raises: [ValueError], raises: [], tags: [], forbids: [].}
- Parses the header and question, then decodes the answer section. Only A/AAAA/TXT answers are returned; other record types are skipped. expectedId is the id of the query this is a response to; a mismatch is rejected to guard against stale or spoofed datagrams. Source Edit