Update to Netty CR6

This commit is contained in:
md_5 2013-06-27 10:27:04 +10:00
parent 7bfc4bf819
commit 3e816f628b
6 changed files with 51 additions and 27 deletions

View File

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

View File

@ -1,6 +1,7 @@
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;
@ -31,7 +32,7 @@ public class CipherBase
}
}
protected void cipher(ByteBuf in, ByteBuf out) throws ShortBufferException
private byte[] bufToByte(ByteBuf in)
{
byte[] heapIn = heapInLocal.get();
int readableBytes = in.readableBytes();
@ -41,6 +42,24 @@ public class CipherBase
heapInLocal.set( heapIn );
}
in.readBytes( heapIn, 0, readableBytes );
return heapIn;
}
protected ByteBuf cipher(ChannelHandlerContext ctx, ByteBuf in) throws ShortBufferException
{
int readableBytes = in.readableBytes();
byte[] heapIn = bufToByte( in );
ByteBuf heapOut = ctx.alloc().heapBuffer( cipher.getOutputSize( readableBytes ) );
heapOut.writerIndex( cipher.update( heapIn, 0, readableBytes, heapOut.array(), heapOut.arrayOffset() ));
return heapOut;
}
protected void cipher(ByteBuf in, ByteBuf out) throws ShortBufferException
{
int readableBytes = in.readableBytes();
byte[] heapIn = bufToByte( in );
byte[] heapOut = heapOutLocal.get();
int outputSize = cipher.getOutputSize( readableBytes );

View File

@ -2,10 +2,11 @@ package net.md_5.bungee.netty;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToByteDecoder;
import io.netty.channel.MessageList;
import io.netty.handler.codec.MessageToMessageDecoder;
import javax.crypto.Cipher;
public class CipherDecoder extends ByteToByteDecoder
public class CipherDecoder extends MessageToMessageDecoder<ByteBuf>
{
private final CipherBase cipher;
@ -16,8 +17,8 @@ public class CipherDecoder extends ByteToByteDecoder
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, MessageList<Object> out) throws Exception
{
cipher.cipher( in, out );
out.add( cipher.cipher( ctx, msg ) );
}
}

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.ByteToByteEncoder;
import io.netty.handler.codec.MessageToByteEncoder;
import javax.crypto.Cipher;
public class CipherEncoder extends ByteToByteEncoder
public class CipherEncoder extends MessageToByteEncoder<ByteBuf>
{
private final CipherBase cipher;

View File

@ -2,7 +2,8 @@ package net.md_5.bungee.netty;
import com.google.common.base.Preconditions;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.MessageList;
import io.netty.handler.timeout.ReadTimeoutException;
import java.io.IOException;
import java.util.logging.Level;
@ -16,7 +17,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 ChannelInboundMessageHandlerAdapter<Object>
public class HandlerBoss extends ChannelInboundHandlerAdapter
{
private ChannelWrapper channel;
@ -58,7 +59,9 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
}
@Override
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception
{
for ( Object msg : msgs )
{
if ( handler != null && ctx.channel().isActive() )
{
@ -82,6 +85,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
}
}
}
}
@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, MessageBuf<Object> out) throws Exception
protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageList<Object> out) throws Exception
{
// While we have enough data
while ( true )