Waterfall/BungeeCord-Patches/0034-Optionally-use-async-Netty-DNS-resolver.patch
Shane Freeder f48db6b757
Disable tab spam limiter for 1.13+ by default
The changes in 1.13 makes this limiter too easy to hit, breaking tab
completion silently for users and causing a lot of confusion around
tab completions not working, for this reason, it's cleaner to disable
this for 1.13+ clients by default and defer this to the server, where
better control is already provided for paper servers (and any other
server will either not have broken tab completions, or can re-enable
this limit if they wish to do so)
2018-10-06 19:59:28 +01:00

186 lines
8.4 KiB
Diff

From 97b134ad0ba83da9fc5539f873b5dbbeaa013400 Mon Sep 17 00:00:00 2001
From: Tux <write@imaginarycode.com>
Date: Wed, 21 Dec 2016 03:13:03 -0500
Subject: [PATCH] Optionally use async Netty DNS resolver
We no longer need to cache the address for the session server now.
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
index 34d7e2cb..47d4ab36 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
@@ -168,6 +168,11 @@ public interface ProxyConfig
*/
String getGameVersion();
+ /**
+ * Whether Netty's async DNS resolver is used for account authentication.
+ */
+ boolean isUseNettyDnsResolver();
+
// Throttling options
/**
diff --git a/proxy/pom.xml b/proxy/pom.xml
index 841f014e..2efeaa9e 100644
--- a/proxy/pom.xml
+++ b/proxy/pom.xml
@@ -41,6 +41,14 @@
<version>${netty.version}</version>
<scope>compile</scope>
</dependency>
+ <!-- Waterfall Start - add Netty DNS resolver -->
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-resolver-dns</artifactId>
+ <version>${netty.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <!-- Waterfall End -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
index e55c28d8..b7e3dad0 100644
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
@@ -22,6 +22,12 @@ public class WaterfallConfiguration extends Configuration {
*/
private String gameVersion;
+ /**
+ * Whether we use Netty's async DNS resolver for the HttpClient.
+ * <p>Default is true (use Netty's async DNS resolver)</p>
+ */
+ private boolean useNettyDnsResolver = true;
+
/*
* Throttling options
* Helps prevent players from overloading the servers behind us
@@ -43,6 +49,7 @@ public class WaterfallConfiguration extends Configuration {
config.load(false); // Load, but no permissions
logServerListPing = config.getBoolean( "log_server_list_ping", logServerListPing );
gameVersion = config.getString("game_version", "").isEmpty() ? Joiner.on(", ").join(ProtocolConstants.SUPPORTED_VERSIONS) : config.getString("game_version", "");
+ useNettyDnsResolver = config.getBoolean("use_netty_dns_resolver", useNettyDnsResolver);
// Throttling options
tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
disableModernTabLimiter = config.getBoolean("disable_modern_tab_limiter", disableModernTabLimiter);
@@ -58,6 +65,11 @@ public class WaterfallConfiguration extends Configuration {
return gameVersion;
}
+ @Override
+ public boolean isUseNettyDnsResolver() {
+ return useNettyDnsResolver;
+ }
+
@Override
public int getTabThrottle() {
return tabThrottle;
diff --git a/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java b/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java
index 2feb4d66..b265bb43 100644
--- a/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java
+++ b/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java
@@ -28,6 +28,10 @@ public class HttpClient
public static final int TIMEOUT = 5000;
private static final Cache<String, InetAddress> addressCache = CacheBuilder.newBuilder().expireAfterWrite( 1, TimeUnit.MINUTES ).build();
+ // Waterfall Start - optionally use async resolver from Netty
+ private static final io.netty.resolver.dns.DnsAddressResolverGroup dnsResolverGroup =
+ new io.netty.resolver.dns.DnsAddressResolverGroup(PipelineUtils.getDatagramChannel(), io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider.INSTANCE);
+ // Waterfall End
@SuppressWarnings("UnusedAssignment")
public static void get(String url, EventLoop eventLoop, final Callback<String> callback)
@@ -57,19 +61,21 @@ public class HttpClient
}
}
- InetAddress inetHost = addressCache.getIfPresent( uri.getHost() );
- if ( inetHost == null )
- {
- try
- {
- inetHost = InetAddress.getByName( uri.getHost() );
- } catch ( UnknownHostException ex )
- {
- callback.done( null, ex );
- return;
- }
- addressCache.put( uri.getHost(), inetHost );
- }
+ // Waterfall Start - Move address creation to implementation method
+ //InetAddress inetHost = addressCache.getIfPresent( uri.getHost() );
+ //if ( inetHost == null )
+ //{
+ // try
+ // {
+ // inetHost = InetAddress.getByName( uri.getHost() );
+ // } catch ( UnknownHostException ex )
+ // {
+ // callback.done( null, ex );
+ // return;
+ // }
+ // addressCache.put( uri.getHost(), inetHost );
+ //}
+ // Waterfall End
ChannelFutureListener future = new ChannelFutureListener()
{
@@ -92,7 +98,39 @@ public class HttpClient
}
};
+ // Waterfall Start - Optionally use Netty's async DNS Resolver
+ if (net.md_5.bungee.api.ProxyServer.getInstance().getConfig().isUseNettyDnsResolver()) {
+ getWithNettyResolver(eventLoop, uri, port, future, callback, ssl);
+ } else {
+ getWithDefaultResolver(eventLoop, uri, port, future, callback, ssl);
+ }
+ //new Bootstrap().channel( PipelineUtils.getChannel() ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
+ // option( ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT ).remoteAddress( inetHost, port ).connect().addListener( future );
+ }
+
+ private static void getWithNettyResolver(EventLoop eventLoop, URI uri, int port, ChannelFutureListener future, Callback<String> callback, boolean ssl) {
+ java.net.InetSocketAddress address = java.net.InetSocketAddress.createUnresolved(uri.getHost(), port);
+ new Bootstrap().channel( PipelineUtils.getChannel() ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
+ option( ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT ).resolver(dnsResolverGroup).remoteAddress( address ).connect().addListener( future );
+ }
+
+ private static void getWithDefaultResolver(EventLoop eventLoop, URI uri, int port, ChannelFutureListener future, Callback<String> callback, boolean ssl) {
+ // This is identical to the Bungee implementation of #get other than the absence of the ChannelFutureListener creation
+ InetAddress inetHost = addressCache.getIfPresent( uri.getHost() );
+ if ( inetHost == null )
+ {
+ try
+ {
+ inetHost = InetAddress.getByName( uri.getHost() );
+ } catch ( UnknownHostException ex )
+ {
+ callback.done( null, ex );
+ return;
+ }
+ addressCache.put( uri.getHost(), inetHost );
+ }
new Bootstrap().channel( PipelineUtils.getChannel() ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
option( ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT ).remoteAddress( inetHost, port ).connect().addListener( future );
}
+ // Waterfall End
}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
index 41330ec2..c26fc55b 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
@@ -112,7 +112,7 @@ public class PipelineUtils
return epoll ? EpollSocketChannel.class : NioSocketChannel.class;
}
- public static Class<? extends Channel> getDatagramChannel()
+ public static Class<? extends io.netty.channel.socket.DatagramChannel> getDatagramChannel() // Waterfall - change to DatagramChannel
{
return epoll ? EpollDatagramChannel.class : NioDatagramChannel.class;
}
--
2.19.0