node: Add ClassSerializer, register default flow parameters for RPC

This commit is contained in:
Andras Slemmer 2016-12-06 13:52:15 +00:00
parent 99219c6a5f
commit fd229df956
2 changed files with 26 additions and 9 deletions

View File

@ -76,6 +76,14 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo
companion object { companion object {
val PRIVATE_KEY_FILE_NAME = "identity-private-key" val PRIVATE_KEY_FILE_NAME = "identity-private-key"
val PUBLIC_IDENTITY_FILE_NAME = "identity-public" val PUBLIC_IDENTITY_FILE_NAME = "identity-public"
val defaultFlowWhiteList: Map<Class<out FlowLogic<*>>, Set<Class<*>>> = mapOf(
CashFlow::class.java to setOf(
CashCommand.IssueCash::class.java,
CashCommand.PayCash::class.java,
CashCommand.ExitCash::class.java
)
)
} }
// TODO: Persist this, as well as whether the node is registered. // TODO: Persist this, as well as whether the node is registered.
@ -309,14 +317,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo
} }
} }
private val defaultFlowWhiteList: Map<Class<out FlowLogic<*>>, Set<Class<*>>> = mapOf(
CashFlow::class.java to setOf(
CashCommand.IssueCash::class.java,
CashCommand.PayCash::class.java,
CashCommand.ExitCash::class.java
)
)
private fun initialiseFlowLogicFactory(): FlowLogicRefFactory { private fun initialiseFlowLogicFactory(): FlowLogicRefFactory {
val flowWhitelist = HashMap<String, Set<String>>() val flowWhitelist = HashMap<String, Set<String>>()

View File

@ -26,6 +26,7 @@ import net.corda.core.serialization.*
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.WireTransaction import net.corda.core.transactions.WireTransaction
import net.corda.flows.CashFlowResult import net.corda.flows.CashFlowResult
import net.corda.node.internal.AbstractNode
import net.corda.node.services.User import net.corda.node.services.User
import net.i2p.crypto.eddsa.EdDSAPrivateKey import net.i2p.crypto.eddsa.EdDSAPrivateKey
import net.i2p.crypto.eddsa.EdDSAPublicKey import net.i2p.crypto.eddsa.EdDSAPublicKey
@ -106,6 +107,17 @@ open class RPCException(msg: String, cause: Throwable?) : RuntimeException(msg,
class DeadlineExceeded(rpcName: String) : RPCException("Deadline exceeded on call to $rpcName") class DeadlineExceeded(rpcName: String) : RPCException("Deadline exceeded on call to $rpcName")
} }
object ClassSerializer : Serializer<Class<*>>() {
override fun read(kryo: Kryo, input: Input, type: Class<Class<*>>): Class<*> {
val className = input.readString()
return Class.forName(className)
}
override fun write(kryo: Kryo, output: Output, clazz: Class<*>) {
output.writeString(clazz.name)
}
}
class PermissionException(msg: String) : RuntimeException(msg) class PermissionException(msg: String) : RuntimeException(msg)
// The Kryo used for the RPC wire protocol. Every type in the wire protocol is listed here explicitly. // The Kryo used for the RPC wire protocol. Every type in the wire protocol is listed here explicitly.
@ -133,7 +145,7 @@ private class RPCKryo(observableSerializer: Serializer<Observable<Any>>? = null)
register(SerializedBytes::class.java, SerializedBytesSerializer) register(SerializedBytes::class.java, SerializedBytesSerializer)
register(Party::class.java) register(Party::class.java)
register(Array<Any>(0,{}).javaClass) register(Array<Any>(0,{}).javaClass)
register(Class::class.java) register(Class::class.java, ClassSerializer)
ImmutableListSerializer.registerSerializers(this) ImmutableListSerializer.registerSerializers(this)
ImmutableSetSerializer.registerSerializers(this) ImmutableSetSerializer.registerSerializers(this)
@ -224,6 +236,11 @@ private class RPCKryo(observableSerializer: Serializer<Observable<Any>>? = null)
register(FlowHandle::class.java) register(FlowHandle::class.java)
register(KryoException::class.java) register(KryoException::class.java)
register(StringBuffer::class.java) register(StringBuffer::class.java)
for ((_flow, argumentTypes) in AbstractNode.defaultFlowWhiteList) {
for (type in argumentTypes) {
register(type)
}
}
pluginRegistries.forEach { it.registerRPCKryoTypes(this) } pluginRegistries.forEach { it.registerRPCKryoTypes(this) }
} }