public static void setup() { DNSUtil.setDNSResolver(getInstance()); }
} else { double rnd = Math.random() * running_total; selectedPos = bisect(totals, rnd);
/** * Returns a list of HostAddresses under which the specified XMPP server can be reached at for client-to-server * communication. A DNS lookup for a SRV 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 * 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". * </p> * * @param domain the domain. * @param failedAddresses on optional list that will be populated with host addresses that failed to resolve. * @param dnssecMode DNSSec mode. * @return List of HostAddress, which encompasses the hostname and port that the * XMPP server can be reached at for the specified domain. */ public static List<HostAddress> resolveXMPPServiceDomain(DnsName domain, List<HostAddress> failedAddresses, DnssecMode dnssecMode) { return resolveDomain(domain, DomainType.client, failedAddresses, dnssecMode); }
/** * Populates {@link #hostAddresses} with the resolved addresses or with the configured host address. If no host * address was configured and all lookups failed, for example with NX_DOMAIN, then {@link #hostAddresses} will be * populated with the empty list. * * @return a list of host addresses where DNS (SRV) RR resolution failed. */ protected List<HostAddress> populateHostAddresses() { List<HostAddress> failedAddresses = new LinkedList<>(); if (config.hostAddress != null) { hostAddresses = new ArrayList<>(1); HostAddress hostAddress = new HostAddress(config.port, config.hostAddress); hostAddresses.add(hostAddress); } else if (config.host != null) { hostAddresses = new ArrayList<>(1); HostAddress hostAddress = DNSUtil.getDNSResolver().lookupHostAddress(config.host, config.port, failedAddresses, config.getDnssecMode()); if (hostAddress != null) { hostAddresses.add(hostAddress); } } else { // N.B.: Important to use config.serviceName and not AbstractXMPPConnection.serviceName DnsName dnsName = DnsName.from(config.getXMPPServiceDomain()); hostAddresses = DNSUtil.resolveXMPPServiceDomain(dnsName, failedAddresses, config.getDnssecMode()); } // Either the populated host addresses are not empty *or* there must be at least one failed address. assert (!hostAddresses.isEmpty() || !failedAddresses.isEmpty()); return failedAddresses; }
@Test public void daneProviderTest() { DNSUtil.setDaneProvider(DNS_UTIL_TEST_DANE_PROVIDER); SmackDaneProvider currentDaneProvider = DNSUtil.getDaneProvider(); assertEquals(DNS_UTIL_TEST_DANE_PROVIDER, currentDaneProvider); } }
/** * Creates a new ConnectionConfiguration for the specified service name * with specified proxy. * A DNS SRV lookup will be performed to find out the actual host address * and port to use for the connection. * * @param serviceName the name of the service provided by an XMPP server. * @param proxy the proxy through which XMPP is to be connected */ public ConnectionConfiguration(String serviceName,ProxyInfo proxy) { // Perform DNS lookup to get host and port to use hostAddresses = DNSUtil.resolveXMPPDomain(serviceName); init(serviceName, proxy); }
LOGGER.fine(logMessage); List<HostAddress> sortedRecords = sortSRVRecords(srvRecords); addresses.addAll(sortedRecords); } else {
public static void setup() { DNSUtil.setDaneProvider(INSTANCE); } }
builder.setHost( DNSUtil.resolveXMPPServiceDomain( serverNameDnsName, null, DnssecMode.disabled ).get( 0 ).getFQDN() ); builder.setPort( 5223 );
SmackDaneProvider daneProvider = DNSUtil.getDaneProvider(); if (daneProvider == null) { throw new UnsupportedOperationException("DANE enabled but no SmackDaneProvider configured");
/** * Creates a new ConnectionConfiguration for the specified service name. * A DNS SRV lookup will be performed to find out the actual host address * and port to use for the connection. * * @param serviceName the name of the service provided by an XMPP server. */ public ConnectionConfiguration(String serviceName) { // Perform DNS lookup to get host and port to use hostAddresses = DNSUtil.resolveXMPPDomain(serviceName); init(serviceName, ProxyInfo.forDefaultProxy()); }
/** * Populates {@link #hostAddresses} with the resolved addresses or with the configured host address. If no host * address was configured and all lookups failed, for example with NX_DOMAIN, then {@link #hostAddresses} will be * populated with the empty list. * * @return a list of host addresses where DNS (SRV) RR resolution failed. */ protected List<HostAddress> populateHostAddresses() { List<HostAddress> failedAddresses = new LinkedList<>(); if (config.hostAddress != null) { hostAddresses = new ArrayList<>(1); HostAddress hostAddress = new HostAddress(config.port, config.hostAddress); hostAddresses.add(hostAddress); } else if (config.host != null) { hostAddresses = new ArrayList<>(1); HostAddress hostAddress = DNSUtil.getDNSResolver().lookupHostAddress(config.host, config.port, failedAddresses, config.getDnssecMode()); if (hostAddress != null) { hostAddresses.add(hostAddress); } } else { // N.B.: Important to use config.serviceName and not AbstractXMPPConnection.serviceName DnsName dnsName = DnsName.from(config.getXMPPServiceDomain()); hostAddresses = DNSUtil.resolveXMPPServiceDomain(dnsName, failedAddresses, config.getDnssecMode()); } // Either the populated host addresses are not empty *or* there must be at least one failed address. assert (!hostAddresses.isEmpty() || !failedAddresses.isEmpty()); return failedAddresses; }
List<HostAddress> sortedRecords = sortSRVRecords(srvRecords); if (sortedRecords != null) addresses.addAll(sortedRecords);
public static void setup() { DNSUtil.setDaneProvider(INSTANCE); } }
builder.setHost( DNSUtil.resolveXMPPServiceDomain( serverNameDnsName, null, DnssecMode.disabled ).get( 0 ).getFQDN() ); builder.setPort( 5223 );
public static void setup() { DNSUtil.setDNSResolver(getInstance()); }
/** * Creates a new ConnectionConfiguration for the specified service name * with specified proxy. * A DNS SRV lookup will be performed to find out the actual host address * and port to use for the connection. * * @param serviceName the name of the service provided by an XMPP server. * @param proxy the proxy through which XMPP is to be connected */ public ConnectionConfiguration(String serviceName,ProxyInfo proxy) { // Perform DNS lookup to get host and port to use DNSUtil.HostAddress address = DNSUtil.resolveXMPPDomain(serviceName); init(address.getHost(), address.getPort(), serviceName, proxy); }
/** * Returns a list of HostAddresses under which the specified XMPP server can be reached at for server-to-server * communication. A DNS lookup for a SRV 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 * 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". * </p> * * @param domain the domain. * @param failedAddresses on optional list that will be populated with host addresses that failed to resolve. * @param dnssecMode DNSSec mode. * @return List of HostAddress, which encompasses the hostname and port that the * XMPP server can be reached at for the specified domain. */ public static List<HostAddress> resolveXMPPServerDomain(DnsName domain, List<HostAddress> failedAddresses, DnssecMode dnssecMode) { return resolveDomain(domain, DomainType.server, failedAddresses, dnssecMode); }
LOGGER.fine(logMessage); List<HostAddress> sortedRecords = sortSRVRecords(srvRecords); addresses.addAll(sortedRecords); } else {
} else { double rnd = Math.random() * running_total; selectedPos = bisect(totals, rnd);