From 9ad90039746b35971c4ccbc4502b87f6ead0a2e0 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 8 Mar 2013 18:07:21 +1100 Subject: [PATCH] Tigthen access + javadocs on a few netty related classes. --- proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 7 ------- .../src/main/java/net/md_5/bungee/netty/CipherCodec.java | 7 +++++-- .../src/main/java/net/md_5/bungee/netty/HandlerBoss.java | 7 ++++++- .../main/java/net/md_5/bungee/netty/PacketDecoder.java | 8 ++++++++ 4 files changed, 19 insertions(+), 10 deletions(-) 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 4ffd581f..52127e97 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -4,19 +4,14 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelException; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; import io.netty.channel.MultithreadEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.handler.timeout.ReadTimeoutHandler; import net.md_5.bungee.config.Configuration; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetSocketAddress; -import java.net.Socket; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -44,8 +39,6 @@ import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.command.*; import net.md_5.bungee.config.YamlConfig; import net.md_5.bungee.netty.ChannelBootstrapper; -import net.md_5.bungee.netty.HandlerBoss; -import net.md_5.bungee.netty.PacketDecoder; import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.PacketFAPluginMessage; diff --git a/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java b/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java index b569e406..530b455e 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java @@ -8,8 +8,10 @@ import javax.crypto.ShortBufferException; /** * This class is a complete solution for encrypting and decoding bytes in a - * Netty stream. It takes two {@link BufferedBlockCipher} instances, used for - * encryption and decryption respectively. + * Netty stream. It takes two {@link Cipher} instances, used for encryption and + * decryption respectively. As newer Netty versions never use a heap + * {@link ByteBuf} for writing to the channel, this class will always create one + * for temporary usage. */ public class CipherCodec extends ByteToByteCodec { @@ -69,6 +71,7 @@ public class CipherCodec extends ByteToByteCodec { out.capacity( outputSize ); } + // TODO: Try and make this use out.nioBuffer() int processed = cipher.update( in.array(), in.arrayOffset() + in.readerIndex(), available, out.array(), out.arrayOffset() + out.writerIndex() ); in.readerIndex( in.readerIndex() + processed ); out.writerIndex( out.writerIndex() + processed ); 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 c404c92a..f57b53cb 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 @@ -7,7 +7,12 @@ import io.netty.channel.ChannelInboundMessageHandlerAdapter; import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.PacketHandler; -public class HandlerBoss extends ChannelInboundMessageHandlerAdapter +/** + * This class is a primitive wrapper for {@link PacketHandler} instances tied to + * channels to maintain simple states, and only call the required, adapted + * methods when the channel is connected. + */ +class HandlerBoss extends ChannelInboundMessageHandlerAdapter { private PacketHandler handler; 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 5dffe828..98f0b821 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 @@ -8,6 +8,14 @@ import lombok.Getter; import lombok.Setter; import net.md_5.bungee.protocol.netty.PacketReader; +/** + * This class will attempt to read a packet from {@link PacketReader}, with the + * specified {@link #protocol} before returning a new {@link ByteBuf} with the + * copied contents of all bytes read in this frame. + *

+ * It is based on {@link ReplayingDecoder} so that packets will only be returned + * when all needed data is present. + */ @AllArgsConstructor public class PacketDecoder extends ReplayingDecoder {