From 61545f02352d9b516ce03dd9a331750f21524caf Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 22 Jul 2015 10:35:45 +0200 Subject: [PATCH] Code cleanup. Removed unnecessary methods from Connection interface --- .../network/connection/Connection.java | 20 ------------------ .../network/connection/ConnectionImpl.java | 13 ++++++------ .../dorkbox/network/connection/EndPoint.java | 9 ++++---- .../network/connection/EndPointClient.java | 2 +- .../KryoCryptoSerializationManager.java | 12 +++++------ .../connection/RegistrationWrapper.java | 4 ++-- .../connection/registration/MetaChannel.java | 4 ++-- .../local/RegistrationLocalHandlerClient.java | 4 ++-- .../local/RegistrationLocalHandlerServer.java | 4 ++-- .../RegistrationRemoteHandlerServerUDP.java | 5 ++--- .../dorkbox/network/pipeline/KryoDecoder.java | 14 ++++++------- .../network/pipeline/KryoDecoderCrypto.java | 17 +++++---------- .../dorkbox/network/pipeline/KryoEncoder.java | 10 ++++----- .../network/pipeline/KryoEncoderCrypto.java | 17 +++++---------- .../network/pipeline/udp/KryoDecoderUdp.java | 10 ++++----- .../pipeline/udp/KryoDecoderUdpCrypto.java | 21 +++++++------------ .../network/pipeline/udp/KryoEncoderUdp.java | 12 +++++------ .../pipeline/udp/KryoEncoderUdpCrypto.java | 17 +++++---------- .../util/CryptoSerializationManager.java | 10 ++++----- 19 files changed, 77 insertions(+), 128 deletions(-) diff --git a/Dorkbox-Network/src/dorkbox/network/connection/Connection.java b/Dorkbox-Network/src/dorkbox/network/connection/Connection.java index 170f205f..67e49807 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/Connection.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/Connection.java @@ -15,8 +15,6 @@ */ package dorkbox.network.connection; -import org.bouncycastle.crypto.params.ParametersWithIV; - import dorkbox.network.connection.bridge.ConnectionBridge; import dorkbox.network.connection.idle.IdleBridge; import dorkbox.network.connection.idle.IdleSender; @@ -27,24 +25,6 @@ import dorkbox.util.exceptions.NetException; @SuppressWarnings("unused") public interface Connection { - /** - * Initialize the connection with any extra info that is needed but was unavailable at the channel construction. - *

- * This happens BEFORE prep. - */ - void init(Bridge bridge); - - /** - * Prepare the channel wrapper, since it doesn't have access to certain fields during it's initialization. - *

- * This happens AFTER init. - */ - void prep(); - - /** - * @return the AES key/IV, etc associated with this connection - */ - ParametersWithIV getCryptoParameters(); /** * Has the remote ECC public key changed. This can be useful if specific actions are necessary when the key has changed. diff --git a/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java b/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java index 5cb6e320..4804d86a 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java @@ -103,9 +103,9 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements Connection, /** * Initialize the connection with any extra info that is needed but was unavailable at the channel construction. + *

+ * This happens BEFORE prep. */ - @Override - public void init(final Bridge bridge) { if (bridge != null) { this.sessionManager = bridge.sessionManager; @@ -126,10 +126,10 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements Connection, } /** - * Prepare the channel wrapper, since it doesn't have access to certain fields during it's construction. + * Prepare the channel wrapper, since it doesn't have access to certain fields during it's initialization. + *

+ * This happens AFTER init. */ - @Override - public void prep() { if (this.channelWrapper != null) { this.channelWrapper.init(); @@ -140,8 +140,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements Connection, /** * @return the AES key/IV, etc associated with this connection */ - @Override - public final + final ParametersWithIV getCryptoParameters() { return this.channelWrapper.cryptoParameters(); } diff --git a/Dorkbox-Network/src/dorkbox/network/connection/EndPoint.java b/Dorkbox-Network/src/dorkbox/network/connection/EndPoint.java index 2215db46..2ea49e8d 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/EndPoint.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/EndPoint.java @@ -77,7 +77,6 @@ class EndPoint { // TODO: maybe some sort of STUN-like connection keep-alive?? - // TODO: do we really need this? Maybe? public static final String LOCAL_CHANNEL = "local_channel"; protected static final String shutdownHookName = "::SHUTDOWN_HOOK::"; protected static final String stopTreadName = "::STOP_THREAD::"; @@ -417,14 +416,14 @@ class EndPoint { /** * This method allows the connections used by the client/server to be subclassed (custom implementations). *

- * As this is for the network stack, the new connection MUST subclass {@link Connection} + * As this is for the network stack, the new connection MUST subclass {@link ConnectionImpl} *

* The parameters are ALL NULL when getting the base class, as this instance is just thrown away. * * @return a new network connection */ public - Connection newConnection(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) { + ConnectionImpl newConnection(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) { return new ConnectionImpl(logger, endPoint, rmiBridge); } @@ -437,7 +436,7 @@ class EndPoint { */ protected final Connection connection0(MetaChannel metaChannel) { - Connection connection; + ConnectionImpl connection; RmiBridge rmiBridge = null; if (metaChannel != null && rmiEnabled) { @@ -490,7 +489,7 @@ class EndPoint { *

* Only the CLIENT injects in front of this) */ - void connectionConnected0(Connection connection) { + void connectionConnected0(ConnectionImpl connection) { this.isConnected.set(true); // prep the channel wrapper diff --git a/Dorkbox-Network/src/dorkbox/network/connection/EndPointClient.java b/Dorkbox-Network/src/dorkbox/network/connection/EndPointClient.java index a5c52e19..a4ffd850 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/EndPointClient.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/EndPointClient.java @@ -131,7 +131,7 @@ class EndPointClient extends EndPoint implements Runnable { */ @Override final - void connectionConnected0(Connection connection) { + void connectionConnected0(ConnectionImpl connection) { // invokes the listener.connection() method, and initialize the connection channels with whatever extra info they might need. super.connectionConnected0(connection); diff --git a/Dorkbox-Network/src/dorkbox/network/connection/KryoCryptoSerializationManager.java b/Dorkbox-Network/src/dorkbox/network/connection/KryoCryptoSerializationManager.java index 087a4732..6aae8e96 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/KryoCryptoSerializationManager.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/KryoCryptoSerializationManager.java @@ -737,7 +737,7 @@ class KryoCryptoSerializationManager implements CryptoSerializationManager { */ @Override public final - void writeWithCryptoTcp(Connection connection, ByteBuf buffer, Object message) { + void writeWithCryptoTcp(ConnectionImpl connection, ByteBuf buffer, Object message) { if (connection == null) { throw new NetException("Unable to perform crypto when NO network connection!"); } @@ -752,7 +752,7 @@ class KryoCryptoSerializationManager implements CryptoSerializationManager { */ @Override public final - void writeWithCryptoUdp(Connection connection, ByteBuf buffer, Object message) { + void writeWithCryptoUdp(ConnectionImpl connection, ByteBuf buffer, Object message) { if (connection == null) { throw new NetException("Unable to perform crypto when NO network connection!"); } @@ -770,7 +770,7 @@ class KryoCryptoSerializationManager implements CryptoSerializationManager { */ @Override public final - Object readWithCryptoTcp(Connection connection, ByteBuf buffer, int length) { + Object readWithCryptoTcp(ConnectionImpl connection, ByteBuf buffer, int length) { if (connection == null) { throw new NetException("Unable to perform crypto when NO network connection!"); } @@ -788,7 +788,7 @@ class KryoCryptoSerializationManager implements CryptoSerializationManager { */ @Override public final - Object readWithCryptoUdp(Connection connection, ByteBuf buffer, int length) { + Object readWithCryptoUdp(ConnectionImpl connection, ByteBuf buffer, int length) { if (connection == null) { throw new NetException("Unable to perform crypto when NO network connection!"); } @@ -801,7 +801,7 @@ class KryoCryptoSerializationManager implements CryptoSerializationManager { */ @SuppressWarnings("unchecked") private - void write0(final Connection connection, final ByteBuf buffer, final Object message, final boolean doCrypto) { + void write0(final ConnectionImpl connection, final ByteBuf buffer, final Object message, final boolean doCrypto) { final KryoExtra kryo = (KryoExtra) this.pool.takeUninterruptibly(); Logger logger2 = logger; @@ -911,7 +911,7 @@ class KryoCryptoSerializationManager implements CryptoSerializationManager { */ @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) private - Object read0(final Connection connection, final ByteBuf buffer, final int length, final boolean doCrypto) { + Object read0(final ConnectionImpl connection, final ByteBuf buffer, final int length, final boolean doCrypto) { final KryoExtra kryo = (KryoExtra) this.pool.takeUninterruptibly(); Logger logger2 = logger; diff --git a/Dorkbox-Network/src/dorkbox/network/connection/RegistrationWrapper.java b/Dorkbox-Network/src/dorkbox/network/connection/RegistrationWrapper.java index d89f3d7f..cd323cfb 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/RegistrationWrapper.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/RegistrationWrapper.java @@ -18,9 +18,9 @@ package dorkbox.network.connection; import dorkbox.network.connection.registration.MetaChannel; import dorkbox.network.pipeline.KryoEncoder; import dorkbox.network.pipeline.KryoEncoderCrypto; -import dorkbox.util.exceptions.SecurityException; import dorkbox.util.collections.IntMap; import dorkbox.util.crypto.Crypto; +import dorkbox.util.exceptions.SecurityException; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.params.ECPublicKeyParameters; import org.slf4j.Logger; @@ -135,7 +135,7 @@ class RegistrationWrapper implements UdpServer { * to the pipeline are finished. */ public - void connectionConnected0(Connection networkConnection) { + void connectionConnected0(ConnectionImpl networkConnection) { this.endPoint.connectionConnected0(networkConnection); } diff --git a/Dorkbox-Network/src/dorkbox/network/connection/registration/MetaChannel.java b/Dorkbox-Network/src/dorkbox/network/connection/registration/MetaChannel.java index 3c26de8e..dba77339 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/registration/MetaChannel.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/registration/MetaChannel.java @@ -15,7 +15,7 @@ */ package dorkbox.network.connection.registration; -import dorkbox.network.connection.Connection; +import dorkbox.network.connection.ConnectionImpl; import io.netty.channel.Channel; import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org.bouncycastle.crypto.params.ECPublicKeyParameters; @@ -43,7 +43,7 @@ class MetaChannel { public Channel udtChannel = null; - public Connection connection; // only needed until the connection has been notified. + public ConnectionImpl connection; // only needed until the connection has been notified. public ECPublicKeyParameters publicKey; // used for ECC crypto + handshake on NETWORK (remote) connections. This is the remote public key. diff --git a/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerClient.java b/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerClient.java index 109750a4..b7c891f8 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerClient.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerClient.java @@ -15,7 +15,7 @@ */ package dorkbox.network.connection.registration.local; -import dorkbox.network.connection.Connection; +import dorkbox.network.connection.ConnectionImpl; import dorkbox.network.connection.RegistrationWrapper; import dorkbox.network.connection.registration.MetaChannel; import dorkbox.network.connection.registration.Registration; @@ -87,7 +87,7 @@ class RegistrationLocalHandlerClient extends RegistrationLocalHandler { // Event though a local channel is XOR with everything else, we still have to make the client clean up it's state. registrationWrapper.registerNextProtocol0(); - Connection connection = metaChannel.connection; + ConnectionImpl connection = metaChannel.connection; registrationWrapper.connectionConnected0(connection); } else { diff --git a/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerServer.java b/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerServer.java index 1e9e1845..9158fe95 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerServer.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/registration/local/RegistrationLocalHandlerServer.java @@ -15,7 +15,7 @@ */ package dorkbox.network.connection.registration.local; -import dorkbox.network.connection.Connection; +import dorkbox.network.connection.ConnectionImpl; import dorkbox.network.connection.RegistrationWrapper; import dorkbox.network.connection.registration.MetaChannel; import dorkbox.util.collections.IntMap; @@ -79,7 +79,7 @@ class RegistrationLocalHandlerServer extends RegistrationLocalHandler { logger2.trace("Sent registration"); } - Connection connection = null; + ConnectionImpl connection = null; try { IntMap channelMap = this.registrationWrapper.getAndLockChannelMap(); MetaChannel metaChannel = channelMap.remove(channel.hashCode()); diff --git a/Dorkbox-Network/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java b/Dorkbox-Network/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java index a715fed2..c46e379e 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java @@ -16,18 +16,17 @@ package dorkbox.network.connection.registration.remote; import dorkbox.network.Broadcast; -import dorkbox.network.connection.Connection; import dorkbox.network.connection.ConnectionImpl; import dorkbox.network.connection.RegistrationWrapper; import dorkbox.network.connection.registration.MetaChannel; import dorkbox.network.connection.registration.Registration; import dorkbox.network.connection.wrapper.UdpWrapper; import dorkbox.network.util.CryptoSerializationManager; -import dorkbox.util.exceptions.NetException; import dorkbox.util.bytes.OptimizeUtilsByteArray; import dorkbox.util.collections.IntMap; import dorkbox.util.collections.IntMap.Entries; import dorkbox.util.crypto.Crypto; +import dorkbox.util.exceptions.NetException; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -149,7 +148,7 @@ class RegistrationRemoteHandlerServerUDP extends MessageToMessageCodec { private static final int reservedLengthIndex = 4; - private final CryptoSerializationManager kryoWrapper; + private final CryptoSerializationManager serializationManager; private final OptimizeUtilsByteBuf optimize; public - KryoEncoder(CryptoSerializationManager kryoWrapper) { + KryoEncoder(CryptoSerializationManager serializationManager) { super(); - this.kryoWrapper = kryoWrapper; + this.serializationManager = serializationManager; this.optimize = OptimizeUtilsByteBuf.get(); } @@ -60,7 +60,7 @@ class KryoEncoder extends MessageToByteEncoder { out.writeInt(0); // put an int in, which is the same size as reservedLengthIndex try { - writeObject(this.kryoWrapper, ctx, msg, out); + writeObject(this.serializationManager, ctx, msg, out); // now set the frame (if it's TCP)! int length = out.readableBytes() - startIndex - diff --git a/Dorkbox-Network/src/dorkbox/network/pipeline/KryoEncoderCrypto.java b/Dorkbox-Network/src/dorkbox/network/pipeline/KryoEncoderCrypto.java index df104203..eedfb903 100644 --- a/Dorkbox-Network/src/dorkbox/network/pipeline/KryoEncoderCrypto.java +++ b/Dorkbox-Network/src/dorkbox/network/pipeline/KryoEncoderCrypto.java @@ -15,9 +15,8 @@ */ package dorkbox.network.pipeline; -import dorkbox.network.connection.Connection; +import dorkbox.network.connection.ConnectionImpl; import dorkbox.network.util.CryptoSerializationManager; -import dorkbox.util.exceptions.NetException; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler.Sharable; @@ -28,21 +27,15 @@ public class KryoEncoderCrypto extends KryoEncoder { public - KryoEncoderCrypto(CryptoSerializationManager kryoWrapper) { - super(kryoWrapper); + KryoEncoderCrypto(CryptoSerializationManager serializationManager) { + super(serializationManager); } @Override protected - void writeObject(CryptoSerializationManager kryoWrapper, ChannelHandlerContext ctx, Object msg, ByteBuf buffer) { + void writeObject(CryptoSerializationManager serializationManager, ChannelHandlerContext ctx, Object msg, ByteBuf buffer) { ChannelHandler last = ctx.pipeline() .last(); - if (last instanceof Connection) { - kryoWrapper.writeWithCryptoTcp((Connection) last, buffer, msg); - } - else { - // SHOULD NEVER HAPPEN! - throw new NetException("Tried to use kryo to WRITE an object with NO network connection (or wrong connection type!)!"); - } + serializationManager.writeWithCryptoTcp((ConnectionImpl) last, buffer, msg); } } diff --git a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java index 24971791..ffdd73c5 100644 --- a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java +++ b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java @@ -29,11 +29,11 @@ import java.util.List; public class KryoDecoderUdp extends MessageToMessageDecoder { - private final CryptoSerializationManager kryoWrapper; + private final CryptoSerializationManager serializationManager; public - KryoDecoderUdp(CryptoSerializationManager kryoWrapper) { - this.kryoWrapper = kryoWrapper; + KryoDecoderUdp(CryptoSerializationManager serializationManager) { + this.serializationManager = serializationManager; } @Override @@ -46,12 +46,12 @@ class KryoDecoderUdp extends MessageToMessageDecoder { // there is a REMOTE possibility that UDP traffic BEAT the TCP registration traffic, which means that THIS packet // COULD be encrypted! - if (kryoWrapper.isEncrypted(data)) { + if (serializationManager.isEncrypted(data)) { throw new NetException("Encrypted UDP packet received before registration complete. WHOOPS!"); } // no connection here because we haven't created one yet. When we do, we replace this handler with a new one. - Object read = kryoWrapper.read(data, data.writerIndex()); + Object read = serializationManager.read(data, data.writerIndex()); out.add(read); } } diff --git a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdpCrypto.java b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdpCrypto.java index 0ea6d4ca..165d7870 100644 --- a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdpCrypto.java +++ b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoDecoderUdpCrypto.java @@ -15,9 +15,8 @@ */ package dorkbox.network.pipeline.udp; -import dorkbox.network.connection.Connection; +import dorkbox.network.connection.ConnectionImpl; import dorkbox.network.util.CryptoSerializationManager; -import dorkbox.util.exceptions.NetException; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler.Sharable; @@ -31,11 +30,11 @@ import java.util.List; public class KryoDecoderUdpCrypto extends MessageToMessageDecoder { - private final CryptoSerializationManager kryoWrapper; + private final CryptoSerializationManager serializationManager; public - KryoDecoderUdpCrypto(CryptoSerializationManager kryoWrapper) { - this.kryoWrapper = kryoWrapper; + KryoDecoderUdpCrypto(CryptoSerializationManager serializationManager) { + this.serializationManager = serializationManager; } @Override @@ -44,14 +43,8 @@ class KryoDecoderUdpCrypto extends MessageToMessageDecoder { ChannelHandler last = ctx.pipeline() .last(); - if (last instanceof Connection) { - ByteBuf data = in.content(); - Object object = kryoWrapper.readWithCryptoUdp((Connection) last, data, data.readableBytes()); - out.add(object); - } - else { - // SHOULD NEVER HAPPEN! - throw new NetException("Tried to use kryo to READ an object with NO network connection!"); - } + ByteBuf data = in.content(); + Object object = serializationManager.readWithCryptoUdp((ConnectionImpl) last, data, data.readableBytes()); + out.add(object); } } diff --git a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdp.java b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdp.java index 76f9af4b..9cdcc40c 100644 --- a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdp.java +++ b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdp.java @@ -36,21 +36,21 @@ public class KryoEncoderUdp extends MessageToMessageEncoder { private static final int maxSize = EndPoint.udpMaxSize; - private final CryptoSerializationManager kryoWrapper; + private final CryptoSerializationManager serializationManager; public - KryoEncoderUdp(CryptoSerializationManager kryoWrapper) { + KryoEncoderUdp(CryptoSerializationManager serializationManager) { super(); - this.kryoWrapper = kryoWrapper; + this.serializationManager = serializationManager; } // the crypto writer will override this @SuppressWarnings("unused") protected - void writeObject(CryptoSerializationManager kryoWrapper, ChannelHandlerContext context, Object msg, ByteBuf buffer) { + void writeObject(CryptoSerializationManager serializationManager, ChannelHandlerContext context, Object msg, ByteBuf buffer) { // no connection here because we haven't created one yet. When we do, we replace this handler with a new one. - kryoWrapper.write(buffer, msg); + serializationManager.write(buffer, msg); } @Override @@ -61,7 +61,7 @@ class KryoEncoderUdp extends MessageToMessageEncoder { ByteBuf outBuffer = Unpooled.buffer(maxSize); // no size info, since this is UDP, it is not segmented - writeObject(this.kryoWrapper, ctx, msg, outBuffer); + writeObject(this.serializationManager, ctx, msg, outBuffer); // have to check to see if we are too big for UDP! diff --git a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdpCrypto.java b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdpCrypto.java index 38b6d791..8241ab8b 100644 --- a/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdpCrypto.java +++ b/Dorkbox-Network/src/dorkbox/network/pipeline/udp/KryoEncoderUdpCrypto.java @@ -15,9 +15,8 @@ */ package dorkbox.network.pipeline.udp; -import dorkbox.network.connection.Connection; +import dorkbox.network.connection.ConnectionImpl; import dorkbox.network.util.CryptoSerializationManager; -import dorkbox.util.exceptions.NetException; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler.Sharable; @@ -28,22 +27,16 @@ public class KryoEncoderUdpCrypto extends KryoEncoderUdp { public - KryoEncoderUdpCrypto(CryptoSerializationManager kryoWrapper) { - super(kryoWrapper); + KryoEncoderUdpCrypto(CryptoSerializationManager serializationManager) { + super(serializationManager); } @Override protected - void writeObject(CryptoSerializationManager kryoWrapper, ChannelHandlerContext ctx, Object msg, ByteBuf buffer) { + void writeObject(CryptoSerializationManager serializationManager, ChannelHandlerContext ctx, Object msg, ByteBuf buffer) { ChannelHandler last = ctx.pipeline() .last(); - if (last instanceof Connection) { - kryoWrapper.writeWithCryptoUdp((Connection) last, buffer, msg); - } - else { - // SHOULD NEVER HAPPEN! - throw new NetException("Tried to use kryo to WRITE an object with NO network connection!"); - } + serializationManager.writeWithCryptoUdp((ConnectionImpl) last, buffer, msg); } } diff --git a/Dorkbox-Network/src/dorkbox/network/util/CryptoSerializationManager.java b/Dorkbox-Network/src/dorkbox/network/util/CryptoSerializationManager.java index 38ff0309..533a75fe 100644 --- a/Dorkbox-Network/src/dorkbox/network/util/CryptoSerializationManager.java +++ b/Dorkbox-Network/src/dorkbox/network/util/CryptoSerializationManager.java @@ -15,7 +15,7 @@ */ package dorkbox.network.util; -import dorkbox.network.connection.Connection; +import dorkbox.network.connection.ConnectionImpl; import dorkbox.util.SerializationManager; import io.netty.buffer.ByteBuf; @@ -37,14 +37,14 @@ interface CryptoSerializationManager extends SerializationManager, RMISerializat *

* There is a small speed penalty if there were no kryo's available to use. */ - void writeWithCryptoTcp(Connection connection, ByteBuf buffer, Object message); + void writeWithCryptoTcp(ConnectionImpl connection, ByteBuf buffer, Object message); /** * Waits until a kryo is available to write, using CAS operations to prevent having to synchronize. *

* There is a small speed penalty if there were no kryo's available to use. */ - void writeWithCryptoUdp(Connection connection, ByteBuf buffer, Object message); + void writeWithCryptoUdp(ConnectionImpl connection, ByteBuf buffer, Object message); /** * Reads an object from the buffer. @@ -54,7 +54,7 @@ interface CryptoSerializationManager extends SerializationManager, RMISerializat * @param connection can be NULL * @param length should ALWAYS be the length of the expected object! */ - Object readWithCryptoTcp(Connection connection, ByteBuf buffer, int length); + Object readWithCryptoTcp(ConnectionImpl connection, ByteBuf buffer, int length); /** * Reads an object from the buffer. @@ -64,5 +64,5 @@ interface CryptoSerializationManager extends SerializationManager, RMISerializat * @param connection can be NULL * @param length should ALWAYS be the length of the expected object! */ - Object readWithCryptoUdp(Connection connection, ByteBuf buffer, int length); + Object readWithCryptoUdp(ConnectionImpl connection, ByteBuf buffer, int length); }