Cleaned up RMI registration validation
This commit is contained in:
parent
450f1aa5fb
commit
760ebf974f
|
@ -566,58 +566,64 @@ class Serialization implements NetworkSerializationManager {
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
boolean verifyKryoRegistration(byte[] otherRegistrationData) {
|
boolean verifyKryoRegistration(byte[] clientRegistrationData) {
|
||||||
// verify the registration IDs if necessary with our own. The CLIENT does not verify anything, only the server!
|
// verify the registration IDs if necessary with our own. The CLIENT does not verify anything, only the server!
|
||||||
byte[] kryoRegistrationDetails = savedRegistrationDetails;
|
byte[] kryoRegistrationDetails = savedRegistrationDetails;
|
||||||
boolean equals = java.util.Arrays.equals(kryoRegistrationDetails, otherRegistrationData);
|
boolean equals = java.util.Arrays.equals(kryoRegistrationDetails, clientRegistrationData);
|
||||||
if (equals) {
|
if (equals) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// now we need to figure out WHAT was screwed up so we know what to fix
|
// now we need to figure out WHAT was screwed up so we know what to fix
|
||||||
|
// NOTE: it could just be that the byte arrays are different, because java has a non-deterministic iteration of hash maps.
|
||||||
KryoExtra kryo = takeKryo();
|
KryoExtra kryo = takeKryo();
|
||||||
|
|
||||||
ByteBuf byteBuf = Unpooled.wrappedBuffer(otherRegistrationData);
|
ByteBuf byteBuf = Unpooled.wrappedBuffer(clientRegistrationData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
boolean success = true;
|
||||||
kryo.setRegistrationRequired(false);
|
kryo.setRegistrationRequired(false);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Object[][] classRegistrations = (Object[][]) kryo.readCompressed(logger, byteBuf, otherRegistrationData.length);
|
Object[][] clientClassRegistrations = (Object[][]) kryo.readCompressed(logger, byteBuf, clientRegistrationData.length);
|
||||||
|
|
||||||
|
|
||||||
int lengthOrg = mergedRegistrations.length;
|
int lengthServer = mergedRegistrations.length;
|
||||||
int lengthNew = classRegistrations.length;
|
int lengthClient = clientClassRegistrations.length;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
// list all of the registrations that are mis-matched between the server/client
|
// list all of the registrations that are mis-matched between the server/client
|
||||||
for (; index < lengthOrg; index++) {
|
for (; index < lengthServer; index++) {
|
||||||
final ClassRegistration classOrg = mergedRegistrations[index];
|
final ClassRegistration classServer = mergedRegistrations[index];
|
||||||
|
|
||||||
if (index >= lengthNew) {
|
if (index < lengthClient) {
|
||||||
logger.error("Missing client registration for {} -> {}", classOrg.id, classOrg.clazz.getName());
|
Object[] classClient = clientClassRegistrations[index];
|
||||||
|
int idClient = (Integer) classClient[0];
|
||||||
|
String nameClient = (String) classClient[1];
|
||||||
|
String serializerClient = (String) classClient[2];
|
||||||
|
|
||||||
|
int idServer = classServer.id;
|
||||||
|
String nameServer = classServer.clazz.getName();
|
||||||
|
String serializerServer = classServer.serializer.getClass().getName();
|
||||||
|
|
||||||
|
if (idClient != idServer || !nameServer.equals(nameClient) || !serializerClient.equalsIgnoreCase(serializerServer)) {
|
||||||
|
success = false;
|
||||||
|
logger.error("Registration {} Client -> {} ({})", idClient, nameClient, serializerClient);
|
||||||
|
logger.error("Registration {} Server -> {} ({})", idServer, nameServer, serializerServer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Object[] classNew = classRegistrations[index];
|
success = false;
|
||||||
int idNew = (Integer) classNew[0];
|
logger.error("Missing client registration for {} -> {}", classServer.id, classServer.clazz.getName());
|
||||||
String nameNew = (String) classNew[1];
|
|
||||||
String serializerNew = (String) classNew[2];
|
|
||||||
|
|
||||||
int idOrg = classOrg.id;
|
|
||||||
String nameOrg = classOrg.clazz.getName();
|
|
||||||
String serializerOrg = classOrg.serializer.getClass().getName();
|
|
||||||
|
|
||||||
if (idNew != idOrg || !nameOrg.equals(nameNew) || !serializerNew.equalsIgnoreCase(serializerOrg)) {
|
|
||||||
logger.error("Registration {} Client -> {} ({})", idNew, nameNew, serializerNew);
|
|
||||||
logger.error("Registration {} Server -> {} ({})", idOrg, nameOrg, serializerOrg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// list all of the registrations that are missing on the server
|
// list all of the registrations that are missing on the server
|
||||||
if (index < lengthNew) {
|
if (index < lengthClient) {
|
||||||
for (; index < lengthNew; index++) {
|
success = false;
|
||||||
Object[] holderClass = classRegistrations[index];
|
|
||||||
|
for (; index < lengthClient; index++) {
|
||||||
|
Object[] holderClass = clientClassRegistrations[index];
|
||||||
int id = (Integer) holderClass[0];
|
int id = (Integer) holderClass[0];
|
||||||
String name = (String) holderClass[1];
|
String name = (String) holderClass[1];
|
||||||
String serializer = (String) holderClass[2];
|
String serializer = (String) holderClass[2];
|
||||||
|
@ -625,6 +631,9 @@ class Serialization implements NetworkSerializationManager {
|
||||||
logger.error("Missing server registration : {} -> {} ({})", id, name, serializer);
|
logger.error("Missing server registration : {} -> {} ({})", id, name, serializer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// maybe everything was actually correct, and the byte arrays were different because hashmaps use non-deterministic ordering.
|
||||||
|
return success;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Error [{}] during registration validation", e.getMessage());
|
logger.error("Error [{}] during registration validation", e.getMessage());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user