hs-libp2p-0.2.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.Discovery.MDNS.Message

Description

Minimal DNS wire-format codec for mDNS (RFC 1035 §4, RFC 6762).

Only what mDNS discovery needs:

  • a 12-byte header with the byte counts of the four sections;
  • question entries (domain name, type, class);
  • resource records with PTR, TXT and SRV rdata decoded (unknown types are passed through as raw bytes);
  • name compression (RFC 1035 §4.1.4 pointers) on read: peers using other implementations compress names, so we must follow pointers. On write we emit plain, uncompressed names — valid for every reader.

mDNS-specific notes (RFC 6762): the header ID is 0 on genuine multicast traffic; legacy unicast queries keep their ID and are answered unicast. Class values carry the cache-flush / unicast-response bits in their high bits; we keep the raw 16-bit class and never interpret those bits.

Synopsis

Packet types

data DnsPacket Source #

An mDNS packet: header plus the four sections (the name-server section is ignored; mDNS never uses it).

Constructors

DnsPacket 

Fields

Instances

Instances details
Show DnsPacket Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

Eq DnsPacket Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

data DnsQuestion Source #

A question section entry.

Constructors

DnsQuestion 

Fields

  • qName :: !Text

    Domain name, dot-separated, lower case (mDNS names are case-insensitive, RFC 6762 §10)

  • qType :: !Word16
     
  • qClass :: !Word16

    Class with the cache-flush / unicast-response bits as received

Instances

Instances details
Show DnsQuestion Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

Eq DnsQuestion Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

data DnsRecord Source #

A resource record from answer / additional sections.

Constructors

DnsRecord 

Fields

Instances

Instances details
Show DnsRecord Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

Eq DnsRecord Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

data DnsRData Source #

Decoded rdata for the record types mDNS discovery uses; anything else travels as raw bytes, so a forward-compatible peer's extra records never break parsing of the records we do care about.

Constructors

RdPtr !Text

PTR: the pointed-to name

RdTxt ![ByteString]

TXT: character-strings (len-prefixed on the wire)

RdSrv !Word16 !Word16 !Word16 !Text

SRV: priority weight port target

RdOther !ByteString 

Instances

Instances details
Show DnsRData Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

Eq DnsRData Source # 
Instance details

Defined in LibP2P.Discovery.MDNS.Message

Record types (RFC 1035)

typePTR :: Word16 Source #

PTR record type (RFC 1035).

typeTXT :: Word16 Source #

TXT record type (RFC 1035).

typeSRV :: Word16 Source #

SRV record type (RFC 2782).

classIN :: Word16 Source #

IN class (RFC 1035) without any cache-flush bit.

Codec

encodeDnsPacket :: DnsPacket -> ByteString Source #

Encode a packet. Names are written uncompressed (valid for every reader); RdPtr RdTxt RdSrv rdata is re-encoded and RdOther passes through verbatim.

Section counts are derived from the lists, so a caller can never set inconsistent counts.

decodeDnsPacket :: ByteString -> Either String DnsPacket Source #

Decode a packet, resolving name compression. A structurally invalid packet is a Left; the mDNS service ignores malformed packets — multicast input is unauthenticated.