Waterfall/BungeeCord-Patches/0040-Use-async-Netty-DNS-resolver.patch
2016-12-24 01:36:32 -05:00

112 lines
4.9 KiB
Diff

From 2a1f5297000df92b5acda072422f68137ae1d2a1 Mon Sep 17 00:00:00 2001
From: Tux <write@imaginarycode.com>
Date: Wed, 21 Dec 2016 03:13:03 -0500
Subject: [PATCH] Use async Netty DNS resolver
We no longer need to cache the address for the session server now.
diff --git a/proxy/pom.xml b/proxy/pom.xml
index 99d4628..180b78d 100644
--- a/proxy/pom.xml
+++ b/proxy/pom.xml
@@ -31,6 +31,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/net/md_5/bungee/http/HttpClient.java b/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java
index 2feb4d6..7e381f5 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
@@ -27,7 +27,11 @@ 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 - use async resolver from Netty
+ //private static final Cache<String, InetAddress> addressCache = CacheBuilder.newBuilder().expireAfterWrite( 1, TimeUnit.MINUTES ).build(); // Waterfall - remove cache
+ private static final io.netty.resolver.dns.DnsAddressResolverGroup dnsResolverGroup =
+ new io.netty.resolver.dns.DnsAddressResolverGroup(PipelineUtils.getDatagramChannel(), io.netty.resolver.dns.DnsServerAddresses.defaultAddresses());
+ // Waterfall End
@SuppressWarnings("UnusedAssignment")
public static void get(String url, EventLoop eventLoop, final Callback<String> callback)
@@ -57,19 +61,22 @@ 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: remove IP address cache
+ //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 );
+ //}
+ java.net.InetSocketAddress address = java.net.InetSocketAddress.createUnresolved(uri.getHost(), port);
+ // Waterfall End
ChannelFutureListener future = new ChannelFutureListener()
{
@@ -86,13 +93,13 @@ public class HttpClient
future.channel().writeAndFlush( request );
} else
{
- addressCache.invalidate( uri.getHost() );
+ // addressCache.invalidate( uri.getHost() ); // Waterfall - use async DNS resolver
callback.done( null, future.cause() );
}
}
};
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 );
+ option( ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT ).resolver(dnsResolverGroup).remoteAddress( address ).connect().addListener( future ); // Waterfall - use async DNS resolver
}
}
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 f6a10e7..ddf598e 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
@@ -103,7 +103,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.7.4