mirror of
https://github.com/PaperMC/Waterfall.git
synced 2025-02-26 08:41:28 +01:00
148 lines
8.1 KiB
Diff
148 lines
8.1 KiB
Diff
From a2c2ea6ec72b2dfd0dac26da6afabd28658b0c3b Mon Sep 17 00:00:00 2001
|
|
From: Janmm14 <gitconfig1@janmm14.de>
|
|
Date: Mon, 21 Jun 2021 23:43:39 +0200
|
|
Subject: [PATCH] Replace reflection inside netty with ChannelFactory.
|
|
|
|
Thanks for pointing it out @MrIvanPlays
|
|
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
|
index 27988fd5..2222791d 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
|
@@ -377,7 +377,7 @@ public class BungeeCord extends ProxyServer
|
|
}
|
|
};
|
|
new ServerBootstrap()
|
|
- .channel( PipelineUtils.getServerChannel( info.getSocketAddress() ) )
|
|
+ .channelFactory( PipelineUtils.getServerChannelFactory( info.getSocketAddress() ) ) // Waterfall - netty reflection -> factory
|
|
.option( ChannelOption.SO_REUSEADDR, true ) // TODO: Move this elsewhere!
|
|
.childAttr( PipelineUtils.LISTENER, info )
|
|
.childHandler( unsafe().getFrontendChannelInitializer().getChannelInitializer() )
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
|
|
index 0d24f1eb..0ce7b343 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
|
|
@@ -184,7 +184,7 @@ public class BungeeServerInfo implements ServerInfo
|
|
}
|
|
};
|
|
new Bootstrap()
|
|
- .channel( PipelineUtils.getChannel( socketAddress ) )
|
|
+ .channelFactory( PipelineUtils.getChannelFactory( socketAddress ) ) // Waterfall - netty reflection -> factory
|
|
.group( BungeeCord.getInstance().workerEventLoopGroup )
|
|
.handler( ProxyServer.getInstance().unsafe().getServerInfoChannelInitializer().getChannelInitializer() )
|
|
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, BungeeCord.getInstance().getConfig().getRemotePingTimeout() )
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
index 8c8fc7a6..867c4d4d 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
@@ -417,7 +417,7 @@ public final class UserConnection implements ProxiedPlayer
|
|
}
|
|
};
|
|
Bootstrap b = new Bootstrap()
|
|
- .channel( PipelineUtils.getChannel( target.getAddress() ) )
|
|
+ .channelFactory( PipelineUtils.getChannelFactory( target.getAddress() ) ) // Waterfall - netty reflection -> factory
|
|
.group( ch.getHandle().eventLoop() )
|
|
.handler( bungee.unsafe().getBackendChannelInitializer().getChannelInitializer() )
|
|
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, request.getConnectTimeout() )
|
|
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 37337429..c3683c30 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
|
|
@@ -111,7 +111,8 @@ public class HttpClient
|
|
|
|
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( null ) ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
|
|
+ // Waterfall - netty reflection -> factory
|
|
+ new Bootstrap().channelFactory( PipelineUtils.getChannelFactory( null ) ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
|
|
option( ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT ).resolver(dnsResolverGroup).remoteAddress( address ).connect().addListener( future );
|
|
}
|
|
|
|
@@ -130,7 +131,8 @@ public class HttpClient
|
|
}
|
|
addressCache.put( uri.getHost(), inetHost );
|
|
}
|
|
- new Bootstrap().channel( PipelineUtils.getChannel( null ) ).group( eventLoop ).handler( new HttpInitializer( callback, ssl, uri.getHost(), port ) ).
|
|
+ // Waterfall - netty reflection -> factory
|
|
+ new Bootstrap().channelFactory( PipelineUtils.getChannelFactory( null ) ).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 15f853a5..b318deab 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
|
|
@@ -5,6 +5,8 @@ import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
|
|
import io.netty.buffer.PooledByteBufAllocator;
|
|
import io.netty.channel.Channel;
|
|
import io.netty.channel.ChannelException;
|
|
+import io.netty.channel.ChannelFactory;
|
|
+import io.netty.channel.ChannelInitializer;
|
|
import io.netty.channel.ChannelOption;
|
|
import io.netty.channel.EventLoopGroup;
|
|
import io.netty.channel.ServerChannel;
|
|
@@ -146,6 +148,12 @@ public class PipelineUtils
|
|
|
|
private static boolean epoll;
|
|
private static boolean io_uring;
|
|
+ // Waterfall start: netty reflection -> factory
|
|
+ private static final ChannelFactory<? extends ServerChannel> serverChannelFactory;
|
|
+ private static final ChannelFactory<? extends ServerChannel> serverChannelDomainFactory;
|
|
+ private static final ChannelFactory<? extends Channel> channelFactory;
|
|
+ private static final ChannelFactory<? extends Channel> channelDomainFactory;
|
|
+ // Waterfall end
|
|
|
|
static
|
|
{
|
|
@@ -178,6 +186,12 @@ public class PipelineUtils
|
|
}
|
|
|
|
setChannelInitializerHolders();
|
|
+ // Waterfall start: netty reflection -> factory
|
|
+ serverChannelFactory = io_uring ? IOUringServerSocketChannel::new : epoll ? EpollServerSocketChannel::new : NioServerSocketChannel::new;
|
|
+ serverChannelDomainFactory = io_uring ? IOUringServerSocketChannel::new : epoll ? EpollServerDomainSocketChannel::new : null;
|
|
+ channelFactory = io_uring ? IOUringSocketChannel::new : epoll ? EpollSocketChannel::new : NioSocketChannel::new;
|
|
+ channelDomainFactory = io_uring ? IOUringSocketChannel::new : epoll ? EpollDomainSocketChannel::new : null;
|
|
+ // Waterfall end
|
|
}
|
|
|
|
public static EventLoopGroup newEventLoopGroup(int threads, ThreadFactory factory)
|
|
@@ -209,6 +223,34 @@ public class PipelineUtils
|
|
return io_uring ? IOUringSocketChannel.class : epoll ? EpollSocketChannel.class : NioSocketChannel.class;
|
|
}
|
|
|
|
+ // Waterfall start: netty reflection -> factory
|
|
+ public static ChannelFactory<? extends ServerChannel> getServerChannelFactory(SocketAddress address)
|
|
+ {
|
|
+ if ( address instanceof DomainSocketAddress )
|
|
+ {
|
|
+ ChannelFactory<? extends ServerChannel> factory = PipelineUtils.serverChannelDomainFactory;
|
|
+ Preconditions.checkState( factory != null, "Epoll required to have UNIX sockets" );
|
|
+
|
|
+ return factory;
|
|
+ }
|
|
+
|
|
+ return serverChannelFactory;
|
|
+ }
|
|
+
|
|
+ public static ChannelFactory<? extends Channel> getChannelFactory(SocketAddress address)
|
|
+ {
|
|
+ if ( address instanceof DomainSocketAddress )
|
|
+ {
|
|
+ ChannelFactory<? extends Channel> factory = PipelineUtils.channelDomainFactory;
|
|
+ Preconditions.checkState( factory != null, "Epoll required to have UNIX sockets" );
|
|
+
|
|
+ return factory;
|
|
+ }
|
|
+
|
|
+ return channelFactory;
|
|
+ }
|
|
+ // Waterfall end
|
|
+
|
|
public static Class<? extends DatagramChannel> getDatagramChannel()
|
|
{
|
|
return io_uring ? IOUringDatagramChannel.class : epoll ? EpollDatagramChannel.class : NioDatagramChannel.class;
|
|
--
|
|
2.47.1.windows.2
|
|
|