Home / Class/ AuthoritativeNameServerList Class — netty Architecture

AuthoritativeNameServerList Class — netty Architecture

Architecture documentation for the AuthoritativeNameServerList class in DnsResolveContext.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  a63c5319_f927_6bfc_6318_415aecf6068e["AuthoritativeNameServerList"]
  21f3aef4_24fe_7168_ea1d_94d7a3f45711["DnsResolveContext.java"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|defined in| 21f3aef4_24fe_7168_ea1d_94d7a3f45711
  a9822690_3b20_920b_81cd_babd343212d1["AuthoritativeNameServerList()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| a9822690_3b20_920b_81cd_babd343212d1
  161fe130_19c1_016b_ea22_8d91937c6452["add()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| 161fe130_19c1_016b_ea22_8d91937c6452
  ce863271_9615_37a8_a591_eac4f9ad92d1["handleWithAdditional()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| ce863271_9615_37a8_a591_eac4f9ad92d1
  7da11410_1c67_395f_375c_64155bdbcc56["handleWithoutAdditionals()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| 7da11410_1c67_395f_375c_64155bdbcc56
  9caaa437_2160_8652_2fbb_0158e6269335["cacheUnresolved()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| 9caaa437_2160_8652_2fbb_0158e6269335
  2a2aba15_7a5f_91b0_1bd0_9d51a9401ccf["cache()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| 2a2aba15_7a5f_91b0_1bd0_9d51a9401ccf
  836e4609_6a00_0ab5_76ae_511f287c23c9["isEmpty()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| 836e4609_6a00_0ab5_76ae_511f287c23c9
  2b098af8_5694_2a00_1f74_a3149167f056["addressList()"]
  a63c5319_f927_6bfc_6318_415aecf6068e -->|method| 2b098af8_5694_2a00_1f74_a3149167f056

Relationship Graph

Source Code

resolver-dns/src/main/java/io/netty/resolver/dns/DnsResolveContext.java lines 1250–1432

    private static final class AuthoritativeNameServerList {

        private final String questionName;

        // We not expect the linked-list to be very long so a double-linked-list is overkill.
        private AuthoritativeNameServer head;

        private int nameServerCount;

        AuthoritativeNameServerList(String questionName) {
            this.questionName = questionName.toLowerCase(Locale.US);
        }

        void add(DnsRecord r) {
            if (r.type() != DnsRecordType.NS || !(r instanceof DnsRawRecord)) {
                return;
            }

            // Only include servers that serve the correct domain.
            if (questionName.length() <  r.name().length()) {
                return;
            }

            String recordName = r.name().toLowerCase(Locale.US);

            int dots = 0;
            for (int a = recordName.length() - 1, b = questionName.length() - 1; a >= 0; a--, b--) {
                char c = recordName.charAt(a);
                if (questionName.charAt(b) != c) {
                    return;
                }
                if (c == '.') {
                    dots++;
                }
            }

            if (head != null && head.dots > dots) {
                // We already have a closer match so ignore this one, no need to parse the domainName etc.
                return;
            }

            final ByteBuf recordContent = ((ByteBufHolder) r).content();
            final String domainName = decodeDomainName(recordContent);
            if (domainName == null) {
                // Could not be parsed, ignore.
                return;
            }

            // We are only interested in preserving the nameservers which are the closest to our qName, so ensure
            // we drop servers that have a smaller dots count.
            if (head == null || head.dots < dots) {
                nameServerCount = 1;
                head = new AuthoritativeNameServer(dots, r.timeToLive(), recordName, domainName);
            } else if (head.dots == dots) {
                AuthoritativeNameServer serverName = head;
                while (serverName.next != null) {
                    serverName = serverName.next;
                }
                serverName.next = new AuthoritativeNameServer(dots, r.timeToLive(), recordName, domainName);
                nameServerCount++;
            }
        }

        void handleWithAdditional(
                DnsNameResolver parent, DnsRecord r, AuthoritativeDnsServerCache authoritativeCache) {
            // Just walk the linked-list and mark the entry as handled when matched.
            AuthoritativeNameServer serverName = head;

            String nsName = r.name();
            InetAddress resolved = decodeAddress(r, nsName, parent.isDecodeIdn());
            if (resolved == null) {
                // Could not parse the address, just ignore.
                return;
            }

            while (serverName != null) {
                if (serverName.nsName.equalsIgnoreCase(nsName)) {
                    if (serverName.address != null) {
                        // We received multiple ADDITIONAL records for the same name.
                        // Search for the last we insert before and then append a new one.
                        while (serverName.next != null && serverName.next.isCopy) {

Frequently Asked Questions

What is the AuthoritativeNameServerList class?
AuthoritativeNameServerList is a class in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/DnsResolveContext.java.
Where is AuthoritativeNameServerList defined?
AuthoritativeNameServerList is defined in resolver-dns/src/main/java/io/netty/resolver/dns/DnsResolveContext.java at line 1250.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free