mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 15:32:06 +01:00
Fallback to host if DNS SRV lookup fails
Also fix javadoc for DNSUtil, _jabber SRV records are no longer tried. Fixes SMACK-616.
This commit is contained in:
parent
1ade4cbc64
commit
4000adb70c
1 changed files with 33 additions and 37 deletions
|
@ -85,24 +85,19 @@ public class DNSUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of HostAddresses under which the specified XMPP server can be
|
* Returns a list of HostAddresses under which the specified XMPP server can be reached at for client-to-server
|
||||||
* reached at for client-to-server communication. A DNS lookup for a SRV
|
* communication. A DNS lookup for a SRV record in the form "_xmpp-client._tcp.example.com" is attempted, according
|
||||||
* record in the form "_xmpp-client._tcp.example.com" is attempted, according
|
* to section 3.2.1 of RFC 6120. If that lookup fails, it's assumed that the XMPP server lives at the host resolved
|
||||||
* to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
|
* by a DNS lookup at the specified domain on the default port of 5222.
|
||||||
* of "_jabber._tcp.example.com" is attempted since servers that implement an
|
* <p>
|
||||||
* 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 lookup at the specified domain on the default port
|
|
||||||
* of 5222.<p>
|
|
||||||
*
|
|
||||||
* As an example, a lookup for "example.com" may return "im.example.com:5269".
|
* As an example, a lookup for "example.com" may return "im.example.com:5269".
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param domain the domain.
|
* @param domain the domain.
|
||||||
* @return List of HostAddress, which encompasses the hostname and port that the
|
* @return List of HostAddress, which encompasses the hostname and port that the XMPP server can be reached at for
|
||||||
* XMPP server can be reached at for the specified domain.
|
* the specified domain.
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static List<HostAddress> resolveXMPPDomain(final String domain) throws Exception {
|
public static List<HostAddress> resolveXMPPDomain(final String domain) {
|
||||||
if (dnsResolver == null) {
|
if (dnsResolver == null) {
|
||||||
List<HostAddress> addresses = new ArrayList<HostAddress>(1);
|
List<HostAddress> addresses = new ArrayList<HostAddress>(1);
|
||||||
addresses.add(new HostAddress(domain, 5222));
|
addresses.add(new HostAddress(domain, 5222));
|
||||||
|
@ -112,24 +107,19 @@ public class DNSUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of HostAddresses under which the specified XMPP server can be
|
* Returns a list of HostAddresses under which the specified XMPP server can be reached at for server-to-server
|
||||||
* reached at for server-to-server communication. A DNS lookup for a SRV
|
* communication. A DNS lookup for a SRV record in the form "_xmpp-server._tcp.example.com" is attempted, according
|
||||||
* record in the form "_xmpp-server._tcp.example.com" is attempted, according
|
* to section 3.2.1 of RFC 6120. If that lookup fails , it's assumed that the XMPP server lives at the host resolved
|
||||||
* to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
|
* by a DNS lookup at the specified domain on the default port of 5269.
|
||||||
* of "_jabber._tcp.example.com" is attempted since servers that implement an
|
* <p>
|
||||||
* 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 lookup at the specified domain on the default port
|
|
||||||
* of 5269.<p>
|
|
||||||
*
|
|
||||||
* As an example, a lookup for "example.com" may return "im.example.com:5269".
|
* As an example, a lookup for "example.com" may return "im.example.com:5269".
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param domain the domain.
|
* @param domain the domain.
|
||||||
* @return List of HostAddress, which encompasses the hostname and port that the
|
* @return List of HostAddress, which encompasses the hostname and port that the XMPP server can be reached at for
|
||||||
* XMPP server can be reached at for the specified domain.
|
* the specified domain.
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static List<HostAddress> resolveXMPPServerDomain(final String domain) throws Exception {
|
public static List<HostAddress> resolveXMPPServerDomain(final String domain) {
|
||||||
if (dnsResolver == null) {
|
if (dnsResolver == null) {
|
||||||
List<HostAddress> addresses = new ArrayList<HostAddress>(1);
|
List<HostAddress> addresses = new ArrayList<HostAddress>(1);
|
||||||
addresses.add(new HostAddress(domain, 5269));
|
addresses.add(new HostAddress(domain, 5269));
|
||||||
|
@ -138,7 +128,7 @@ public class DNSUtil {
|
||||||
return resolveDomain(domain, 's');
|
return resolveDomain(domain, 's');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<HostAddress> resolveDomain(String domain, char keyPrefix) throws Exception {
|
private static List<HostAddress> resolveDomain(String domain, char keyPrefix) {
|
||||||
List<HostAddress> addresses = new ArrayList<HostAddress>();
|
List<HostAddress> addresses = new ArrayList<HostAddress>();
|
||||||
|
|
||||||
// Step one: Do SRV lookups
|
// Step one: Do SRV lookups
|
||||||
|
@ -150,6 +140,7 @@ public class DNSUtil {
|
||||||
} else {
|
} else {
|
||||||
srvDomain = domain;
|
srvDomain = domain;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
List<SRVRecord> srvRecords = dnsResolver.lookupSRVRecords(srvDomain);
|
List<SRVRecord> srvRecords = dnsResolver.lookupSRVRecords(srvDomain);
|
||||||
if (LOGGER.isLoggable(Level.FINE)) {
|
if (LOGGER.isLoggable(Level.FINE)) {
|
||||||
String logMessage = "Resolved SRV RR for " + srvDomain + ":";
|
String logMessage = "Resolved SRV RR for " + srvDomain + ":";
|
||||||
|
@ -159,6 +150,11 @@ public class DNSUtil {
|
||||||
}
|
}
|
||||||
List<HostAddress> sortedRecords = sortSRVRecords(srvRecords);
|
List<HostAddress> sortedRecords = sortSRVRecords(srvRecords);
|
||||||
addresses.addAll(sortedRecords);
|
addresses.addAll(sortedRecords);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Exception while resovling SRV records for " + domain
|
||||||
|
+ ". Consider adding '_xmpp-(server|client)._tcp' DNS SRV Records");
|
||||||
|
}
|
||||||
|
|
||||||
// Step two: Add the hostname to the end of the list
|
// Step two: Add the hostname to the end of the list
|
||||||
addresses.add(new HostAddress(domain));
|
addresses.add(new HostAddress(domain));
|
||||||
|
|
Loading…
Reference in a new issue