Optimize Channel Initialization

This commit is contained in:
LinsaFTW 2023-03-23 22:37:13 -03:00
parent 3a53e525cd
commit 5f48c85d6f

View File

@ -0,0 +1,83 @@
From 18f49182ce45a066df5a3cf10fb9cfc7d1c23eb3 Mon Sep 17 00:00:00 2001
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
Date: Thu, 23 Mar 2023 22:35:42 -0300
Subject: [PATCH] Optimize PipelineUtils
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 9aebc9e1..3bd25647 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
@@ -6,10 +6,12 @@ import dev._2lstudios.flamecord.FlameCord;
import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
+import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel;
import io.netty.channel.WriteBufferWaterMark;
@@ -50,7 +52,6 @@ import net.md_5.bungee.protocol.Varint21LengthFieldPrepender;
public class PipelineUtils
{
-
public static final AttributeKey<ListenerInfo> LISTENER = AttributeKey.newInstance( "ListerInfo" );
public static final ChannelInitializer<Channel> SERVER_CHILD = new ChannelInitializer<Channel>()
{
@@ -195,31 +196,39 @@ public class PipelineUtils
private static final int HIGH_MARK = Integer.getInteger( "net.md_5.bungee.high_mark", 2 << 20 ); // 2 mb
private static final WriteBufferWaterMark MARK = new WriteBufferWaterMark( LOW_MARK, HIGH_MARK );
+ // FlameCord start - Optimize PipelineUtils
+ private static ReadTimeoutHandler READ_TIMEOUT_HANDLER = null;
+ private static final Varint21FrameDecoder VARINT21_FRAME_DECODER = new Varint21FrameDecoder();
+
public static final class Base extends ChannelInitializer<Channel>
{
@Override
public void initChannel(Channel ch) throws Exception
{
+ ChannelPipeline pipeline = ch.pipeline();
+ ChannelConfig channelConfig = ch.config();
try
{
- ch.config().setOption( ChannelOption.IP_TOS, 0x18 );
+ channelConfig.setOption( ChannelOption.IP_TOS, 0x18 );
} catch ( ChannelException ex )
{
// IP_TOS is not supported (Windows XP / Windows Server 2003)
}
- ch.config().setOption( ChannelOption.TCP_NODELAY, true );
+ channelConfig.setOption( ChannelOption.TCP_NODELAY, true );
// FlameCord - TCP Fast Open
- ch.config().setOption( ChannelOption.TCP_FASTOPEN, FlameCord.getInstance().getFlameCordConfiguration().getTcpFastOpen() );
- ch.config().setAllocator( PooledByteBufAllocator.DEFAULT );
- ch.config().setWriteBufferWaterMark( MARK );
+ channelConfig.setOption( ChannelOption.TCP_FASTOPEN, FlameCord.getInstance().getFlameCordConfiguration().getTcpFastOpen() );
+ channelConfig.setAllocator( PooledByteBufAllocator.DEFAULT );
+ channelConfig.setWriteBufferWaterMark( MARK );
- ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
- ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
- ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );
+ pipeline.addLast( FRAME_DECODER, VARINT21_FRAME_DECODER );
+ if (READ_TIMEOUT_HANDLER == null) READ_TIMEOUT_HANDLER = new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS );
+ pipeline.addLast( TIMEOUT_HANDLER, READ_TIMEOUT_HANDLER );
+ pipeline.addLast( FRAME_PREPENDER, framePrepender );
- ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
+ pipeline.addLast( BOSS_HANDLER, new HandlerBoss() );
}
+ // FlameCord end - Optimize PipelineUtils
// FlameCord - Close on exception caught
@Override
--
2.37.3.windows.1