Waterfall/BungeeCord-Patches/0064-Replace-reflection-inside-netty-with-ChannelFactory.patch
Shane Freeder 77a8bd1767 Updated Upstream (BungeeCord)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

BungeeCord Changes:
5a1e342e Minecraft 1.20.2 support
d9bbdc32 Add Java 21 compilation support
cfe00fa4 #3490: Add ComponentBuilder#build() and ComponentSerializer#deserialize()
d68ebd1e Minecraft 1.20.2-rc1 support
a7cd79eb #3516: Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.5.0 to 3.6.0
9e83ee6f #3508: Use same compression threshold checks as Vanilla
7c81d917 #3513: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.4.0 to 3.4.1
5b126b7f Fix javadoc plugin version in non-dist builds
9fe7d21f #3510: Bump actions/checkout from 3 to 4
94ea0271 #3505: Bump io.netty:netty-bom from 4.1.96.Final to 4.1.97.Final
3af672d2 #3504: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.3.0 to 3.4.0
0dd7b984 Bump version to 1.20-R0.2-SNAPSHOT
a793692a Release 1.20-R0.1
23fb8382 #3493: Bump io.netty:netty-bom from 4.1.95.Final to 4.1.96.Final
2d6d89d6 #3492: Bump io.netty:netty-bom from 4.1.94.Final to 4.1.95.Final
0199cb90 #3489: Add command string length limit when decoding ClientCommand
958cef50 #3488: Bump scriptus from 0.4.1 to 0.5.0
9f5ace90 #3418: Add tab completion for bungee command names in pre-1.13 versions
3a6e2631 #3479: Bump netty-bom from 4.1.93.Final to 4.1.94.Final
c7adcf9f Disable maven enforcer for now
da3616e6 SPIGOT-7400: Downgrade maven-resolver due to issues resolving certain depends
b371fe67 #3478: Bump maven-shade-plugin from 3.4.1 to 3.5.0
6324c7d5 #3401: Only synchronize necessary parts of the BungeeServerInfo#sendData method
6263fe28 #3426: Made find command output hover and clickable
9a7617f9 #3475: Add KickPlayerRaw channel
9a71358d #3439: Add GetPlayerServer bungee plugin message subchannel
a96a2e80 #3437: Remove unused enum in ServerConnector and add color to exception message
2023-09-21 18:32:26 +01:00

147 lines
7.8 KiB
Diff

From 1dc384718469865083289a3c4239082c5a68f9ce 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 3a86fac8..a7091ab6 100644
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
@@ -358,7 +358,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( PipelineUtils.SERVER_CHILD )
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 377df7ec..8f531f85 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( PipelineUtils.BASE_SERVERSIDE )
.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 fb08c080..96f4d017 100644
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
@@ -387,7 +387,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( initializer )
.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 af65e192..6a045d16 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,7 @@ 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;
@@ -119,6 +120,12 @@ public class PipelineUtils
public static final String LEGACY_KICKER = "legacy-kick";
private static boolean epoll;
+ // 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
{
@@ -134,6 +141,12 @@ public class PipelineUtils
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Epoll is not working, falling back to NIO: {0}", Util.exception( Epoll.unavailabilityCause() ) );
}
}
+ // Waterfall start: netty reflection -> factory
+ serverChannelFactory = epoll ? EpollServerSocketChannel::new : NioServerSocketChannel::new;
+ serverChannelDomainFactory = epoll ? EpollServerDomainSocketChannel::new : null;
+ channelFactory = epoll ? EpollSocketChannel::new : NioSocketChannel::new;
+ channelDomainFactory = epoll ? EpollDomainSocketChannel::new : null;
+ // Waterfall end
}
public static EventLoopGroup newEventLoopGroup(int threads, ThreadFactory factory)
@@ -165,6 +178,34 @@ public class PipelineUtils
return 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 epoll ? EpollDatagramChannel.class : NioDatagramChannel.class;
--
2.42.0