diff --git a/src/dorkbox/network/connection/KryoExtra.java b/src/dorkbox/network/connection/KryoExtra.java index ef897d0b..3a15f420 100644 --- a/src/dorkbox/network/connection/KryoExtra.java +++ b/src/dorkbox/network/connection/KryoExtra.java @@ -44,6 +44,18 @@ class KryoExtra extends Kryo { */ static final byte crypto = (byte) (1 << 1); + /** + * Determines if this buffer is encrypted or not. + */ + public static + boolean isEncrypted(final ByteBuf buffer) { + // read off the magic byte + byte magicByte = buffer.getByte(buffer.readerIndex()); + return (magicByte & crypto) == crypto; + } + + + // snappycomp : 7.534 micros/op; 518.5 MB/s (output: 55.1%) // snappyuncomp : 1.391 micros/op; 2808.1 MB/s // lz4comp : 6.210 micros/op; 629.0 MB/s (output: 55.4%) diff --git a/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java b/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java index afad2d5c..affd467a 100644 --- a/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java +++ b/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java @@ -25,8 +25,8 @@ import org.slf4j.Logger; import dorkbox.network.Broadcast; import dorkbox.network.connection.Connection; import dorkbox.network.connection.ConnectionImpl; -import dorkbox.network.connection.CryptoSerializationManager; import dorkbox.network.connection.EndPointBase; +import dorkbox.network.connection.KryoExtra; import dorkbox.network.connection.RegistrationWrapper; import dorkbox.network.connection.registration.MetaChannel; import dorkbox.network.connection.registration.Registration; @@ -178,7 +178,7 @@ class RegistrationRemoteHandlerServerUDP extends MessageTo RegistrationWrapper registrationWrapper2 = this.registrationWrapper; dorkbox.network.util.CryptoSerializationManager serializationManager2 = this.serializationManager; - if (CryptoSerializationManager.isEncrypted(message)) { + if (KryoExtra.isEncrypted(message)) { // we need to FORWARD this message "down the pipeline". ConnectionImpl connection = registrationWrapper2.getServerUDP(udpRemoteAddress); diff --git a/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java b/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java index ec91cb6c..d0eca687 100644 --- a/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java +++ b/src/dorkbox/network/pipeline/udp/KryoDecoderUdp.java @@ -20,7 +20,7 @@ import java.util.List; import org.slf4j.LoggerFactory; -import dorkbox.network.connection.CryptoSerializationManager; +import dorkbox.network.connection.KryoExtra; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; @@ -48,7 +48,7 @@ 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 (CryptoSerializationManager.isEncrypted(data)) { + if (KryoExtra.isEncrypted(data)) { String message = "Encrypted UDP packet received before registration complete."; LoggerFactory.getLogger(this.getClass()).error(message); throw new IOException(message);