Search in sources :

Example 1 with DnsServerAddressStreamProvider

use of io.netty.resolver.dns.DnsServerAddressStreamProvider in project netty by netty.

the class MacOSDnsServerAddressStreamProviderTest method testStream.

@Test
void testStream() {
    MacOSDnsServerAddressStreamProvider.ensureAvailability();
    DnsServerAddressStreamProvider provider = new MacOSDnsServerAddressStreamProvider();
    DnsServerAddressStream stream = provider.nameServerAddressStream("netty.io");
    assertNotNull(stream);
    assertNotEquals(0, stream.size());
    for (int i = 0; i < stream.size(); i++) {
        assertNotEquals(0, stream.next().getPort());
    }
}
Also used : DnsServerAddressStreamProvider(io.netty.resolver.dns.DnsServerAddressStreamProvider) DnsServerAddressStream(io.netty.resolver.dns.DnsServerAddressStream) Test(org.junit.jupiter.api.Test)

Example 2 with DnsServerAddressStreamProvider

use of io.netty.resolver.dns.DnsServerAddressStreamProvider in project graylog2-server by Graylog2.

the class DnsClient method start.

public void start(String dnsServerIps) {
    LOG.debug("Attempting to start DNS client");
    final List<InetSocketAddress> iNetDnsServerIps = parseServerIpAddresses(dnsServerIps);
    nettyEventLoop = new NioEventLoopGroup();
    final DnsNameResolverBuilder dnsNameResolverBuilder = new DnsNameResolverBuilder(nettyEventLoop.next());
    dnsNameResolverBuilder.channelType(NioDatagramChannel.class).queryTimeoutMillis(queryTimeout);
    // Specify custom DNS servers if provided. If not, use those specified in local network adapter settings.
    if (CollectionUtils.isNotEmpty(iNetDnsServerIps)) {
        LOG.debug("Attempting to start DNS client with server IPs [{}] on port [{}] with timeout [{}]", dnsServerIps, DEFAULT_DNS_PORT, requestTimeout);
        final DnsServerAddressStreamProvider dnsServer = new SequentialDnsServerAddressStreamProvider(iNetDnsServerIps);
        dnsNameResolverBuilder.nameServerProvider(dnsServer);
    } else {
        LOG.debug("Attempting to start DNS client with the local network adapter DNS server address on port [{}] with timeout [{}]", DEFAULT_DNS_PORT, requestTimeout);
    }
    resolver = dnsNameResolverBuilder.build();
    LOG.debug("DNS client startup successful");
}
Also used : DnsServerAddressStreamProvider(io.netty.resolver.dns.DnsServerAddressStreamProvider) SequentialDnsServerAddressStreamProvider(io.netty.resolver.dns.SequentialDnsServerAddressStreamProvider) SequentialDnsServerAddressStreamProvider(io.netty.resolver.dns.SequentialDnsServerAddressStreamProvider) DnsNameResolverBuilder(io.netty.resolver.dns.DnsNameResolverBuilder) InetSocketAddress(java.net.InetSocketAddress) NioDatagramChannel(io.netty.channel.socket.nio.NioDatagramChannel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

DnsServerAddressStreamProvider (io.netty.resolver.dns.DnsServerAddressStreamProvider)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioDatagramChannel (io.netty.channel.socket.nio.NioDatagramChannel)1 DnsNameResolverBuilder (io.netty.resolver.dns.DnsNameResolverBuilder)1 DnsServerAddressStream (io.netty.resolver.dns.DnsServerAddressStream)1 SequentialDnsServerAddressStreamProvider (io.netty.resolver.dns.SequentialDnsServerAddressStreamProvider)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.jupiter.api.Test)1