Update to Netty CR6
This commit is contained in:
parent
7bfc4bf819
commit
3e816f628b
2
pom.xml
2
pom.xml
@ -59,7 +59,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<build.number>unknown</build.number>
|
<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>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.md_5.bungee.netty;
|
package net.md_5.bungee.netty;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
import lombok.AccessLevel;
|
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();
|
byte[] heapIn = heapInLocal.get();
|
||||||
int readableBytes = in.readableBytes();
|
int readableBytes = in.readableBytes();
|
||||||
@ -41,6 +42,24 @@ public class CipherBase
|
|||||||
heapInLocal.set( heapIn );
|
heapInLocal.set( heapIn );
|
||||||
}
|
}
|
||||||
in.readBytes( heapIn, 0, readableBytes );
|
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();
|
byte[] heapOut = heapOutLocal.get();
|
||||||
int outputSize = cipher.getOutputSize( readableBytes );
|
int outputSize = cipher.getOutputSize( readableBytes );
|
||||||
|
@ -2,10 +2,11 @@ package net.md_5.bungee.netty;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
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;
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
public class CipherDecoder extends ByteToByteDecoder
|
public class CipherDecoder extends MessageToMessageDecoder<ByteBuf>
|
||||||
{
|
{
|
||||||
|
|
||||||
private final CipherBase cipher;
|
private final CipherBase cipher;
|
||||||
@ -16,8 +17,8 @@ public class CipherDecoder extends ByteToByteDecoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package net.md_5.bungee.netty;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
public class CipherEncoder extends ByteToByteEncoder
|
public class CipherEncoder extends MessageToByteEncoder<ByteBuf>
|
||||||
{
|
{
|
||||||
|
|
||||||
private final CipherBase cipher;
|
private final CipherBase cipher;
|
||||||
|
@ -2,7 +2,8 @@ package net.md_5.bungee.netty;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
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 io.netty.handler.timeout.ReadTimeoutException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
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
|
* channels to maintain simple states, and only call the required, adapted
|
||||||
* methods when the channel is connected.
|
* methods when the channel is connected.
|
||||||
*/
|
*/
|
||||||
public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
|
public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||||
{
|
{
|
||||||
|
|
||||||
private ChannelWrapper channel;
|
private ChannelWrapper channel;
|
||||||
@ -58,7 +59,9 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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() )
|
if ( handler != null && ctx.channel().isActive() )
|
||||||
{
|
{
|
||||||
@ -82,6 +85,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.md_5.bungee.netty;
|
package net.md_5.bungee.netty;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.MessageBuf;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.MessageList;
|
||||||
import io.netty.handler.codec.ReplayingDecoder;
|
import io.netty.handler.codec.ReplayingDecoder;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -28,7 +28,7 @@ public class PacketDecoder extends ReplayingDecoder<Void>
|
|||||||
private Protocol protocol;
|
private Protocol protocol;
|
||||||
|
|
||||||
@Override
|
@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 we have enough data
|
||||||
while ( true )
|
while ( true )
|
||||||
|
Loading…
Reference in New Issue
Block a user