diff --git a/pom.xml b/pom.xml index e944a4aa..1623896c 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ unknown - 4.0.0.CR5 + 4.0.0.CR1 UTF-8 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 609e6674..bab6868e 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -88,7 +88,7 @@ public class BungeeCord extends ProxyServer * Thread pools. */ public final ScheduledThreadPoolExecutor executors = new BungeeThreadPool( new ThreadFactoryBuilder().setNameFormat( "Bungee Pool Thread #%1$d" ).build() ); - public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() ); + public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() ); /** * locations.yml save thread. */ diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 44bc56df..a2d00532 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -37,7 +37,6 @@ import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.CipherEncoder; import net.md_5.bungee.netty.PacketDecoder; import net.md_5.bungee.netty.PacketHandler; -import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.Forge; import net.md_5.bungee.protocol.packet.DefinedPacket; import net.md_5.bungee.protocol.packet.Packet1Login; @@ -175,7 +174,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection sharedKey = EncryptionUtil.getSecret( encryptResponse, request ); Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, sharedKey ); - ch.getHandle().pipeline().addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) ); + ch.getHandle().pipeline().addBefore( "decoder", "decrypt", new CipherDecoder( decrypt ) ); if ( BungeeCord.getInstance().config.isOnlineMode() ) { @@ -248,7 +247,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection try { Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey ); - ch.getHandle().pipeline().addBefore( PipelineUtils.DECRYPT_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); + ch.getHandle().pipeline().addBefore( "decoder", "encrypt", new CipherEncoder( encrypt ) ); } catch ( GeneralSecurityException ex ) { disconnect( "Cipher error: " + Util.exception( ex ) ); diff --git a/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java b/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java index e571d1b3..f5999cdc 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java @@ -1,7 +1,6 @@ package net.md_5.bungee.netty; import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; import javax.crypto.Cipher; import javax.crypto.ShortBufferException; import lombok.AccessLevel; @@ -52,21 +51,4 @@ public class CipherBase } out.writeBytes( heapOut, 0, cipher.update( heapIn, 0, readableBytes, heapOut ) ); } - - protected ByteBuf cipher(ChannelHandlerContext ctx, ByteBuf in) throws ShortBufferException - { - byte[] heapIn = heapInLocal.get(); - int readableBytes = in.readableBytes(); - if ( heapIn.length < readableBytes ) - { - heapIn = new byte[ readableBytes ]; - heapInLocal.set( heapIn ); - } - in.readBytes( heapIn, 0, readableBytes ); - - ByteBuf out = ctx.alloc().heapBuffer( cipher.getOutputSize( readableBytes ) ); - out.writerIndex( cipher.update( heapIn, 0, readableBytes, out.array(), out.arrayOffset() ) ); - - return out; - } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java b/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java index 37b629a1..cc4055b3 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java @@ -2,11 +2,10 @@ package net.md_5.bungee.netty; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.MessageList; -import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.ByteToByteDecoder; import javax.crypto.Cipher; -public class CipherDecoder extends ByteToMessageDecoder +public class CipherDecoder extends ByteToByteDecoder { private final CipherBase cipher; @@ -17,8 +16,8 @@ public class CipherDecoder extends ByteToMessageDecoder } @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageList out) throws Exception + protected void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { - out.add( cipher.cipher( ctx, in ) ); + cipher.cipher( in, out ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/CipherEncoder.java b/proxy/src/main/java/net/md_5/bungee/netty/CipherEncoder.java index 75adea97..6d5232e3 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/CipherEncoder.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/CipherEncoder.java @@ -2,10 +2,10 @@ package net.md_5.bungee.netty; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; +import io.netty.handler.codec.ByteToByteEncoder; import javax.crypto.Cipher; -public class CipherEncoder extends MessageToByteEncoder +public class CipherEncoder extends ByteToByteEncoder { private final CipherBase cipher; @@ -16,8 +16,8 @@ public class CipherEncoder extends MessageToByteEncoder } @Override - protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception + protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { - cipher.cipher( msg, out ); + cipher.cipher( in, out ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index c3ed29a8..c321044c 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -2,8 +2,7 @@ package net.md_5.bungee.netty; import com.google.common.base.Preconditions; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.channel.MessageList; +import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.handler.timeout.ReadTimeoutException; import java.io.IOException; import java.util.logging.Level; @@ -17,7 +16,7 @@ import net.md_5.bungee.connection.PingHandler; * channels to maintain simple states, and only call the required, adapted * methods when the channel is connected. */ -public class HandlerBoss extends ChannelInboundHandlerAdapter +public class HandlerBoss extends ChannelInboundMessageHandlerAdapter { private ChannelWrapper channel; @@ -59,30 +58,27 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter } @Override - public void messageReceived(ChannelHandlerContext ctx, MessageList msgs) throws Exception + public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { - for ( Object msg : msgs ) + if ( handler != null && ctx.channel().isActive() ) { - if ( handler != null && ctx.channel().isActive() ) + if ( msg instanceof PacketWrapper ) { - if ( msg instanceof PacketWrapper ) + boolean sendPacket = true; + try { - boolean sendPacket = true; - try - { - ( (PacketWrapper) msg ).packet.handle( handler ); - } catch ( CancelSendSignal ex ) - { - sendPacket = false; - } - if ( sendPacket ) - { - handler.handle( ( (PacketWrapper) msg ).buf ); - } - } else + ( (PacketWrapper) msg ).packet.handle( handler ); + } catch ( CancelSendSignal ex ) { - handler.handle( (byte[]) msg ); + sendPacket = false; } + if ( sendPacket ) + { + handler.handle( ( (PacketWrapper) msg ).buf ); + } + } else + { + handler.handle( (byte[]) msg ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/OutboundBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/OutboundBoss.java index f0e4771c..fcf9cf32 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/OutboundBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/OutboundBoss.java @@ -1,12 +1,19 @@ package net.md_5.bungee.netty; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelOutboundHandlerAdapter; +import io.netty.channel.ChannelOperationHandlerAdapter; +import io.netty.channel.ChannelPromise; import java.nio.channels.ClosedChannelException; -public class OutboundBoss extends ChannelOutboundHandlerAdapter +public class OutboundBoss extends ChannelOperationHandlerAdapter { + @Override + public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception + { + ctx.flush( promise ); + } + @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java index 6c4ef785..3f208951 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java @@ -1,8 +1,8 @@ package net.md_5.bungee.netty; import io.netty.buffer.ByteBuf; +import io.netty.buffer.MessageBuf; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.MessageList; import io.netty.handler.codec.ReplayingDecoder; import lombok.AllArgsConstructor; import lombok.Getter; @@ -28,7 +28,7 @@ public class PacketDecoder extends ReplayingDecoder private Protocol protocol; @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageList out) throws Exception + protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { // While we have enough data while ( true ) @@ -53,10 +53,10 @@ public class PacketDecoder extends ReplayingDecoder // Store our decoded message if ( packet != null ) { - out.add( new PacketWrapper( packet, buf ) ); + return( new PacketWrapper( packet, buf ) ); } else { - out.add( buf ); + return( buf ); } } } 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 c25724b6..5a209b6f 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 @@ -4,7 +4,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelException; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; -import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.bytes.ByteArrayEncoder; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.util.AttributeKey;