From 4a872ffabe0d0020063133f9545f42a6ac88e292 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 24 Dec 2018 07:37:59 -0500 Subject: [PATCH] Add asynchronous DNS resolution. --- proxy/build.gradle | 1 + .../proxy/network/ConnectionManager.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/proxy/build.gradle b/proxy/build.gradle index 140e50405..93e0f094f 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -33,6 +33,7 @@ dependencies { compile "io.netty:netty-transport-native-epoll:${nettyVersion}" compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64" compile "io.netty:netty-transport-native-kqueue:${nettyVersion}:osx-x86_64" + compile "io.netty:netty-resolver-dns:${nettyVersion}" compile "org.apache.logging.log4j:log4j-api:${log4jVersion}" compile "org.apache.logging.log4j:log4j-core:${log4jVersion}" diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 21d2eac88..110dd94fd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -11,6 +11,9 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.WriteBufferWaterMark; +import io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider; +import io.netty.resolver.dns.DnsAddressResolverGroup; +import io.netty.resolver.dns.MultiDnsServerAddressStreamProvider; import java.net.InetSocketAddress; import java.util.HashMap; import java.util.HashSet; @@ -31,6 +34,8 @@ public final class ConnectionManager { private final VelocityServer server; public final ServerChannelInitializerHolder serverChannelInitializer; + private final DnsAddressResolverGroup resolverGroup; + public ConnectionManager(VelocityServer server) { this.server = server; this.transportType = TransportType.bestType(); @@ -38,6 +43,8 @@ public final class ConnectionManager { this.workerGroup = this.transportType.createEventLoopGroup(TransportType.Type.WORKER); this.serverChannelInitializer = new ServerChannelInitializerHolder( new ServerChannelInitializer(this.server)); + this.resolverGroup = new DnsAddressResolverGroup(this.transportType.datagramChannelClass, + DefaultDnsServerAddressStreamProvider.INSTANCE); } public void logChannelInformation() { @@ -91,7 +98,8 @@ public final class ConnectionManager { .group(this.workerGroup) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, - this.server.getConfiguration().getConnectTimeout()); + this.server.getConfiguration().getConnectTimeout()) + .resolver(this.resolverGroup); } public void close(InetSocketAddress oldBind) {