From 8c3b98be33d59a7b0d3abad1b7822f7bfc95239a Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 13 Jun 2019 21:24:53 +0200 Subject: [PATCH] Lowered class registration frame size to fix potential UDP issues --- .../network/connection/RegistrationWrapper.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dorkbox/network/connection/RegistrationWrapper.java b/src/dorkbox/network/connection/RegistrationWrapper.java index d74b52e7..94d847f0 100644 --- a/src/dorkbox/network/connection/RegistrationWrapper.java +++ b/src/dorkbox/network/connection/RegistrationWrapper.java @@ -47,6 +47,8 @@ import io.netty.channel.Channel; */ public class RegistrationWrapper { + private static final int CLASS_REGISTRATION_VALIDATION_FRAGMENT_SIZE = 400; + public enum STATE { ERROR, WAIT, CONTINUE } @@ -327,17 +329,16 @@ class RegistrationWrapper { } } - public boolean initClassRegistration(final Channel channel, final Registration registration) { byte[] details = this.endPoint.getSerialization().getKryoRegistrationDetails(); int length = details.length; - if (length > 480) { + if (length > CLASS_REGISTRATION_VALIDATION_FRAGMENT_SIZE) { // it is too large to send in a single packet // child arrays have index 0 also as their 'index' and 1 is the total number of fragments - byte[][] fragments = divideArray(details, 480); + byte[][] fragments = divideArray(details, CLASS_REGISTRATION_VALIDATION_FRAGMENT_SIZE); if (fragments == null) { logger.error("Too many classes have been registered for Serialization. Please report this issue"); @@ -386,19 +387,19 @@ class RegistrationWrapper { byte[] fragment = registration.payload; // this means that the registrations are FRAGMENTED! - // max size of ALL fragments is 480 * 127 + // max size of ALL fragments is xxx * 127 if (metaChannel.fragmentedRegistrationDetails == null) { metaChannel.remainingFragments = fragment[1]; - metaChannel.fragmentedRegistrationDetails = new byte[480 * fragment[1]]; + metaChannel.fragmentedRegistrationDetails = new byte[CLASS_REGISTRATION_VALIDATION_FRAGMENT_SIZE * fragment[1]]; } - System.arraycopy(fragment, 2, metaChannel.fragmentedRegistrationDetails, fragment[0] * 480, fragment.length - 2); + System.arraycopy(fragment, 2, metaChannel.fragmentedRegistrationDetails, fragment[0] * CLASS_REGISTRATION_VALIDATION_FRAGMENT_SIZE, fragment.length - 2); metaChannel.remainingFragments--; if (fragment[0] + 1 == fragment[1]) { // this is the last fragment in the in byte array (but NOT necessarily the last fragment to arrive) - int correctSize = (480 * (fragment[1] - 1)) + (fragment.length - 2); + int correctSize = (CLASS_REGISTRATION_VALIDATION_FRAGMENT_SIZE * (fragment[1] - 1)) + (fragment.length - 2); byte[] correctlySized = new byte[correctSize]; System.arraycopy(metaChannel.fragmentedRegistrationDetails, 0, correctlySized, 0, correctSize); metaChannel.fragmentedRegistrationDetails = correctlySized;