Waterfall/BungeeCord-Patches/0040-Use-async-Netty-DNS-resolver.patch
2017-06-21 22:19:45 +01:00

112 lines
4.9 KiB
Diff

From 4e5f8b6986efb9ca27fb5662c63869d82dfaf601 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 85b9df7d..90dd3fa4 100644
--- a/proxy/pom.xml
+++ b/proxy/pom.xml
@@ -35,6 +35,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 2feb4d66..3db36399 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.DefaultDnsServerAddressStreamProvider.INSTANCE);
+ // 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 f6a10e77..ddf598ef 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.13.0