Package org.jivesoftware.openfire.net
Class DNSUtil
- java.lang.Object
-
- org.jivesoftware.openfire.net.DNSUtil
-
public class DNSUtil extends Object
Utility class to perform DNS lookups for XMPP services.- Author:
- Matt Tucker
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DNSUtil.HostAddress
Encapsulates a hostname and port.static class
DNSUtil.WeightedHostAddress
The representation of weighted address.
-
Constructor Summary
Constructors Constructor Description DNSUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,DNSUtil.HostAddress>
getDnsOverride()
Returns the internal DNS that allows to specify target IP addresses and ports to use for domains.static boolean
isNameCoveredByPattern(String name, String pattern)
Checks if the provided DNS pattern matches the provided name.static List<DNSUtil.WeightedHostAddress>
prioritize(DNSUtil.WeightedHostAddress[] records)
static List<DNSUtil.HostAddress>
resolveXMPPDomain(String domain, int defaultPort)
Returns a sorted list of host names and ports that the specified XMPP domain can be reached at for server-to-server communication.static void
setDnsOverride(Map<String,DNSUtil.HostAddress> dnsOverride)
Sets the internal DNS that allows to specify target IP addresses and ports to use for domains.static List<DNSUtil.WeightedHostAddress>
srvLookup(String service, String proto, String name)
Performs a DNS SRV lookup.
-
-
-
Method Detail
-
resolveXMPPDomain
public static List<DNSUtil.HostAddress> resolveXMPPDomain(String domain, int defaultPort)
Returns a sorted list 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".
-
getDnsOverride
public static Map<String,DNSUtil.HostAddress> getDnsOverride()
Returns the internal DNS that allows to specify target IP addresses and ports to use for domains. The internal DNS will be checked up before performing an actual DNS SRV lookup.- Returns:
- the internal DNS that allows to specify target IP addresses and ports to use for domains.
-
setDnsOverride
public static void setDnsOverride(Map<String,DNSUtil.HostAddress> dnsOverride)
Sets the internal DNS that allows to specify target IP addresses and ports to use for domains. The internal DNS will be checked up before performing an actual DNS SRV lookup.- Parameters:
dnsOverride
- the internal DNS that allows to specify target IP addresses and ports to use for domains.
-
srvLookup
public static List<DNSUtil.WeightedHostAddress> srvLookup(@Nonnull String service, @Nonnull String proto, @Nonnull String name)
Performs a DNS SRV lookup. Does not take into account any DNS overrides configured in this class. The results returned by this method are ordered by priority (ascending), and order of equal priority entries is randomized by weight, as defined in the DNS SRV specification.- Parameters:
service
- the symbolic name of the desired service.proto
- the transport protocol of the desired service; this is usually either TCP or UDP.name
- the domain name for which this record is valid.- Returns:
- An ordered of results (possibly empty, never null).
-
isNameCoveredByPattern
public static boolean isNameCoveredByPattern(String name, String pattern)
Checks if the provided DNS pattern matches the provided name. For example, this method will: return true for name:xmpp.example.org
, pattern:*.example.org
return false for name:xmpp.example.org
, pattern:example.org
This method is not case sensitive.- Parameters:
name
- The name to check against a pattern (cannot be null or empty).pattern
- the pattern (cannot be null or empty).- Returns:
- true when the name is covered by the pattern, otherwise false.
-
prioritize
public static List<DNSUtil.WeightedHostAddress> prioritize(DNSUtil.WeightedHostAddress[] records)
-
-