Back to CR1 we go. Deal with the issues.

This commit is contained in:
md_5 2013-06-19 07:36:40 +10:00
parent 22133bc8d2
commit a6ba661a32
10 changed files with 42 additions and 60 deletions

View File

@ -59,7 +59,7 @@
<properties>
<build.number>unknown</build.number>
<netty.version>4.0.0.CR5</netty.version>
<netty.version>4.0.0.CR1</netty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

View File

@ -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.
*/

View File

@ -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 ) );

View File

@ -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;
}
}

View File

@ -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<Object> out) throws Exception
protected void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
{
out.add( cipher.cipher( ctx, in ) );
cipher.cipher( in, out );
}
}

View File

@ -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<ByteBuf>
public class CipherEncoder extends ByteToByteEncoder
{
private final CipherBase cipher;
@ -16,8 +16,8 @@ public class CipherEncoder extends MessageToByteEncoder<ByteBuf>
}
@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 );
}
}

View File

@ -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<Object>
{
private ChannelWrapper channel;
@ -59,9 +58,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
}
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception
{
for ( Object msg : msgs )
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception
{
if ( handler != null && ctx.channel().isActive() )
{
@ -85,7 +82,6 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
}
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

View File

@ -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
{

View File

@ -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<Void>
private Protocol protocol;
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageList<Object> 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<Void>
// Store our decoded message
if ( packet != null )
{
out.add( new PacketWrapper( packet, buf ) );
return( new PacketWrapper( packet, buf ) );
} else
{
out.add( buf );
return( buf );
}
}
}

View File

@ -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;