Advertised services now contain ServiceInfo which describes ServiceType and a service identifier. This will be used, e.g. for grouping distributed notary nodes into the same service cluster.

This commit is contained in:
Andrius Dagys
2016-10-03 10:44:33 +01:00
parent 4ed73dc9f2
commit 5efa0fd5b3
22 changed files with 110 additions and 84 deletions

View File

@ -1,6 +1,7 @@
package com.r3corda.client package com.r3corda.client
import com.r3corda.core.contracts.* import com.r3corda.core.contracts.*
import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.serialization.OpaqueBytes import com.r3corda.core.serialization.OpaqueBytes
import com.r3corda.node.driver.driver import com.r3corda.node.driver.driver
import com.r3corda.node.driver.startClient import com.r3corda.node.driver.startClient
@ -22,7 +23,7 @@ class NodeMonitorClientTests {
fun cashIssueWorksEndToEnd() { fun cashIssueWorksEndToEnd() {
driver { driver {
val aliceNodeFuture = startNode("Alice") val aliceNodeFuture = startNode("Alice")
val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(SimpleNotaryService.Type)) val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(ServiceInfo(SimpleNotaryService.Type)))
val aliceNode = aliceNodeFuture.get() val aliceNode = aliceNodeFuture.get()
val notaryNode = notaryNodeFuture.get() val notaryNode = notaryNodeFuture.get()
@ -65,7 +66,7 @@ class NodeMonitorClientTests {
fun issueAndMoveWorks() { fun issueAndMoveWorks() {
driver { driver {
val aliceNodeFuture = startNode("Alice") val aliceNodeFuture = startNode("Alice")
val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(SimpleNotaryService.Type)) val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(ServiceInfo(SimpleNotaryService.Type)))
val aliceNode = aliceNodeFuture.get() val aliceNode = aliceNodeFuture.get()
val notaryNode = notaryNodeFuture.get() val notaryNode = notaryNodeFuture.get()
@ -173,7 +174,7 @@ class NodeMonitorClientTests {
fun movingCashOfDifferentIssueRefsFails() { fun movingCashOfDifferentIssueRefsFails() {
driver { driver {
val aliceNodeFuture = startNode("Alice") val aliceNodeFuture = startNode("Alice")
val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(SimpleNotaryService.Type)) val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(ServiceInfo(SimpleNotaryService.Type)))
val aliceNode = aliceNodeFuture.get() val aliceNode = aliceNodeFuture.get()
val notaryNode = notaryNodeFuture.get() val notaryNode = notaryNodeFuture.get()

View File

@ -2,11 +2,11 @@ package com.r3corda.core.node
import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.Party
import com.r3corda.core.messaging.SingleMessageRecipient import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
/** /**
* Info about a network node that acts on behalf of some form of contract party. * Info about a network node that acts on behalf of some form of contract party.
*/ */
data class NodeInfo(val address: SingleMessageRecipient, val identity: Party, data class NodeInfo(val address: SingleMessageRecipient, val identity: Party,
var advertisedServices: Set<ServiceType> = emptySet(), var advertisedServices: Set<ServiceInfo> = emptySet(),
val physicalLocation: PhysicalLocation? = null) val physicalLocation: PhysicalLocation? = null)

View File

@ -0,0 +1,22 @@
package com.r3corda.core.node.services
/**
* A container for additional information for an advertised service.
*
* @param ServiceType the service type identifier
* @param name the service name, used for differentiating multiple services of the same type. Can also be used as a
* grouping identifier for nodes collectively running a distributed service.
*/
data class ServiceInfo(val type: ServiceType, val name: String? = null) {
companion object {
fun parse(encoded: String): ServiceInfo {
val parts = encoded.split("|")
require(parts.size > 0 && parts.size <= 2)
return ServiceInfo(object : ServiceType(parts[0]) {}, parts[1])
}
}
override fun toString() = if (name != null) "$type|$name" else type.toString()
}
fun Iterable<ServiceInfo>.containsType(type: ServiceType) = any { it.type == type }

View File

@ -8,6 +8,7 @@ import com.r3corda.client.model.Models
import com.r3corda.client.model.NodeMonitorModel import com.r3corda.client.model.NodeMonitorModel
import com.r3corda.client.model.observer import com.r3corda.client.model.observer
import com.r3corda.core.contracts.ClientToServiceCommand import com.r3corda.core.contracts.ClientToServiceCommand
import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.explorer.model.IdentityModel import com.r3corda.explorer.model.IdentityModel
import com.r3corda.node.driver.PortAllocation import com.r3corda.node.driver.PortAllocation
import com.r3corda.node.driver.driver import com.r3corda.node.driver.driver
@ -42,7 +43,7 @@ class Main : App() {
val aliceNodeFuture = startNode("Alice") val aliceNodeFuture = startNode("Alice")
val bobNodeFuture = startNode("Bob") val bobNodeFuture = startNode("Bob")
val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(SimpleNotaryService.Type)) val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(ServiceInfo(SimpleNotaryService.Type)))
val aliceNode = aliceNodeFuture.get() val aliceNode = aliceNodeFuture.get()
val bobNode = bobNodeFuture.get() val bobNode = bobNodeFuture.get()

View File

@ -2,6 +2,7 @@ package com.r3corda.node.driver
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.NetworkMapCache import com.r3corda.core.node.services.NetworkMapCache
import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.node.services.api.RegulatorService import com.r3corda.node.services.api.RegulatorService
import com.r3corda.node.services.messaging.ArtemisMessagingComponent import com.r3corda.node.services.messaging.ArtemisMessagingComponent
import com.r3corda.node.services.transactions.SimpleNotaryService import com.r3corda.node.services.transactions.SimpleNotaryService
@ -32,8 +33,8 @@ class DriverTests {
@Test @Test
fun simpleNodeStartupShutdownWorks() { fun simpleNodeStartupShutdownWorks() {
val (notary, regulator) = driver { val (notary, regulator) = driver {
val notary = startNode("TestNotary", setOf(SimpleNotaryService.Type)) val notary = startNode("TestNotary", setOf(ServiceInfo(SimpleNotaryService.Type)))
val regulator = startNode("Regulator", setOf(RegulatorService.Type)) val regulator = startNode("Regulator", setOf(ServiceInfo(RegulatorService.Type)))
nodeMustBeUp(networkMapCache, notary.get(), "TestNotary") nodeMustBeUp(networkMapCache, notary.get(), "TestNotary")
nodeMustBeUp(networkMapCache, regulator.get(), "Regulator") nodeMustBeUp(networkMapCache, regulator.get(), "Regulator")

View File

@ -6,7 +6,7 @@ import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.generateKeyPair import com.r3corda.core.crypto.generateKeyPair
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.NetworkMapCache import com.r3corda.core.node.services.NetworkMapCache
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.node.services.config.FullNodeConfiguration import com.r3corda.node.services.config.FullNodeConfiguration
import com.r3corda.node.services.config.NodeConfiguration import com.r3corda.node.services.config.NodeConfiguration
import com.r3corda.node.services.config.NodeConfigurationFromConfig import com.r3corda.node.services.config.NodeConfigurationFromConfig
@ -56,7 +56,7 @@ interface DriverDSLExposedInterface {
* @param advertisedServices The set of services to be advertised by the node. Defaults to empty set. * @param advertisedServices The set of services to be advertised by the node. Defaults to empty set.
* @return The [NodeInfo] of the started up node retrieved from the network map service. * @return The [NodeInfo] of the started up node retrieved from the network map service.
*/ */
fun startNode(providedName: String? = null, advertisedServices: Set<ServiceType> = setOf()): Future<NodeInfo> fun startNode(providedName: String? = null, advertisedServices: Set<ServiceInfo> = setOf()): Future<NodeInfo>
/** /**
* Starts an [NodeMessagingClient]. * Starts an [NodeMessagingClient].
@ -286,14 +286,14 @@ class DriverDSL(
addressMustNotBeBound(networkMapAddress) addressMustNotBeBound(networkMapAddress)
} }
override fun startNode(providedName: String?, advertisedServices: Set<ServiceType>): Future<NodeInfo> { override fun startNode(providedName: String?, advertisedServices: Set<ServiceInfo>): Future<NodeInfo> {
val messagingAddress = portAllocation.nextHostAndPort() val messagingAddress = portAllocation.nextHostAndPort()
val apiAddress = portAllocation.nextHostAndPort() val apiAddress = portAllocation.nextHostAndPort()
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
val name = providedName ?: "${pickA(name)}-${messagingAddress.port}" val name = providedName ?: "${pickA(name)}-${messagingAddress.port}"
val nodeDirectory = "$baseDirectory/$name" val nodeDirectory = "$baseDirectory/$name"
val useNotary = advertisedServices.any { it.isSubTypeOf(NotaryService.Type) } val useNotary = advertisedServices.any { it.type.isSubTypeOf(NotaryService.Type) }
val config = NodeConfiguration.loadConfig( val config = NodeConfiguration.loadConfig(
baseDirectoryPath = Paths.get(nodeDirectory), baseDirectoryPath = Paths.get(nodeDirectory),
@ -304,7 +304,7 @@ class DriverDSL(
"artemisAddress" to messagingAddress.toString(), "artemisAddress" to messagingAddress.toString(),
"webAddress" to apiAddress.toString(), "webAddress" to apiAddress.toString(),
"hostNotaryServiceLocally" to useNotary.toString(), "hostNotaryServiceLocally" to useNotary.toString(),
"extraAdvertisedServiceIds" to advertisedServices.map { x -> x.id }.joinToString(","), "extraAdvertisedServiceIds" to advertisedServices.joinToString(","),
"networkMapAddress" to networkMapAddress.toString() "networkMapAddress" to networkMapAddress.toString()
) )
) )
@ -446,7 +446,7 @@ class DriverDSL(
listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort") listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort")
else else
emptyList() emptyList()
val javaArgs = listOf(path) + val javaArgs = listOf(path) +
listOf("-Dname=${nodeConf.myLegalName}", "-javaagent:$quasarJarPath") + debugPortArg + listOf("-Dname=${nodeConf.myLegalName}", "-javaagent:$quasarJarPath") + debugPortArg +
listOf("-cp", classpath, className) + listOf("-cp", classpath, className) +

View File

@ -71,7 +71,7 @@ import kotlin.reflect.KClass
// In theory the NodeInfo for the node should be passed in, instead, however currently this is constructed by the // In theory the NodeInfo for the node should be passed in, instead, however currently this is constructed by the
// AbstractNode. It should be possible to generate the NodeInfo outside of AbstractNode, so it can be passed in. // AbstractNode. It should be possible to generate the NodeInfo outside of AbstractNode, so it can be passed in.
abstract class AbstractNode(val configuration: NodeConfiguration, val networkMapService: SingleMessageRecipient?, abstract class AbstractNode(val configuration: NodeConfiguration, val networkMapService: SingleMessageRecipient?,
val advertisedServices: Set<ServiceType>, val platformClock: Clock) : SingletonSerializeAsToken() { val advertisedServices: Set<ServiceInfo>, val platformClock: Clock) : SingletonSerializeAsToken() {
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"
@ -211,7 +211,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, val networkMap
// TODO: uniquenessProvider creation should be inside makeNotaryService(), but notary service initialisation // TODO: uniquenessProvider creation should be inside makeNotaryService(), but notary service initialisation
// depends on smm, while smm depends on tokenizableServices, which uniquenessProvider is part of // depends on smm, while smm depends on tokenizableServices, which uniquenessProvider is part of
advertisedServices.singleOrNull { it.isSubTypeOf(NotaryService.Type) }?.let { advertisedServices.singleOrNull { it.type.isSubTypeOf(NotaryService.Type) }?.let {
uniquenessProvider = makeUniquenessProvider() uniquenessProvider = makeUniquenessProvider()
tokenizableServices.add(uniquenessProvider!!) tokenizableServices.add(uniquenessProvider!!)
} }
@ -318,7 +318,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, val networkMap
} }
private fun buildAdvertisedServices() { private fun buildAdvertisedServices() {
val serviceTypes = info.advertisedServices val serviceTypes = info.advertisedServices.map { it.type }
if (NetworkMapService.Type in serviceTypes) makeNetworkMapService() if (NetworkMapService.Type in serviceTypes) makeNetworkMapService()
val notaryServiceType = serviceTypes.singleOrNull { it.isSubTypeOf(NotaryService.Type) } val notaryServiceType = serviceTypes.singleOrNull { it.isSubTypeOf(NotaryService.Type) }
@ -332,7 +332,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, val networkMap
* updates) if one has been supplied. * updates) if one has been supplied.
*/ */
private fun registerWithNetworkMap(): ListenableFuture<Unit> { private fun registerWithNetworkMap(): ListenableFuture<Unit> {
require(networkMapService != null || NetworkMapService.Type in advertisedServices) { require(networkMapService != null || NetworkMapService.Type in advertisedServices.map { it.type }) {
"Initial network map address must indicate a node that provides a network map service" "Initial network map address must indicate a node that provides a network map service"
} }
services.networkMapCache.addNode(info) services.networkMapCache.addNode(info)

View File

@ -4,7 +4,7 @@ import com.codahale.metrics.JmxReporter
import com.google.common.net.HostAndPort import com.google.common.net.HostAndPort
import com.r3corda.core.messaging.SingleMessageRecipient import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.ServiceHub import com.r3corda.core.node.ServiceHub
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.utilities.loggerFor import com.r3corda.core.utilities.loggerFor
import com.r3corda.node.serialization.NodeClock import com.r3corda.node.serialization.NodeClock
import com.r3corda.node.services.api.MessagingServiceInternal import com.r3corda.node.services.api.MessagingServiceInternal
@ -61,7 +61,7 @@ class ConfigurationException(message: String) : Exception(message)
*/ */
class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort, class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
configuration: NodeConfiguration, networkMapAddress: SingleMessageRecipient?, configuration: NodeConfiguration, networkMapAddress: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, clock: Clock = NodeClock(), advertisedServices: Set<ServiceInfo>, clock: Clock = NodeClock(),
val messagingServerAddr: HostAndPort? = null) : AbstractNode(configuration, networkMapAddress, advertisedServices, clock) { val messagingServerAddr: HostAndPort? = null) : AbstractNode(configuration, networkMapAddress, advertisedServices, clock) {
companion object { companion object {
/** The port that is used by default if none is specified. As you know, 31337 is the most elite number. */ /** The port that is used by default if none is specified. As you know, 31337 is the most elite number. */

View File

@ -4,7 +4,7 @@ import com.google.common.net.HostAndPort
import com.r3corda.core.crypto.X509Utilities import com.r3corda.core.crypto.X509Utilities
import com.r3corda.core.div import com.r3corda.core.div
import com.r3corda.core.messaging.SingleMessageRecipient import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.node.internal.Node import com.r3corda.node.internal.Node
import com.r3corda.node.serialization.NodeClock import com.r3corda.node.serialization.NodeClock
import com.r3corda.node.services.messaging.NodeMessagingClient import com.r3corda.node.services.messaging.NodeMessagingClient
@ -157,14 +157,14 @@ class FullNodeConfiguration(conf: Config) : NodeConfiguration {
val clock: Clock = NodeClock() val clock: Clock = NodeClock()
fun createNode(): Node { fun createNode(): Node {
val advertisedServices = mutableSetOf<ServiceType>() val advertisedServices = mutableSetOf<ServiceInfo>()
if (hostNotaryServiceLocally) advertisedServices.add(SimpleNotaryService.Type) if (hostNotaryServiceLocally) advertisedServices.add(ServiceInfo(SimpleNotaryService.Type))
if (!extraAdvertisedServiceIds.isNullOrEmpty()) { if (!extraAdvertisedServiceIds.isNullOrEmpty()) {
for (serviceId in extraAdvertisedServiceIds.split(",")) { for (serviceId in extraAdvertisedServiceIds.split(",")) {
advertisedServices.add(object : ServiceType(serviceId) {}) advertisedServices.add(ServiceInfo.parse(serviceId))
} }
} }
if (networkMapAddress == null) advertisedServices.add(NetworkMapService.Type) if (networkMapAddress == null) advertisedServices.add(ServiceInfo(NetworkMapService.Type))
val networkMapMessageAddress: SingleMessageRecipient? = if (networkMapAddress == null) null else NodeMessagingClient.makeNetworkMapAddress(networkMapAddress) val networkMapMessageAddress: SingleMessageRecipient? = if (networkMapAddress == null) null else NodeMessagingClient.makeNetworkMapAddress(networkMapAddress)
return Node(artemisAddress, return Node(artemisAddress,
webAddress, webAddress,

View File

@ -51,7 +51,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
protected var registeredNodes = Collections.synchronizedMap(HashMap<Party, NodeInfo>()) protected var registeredNodes = Collections.synchronizedMap(HashMap<Party, NodeInfo>())
override fun get() = registeredNodes.map { it.value } override fun get() = registeredNodes.map { it.value }
override fun get(serviceType: ServiceType) = registeredNodes.filterValues { it.advertisedServices.any { it.isSubTypeOf(serviceType) } }.map { it.value } override fun get(serviceType: ServiceType) = registeredNodes.filterValues { it.advertisedServices.any { it.type.isSubTypeOf(serviceType) } }.map { it.value }
override fun getRecommended(type: ServiceType, contract: Contract, vararg party: Party): NodeInfo? = get(type).firstOrNull() override fun getRecommended(type: ServiceType, contract: Contract, vararg party: Party): NodeInfo? = get(type).firstOrNull()
override fun getNodeByLegalName(name: String) = get().singleOrNull { it.identity.name == name } override fun getNodeByLegalName(name: String) = get().singleOrNull { it.identity.name == name }
override fun getNodeByPublicKey(publicKey: PublicKey) = get().singleOrNull { it.identity.owningKey == publicKey } override fun getNodeByPublicKey(publicKey: PublicKey) = get().singleOrNull { it.identity.owningKey == publicKey }

View File

@ -4,16 +4,15 @@ import com.r3corda.core.contracts.Attachment
import com.r3corda.core.crypto.SecureHash import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.crypto.sha256 import com.r3corda.core.crypto.sha256
import com.r3corda.core.messaging.SingleMessageRecipient import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.node.services.ServiceType
import com.r3corda.core.serialization.OpaqueBytes import com.r3corda.core.serialization.OpaqueBytes
import com.r3corda.testing.node.MockNetwork
import com.r3corda.node.services.config.NodeConfiguration import com.r3corda.node.services.config.NodeConfiguration
import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NetworkMapService
import com.r3corda.node.services.persistence.NodeAttachmentService import com.r3corda.node.services.persistence.NodeAttachmentService
import com.r3corda.node.services.transactions.SimpleNotaryService import com.r3corda.node.services.transactions.SimpleNotaryService
import com.r3corda.protocols.FetchAttachmentsProtocol import com.r3corda.protocols.FetchAttachmentsProtocol
import com.r3corda.protocols.FetchDataProtocol import com.r3corda.protocols.FetchDataProtocol
import com.r3corda.testing.node.MockNetwork
import com.r3corda.testing.rootCauseExceptions import com.r3corda.testing.rootCauseExceptions
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -21,7 +20,6 @@ import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardOpenOption import java.nio.file.StandardOpenOption
import java.security.KeyPair import java.security.KeyPair
import java.util.jar.JarOutputStream import java.util.jar.JarOutputStream
@ -89,7 +87,7 @@ class AttachmentTests {
// Make a node that doesn't do sanity checking at load time. // Make a node that doesn't do sanity checking at load time.
val n0 = network.createNode(null, -1, object : MockNetwork.Factory { val n0 = network.createNode(null, -1, object : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair) { return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair) {
override fun start(): MockNetwork.MockNode { override fun start(): MockNetwork.MockNode {
super.start() super.start()
@ -98,7 +96,7 @@ class AttachmentTests {
} }
} }
} }
}, true, null, null, NetworkMapService.Type, SimpleNotaryService.Type) }, true, null, null, ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type))
val n1 = network.createNode(n0.info.address) val n1 = network.createNode(n0.info.address)
// Insert an attachment into node zero's store directly. // Insert an attachment into node zero's store directly.

View File

@ -6,6 +6,7 @@ import com.r3corda.core.messaging.Message
import com.r3corda.core.messaging.TopicStringValidator import com.r3corda.core.messaging.TopicStringValidator
import com.r3corda.core.messaging.createMessage import com.r3corda.core.messaging.createMessage
import com.r3corda.core.node.services.DEFAULT_SESSION_ID import com.r3corda.core.node.services.DEFAULT_SESSION_ID
import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NetworkMapService
import com.r3corda.testing.node.MockNetwork import com.r3corda.testing.node.MockNetwork
import org.junit.Before import org.junit.Before
@ -40,7 +41,7 @@ class InMemoryMessagingTests {
@Test @Test
fun basics() { fun basics() {
val node1 = network.createNode(advertisedServices = NetworkMapService.Type) val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.Type))
val node2 = network.createNode(networkMapAddress = node1.info.address) val node2 = network.createNode(networkMapAddress = node1.info.address)
val node3 = network.createNode(networkMapAddress = node1.info.address) val node3 = network.createNode(networkMapAddress = node1.info.address)
@ -69,7 +70,7 @@ class InMemoryMessagingTests {
@Test @Test
fun broadcast() { fun broadcast() {
val node1 = network.createNode(advertisedServices = NetworkMapService.Type) val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.Type))
val node2 = network.createNode(networkMapAddress = node1.info.address) val node2 = network.createNode(networkMapAddress = node1.info.address)
val node3 = network.createNode(networkMapAddress = node1.info.address) val node3 = network.createNode(networkMapAddress = node1.info.address)
@ -88,7 +89,7 @@ class InMemoryMessagingTests {
*/ */
@Test @Test
fun `skip unhandled messages`() { fun `skip unhandled messages`() {
val node1 = network.createNode(advertisedServices = NetworkMapService.Type) val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.Type))
val node2 = network.createNode(networkMapAddress = node1.info.address) val node2 = network.createNode(networkMapAddress = node1.info.address)
var received: Int = 0 var received: Int = 0

View File

@ -162,7 +162,7 @@ class TwoPartyTradeProtocolTests {
// that Bob was waiting on before the reboot occurred. // that Bob was waiting on before the reboot occurred.
bobNode = net.createNode(networkMapAddr, bobAddr.id, object : MockNetwork.Factory { bobNode = net.createNode(networkMapAddr, bobAddr.id, object : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
return MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, bobAddr.id, BOB_KEY) return MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, bobAddr.id, BOB_KEY)
} }
}, true, BOB.name, BOB_KEY) }, true, BOB.name, BOB_KEY)
@ -192,7 +192,7 @@ class TwoPartyTradeProtocolTests {
// Create a node in the mock network ... // Create a node in the mock network ...
return net.createNode(networkMapAddr, -1, object : MockNetwork.Factory { return net.createNode(networkMapAddr, -1, object : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair) { return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair) {
// That constructs the storage service object in a customised way ... // That constructs the storage service object in a customised way ...
override fun constructStorageService( override fun constructStorageService(

View File

@ -3,6 +3,7 @@ package com.r3corda.node.services
import com.r3corda.core.contracts.* import com.r3corda.core.contracts.*
import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.generateKeyPair import com.r3corda.core.crypto.generateKeyPair
import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.seconds import com.r3corda.core.seconds
import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_NOTARY
import com.r3corda.core.utilities.DUMMY_NOTARY_KEY import com.r3corda.core.utilities.DUMMY_NOTARY_KEY
@ -35,10 +36,10 @@ class NotaryChangeTests {
oldNotaryNode = net.createNode( oldNotaryNode = net.createNode(
legalName = DUMMY_NOTARY.name, legalName = DUMMY_NOTARY.name,
keyPair = DUMMY_NOTARY_KEY, keyPair = DUMMY_NOTARY_KEY,
advertisedServices = *arrayOf(NetworkMapService.Type, SimpleNotaryService.Type)) advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type)))
clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info.address) clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info.address)
clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info.address) clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info.address)
newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info.address, advertisedServices = SimpleNotaryService.Type) newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info.address, advertisedServices = ServiceInfo(SimpleNotaryService.Type))
net.runNetwork() // Clear network map registration messages net.runNetwork() // Clear network map registration messages
} }

View File

@ -2,6 +2,7 @@ package com.r3corda.node.services
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import com.r3corda.core.contracts.TransactionType import com.r3corda.core.contracts.TransactionType
import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.crypto.DigitalSignature import com.r3corda.core.crypto.DigitalSignature
import com.r3corda.core.seconds import com.r3corda.core.seconds
import com.r3corda.core.transactions.SignedTransaction import com.r3corda.core.transactions.SignedTransaction
@ -32,8 +33,7 @@ class NotaryServiceTests {
notaryNode = net.createNode( notaryNode = net.createNode(
legalName = DUMMY_NOTARY.name, legalName = DUMMY_NOTARY.name,
keyPair = DUMMY_NOTARY_KEY, keyPair = DUMMY_NOTARY_KEY,
advertisedServices = *arrayOf(NetworkMapService.Type, SimpleNotaryService.Type) advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type)))
)
clientNode = net.createNode(networkMapAddress = notaryNode.info.address, keyPair = MINI_CORP_KEY) clientNode = net.createNode(networkMapAddress = notaryNode.info.address, keyPair = MINI_CORP_KEY)
net.runNetwork() // Clear network map registration messages net.runNetwork() // Clear network map registration messages
} }

View File

@ -2,22 +2,18 @@ package com.r3corda.node.services
import com.r3corda.core.messaging.SingleMessageRecipient import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.node.services.api.ServiceHubInternal import com.r3corda.node.services.api.ServiceHubInternal
import com.r3corda.node.services.config.NodeConfiguration import com.r3corda.node.services.config.NodeConfiguration
import com.r3corda.node.services.network.AbstractNetworkMapService import com.r3corda.node.services.network.AbstractNetworkMapService
import com.r3corda.node.services.network.InMemoryNetworkMapService import com.r3corda.node.services.network.InMemoryNetworkMapService
import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NetworkMapService
import com.r3corda.node.services.network.PersistentNetworkMapService import com.r3corda.node.services.network.PersistentNetworkMapService
import com.r3corda.node.utilities.configureDatabase
import com.r3corda.node.utilities.databaseTransaction import com.r3corda.node.utilities.databaseTransaction
import com.r3corda.testing.node.MockNetwork import com.r3corda.testing.node.MockNetwork
import com.r3corda.testing.node.makeTestDataSourceProperties
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import java.io.Closeable
import java.nio.file.Path
import java.security.KeyPair import java.security.KeyPair
/** /**
@ -59,7 +55,7 @@ class PersistentNetworkMapServiceTest : AbstractNetworkMapServiceTest() {
private object NodeFactory : MockNetwork.Factory { private object NodeFactory : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair) { return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair) {
override fun makeNetworkMapService() { override fun makeNetworkMapService() {

View File

@ -6,6 +6,7 @@ import com.r3corda.core.contracts.DummyContract
import com.r3corda.core.contracts.TransactionType import com.r3corda.core.contracts.TransactionType
import com.r3corda.core.crypto.DigitalSignature import com.r3corda.core.crypto.DigitalSignature
import com.r3corda.core.transactions.SignedTransaction import com.r3corda.core.transactions.SignedTransaction
import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_NOTARY
import com.r3corda.core.utilities.DUMMY_NOTARY_KEY import com.r3corda.core.utilities.DUMMY_NOTARY_KEY
import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NetworkMapService
@ -33,7 +34,7 @@ class ValidatingNotaryServiceTests {
notaryNode = net.createNode( notaryNode = net.createNode(
legalName = DUMMY_NOTARY.name, legalName = DUMMY_NOTARY.name,
keyPair = DUMMY_NOTARY_KEY, keyPair = DUMMY_NOTARY_KEY,
advertisedServices = *arrayOf(NetworkMapService.Type, ValidatingNotaryService.Type) advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.Type), ServiceInfo(ValidatingNotaryService.Type))
) )
clientNode = net.createNode(networkMapAddress = notaryNode.info.address, keyPair = MINI_CORP_KEY) clientNode = net.createNode(networkMapAddress = notaryNode.info.address, keyPair = MINI_CORP_KEY)
net.runNetwork() // Clear network map registration messages net.runNetwork() // Clear network map registration messages

View File

@ -8,11 +8,11 @@ import com.r3corda.core.crypto.Party
import com.r3corda.core.logElapsedTime import com.r3corda.core.logElapsedTime
import com.r3corda.core.messaging.SingleMessageRecipient import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.CordaPluginRegistry import com.r3corda.core.node.CordaPluginRegistry
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.node.services.ServiceType
import com.r3corda.core.serialization.deserialize import com.r3corda.core.serialization.deserialize
import com.r3corda.core.utilities.LogHelper import com.r3corda.core.utilities.LogHelper
import com.r3corda.demos.api.InterestRateSwapAPI import com.r3corda.demos.api.InterestRateSwapAPI
import com.r3corda.demos.api.NodeInterestRates
import com.r3corda.demos.protocols.AutoOfferProtocol import com.r3corda.demos.protocols.AutoOfferProtocol
import com.r3corda.demos.protocols.ExitServerProtocol import com.r3corda.demos.protocols.ExitServerProtocol
import com.r3corda.demos.protocols.UpdateBusinessDayProtocol import com.r3corda.demos.protocols.UpdateBusinessDayProtocol
@ -21,7 +21,6 @@ import com.r3corda.demos.utilities.putJson
import com.r3corda.demos.utilities.uploadFile import com.r3corda.demos.utilities.uploadFile
import com.r3corda.node.internal.AbstractNode import com.r3corda.node.internal.AbstractNode
import com.r3corda.node.internal.Node import com.r3corda.node.internal.Node
import com.r3corda.demos.api.NodeInterestRates
import com.r3corda.node.services.config.NodeConfiguration import com.r3corda.node.services.config.NodeConfiguration
import com.r3corda.node.services.config.NodeConfigurationFromConfig import com.r3corda.node.services.config.NodeConfigurationFromConfig
import com.r3corda.node.services.messaging.NodeMessagingClient import com.r3corda.node.services.messaging.NodeMessagingClient
@ -393,15 +392,15 @@ private fun createRecipient(addr: String): SingleMessageRecipient {
private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipient): Node { private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipient): Node {
val config = getNodeConfig(params) val config = getNodeConfig(params)
val advertisedServices: Set<ServiceType> val advertisedServices: Set<ServiceInfo>
val networkMapId = val networkMapId =
when (params.node) { when (params.node) {
IRSDemoNode.NodeA -> { IRSDemoNode.NodeA -> {
advertisedServices = setOf(NetworkMapService.Type, SimpleNotaryService.Type) advertisedServices = setOf(ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type))
null null
} }
IRSDemoNode.NodeB -> { IRSDemoNode.NodeB -> {
advertisedServices = setOf(NodeInterestRates.Type) advertisedServices = setOf(ServiceInfo(NodeInterestRates.Type))
networkMap networkMap
} }
} }
@ -461,7 +460,7 @@ private fun loadConfigFile(baseDir: Path, configFile: Path, defaultLegalName: St
private fun createIdentities(nodeConf: NodeConfiguration) { private fun createIdentities(nodeConf: NodeConfiguration) {
val mockNetwork = MockNetwork(false) val mockNetwork = MockNetwork(false)
val node = MockNetwork.MockNode(nodeConf, mockNetwork, null, setOf(NetworkMapService.Type, SimpleNotaryService.Type), 0, null) val node = MockNetwork.MockNode(nodeConf, mockNetwork, null, setOf(ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type)), 0, null)
node.start() node.start()
node.stop() node.stop()
} }

View File

@ -5,7 +5,7 @@ import com.r3corda.contracts.InterestRateSwap
import com.r3corda.contracts.asset.Cash import com.r3corda.contracts.asset.Cash
import com.r3corda.core.contracts.* import com.r3corda.core.contracts.*
import com.r3corda.core.logElapsedTime import com.r3corda.core.logElapsedTime
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.utilities.Emoji import com.r3corda.core.utilities.Emoji
import com.r3corda.core.utilities.LogHelper import com.r3corda.core.utilities.LogHelper
import com.r3corda.demos.api.NodeInterestRates import com.r3corda.demos.api.NodeInterestRates
@ -57,7 +57,7 @@ fun main(args: Array<String>) {
val rateTolerance = BigDecimal(options.valueOf(rateToleranceArg)) val rateTolerance = BigDecimal(options.valueOf(rateToleranceArg))
// Bring up node. // Bring up node.
val advertisedServices: Set<ServiceType> = emptySet() val advertisedServices: Set<ServiceInfo> = emptySet()
val myNetAddr = HostAndPort.fromString(options.valueOf(networkAddressArg)) val myNetAddr = HostAndPort.fromString(options.valueOf(networkAddressArg))
// TODO: create a base class that provides a default implementation // TODO: create a base class that provides a default implementation
@ -77,8 +77,10 @@ fun main(args: Array<String>) {
val apiAddr = HostAndPort.fromParts(myNetAddr.hostText, myNetAddr.port + 1) val apiAddr = HostAndPort.fromParts(myNetAddr.hostText, myNetAddr.port + 1)
val node = logElapsedTime("Node startup") { Node(myNetAddr, apiAddr, config, networkMapAddr, val node = logElapsedTime("Node startup") {
advertisedServices, DemoClock()).setup().start() } Node(myNetAddr, apiAddr, config, networkMapAddr,
advertisedServices, DemoClock()).setup().start()
}
node.networkMapRegistrationFuture.get() node.networkMapRegistrationFuture.get()
val notaryNode = node.services.networkMapCache.notaryNodes[0] val notaryNode = node.services.networkMapCache.notaryNodes[0]
val rateOracle = node.services.networkMapCache.get(InterestRateSwap.OracleType).first() val rateOracle = node.services.networkMapCache.get(InterestRateSwap.OracleType).first()

View File

@ -14,7 +14,7 @@ import com.r3corda.core.crypto.generateKeyPair
import com.r3corda.core.days import com.r3corda.core.days
import com.r3corda.core.logElapsedTime import com.r3corda.core.logElapsedTime
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.protocols.ProtocolLogic import com.r3corda.core.protocols.ProtocolLogic
import com.r3corda.core.seconds import com.r3corda.core.seconds
import com.r3corda.core.success import com.r3corda.core.success
@ -126,13 +126,13 @@ fun main(args: Array<String>) {
} }
// Which services will this instance of the node provide to the network? // Which services will this instance of the node provide to the network?
val advertisedServices: Set<ServiceType> val advertisedServices: Set<ServiceInfo>
// One of the two servers needs to run the network map and notary services. In such a trivial two-node network // One of the two servers needs to run the network map and notary services. In such a trivial two-node network
// the map is not very helpful, but we need one anyway. So just make the buyer side run the network map as it's // the map is not very helpful, but we need one anyway. So just make the buyer side run the network map as it's
// the side that sticks around waiting for the seller. // the side that sticks around waiting for the seller.
val networkMapId = if (role == Role.BUYER) { val networkMapId = if (role == Role.BUYER) {
advertisedServices = setOf(NetworkMapService.Type, SimpleNotaryService.Type) advertisedServices = setOf(ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type))
null null
} else { } else {
advertisedServices = emptySet() advertisedServices = emptySet()

View File

@ -7,7 +7,8 @@ import com.r3corda.core.crypto.generateKeyPair
import com.r3corda.core.messaging.SingleMessageRecipient import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.CityDatabase import com.r3corda.core.node.CityDatabase
import com.r3corda.core.node.PhysicalLocation import com.r3corda.core.node.PhysicalLocation
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.node.services.containsType
import com.r3corda.core.protocols.ProtocolLogic import com.r3corda.core.protocols.ProtocolLogic
import com.r3corda.core.then import com.r3corda.core.then
import com.r3corda.core.utilities.ProgressTracker import com.r3corda.core.utilities.ProgressTracker
@ -45,7 +46,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
// This puts together a mock network of SimulatedNodes. // This puts together a mock network of SimulatedNodes.
open class SimulatedNode(config: NodeConfiguration, mockNet: MockNetwork, networkMapAddress: SingleMessageRecipient?, open class SimulatedNode(config: NodeConfiguration, mockNet: MockNetwork, networkMapAddress: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?) : MockNetwork.MockNode(config, mockNet, networkMapAddress, advertisedServices, id, keyPair) { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?) : MockNetwork.MockNode(config, mockNet, networkMapAddress, advertisedServices, id, keyPair) {
override fun findMyLocation(): PhysicalLocation? = CityDatabase[configuration.nearestCity] override fun findMyLocation(): PhysicalLocation? = CityDatabase[configuration.nearestCity]
} }
@ -53,7 +54,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
var counter = 0 var counter = 0
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
val letter = 'A' + counter val letter = 'A' + counter
val city = bankLocations[counter++ % bankLocations.size] val city = bankLocations[counter++ % bankLocations.size]
@ -85,8 +86,8 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
object NetworkMapNodeFactory : MockNetwork.Factory { object NetworkMapNodeFactory : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, override fun create(config: NodeConfiguration, network: MockNetwork,
networkMapAddr: SingleMessageRecipient?, advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { networkMapAddr: SingleMessageRecipient?, advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
require(advertisedServices.contains(NetworkMapService.Type)) require(advertisedServices.containsType(NetworkMapService.Type))
// TODO: create a base class that provides a default implementation // TODO: create a base class that provides a default implementation
val cfg = object : NodeConfiguration { val cfg = object : NodeConfiguration {
@ -108,8 +109,8 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
object NotaryNodeFactory : MockNetwork.Factory { object NotaryNodeFactory : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
require(advertisedServices.contains(SimpleNotaryService.Type)) require(advertisedServices.containsType(SimpleNotaryService.Type))
// TODO: create a base class that provides a default implementation // TODO: create a base class that provides a default implementation
val cfg = object : NodeConfiguration { val cfg = object : NodeConfiguration {
@ -130,8 +131,8 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
object RatesOracleFactory : MockNetwork.Factory { object RatesOracleFactory : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
require(advertisedServices.contains(NodeInterestRates.Type)) require(advertisedServices.containsType(NodeInterestRates.Type))
// TODO: create a base class that provides a default implementation // TODO: create a base class that provides a default implementation
val cfg = object : NodeConfiguration { val cfg = object : NodeConfiguration {
@ -159,7 +160,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
object RegulatorFactory : MockNetwork.Factory { object RegulatorFactory : MockNetwork.Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
// TODO: create a base class that provides a default implementation // TODO: create a base class that provides a default implementation
val cfg = object : NodeConfiguration { val cfg = object : NodeConfiguration {
@ -187,12 +188,12 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
val network = MockNetwork(networkSendManuallyPumped, runAsync) val network = MockNetwork(networkSendManuallyPumped, runAsync)
// This one must come first. // This one must come first.
val networkMap: SimulatedNode val networkMap: SimulatedNode
= network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = NetworkMapService.Type) as SimulatedNode = network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = ServiceInfo(NetworkMapService.Type)) as SimulatedNode
val notary: SimulatedNode val notary: SimulatedNode
= network.createNode(networkMap.info.address, nodeFactory = NotaryNodeFactory, advertisedServices = SimpleNotaryService.Type) as SimulatedNode = network.createNode(networkMap.info.address, nodeFactory = NotaryNodeFactory, advertisedServices = ServiceInfo(SimpleNotaryService.Type)) as SimulatedNode
val regulators: List<SimulatedNode> = listOf(network.createNode(networkMap.info.address, start = false, nodeFactory = RegulatorFactory) as SimulatedNode) val regulators: List<SimulatedNode> = listOf(network.createNode(networkMap.info.address, start = false, nodeFactory = RegulatorFactory) as SimulatedNode)
val ratesOracle: SimulatedNode val ratesOracle: SimulatedNode
= network.createNode(networkMap.info.address, start = false, nodeFactory = RatesOracleFactory, advertisedServices = NodeInterestRates.Type) as SimulatedNode = network.createNode(networkMap.info.address, start = false, nodeFactory = RatesOracleFactory, advertisedServices = ServiceInfo(NodeInterestRates.Type)) as SimulatedNode
// All nodes must be in one of these two lists for the purposes of the visualiser tool. // All nodes must be in one of these two lists for the purposes of the visualiser tool.
val serviceProviders: List<SimulatedNode> = listOf(notary, ratesOracle, networkMap) val serviceProviders: List<SimulatedNode> = listOf(notary, ratesOracle, networkMap)

View File

@ -13,7 +13,7 @@ import com.r3corda.core.messaging.runOnNextMessage
import com.r3corda.core.messaging.send import com.r3corda.core.messaging.send
import com.r3corda.core.node.PhysicalLocation import com.r3corda.core.node.PhysicalLocation
import com.r3corda.core.node.services.KeyManagementService import com.r3corda.core.node.services.KeyManagementService
import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.ServiceInfo
import com.r3corda.core.node.services.VaultService import com.r3corda.core.node.services.VaultService
import com.r3corda.core.random63BitValue import com.r3corda.core.random63BitValue
import com.r3corda.core.serialization.deserialize import com.r3corda.core.serialization.deserialize
@ -28,7 +28,9 @@ import com.r3corda.node.services.messaging.CordaRPCOps
import com.r3corda.node.services.network.InMemoryNetworkMapService import com.r3corda.node.services.network.InMemoryNetworkMapService
import com.r3corda.node.services.persistence.DBCheckpointStorage import com.r3corda.node.services.persistence.DBCheckpointStorage
import com.r3corda.node.services.persistence.PerFileCheckpointStorage import com.r3corda.node.services.persistence.PerFileCheckpointStorage
import com.r3corda.node.services.network.NetworkMapService
import com.r3corda.node.services.transactions.InMemoryUniquenessProvider import com.r3corda.node.services.transactions.InMemoryUniquenessProvider
import com.r3corda.node.services.transactions.SimpleNotaryService
import com.r3corda.node.utilities.databaseTransaction import com.r3corda.node.utilities.databaseTransaction
import com.r3corda.protocols.ServiceRequestMessage import com.r3corda.protocols.ServiceRequestMessage
import org.slf4j.Logger import org.slf4j.Logger
@ -73,18 +75,18 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
/** Allows customisation of how nodes are created. */ /** Allows customisation of how nodes are created. */
interface Factory { interface Factory {
fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNode advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNode
} }
object DefaultFactory : Factory { object DefaultFactory : Factory {
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNode { advertisedServices: Set<ServiceInfo>, id: Int, keyPair: KeyPair?): MockNode {
return MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair) return MockNode(config, network, networkMapAddr, advertisedServices, id, keyPair)
} }
} }
open class MockNode(config: NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: SingleMessageRecipient?, open class MockNode(config: NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, val id: Int, val keyPair: KeyPair?) : AbstractNode(config, networkMapAddr, advertisedServices, TestClock()) { advertisedServices: Set<ServiceInfo>, val id: Int, val keyPair: KeyPair?) : AbstractNode(config, networkMapAddr, advertisedServices, TestClock()) {
override val log: Logger = loggerFor<MockNode>() override val log: Logger = loggerFor<MockNode>()
override val serverThread: com.r3corda.node.utilities.AffinityExecutor = override val serverThread: com.r3corda.node.utilities.AffinityExecutor =
if (mockNet.threadPerNode) if (mockNet.threadPerNode)
@ -179,7 +181,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
/** Returns a node, optionally created by the passed factory method. */ /** Returns a node, optionally created by the passed factory method. */
fun createNode(networkMapAddress: SingleMessageRecipient? = null, forcedID: Int = -1, nodeFactory: Factory = defaultFactory, fun createNode(networkMapAddress: SingleMessageRecipient? = null, forcedID: Int = -1, nodeFactory: Factory = defaultFactory,
start: Boolean = true, legalName: String? = null, keyPair: KeyPair? = null, start: Boolean = true, legalName: String? = null, keyPair: KeyPair? = null,
vararg advertisedServices: ServiceType): MockNode { vararg advertisedServices: ServiceInfo): MockNode {
val newNode = forcedID == -1 val newNode = forcedID == -1
val id = if (newNode) counter++ else forcedID val id = if (newNode) counter++ else forcedID
@ -238,7 +240,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
fun createTwoNodes(nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = null): Pair<MockNode, MockNode> { fun createTwoNodes(nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = null): Pair<MockNode, MockNode> {
require(nodes.isEmpty()) require(nodes.isEmpty())
return Pair( return Pair(
createNode(null, -1, nodeFactory, true, null, notaryKeyPair, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type), createNode(null, -1, nodeFactory, true, null, notaryKeyPair, ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type)),
createNode(nodes[0].info.address, -1, nodeFactory, true, null) createNode(nodes[0].info.address, -1, nodeFactory, true, null)
) )
} }
@ -255,9 +257,9 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
*/ */
fun createSomeNodes(numPartyNodes: Int = 2, nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = DUMMY_NOTARY_KEY): BasketOfNodes { fun createSomeNodes(numPartyNodes: Int = 2, nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = DUMMY_NOTARY_KEY): BasketOfNodes {
require(nodes.isEmpty()) require(nodes.isEmpty())
val mapNode = createNode(null, nodeFactory = nodeFactory, advertisedServices = com.r3corda.node.services.network.NetworkMapService.Type) val mapNode = createNode(null, nodeFactory = nodeFactory, advertisedServices = ServiceInfo(NetworkMapService.Type))
val notaryNode = createNode(mapNode.info.address, nodeFactory = nodeFactory, keyPair = notaryKeyPair, val notaryNode = createNode(mapNode.info.address, nodeFactory = nodeFactory, keyPair = notaryKeyPair,
advertisedServices = com.r3corda.node.services.transactions.SimpleNotaryService.Type) advertisedServices = ServiceInfo(SimpleNotaryService.Type))
val nodes = ArrayList<MockNode>() val nodes = ArrayList<MockNode>()
repeat(numPartyNodes) { repeat(numPartyNodes) {
nodes += createPartyNode(mapNode.info.address) nodes += createPartyNode(mapNode.info.address)
@ -266,7 +268,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
} }
fun createNotaryNode(legalName: String? = null, keyPair: KeyPair? = null): MockNode { fun createNotaryNode(legalName: String? = null, keyPair: KeyPair? = null): MockNode {
return createNode(null, -1, defaultFactory, true, legalName, keyPair, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type) return createNode(null, -1, defaultFactory, true, legalName, keyPair, ServiceInfo(NetworkMapService.Type), ServiceInfo(SimpleNotaryService.Type))
} }
fun createPartyNode(networkMapAddr: SingleMessageRecipient, legalName: String? = null, keyPair: KeyPair? = null): MockNode { fun createPartyNode(networkMapAddr: SingleMessageRecipient, legalName: String? = null, keyPair: KeyPair? = null): MockNode {