mirror of
https://github.com/corda/corda.git
synced 2024-12-27 08:22:35 +00:00
Register Kryo and AMQP serialisation schemes for the SGX enclave.
This commit is contained in:
parent
cca532b5c0
commit
9403e231cc
@ -53,7 +53,7 @@ void check_transaction(void *reqbuf, size_t buflen, char *error) {
|
||||
JNI_CreateJavaVM(&vm, &env_void, &vmArgs);
|
||||
JNIEnv* env = static_cast<JNIEnv*>(env_void);
|
||||
|
||||
env->FindClass("com/r3/enclaves/txverify/KryoVerifierSerializationScheme");
|
||||
env->FindClass("com/r3/enclaves/txverify/EnclaveletSerializationScheme");
|
||||
if (!env->ExceptionCheck()) {
|
||||
jclass c = env->FindClass("com/r3/enclaves/txverify/Enclavelet");
|
||||
if (!env->ExceptionCheck()) {
|
||||
|
@ -0,0 +1,52 @@
|
||||
@file:JvmName("EnclaveletSerializationScheme")
|
||||
package com.r3.enclaves.txverify
|
||||
|
||||
import net.corda.core.serialization.SerializationContext
|
||||
import net.corda.core.serialization.internal.SerializationEnvironmentImpl
|
||||
import net.corda.core.serialization.internal.nodeSerializationEnv
|
||||
import net.corda.core.utilities.ByteSequence
|
||||
import net.corda.nodeapi.internal.serialization.*
|
||||
import net.corda.nodeapi.internal.serialization.amqp.AbstractAMQPSerializationScheme
|
||||
import net.corda.nodeapi.internal.serialization.amqp.AmqpHeaderV1_0
|
||||
import net.corda.nodeapi.internal.serialization.amqp.SerializerFactory
|
||||
import net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme
|
||||
import net.corda.nodeapi.internal.serialization.kryo.KryoHeaderV0_1
|
||||
|
||||
@Suppress("UNUSED")
|
||||
private class EnclaveletSerializationScheme {
|
||||
/*
|
||||
* Registers the serialisation schemes as soon as this class is loaded into the JVM.
|
||||
*/
|
||||
private companion object {
|
||||
init {
|
||||
nodeSerializationEnv = SerializationEnvironmentImpl(
|
||||
SerializationFactoryImpl().apply {
|
||||
registerScheme(KryoVerifierSerializationScheme)
|
||||
registerScheme(AMQPVerifierSerializationScheme)
|
||||
},
|
||||
/**
|
||||
* Even though default context is set to Kryo P2P, the encoding will be adjusted depending on the
|
||||
* incoming request received.
|
||||
*/
|
||||
KRYO_P2P_CONTEXT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object KryoVerifierSerializationScheme : AbstractKryoSerializationScheme() {
|
||||
override fun canDeserializeVersion(byteSequence: ByteSequence, target: SerializationContext.UseCase): Boolean {
|
||||
return byteSequence == KryoHeaderV0_1 && target == SerializationContext.UseCase.P2P
|
||||
}
|
||||
|
||||
override fun rpcClientKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
|
||||
override fun rpcServerKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
private object AMQPVerifierSerializationScheme : AbstractAMQPSerializationScheme() {
|
||||
override fun canDeserializeVersion(byteSequence: ByteSequence, target: SerializationContext.UseCase): Boolean {
|
||||
return (byteSequence == AmqpHeaderV1_0 && (target == SerializationContext.UseCase.P2P))
|
||||
}
|
||||
|
||||
override fun rpcClientSerializerFactory(context: SerializationContext): SerializerFactory = throw UnsupportedOperationException()
|
||||
override fun rpcServerSerializerFactory(context: SerializationContext): SerializerFactory = throw UnsupportedOperationException()
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.r3.enclaves.txverify
|
||||
|
||||
import net.corda.core.serialization.SerializationContext
|
||||
import net.corda.core.serialization.SerializationDefaults
|
||||
import net.corda.core.utilities.ByteSequence
|
||||
import net.corda.nodeapi.internal.serialization.KRYO_P2P_CONTEXT
|
||||
import net.corda.nodeapi.internal.serialization.SerializationFactoryImpl
|
||||
import net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme
|
||||
import net.corda.nodeapi.internal.serialization.kryo.KryoHeaderV0_1
|
||||
|
||||
@Suppress("UNUSED")
|
||||
private class KryoVerifierSerializationScheme : AbstractKryoSerializationScheme() {
|
||||
override fun canDeserializeVersion(byteSequence: ByteSequence, target: SerializationContext.UseCase): Boolean {
|
||||
return byteSequence == KryoHeaderV0_1 && target == SerializationContext.UseCase.P2P
|
||||
}
|
||||
|
||||
override fun rpcClientKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
|
||||
override fun rpcServerKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
|
||||
|
||||
/*
|
||||
* Registers the serialisation scheme as soon as the class is loaded into the JVM.
|
||||
*/
|
||||
private companion object {
|
||||
init {
|
||||
// TODO: SerializationDefaults are now global singletons. Revisit this initialisation block.
|
||||
// SerializationDefaults.SERIALIZATION_FACTORY = SerializationFactoryImpl().apply {
|
||||
// registerScheme(KryoVerifierSerializationScheme())
|
||||
// }
|
||||
// SerializationDefaults.P2P_CONTEXT = KRYO_P2P_CONTEXT
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user