public static List<Set<SrvRecord>> resolveXMPPDomain(String domain, int defaultPort) {
        // Check if there is an entry in the internal DNS for the specified domain
        List<Set<SrvRecord>> results = new LinkedList<>();
        if (dnsOverride != null) {
            SrvRecord serviceRecord = dnsOverride.get(domain);
            if (serviceRecord == null) {
                serviceRecord = dnsOverride.get("*");
            }
            if (serviceRecord != null) {
                logger.debug("Answering lookup for domain '{}' from DNS override property. Returning: {}", domain, serviceRecord);
                results.add(Set.of(serviceRecord));
                return results;
            }
        }

        // Attempt the SRV lookup.
        final List<SrvRecord> srvLookups = new LinkedList<>(srvLookup("xmpp-server", "tcp", domain));

        final String propertyValue = JiveGlobals.getProperty(ConnectionSettings.Server.TLS_POLICY, Connection.TLSPolicy.optional.toString());
        Connection.TLSPolicy configuredPolicy;
        try {
            configuredPolicy = Connection.TLSPolicy.valueOf(propertyValue);
        } catch (RuntimeException e) {
            // In case of misconfiguration, default to the highest level of security.
            logger.warn("Unexpected value for '{}': '{}'. Defaulting to '{}'", ConnectionSettings.Server.TLS_POLICY, propertyValue, Connection.TLSPolicy.required);
            configuredPolicy = Connection.TLSPolicy.required;
        }
        final boolean allowTLS = configuredPolicy == Connection.TLSPolicy.required || configuredPolicy == Connection.TLSPolicy.optional;
        if (allowTLS) {
            srvLookups.addAll(srvLookup("xmpps-server", "tcp", domain));
        }

        if (srvLookups.isEmpty()) {
            srvLookups.addAll(srvLookup( "jabber", "tcp", domain ));
        }

        if (!srvLookups.isEmpty()) {
            // we have to re-prioritize the combination of both lookups.
            results.addAll( SrvRecord.prioritize(srvLookups) );
        }

        // Use domain and default port as fallback, if that's not already in the list.
        if (results.stream().flatMap(Set::stream).noneMatch(h -> h.getHostname().equals(domain) && h.getPort() == defaultPort && !h.isDirectTLS())) {
            results.add(Set.of(new SrvRecord(domain, defaultPort, false, Integer.MAX_VALUE, 0)));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Answering lookup for domain '{}' from DNS responses. Returning:", domain);
            for (final Set<SrvRecord> srvLookup : results) {
                for (final SrvRecord hostAddress : srvLookup) {
                    if (hostAddress.getPriority() != Integer.MAX_VALUE) {
                        logger.debug(" - {} (based on a DNS lookup)", hostAddress);
                    } else {
                        logger.debug(" - {} (a fallback, based on the XMPP domain and default port)", hostAddress);
                    }
                }
            }
        }
        return results;
    }
Returns a collection of host names and ports that the specified XMPP
domain can be reached at for server-to-server communication.

DNS lookups for a SRV records in the form "_xmpp-server._tcp.example.com"
and "_xmpps-server._tcp.example.com" are attempted, in line with section
3.2 of XMPP Core and XEP-0368.

If those lookup fail to provide any records, a lookup in the older form
of "_jabber._tcp.example.com" is attempted since servers that implement
an older version of the protocol may be listed using that notation.

If that lookup fails as well, it's assumed that the XMPP server lives at
the host resolved by a DNS A lookup at the specified domain on the
specified default port.

As an example, a lookup for "example.com" may return "im.example.com:5269".

The returned collection is a list of sets of host names. The 'inner'
collection, the sets of host names, are grouping host names that have an
equal 'priority' SRV value. The 'outer' collection, the list, defines the
order that's defined by the 'priority' value (lowest first). Generally
speaking, all values from the first set of the outer list should be
processed, before elements from the next set of that list are to be processed.

The Sets that are returned as elements of the list have a predictable
iteration order. This order is based on a randomization based on the
SRV 'weight' value of each host.

@param domain the domain.
@param defaultPort default port to return if the DNS look up fails.
@return SRV records (grouped by priority) which encompasses the hostname and port
        that the XMPP server can be reached at for the specified domain.
@see <a href="https://tools.ietf.org/html/rfc6120#section-3.2">XMPP CORE</a>
@see <a href="https://xmpp.org/extensions/xep-0368.html">XEP-0368</a>
xmppserver/src/main/java/org/jivesoftware/openfire/net/DNSUtil.java