2023-09-21 12:33:23 +02:00
From fe8d22926e5d35ec817b333c8546f8ba527ead79 Mon Sep 17 00:00:00 2001
2017-07-26 19:52:48 +02:00
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
2020-02-01 16:39:53 +01:00
index 749059ab..6141128b 100644
2017-07-26 19:52:48 +02:00
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
2020-02-01 16:39:53 +01:00
@@ -221,6 +221,13 @@ public interface ProxyConfig
2017-07-26 19:52:48 +02:00
*/
String getGameVersion();
+ /**
+ * Whether Netty's async DNS resolver is used for account authentication.
2019-03-30 17:09:06 +01:00
+ *
+ * @return whether Netty's async DNS resolver is used for account authentication.
2017-07-26 19:52:48 +02:00
+ */
+ boolean isUseNettyDnsResolver();
+
// Throttling options
/**
diff --git a/proxy/pom.xml b/proxy/pom.xml
2023-09-21 12:33:23 +02:00
index c0a8ae4c..342551a6 100644
2017-07-26 19:52:48 +02:00
--- a/proxy/pom.xml
+++ b/proxy/pom.xml
2023-03-15 19:37:00 +01:00
@@ -34,6 +34,18 @@
<artifactId>netty-codec-http</artifactId>
2017-07-26 19:52:48 +02:00
<scope>compile</scope>
</dependency>
+ <!-- Waterfall Start - add Netty DNS resolver -->
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-resolver-dns</artifactId>
+ <scope>compile</scope>
+ </dependency>
2021-04-12 08:37:52 +02:00
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-resolver-dns-native-macos</artifactId>
+ <classifier>osx-x86_64</classifier>
+ </dependency>
2017-07-26 19:52:48 +02:00
+ <!-- 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
2019-03-30 19:01:17 +01:00
index 111404fb..ef44d334 100644
2017-07-26 19:52:48 +02:00
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
2019-03-30 19:01:17 +01:00
@@ -15,6 +15,12 @@ public class WaterfallConfiguration extends Configuration {
2018-07-22 18:40:31 +02:00
*/
2017-07-26 19:52:48 +02:00
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
2019-03-30 19:01:17 +01:00
@@ -35,6 +41,7 @@ public class WaterfallConfiguration extends Configuration {
YamlConfig config = new YamlConfig(new File("waterfall.yml"));
2018-07-22 18:40:31 +02:00
config.load(false); // Load, but no permissions
2017-07-26 19:52:48 +02:00
gameVersion = config.getString("game_version", "").isEmpty() ? Joiner.on(", ").join(ProtocolConstants.SUPPORTED_VERSIONS) : config.getString("game_version", "");
+ useNettyDnsResolver = config.getBoolean("use_netty_dns_resolver", useNettyDnsResolver);
2018-07-22 18:40:31 +02:00
// Throttling options
tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
2018-10-06 20:54:52 +02:00
disableModernTabLimiter = config.getBoolean("disable_modern_tab_limiter", disableModernTabLimiter);
2019-03-30 19:01:17 +01:00
@@ -45,6 +52,11 @@ public class WaterfallConfiguration extends Configuration {
2018-07-22 18:40:31 +02:00
return gameVersion;
2017-07-26 19:52:48 +02:00
}
2018-07-22 18:40:31 +02:00
+ @Override
+ public boolean isUseNettyDnsResolver() {
+ return useNettyDnsResolver;
+ }
+
2017-07-26 19:52:48 +02:00
@Override
2018-07-22 18:40:31 +02:00
public int getTabThrottle() {
return tabThrottle;
2017-07-26 19:52:48 +02:00
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
2020-01-21 18:36:22 +01:00
index e0c52f21..37337429 100644
2017-07-26 19:52:48 +02:00
--- 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()
{
2020-01-21 18:36:22 +01:00
@@ -92,7 +98,40 @@ public class HttpClient
2017-07-26 19:52:48 +02:00
}
};
2020-01-21 18:36:22 +01:00
+
2017-07-26 19:52:48 +02:00
+ // 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);
2020-01-21 18:36:22 +01:00
+ new Bootstrap().channel( PipelineUtils.getChannel( null ) ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
2017-07-26 19:52:48 +02:00
+ 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 );
+ }
2020-01-21 18:36:22 +01:00
new Bootstrap().channel( PipelineUtils.getChannel( null ) ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
2017-07-26 19:52:48 +02:00
option( ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT ).remoteAddress( inetHost, port ).connect().addListener( future );
}
+ // Waterfall End
}
--
2023-09-21 12:33:23 +02:00
2.42.0
2017-07-26 19:52:48 +02:00