mirror of
https://github.com/corda/corda.git
synced 2025-02-22 10:10:59 +00:00
Merged in mnesbit-cleanup-fake-networkmap-nodeinfo (pull request #336)
Get rid of the fake NodeInfo used to identify the NetworkMapService node.
This commit is contained in:
commit
b89f86d013
@ -4,6 +4,7 @@ import com.google.common.util.concurrent.ListenableFuture
|
|||||||
import com.r3corda.core.contracts.Contract
|
import com.r3corda.core.contracts.Contract
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.messaging.MessagingService
|
import com.r3corda.core.messaging.MessagingService
|
||||||
|
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||||
import com.r3corda.core.node.NodeInfo
|
import com.r3corda.core.node.NodeInfo
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
@ -73,12 +74,12 @@ interface NetworkMapCache {
|
|||||||
* updates.
|
* updates.
|
||||||
*
|
*
|
||||||
* @param net the network messaging service.
|
* @param net the network messaging service.
|
||||||
* @param service the network map service to fetch current state from.
|
* @param networkMapAddress the network map service to fetch current state from.
|
||||||
* @param subscribe if the cache should subscribe to updates.
|
* @param subscribe if the cache should subscribe to updates.
|
||||||
* @param ifChangedSinceVer an optional version number to limit updating the map based on. If the latest map
|
* @param ifChangedSinceVer an optional version number to limit updating the map based on. If the latest map
|
||||||
* version is less than or equal to the given version, no update is fetched.
|
* version is less than or equal to the given version, no update is fetched.
|
||||||
*/
|
*/
|
||||||
fun addMapService(net: MessagingService, service: NodeInfo,
|
fun addMapService(net: MessagingService, networkMapAddress: SingleMessageRecipient,
|
||||||
subscribe: Boolean, ifChangedSinceVer: Int? = null): ListenableFuture<Unit>
|
subscribe: Boolean, ifChangedSinceVer: Int? = null): ListenableFuture<Unit>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -300,8 +300,6 @@ class DriverDSL(
|
|||||||
|
|
||||||
val driverCliParams = NodeRunner.CliParams(
|
val driverCliParams = NodeRunner.CliParams(
|
||||||
services = advertisedServices,
|
services = advertisedServices,
|
||||||
networkMapName = networkMapNodeInfo!!.identity.name,
|
|
||||||
networkMapPublicKey = networkMapNodeInfo!!.identity.owningKey,
|
|
||||||
networkMapAddress = networkMapAddress,
|
networkMapAddress = networkMapAddress,
|
||||||
messagingAddress = messagingAddress,
|
messagingAddress = messagingAddress,
|
||||||
apiAddress = apiAddress,
|
apiAddress = apiAddress,
|
||||||
@ -386,17 +384,8 @@ class DriverDSL(
|
|||||||
override fun start() {
|
override fun start() {
|
||||||
startNetworkMapService()
|
startNetworkMapService()
|
||||||
val networkMapClient = startClient("driver-$networkMapName-client", networkMapAddress).get()
|
val networkMapClient = startClient("driver-$networkMapName-client", networkMapAddress).get()
|
||||||
// We fake the network map's NodeInfo with a random public key in order to retrieve the correct NodeInfo from
|
val networkMapAddr = ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress)
|
||||||
// the network map service itself.
|
networkMapCache.addMapService(networkMapClient, networkMapAddr, true)
|
||||||
val fakeNodeInfo = NodeInfo(
|
|
||||||
address = ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress),
|
|
||||||
identity = Party(
|
|
||||||
name = networkMapName,
|
|
||||||
owningKey = generateKeyPair().public
|
|
||||||
),
|
|
||||||
advertisedServices = setOf(NetworkMapService.Type)
|
|
||||||
)
|
|
||||||
networkMapCache.addMapService(networkMapClient, fakeNodeInfo, true)
|
|
||||||
networkMapNodeInfo = poll("network map cache for $networkMapName") {
|
networkMapNodeInfo = poll("network map cache for $networkMapName") {
|
||||||
networkMapCache.partyNodes.forEach {
|
networkMapCache.partyNodes.forEach {
|
||||||
if (it.identity.name == networkMapName) {
|
if (it.identity.name == networkMapName) {
|
||||||
@ -423,8 +412,6 @@ class DriverDSL(
|
|||||||
|
|
||||||
val driverCliParams = NodeRunner.CliParams(
|
val driverCliParams = NodeRunner.CliParams(
|
||||||
services = setOf(NetworkMapService.Type),
|
services = setOf(NetworkMapService.Type),
|
||||||
networkMapName = null,
|
|
||||||
networkMapPublicKey = null,
|
|
||||||
networkMapAddress = null,
|
networkMapAddress = null,
|
||||||
messagingAddress = networkMapAddress,
|
messagingAddress = networkMapAddress,
|
||||||
apiAddress = apiAddress,
|
apiAddress = apiAddress,
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
package com.r3corda.node.driver
|
package com.r3corda.node.driver
|
||||||
|
|
||||||
import com.google.common.net.HostAndPort
|
import com.google.common.net.HostAndPort
|
||||||
import com.r3corda.core.crypto.Party
|
|
||||||
import com.r3corda.core.crypto.parsePublicKeyBase58
|
|
||||||
import com.r3corda.core.crypto.toBase58String
|
|
||||||
import com.r3corda.core.node.NodeInfo
|
|
||||||
import com.r3corda.core.node.services.ServiceType
|
import com.r3corda.core.node.services.ServiceType
|
||||||
import com.r3corda.node.internal.Node
|
import com.r3corda.node.internal.Node
|
||||||
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.ArtemisMessagingClient
|
import com.r3corda.node.services.messaging.ArtemisMessagingClient
|
||||||
import com.r3corda.node.services.network.NetworkMapService
|
|
||||||
import joptsimple.ArgumentAcceptingOptionSpec
|
import joptsimple.ArgumentAcceptingOptionSpec
|
||||||
import joptsimple.OptionParser
|
import joptsimple.OptionParser
|
||||||
import joptsimple.OptionSet
|
import joptsimple.OptionSet
|
||||||
@ -18,7 +13,6 @@ import org.slf4j.Logger
|
|||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.security.PublicKey
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
private val log: Logger = LoggerFactory.getLogger(NodeRunner::class.java)
|
private val log: Logger = LoggerFactory.getLogger(NodeRunner::class.java)
|
||||||
@ -33,15 +27,8 @@ class NodeRunner {
|
|||||||
with(cliParams) {
|
with(cliParams) {
|
||||||
|
|
||||||
val networkMapNodeInfo =
|
val networkMapNodeInfo =
|
||||||
if (networkMapName != null && networkMapPublicKey != null && networkMapAddress != null) {
|
if (networkMapAddress != null) {
|
||||||
NodeInfo(
|
ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress)
|
||||||
address = ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress),
|
|
||||||
identity = Party(
|
|
||||||
name = networkMapName,
|
|
||||||
owningKey = networkMapPublicKey
|
|
||||||
),
|
|
||||||
advertisedServices = setOf(NetworkMapService.Type)
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@ -70,8 +57,6 @@ class NodeRunner {
|
|||||||
|
|
||||||
class CliParams (
|
class CliParams (
|
||||||
val services: Set<ServiceType>,
|
val services: Set<ServiceType>,
|
||||||
val networkMapName: String?,
|
|
||||||
val networkMapPublicKey: PublicKey?,
|
|
||||||
val networkMapAddress: HostAndPort?,
|
val networkMapAddress: HostAndPort?,
|
||||||
val messagingAddress: HostAndPort,
|
val messagingAddress: HostAndPort,
|
||||||
val apiAddress: HostAndPort,
|
val apiAddress: HostAndPort,
|
||||||
@ -82,10 +67,6 @@ class NodeRunner {
|
|||||||
val parser = OptionParser()
|
val parser = OptionParser()
|
||||||
val services =
|
val services =
|
||||||
parser.accepts("services").withRequiredArg().ofType(String::class.java)
|
parser.accepts("services").withRequiredArg().ofType(String::class.java)
|
||||||
val networkMapName =
|
|
||||||
parser.accepts("network-map-name").withOptionalArg().ofType(String::class.java)
|
|
||||||
val networkMapPublicKey =
|
|
||||||
parser.accepts("network-map-public-key").withOptionalArg().ofType(String::class.java)
|
|
||||||
val networkMapAddress =
|
val networkMapAddress =
|
||||||
parser.accepts("network-map-address").withOptionalArg().ofType(String::class.java)
|
parser.accepts("network-map-address").withOptionalArg().ofType(String::class.java)
|
||||||
val messagingAddress =
|
val messagingAddress =
|
||||||
@ -100,8 +81,6 @@ class NodeRunner {
|
|||||||
|
|
||||||
fun parse(optionSet: OptionSet): CliParams {
|
fun parse(optionSet: OptionSet): CliParams {
|
||||||
val services = optionSet.valuesOf(services)
|
val services = optionSet.valuesOf(services)
|
||||||
val networkMapName = optionSet.valueOf(networkMapName)
|
|
||||||
val networkMapPublicKey = optionSet.valueOf(networkMapPublicKey)?.run { parsePublicKeyBase58(this) }
|
|
||||||
val networkMapAddress = optionSet.valueOf(networkMapAddress)
|
val networkMapAddress = optionSet.valueOf(networkMapAddress)
|
||||||
val messagingAddress = requiredArgument(optionSet, messagingAddress)
|
val messagingAddress = requiredArgument(optionSet, messagingAddress)
|
||||||
val apiAddress = requiredArgument(optionSet, apiAddress)
|
val apiAddress = requiredArgument(optionSet, apiAddress)
|
||||||
@ -112,8 +91,6 @@ class NodeRunner {
|
|||||||
messagingAddress = HostAndPort.fromString(messagingAddress),
|
messagingAddress = HostAndPort.fromString(messagingAddress),
|
||||||
apiAddress = HostAndPort.fromString(apiAddress),
|
apiAddress = HostAndPort.fromString(apiAddress),
|
||||||
baseDirectory = baseDirectory,
|
baseDirectory = baseDirectory,
|
||||||
networkMapName = networkMapName,
|
|
||||||
networkMapPublicKey = networkMapPublicKey,
|
|
||||||
networkMapAddress = networkMapAddress?.let { HostAndPort.fromString(it) }
|
networkMapAddress = networkMapAddress?.let { HostAndPort.fromString(it) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -125,14 +102,6 @@ class NodeRunner {
|
|||||||
cliArguments.add("--services")
|
cliArguments.add("--services")
|
||||||
cliArguments.addAll(services.map { it.toString() })
|
cliArguments.addAll(services.map { it.toString() })
|
||||||
}
|
}
|
||||||
if (networkMapName != null) {
|
|
||||||
cliArguments.add("--network-map-name")
|
|
||||||
cliArguments.add(networkMapName)
|
|
||||||
}
|
|
||||||
if (networkMapPublicKey != null) {
|
|
||||||
cliArguments.add("--network-map-public-key")
|
|
||||||
cliArguments.add(networkMapPublicKey.toBase58String())
|
|
||||||
}
|
|
||||||
if (networkMapAddress != null) {
|
if (networkMapAddress != null) {
|
||||||
cliArguments.add("--network-map-address")
|
cliArguments.add("--network-map-address")
|
||||||
cliArguments.add(networkMapAddress.toString())
|
cliArguments.add(networkMapAddress.toString())
|
||||||
|
@ -6,6 +6,7 @@ import com.google.common.util.concurrent.MoreExecutors
|
|||||||
import com.google.common.util.concurrent.SettableFuture
|
import com.google.common.util.concurrent.SettableFuture
|
||||||
import com.r3corda.core.RunOnCallerThread
|
import com.r3corda.core.RunOnCallerThread
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
|
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||||
import com.r3corda.core.messaging.runOnNextMessage
|
import com.r3corda.core.messaging.runOnNextMessage
|
||||||
import com.r3corda.core.node.CityDatabase
|
import com.r3corda.core.node.CityDatabase
|
||||||
import com.r3corda.core.node.CordaPluginRegistry
|
import com.r3corda.core.node.CordaPluginRegistry
|
||||||
@ -69,7 +70,7 @@ import java.util.concurrent.TimeUnit
|
|||||||
// TODO: Where this node is the initial network map service, currently no networkMapService is provided.
|
// TODO: Where this node is the initial network map service, currently no networkMapService is provided.
|
||||||
// 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 dir: Path, val configuration: NodeConfiguration, val networkMapService: NodeInfo?,
|
abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, val networkMapService: SingleMessageRecipient?,
|
||||||
val advertisedServices: Set<ServiceType>, val platformClock: Clock): SingletonSerializeAsToken() {
|
val advertisedServices: Set<ServiceType>, val platformClock: Clock): SingletonSerializeAsToken() {
|
||||||
companion object {
|
companion object {
|
||||||
val PRIVATE_KEY_FILE_NAME = "identity-private-key"
|
val PRIVATE_KEY_FILE_NAME = "identity-private-key"
|
||||||
@ -277,11 +278,11 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
* 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 networkMapService.advertisedServices) {
|
require(networkMapService != null || NetworkMapService.Type in advertisedServices) {
|
||||||
"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)
|
||||||
if (networkMapService != null && networkMapService != info) {
|
if (networkMapService != null) {
|
||||||
// Only register if we are pointed at a network map service and it's not us.
|
// Only register if we are pointed at a network map service and it's not us.
|
||||||
// TODO: Return a future so the caller knows these operations may not have completed yet, and can monitor if needed
|
// TODO: Return a future so the caller knows these operations may not have completed yet, and can monitor if needed
|
||||||
updateRegistration(networkMapService, AddOrRemove.ADD)
|
updateRegistration(networkMapService, AddOrRemove.ADD)
|
||||||
@ -291,7 +292,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
if (inNodeNetworkMapService == null)
|
if (inNodeNetworkMapService == null)
|
||||||
return noNetworkMapConfigured()
|
return noNetworkMapConfigured()
|
||||||
// Register for updates, even if we're the one running the network map.
|
// Register for updates, even if we're the one running the network map.
|
||||||
return services.networkMapCache.addMapService(net, info, true, null)
|
return services.networkMapCache.addMapService(net, info.address, true, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This is overriden by the mock node implementation to enable operation without any network map service */
|
/** This is overriden by the mock node implementation to enable operation without any network map service */
|
||||||
@ -301,7 +302,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
"has any other map node been configured.")
|
"has any other map node been configured.")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateRegistration(serviceInfo: NodeInfo, type: AddOrRemove): ListenableFuture<NetworkMapService.RegistrationResponse> {
|
private fun updateRegistration(networkMapAddr: SingleMessageRecipient, type: AddOrRemove): ListenableFuture<NetworkMapService.RegistrationResponse> {
|
||||||
// Register this node against the network
|
// Register this node against the network
|
||||||
val expires = platformClock.instant() + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
val expires = platformClock.instant() + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
||||||
val reg = NodeRegistration(info, networkMapSeq++, type, expires)
|
val reg = NodeRegistration(info, networkMapSeq++, type, expires)
|
||||||
@ -313,7 +314,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
net.runOnNextMessage(REGISTER_PROTOCOL_TOPIC, sessionID, RunOnCallerThread) { message ->
|
net.runOnNextMessage(REGISTER_PROTOCOL_TOPIC, sessionID, RunOnCallerThread) { message ->
|
||||||
future.set(message.data.deserialize())
|
future.set(message.data.deserialize())
|
||||||
}
|
}
|
||||||
net.send(message, serviceInfo.address)
|
net.send(message, networkMapAddr)
|
||||||
|
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
@ -339,8 +340,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
|
|
||||||
protected open fun makeIdentityService(): IdentityService {
|
protected open fun makeIdentityService(): IdentityService {
|
||||||
val service = InMemoryIdentityService()
|
val service = InMemoryIdentityService()
|
||||||
if (networkMapService != null)
|
|
||||||
service.registerIdentity(networkMapService.identity)
|
|
||||||
service.registerIdentity(storage.myLegalIdentity)
|
service.registerIdentity(storage.myLegalIdentity)
|
||||||
|
|
||||||
services.networkMapCache.partyNodes.forEach { service.registerIdentity(it.identity) }
|
services.networkMapCache.partyNodes.forEach { service.registerIdentity(it.identity) }
|
||||||
|
@ -2,6 +2,7 @@ package com.r3corda.node.internal
|
|||||||
|
|
||||||
import com.codahale.metrics.JmxReporter
|
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.node.NodeInfo
|
import com.r3corda.core.node.NodeInfo
|
||||||
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.ServiceType
|
||||||
@ -53,7 +54,7 @@ class ConfigurationException(message: String) : Exception(message)
|
|||||||
* @param messagingServerAddr The address of the Artemis broker instance. If not provided the node will run one locally.
|
* @param messagingServerAddr The address of the Artemis broker instance. If not provided the node will run one locally.
|
||||||
*/
|
*/
|
||||||
class Node(dir: Path, val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
|
class Node(dir: Path, val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
|
||||||
configuration: NodeConfiguration, networkMapAddress: NodeInfo?,
|
configuration: NodeConfiguration, networkMapAddress: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, clock: Clock = NodeClock(),
|
advertisedServices: Set<ServiceType>, clock: Clock = NodeClock(),
|
||||||
val messagingServerAddr: HostAndPort? = null) : AbstractNode(dir, configuration, networkMapAddress, advertisedServices, clock) {
|
val messagingServerAddr: HostAndPort? = null) : AbstractNode(dir, configuration, networkMapAddress, advertisedServices, clock) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -3,6 +3,7 @@ package com.r3corda.node.services.config
|
|||||||
import com.google.common.net.HostAndPort
|
import com.google.common.net.HostAndPort
|
||||||
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.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.ServiceType
|
||||||
import com.r3corda.node.internal.Node
|
import com.r3corda.node.internal.Node
|
||||||
@ -122,9 +123,8 @@ class FullNodeConfiguration(conf: Config) : NodeConfiguration {
|
|||||||
advertisedServices.add(object : ServiceType(serviceId) {})
|
advertisedServices.add(object : ServiceType(serviceId) {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO Node startup should not need a full NodeInfo for the remote NetworkMapService provider as bootstrap
|
|
||||||
val networkMapBootstrapIdentity = Party(mapService.identity, generateKeyPair().public)
|
val networkMapAddress: SingleMessageRecipient? = if (mapService.hostServiceLocally) null else networkMapTarget
|
||||||
val networkMapAddress: NodeInfo? = if (mapService.hostServiceLocally) null else NodeInfo(networkMapTarget, networkMapBootstrapIdentity, setOf(NetworkMapService.Type))
|
|
||||||
return Node(basedir.toAbsolutePath().normalize(),
|
return Node(basedir.toAbsolutePath().normalize(),
|
||||||
artemisAddress,
|
artemisAddress,
|
||||||
webAddress,
|
webAddress,
|
||||||
|
@ -3,6 +3,7 @@ package com.r3corda.node.services.messaging
|
|||||||
import com.google.common.net.HostAndPort
|
import com.google.common.net.HostAndPort
|
||||||
import com.r3corda.core.ThreadBox
|
import com.r3corda.core.ThreadBox
|
||||||
import com.r3corda.core.crypto.newSecureRandom
|
import com.r3corda.core.crypto.newSecureRandom
|
||||||
|
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||||
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.utilities.loggerFor
|
import com.r3corda.core.utilities.loggerFor
|
||||||
@ -67,8 +68,8 @@ class ArtemisMessagingServer(directory: Path,
|
|||||||
running = false
|
running = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bridgeToNetworkMapService(networkMapService: NodeInfo?) {
|
fun bridgeToNetworkMapService(networkMapService: SingleMessageRecipient?) {
|
||||||
if ((networkMapService != null) && (networkMapService.address is NetworkMapAddress)) {
|
if ((networkMapService != null) && (networkMapService is NetworkMapAddress)) {
|
||||||
val query = activeMQServer.queueQuery(NETWORK_MAP_ADDRESS)
|
val query = activeMQServer.queueQuery(NETWORK_MAP_ADDRESS)
|
||||||
if (!query.isExists) {
|
if (!query.isExists) {
|
||||||
activeMQServer.createQueue(NETWORK_MAP_ADDRESS, NETWORK_MAP_ADDRESS, null, true, false)
|
activeMQServer.createQueue(NETWORK_MAP_ADDRESS, NETWORK_MAP_ADDRESS, null, true, false)
|
||||||
@ -87,7 +88,7 @@ class ArtemisMessagingServer(directory: Path,
|
|||||||
val query = activeMQServer.queueQuery(queueName)
|
val query = activeMQServer.queueQuery(queueName)
|
||||||
if (query.isExists) {
|
if (query.isExists) {
|
||||||
// Queue exists so now wire up bridge
|
// Queue exists so now wire up bridge
|
||||||
maybeDeployBridgeForAddress(queueName, change.node)
|
maybeDeployBridgeForAddress(queueName, change.node.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ class ArtemisMessagingServer(directory: Path,
|
|||||||
val query = activeMQServer.queueQuery(queueName)
|
val query = activeMQServer.queueQuery(queueName)
|
||||||
if (query.isExists) {
|
if (query.isExists) {
|
||||||
// Deploy new bridge
|
// Deploy new bridge
|
||||||
maybeDeployBridgeForAddress(queueName, change.node)
|
maybeDeployBridgeForAddress(queueName, change.node.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ class ArtemisMessagingServer(directory: Path,
|
|||||||
if (identity != null) {
|
if (identity != null) {
|
||||||
val nodeInfo = networkMapCache.getNodeByPublicKey(identity)
|
val nodeInfo = networkMapCache.getNodeByPublicKey(identity)
|
||||||
if (nodeInfo != null) {
|
if (nodeInfo != null) {
|
||||||
maybeDeployBridgeForAddress(queueName, nodeInfo)
|
maybeDeployBridgeForAddress(queueName, nodeInfo.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,8 +192,8 @@ class ArtemisMessagingServer(directory: Path,
|
|||||||
* For every queue created we need to have a bridge deployed in case the address of the queue
|
* For every queue created we need to have a bridge deployed in case the address of the queue
|
||||||
* is that of a remote party
|
* is that of a remote party
|
||||||
*/
|
*/
|
||||||
private fun maybeDeployBridgeForAddress(name: SimpleString, nodeInfo: NodeInfo) {
|
private fun maybeDeployBridgeForAddress(name: SimpleString, address: SingleMessageRecipient) {
|
||||||
val hostAndPort = toHostAndPort(nodeInfo.address)
|
val hostAndPort = toHostAndPort(address)
|
||||||
|
|
||||||
if (hostAndPort == myHostPort) {
|
if (hostAndPort == myHostPort) {
|
||||||
return
|
return
|
||||||
|
@ -6,6 +6,7 @@ import com.google.common.util.concurrent.SettableFuture
|
|||||||
import com.r3corda.core.contracts.Contract
|
import com.r3corda.core.contracts.Contract
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.messaging.MessagingService
|
import com.r3corda.core.messaging.MessagingService
|
||||||
|
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||||
import com.r3corda.core.messaging.runOnNextMessage
|
import com.r3corda.core.messaging.runOnNextMessage
|
||||||
import com.r3corda.core.messaging.send
|
import com.r3corda.core.messaging.send
|
||||||
import com.r3corda.core.node.NodeInfo
|
import com.r3corda.core.node.NodeInfo
|
||||||
@ -57,7 +58,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
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 }
|
||||||
|
|
||||||
override fun addMapService(net: MessagingService, service: NodeInfo, subscribe: Boolean,
|
override fun addMapService(net: MessagingService, networkMapAddress: SingleMessageRecipient, subscribe: Boolean,
|
||||||
ifChangedSinceVer: Int?): ListenableFuture<Unit> {
|
ifChangedSinceVer: Int?): ListenableFuture<Unit> {
|
||||||
if (subscribe && !registeredForPush) {
|
if (subscribe && !registeredForPush) {
|
||||||
// Add handler to the network, for updates received from the remote network map service.
|
// Add handler to the network, for updates received from the remote network map service.
|
||||||
@ -90,7 +91,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
resp.nodes?.forEach { processRegistration(it) }
|
resp.nodes?.forEach { processRegistration(it) }
|
||||||
future.set(Unit)
|
future.set(Unit)
|
||||||
}
|
}
|
||||||
net.send(NetworkMapService.FETCH_PROTOCOL_TOPIC, DEFAULT_SESSION_ID, req, service.address)
|
net.send(NetworkMapService.FETCH_PROTOCOL_TOPIC, DEFAULT_SESSION_ID, req, networkMapAddress)
|
||||||
|
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.r3corda.node.messaging
|
|||||||
import com.r3corda.core.contracts.Attachment
|
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.node.NodeInfo
|
import com.r3corda.core.node.NodeInfo
|
||||||
import com.r3corda.core.node.services.ServiceType
|
import com.r3corda.core.node.services.ServiceType
|
||||||
import com.r3corda.core.serialization.OpaqueBytes
|
import com.r3corda.core.serialization.OpaqueBytes
|
||||||
@ -87,7 +88,7 @@ class AttachmentTests {
|
|||||||
fun `malicious response`() {
|
fun `malicious response`() {
|
||||||
// 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(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
||||||
return object : MockNetwork.MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair) {
|
return object : MockNetwork.MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair) {
|
||||||
override fun start(): MockNetwork.MockNode {
|
override fun start(): MockNetwork.MockNode {
|
||||||
@ -98,7 +99,7 @@ class AttachmentTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, true, null, null, false, NetworkMapService.Type, SimpleNotaryService.Type)
|
}, true, null, null, false, NetworkMapService.Type, SimpleNotaryService.Type)
|
||||||
val n1 = network.createNode(n0.info)
|
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.
|
||||||
val id = n0.storage.attachments.importAttachment(ByteArrayInputStream(fakeAttachment()))
|
val id = n0.storage.attachments.importAttachment(ByteArrayInputStream(fakeAttachment()))
|
||||||
|
@ -5,6 +5,7 @@ package com.r3corda.node.messaging
|
|||||||
import com.r3corda.core.messaging.Message
|
import com.r3corda.core.messaging.Message
|
||||||
import com.r3corda.core.messaging.TopicStringValidator
|
import com.r3corda.core.messaging.TopicStringValidator
|
||||||
import com.r3corda.core.node.services.DEFAULT_SESSION_ID
|
import com.r3corda.core.node.services.DEFAULT_SESSION_ID
|
||||||
|
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
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -38,9 +39,9 @@ class InMemoryMessagingTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun basics() {
|
fun basics() {
|
||||||
val node1 = network.createNode()
|
val node1 = network.createNode(advertisedServices = NetworkMapService.Type)
|
||||||
val node2 = network.createNode()
|
val node2 = network.createNode(networkMapAddress = node1.info.address)
|
||||||
val node3 = network.createNode()
|
val node3 = network.createNode(networkMapAddress = node1.info.address)
|
||||||
|
|
||||||
val bits = "test-content".toByteArray()
|
val bits = "test-content".toByteArray()
|
||||||
var finalDelivery: Message? = null
|
var finalDelivery: Message? = null
|
||||||
@ -67,9 +68,9 @@ class InMemoryMessagingTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun broadcast() {
|
fun broadcast() {
|
||||||
val node1 = network.createNode()
|
val node1 = network.createNode(advertisedServices = NetworkMapService.Type)
|
||||||
val node2 = network.createNode()
|
val node2 = network.createNode(networkMapAddress = node1.info.address)
|
||||||
val node3 = network.createNode()
|
val node3 = network.createNode(networkMapAddress = node1.info.address)
|
||||||
|
|
||||||
val bits = "test-content".toByteArray()
|
val bits = "test-content".toByteArray()
|
||||||
|
|
||||||
@ -86,8 +87,8 @@ class InMemoryMessagingTests {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
fun `skip unhandled messages`() {
|
fun `skip unhandled messages`() {
|
||||||
val node1 = network.createNode()
|
val node1 = network.createNode(advertisedServices = NetworkMapService.Type)
|
||||||
val node2 = network.createNode()
|
val node2 = network.createNode(networkMapAddress = node1.info.address)
|
||||||
var received: Int = 0
|
var received: Int = 0
|
||||||
|
|
||||||
node1.net.addMessageHandler("valid_message") { msg, reg ->
|
node1.net.addMessageHandler("valid_message") { msg, reg ->
|
||||||
|
@ -8,6 +8,7 @@ import com.r3corda.core.contracts.*
|
|||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.crypto.SecureHash
|
import com.r3corda.core.crypto.SecureHash
|
||||||
import com.r3corda.core.days
|
import com.r3corda.core.days
|
||||||
|
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||||
import com.r3corda.core.node.NodeInfo
|
import com.r3corda.core.node.NodeInfo
|
||||||
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.ServiceType
|
||||||
@ -93,8 +94,8 @@ class TwoPartyTradeProtocolTests {
|
|||||||
ledger {
|
ledger {
|
||||||
|
|
||||||
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
||||||
val aliceNode = net.createPartyNode(notaryNode.info, ALICE.name, ALICE_KEY)
|
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name, ALICE_KEY)
|
||||||
val bobNode = net.createPartyNode(notaryNode.info, BOB.name, BOB_KEY)
|
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name, BOB_KEY)
|
||||||
|
|
||||||
bobNode.services.fillWithSomeTestCash(2000.DOLLARS)
|
bobNode.services.fillWithSomeTestCash(2000.DOLLARS)
|
||||||
val alicesFakePaper = fillUpForSeller(false, aliceNode.storage.myLegalIdentity.owningKey,
|
val alicesFakePaper = fillUpForSeller(false, aliceNode.storage.myLegalIdentity.owningKey,
|
||||||
@ -139,11 +140,11 @@ class TwoPartyTradeProtocolTests {
|
|||||||
fun `shutdown and restore`() {
|
fun `shutdown and restore`() {
|
||||||
ledger {
|
ledger {
|
||||||
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
||||||
val aliceNode = net.createPartyNode(notaryNode.info, ALICE.name, ALICE_KEY)
|
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name, ALICE_KEY)
|
||||||
var bobNode = net.createPartyNode(notaryNode.info, BOB.name, BOB_KEY)
|
var bobNode = net.createPartyNode(notaryNode.info.address, BOB.name, BOB_KEY)
|
||||||
|
|
||||||
val bobAddr = bobNode.net.myAddress as InMemoryMessagingNetwork.Handle
|
val bobAddr = bobNode.net.myAddress as InMemoryMessagingNetwork.Handle
|
||||||
val networkMapAddr = notaryNode.info
|
val networkMapAddr = notaryNode.info.address
|
||||||
|
|
||||||
net.runNetwork() // Clear network map registration messages
|
net.runNetwork() // Clear network map registration messages
|
||||||
|
|
||||||
@ -202,7 +203,7 @@ class TwoPartyTradeProtocolTests {
|
|||||||
// ... bring the node back up ... the act of constructing the SMM will re-register the message handlers
|
// ... bring the node back up ... the act of constructing the SMM will re-register the message handlers
|
||||||
// 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(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
||||||
return MockNetwork.MockNode(dir, config, network, networkMapAddr, advertisedServices, bobAddr.id, BOB_KEY)
|
return MockNetwork.MockNode(dir, config, network, networkMapAddr, advertisedServices, bobAddr.id, BOB_KEY)
|
||||||
}
|
}
|
||||||
@ -229,10 +230,10 @@ class TwoPartyTradeProtocolTests {
|
|||||||
|
|
||||||
// Creates a mock node with an overridden storage service that uses a RecordingMap, that lets us test the order
|
// Creates a mock node with an overridden storage service that uses a RecordingMap, that lets us test the order
|
||||||
// of gets and puts.
|
// of gets and puts.
|
||||||
private fun makeNodeWithTracking(networkMapAddr: NodeInfo?, name: String, keyPair: KeyPair): MockNetwork.MockNode {
|
private fun makeNodeWithTracking(networkMapAddr: SingleMessageRecipient?, name: String, keyPair: KeyPair): MockNetwork.MockNode {
|
||||||
// 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(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
||||||
return object : MockNetwork.MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair) {
|
return object : MockNetwork.MockNode(dir, 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 ...
|
||||||
@ -250,8 +251,8 @@ class TwoPartyTradeProtocolTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `check dependencies of sale asset are resolved`() {
|
fun `check dependencies of sale asset are resolved`() {
|
||||||
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
||||||
val aliceNode = makeNodeWithTracking(notaryNode.info, ALICE.name, ALICE_KEY)
|
val aliceNode = makeNodeWithTracking(notaryNode.info.address, ALICE.name, ALICE_KEY)
|
||||||
val bobNode = makeNodeWithTracking(notaryNode.info, BOB.name, BOB_KEY)
|
val bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name, BOB_KEY)
|
||||||
|
|
||||||
ledger(aliceNode.services) {
|
ledger(aliceNode.services) {
|
||||||
|
|
||||||
@ -371,8 +372,8 @@ class TwoPartyTradeProtocolTests {
|
|||||||
expectedMessageSubstring: String
|
expectedMessageSubstring: String
|
||||||
) {
|
) {
|
||||||
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
|
||||||
val aliceNode = net.createPartyNode(notaryNode.info, ALICE.name, ALICE_KEY)
|
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name, ALICE_KEY)
|
||||||
val bobNode = net.createPartyNode(notaryNode.info, BOB.name, BOB_KEY)
|
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name, BOB_KEY)
|
||||||
val issuer = MEGA_CORP.ref(1, 2, 3)
|
val issuer = MEGA_CORP.ref(1, 2, 3)
|
||||||
|
|
||||||
val bobKey = bobNode.keyManagement.freshKey()
|
val bobKey = bobNode.keyManagement.freshKey()
|
||||||
|
@ -16,7 +16,7 @@ class InMemoryNetworkMapCacheTest {
|
|||||||
fun registerWithNetwork() {
|
fun registerWithNetwork() {
|
||||||
val (n0, n1) = network.createTwoNodes()
|
val (n0, n1) = network.createTwoNodes()
|
||||||
|
|
||||||
val future = n1.services.networkMapCache.addMapService(n1.net, n0.info, false, null)
|
val future = n1.services.networkMapCache.addMapService(n1.net, n0.info.address, false, null)
|
||||||
network.runNetwork()
|
network.runNetwork()
|
||||||
future.get()
|
future.get()
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ class NotaryChangeTests {
|
|||||||
legalName = DUMMY_NOTARY.name,
|
legalName = DUMMY_NOTARY.name,
|
||||||
keyPair = DUMMY_NOTARY_KEY,
|
keyPair = DUMMY_NOTARY_KEY,
|
||||||
advertisedServices = *arrayOf(NetworkMapService.Type, SimpleNotaryService.Type))
|
advertisedServices = *arrayOf(NetworkMapService.Type, SimpleNotaryService.Type))
|
||||||
clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info)
|
clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info.address)
|
||||||
clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info)
|
clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info.address)
|
||||||
newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info, advertisedServices = SimpleNotaryService.Type)
|
newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info.address, advertisedServices = SimpleNotaryService.Type)
|
||||||
|
|
||||||
net.runNetwork() // Clear network map registration messages
|
net.runNetwork() // Clear network map registration messages
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class NotaryServiceTests {
|
|||||||
keyPair = DUMMY_NOTARY_KEY,
|
keyPair = DUMMY_NOTARY_KEY,
|
||||||
advertisedServices = *arrayOf(NetworkMapService.Type, SimpleNotaryService.Type)
|
advertisedServices = *arrayOf(NetworkMapService.Type, SimpleNotaryService.Type)
|
||||||
)
|
)
|
||||||
clientNode = net.createNode(networkMapAddress = notaryNode.info, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class ValidatingNotaryServiceTests {
|
|||||||
keyPair = DUMMY_NOTARY_KEY,
|
keyPair = DUMMY_NOTARY_KEY,
|
||||||
advertisedServices = *arrayOf(NetworkMapService.Type, ValidatingNotaryService.Type)
|
advertisedServices = *arrayOf(NetworkMapService.Type, ValidatingNotaryService.Type)
|
||||||
)
|
)
|
||||||
clientNode = net.createNode(networkMapAddress = notaryNode.info, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package com.r3corda.node.services.statemachine
|
|||||||
import co.paralleluniverse.fibers.Fiber
|
import co.paralleluniverse.fibers.Fiber
|
||||||
import co.paralleluniverse.fibers.Suspendable
|
import co.paralleluniverse.fibers.Suspendable
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.node.NodeInfo
|
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||||
import com.r3corda.core.protocols.ProtocolLogic
|
import com.r3corda.core.protocols.ProtocolLogic
|
||||||
import com.r3corda.core.random63BitValue
|
import com.r3corda.core.random63BitValue
|
||||||
import com.r3corda.testing.node.MockNetwork
|
import com.r3corda.testing.node.MockNetwork
|
||||||
@ -55,12 +55,13 @@ class StateMachineManagerTests {
|
|||||||
node2.smm.add("test", ReceiveProtocol(topic, sessionID))
|
node2.smm.add("test", ReceiveProtocol(topic, sessionID))
|
||||||
net.runNetwork()
|
net.runNetwork()
|
||||||
node2.stop()
|
node2.stop()
|
||||||
val restoredProtocol = node2.restartAndGetRestoredProtocol<ReceiveProtocol>(node1.info)
|
val restoredProtocol = node2.restartAndGetRestoredProtocol<ReceiveProtocol>(node1.info.address)
|
||||||
assertThat(restoredProtocol.receivedPayload).isEqualTo(payload)
|
assertThat(restoredProtocol.receivedPayload).isEqualTo(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified P : NonTerminatingProtocol> MockNode.restartAndGetRestoredProtocol(networkMapAddress: NodeInfo? = null): P {
|
private inline fun <reified P : NonTerminatingProtocol> MockNode.restartAndGetRestoredProtocol(networkMapAddress: SingleMessageRecipient? = null): P {
|
||||||
val node = mockNet.createNode(networkMapAddress, id)
|
val servicesArray = advertisedServices.toTypedArray()
|
||||||
|
val node = mockNet.createNode(networkMapAddress, id, advertisedServices = *servicesArray)
|
||||||
return node.smm.findStateMachines(P::class.java).single().first
|
return node.smm.findStateMachines(P::class.java).single().first
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,6 @@ sealed class CliParams {
|
|||||||
val networkAddress: HostAndPort,
|
val networkAddress: HostAndPort,
|
||||||
val apiAddress: HostAndPort,
|
val apiAddress: HostAndPort,
|
||||||
val mapAddress: String,
|
val mapAddress: String,
|
||||||
val identityFile: Path,
|
|
||||||
val tradeWithIdentities: List<Path>,
|
val tradeWithIdentities: List<Path>,
|
||||||
val uploadRates: Boolean,
|
val uploadRates: Boolean,
|
||||||
val defaultLegalName: String,
|
val defaultLegalName: String,
|
||||||
@ -166,11 +165,6 @@ sealed class CliParams {
|
|||||||
CliParamsSpec.apiAddressArg.defaultsTo("localhost:${defaultApiPort(node)}")
|
CliParamsSpec.apiAddressArg.defaultsTo("localhost:${defaultApiPort(node)}")
|
||||||
)),
|
)),
|
||||||
mapAddress = options.valueOf(CliParamsSpec.networkMapNetAddr),
|
mapAddress = options.valueOf(CliParamsSpec.networkMapNetAddr),
|
||||||
identityFile = if (options.has(CliParamsSpec.networkMapIdentityFile)) {
|
|
||||||
Paths.get(options.valueOf(CliParamsSpec.networkMapIdentityFile))
|
|
||||||
} else {
|
|
||||||
dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME)
|
|
||||||
},
|
|
||||||
tradeWithIdentities = if (options.has(CliParamsSpec.fakeTradeWithIdentityFile)) {
|
tradeWithIdentities = if (options.has(CliParamsSpec.fakeTradeWithIdentityFile)) {
|
||||||
options.valuesOf(CliParamsSpec.fakeTradeWithIdentityFile).map { Paths.get(it) }
|
options.valuesOf(CliParamsSpec.fakeTradeWithIdentityFile).map { Paths.get(it) }
|
||||||
} else {
|
} else {
|
||||||
@ -264,9 +258,6 @@ object CliParamsSpec {
|
|||||||
val baseDirectoryArg =
|
val baseDirectoryArg =
|
||||||
parser.accepts("base-directory", "The directory to put all files under")
|
parser.accepts("base-directory", "The directory to put all files under")
|
||||||
.withOptionalArg().defaultsTo(CliParams.defaultBaseDirectory)
|
.withOptionalArg().defaultsTo(CliParams.defaultBaseDirectory)
|
||||||
val networkMapIdentityFile =
|
|
||||||
parser.accepts("network-map-identity-file", "The file containing the Party info of the network map")
|
|
||||||
.withOptionalArg()
|
|
||||||
val networkMapNetAddr =
|
val networkMapNetAddr =
|
||||||
parser.accepts("network-map-address", "The address of the network map")
|
parser.accepts("network-map-address", "The address of the network map")
|
||||||
.withRequiredArg().defaultsTo("localhost")
|
.withRequiredArg().defaultsTo("localhost")
|
||||||
@ -411,7 +402,7 @@ private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipi
|
|||||||
}
|
}
|
||||||
IRSDemoNode.NodeB -> {
|
IRSDemoNode.NodeB -> {
|
||||||
advertisedServices = setOf(NodeInterestRates.Type)
|
advertisedServices = setOf(NodeInterestRates.Type)
|
||||||
nodeInfo(networkMap, params.identityFile, setOf(NetworkMapService.Type, SimpleNotaryService.Type))
|
networkMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,16 +415,6 @@ private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipi
|
|||||||
|
|
||||||
private fun parsePartyFromFile(path: Path) = Files.readAllBytes(path).deserialize<Party>()
|
private fun parsePartyFromFile(path: Path) = Files.readAllBytes(path).deserialize<Party>()
|
||||||
|
|
||||||
private fun nodeInfo(recipient: SingleMessageRecipient, identityFile: Path, advertisedServices: Set<ServiceType> = emptySet()): NodeInfo {
|
|
||||||
try {
|
|
||||||
val party = parsePartyFromFile(identityFile)
|
|
||||||
return NodeInfo(recipient, party, advertisedServices)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
log.error("Could not find identify file $identityFile.")
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun runUploadRates(host: HostAndPort): ListenableFuture<Int> {
|
private fun runUploadRates(host: HostAndPort): ListenableFuture<Int> {
|
||||||
// Note: the getResourceAsStream is an ugly hack to get the jvm to search in the right location
|
// Note: the getResourceAsStream is an ugly hack to get the jvm to search in the right location
|
||||||
val fileContents = IOUtils.toString(CliParams::class.java.getResourceAsStream("example.rates.txt"))
|
val fileContents = IOUtils.toString(CliParams::class.java.getResourceAsStream("example.rates.txt"))
|
||||||
|
@ -38,7 +38,6 @@ fun main(args: Array<String>) {
|
|||||||
val networkAddressArg = parser.accepts("network-address").withRequiredArg().required()
|
val networkAddressArg = parser.accepts("network-address").withRequiredArg().required()
|
||||||
val dirArg = parser.accepts("directory").withRequiredArg().defaultsTo("rate-fix-demo-data")
|
val dirArg = parser.accepts("directory").withRequiredArg().defaultsTo("rate-fix-demo-data")
|
||||||
val networkMapAddrArg = parser.accepts("network-map").withRequiredArg().required()
|
val networkMapAddrArg = parser.accepts("network-map").withRequiredArg().required()
|
||||||
val networkMapIdentityArg = parser.accepts("network-map-identity-file").withRequiredArg().required()
|
|
||||||
|
|
||||||
val fixOfArg = parser.accepts("fix-of").withRequiredArg().defaultsTo("ICE LIBOR 2016-03-16 1M")
|
val fixOfArg = parser.accepts("fix-of").withRequiredArg().defaultsTo("ICE LIBOR 2016-03-16 1M")
|
||||||
val expectedRateArg = parser.accepts("expected-rate").withRequiredArg().defaultsTo("0.67")
|
val expectedRateArg = parser.accepts("expected-rate").withRequiredArg().defaultsTo("0.67")
|
||||||
@ -56,8 +55,6 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
val dir = Paths.get(options.valueOf(dirArg))
|
val dir = Paths.get(options.valueOf(dirArg))
|
||||||
val networkMapAddr = ArtemisMessagingClient.makeNetworkMapAddress(HostAndPort.fromString(options.valueOf(networkMapAddrArg)))
|
val networkMapAddr = ArtemisMessagingClient.makeNetworkMapAddress(HostAndPort.fromString(options.valueOf(networkMapAddrArg)))
|
||||||
val networkMapIdentity = Files.readAllBytes(Paths.get(options.valueOf(networkMapIdentityArg))).deserialize<Party>()
|
|
||||||
val networkMapAddress = NodeInfo(networkMapAddr, networkMapIdentity, setOf(NetworkMapService.Type, NotaryService.Type))
|
|
||||||
|
|
||||||
val fixOf: FixOf = NodeInterestRates.parseFixOf(options.valueOf(fixOfArg))
|
val fixOf: FixOf = NodeInterestRates.parseFixOf(options.valueOf(fixOfArg))
|
||||||
val expectedRate = BigDecimal(options.valueOf(expectedRateArg))
|
val expectedRate = BigDecimal(options.valueOf(expectedRateArg))
|
||||||
@ -77,7 +74,7 @@ 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(dir, myNetAddr, apiAddr, config, networkMapAddress,
|
val node = logElapsedTime("Node startup") { Node(dir, myNetAddr, apiAddr, config, networkMapAddr,
|
||||||
advertisedServices, DemoClock()).setup().start() }
|
advertisedServices, DemoClock()).setup().start() }
|
||||||
node.networkMapRegistrationFuture.get()
|
node.networkMapRegistrationFuture.get()
|
||||||
val notaryNode = node.services.networkMapCache.notaryNodes[0]
|
val notaryNode = node.services.networkMapCache.notaryNodes[0]
|
||||||
|
@ -134,14 +134,8 @@ fun main(args: Array<String>) {
|
|||||||
advertisedServices = setOf(NetworkMapService.Type, SimpleNotaryService.Type)
|
advertisedServices = setOf(NetworkMapService.Type, SimpleNotaryService.Type)
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
// In a real system, the identity file of the network map would be shipped with the server software, and there'd
|
|
||||||
// be a single shared map service (this is analagous to the DNS seeds in Bitcoin).
|
|
||||||
//
|
|
||||||
// TODO: AbstractNode should write out the full NodeInfo object and we should just load it here.
|
|
||||||
val path = Paths.get(baseDirectory, Role.BUYER.name.toLowerCase(), "identity-public")
|
|
||||||
val party = Files.readAllBytes(path).deserialize<Party>()
|
|
||||||
advertisedServices = emptySet()
|
advertisedServices = emptySet()
|
||||||
NodeInfo(ArtemisMessagingClient.makeNetworkMapAddress(theirNetAddr), party, setOf(NetworkMapService.Type))
|
ArtemisMessagingClient.makeNetworkMapAddress(theirNetAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// And now construct then start the node object. It takes a little while.
|
// And now construct then start the node object. It takes a little while.
|
||||||
|
@ -2,6 +2,7 @@ package com.r3corda.simulation
|
|||||||
|
|
||||||
import com.google.common.util.concurrent.Futures
|
import com.google.common.util.concurrent.Futures
|
||||||
import com.google.common.util.concurrent.ListenableFuture
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
|
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||||
import com.r3corda.core.node.CityDatabase
|
import com.r3corda.core.node.CityDatabase
|
||||||
import com.r3corda.core.node.NodeInfo
|
import com.r3corda.core.node.NodeInfo
|
||||||
import com.r3corda.core.node.PhysicalLocation
|
import com.r3corda.core.node.PhysicalLocation
|
||||||
@ -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(dir: Path, config: NodeConfiguration, mockNet: MockNetwork, networkMapAddress: NodeInfo?,
|
open class SimulatedNode(dir: Path, config: NodeConfiguration, mockNet: MockNetwork, networkMapAddress: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?) : MockNetwork.MockNode(dir, config, mockNet, networkMapAddress, advertisedServices, id, keyPair) {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?) : MockNetwork.MockNode(dir, 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,
|
|||||||
inner class BankFactory : MockNetwork.Factory {
|
inner class BankFactory : MockNetwork.Factory {
|
||||||
var counter = 0
|
var counter = 0
|
||||||
|
|
||||||
override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
advertisedServices: Set<ServiceType>, 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]
|
||||||
@ -69,14 +70,14 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createAll(): List<SimulatedNode> = bankLocations.
|
fun createAll(): List<SimulatedNode> = bankLocations.
|
||||||
map { network.createNode(networkMap.info, start = false, nodeFactory = this) as SimulatedNode }
|
map { network.createNode(networkMap.info.address, start = false, nodeFactory = this) as SimulatedNode }
|
||||||
}
|
}
|
||||||
|
|
||||||
val bankFactory = BankFactory()
|
val bankFactory = BankFactory()
|
||||||
|
|
||||||
object NetworkMapNodeFactory : MockNetwork.Factory {
|
object NetworkMapNodeFactory : MockNetwork.Factory {
|
||||||
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork,
|
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork,
|
||||||
networkMapAddr: NodeInfo?, advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
networkMapAddr: SingleMessageRecipient?, advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
||||||
require(advertisedServices.contains(com.r3corda.node.services.network.NetworkMapService.Type))
|
require(advertisedServices.contains(com.r3corda.node.services.network.NetworkMapService.Type))
|
||||||
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
||||||
override val myLegalName: String = "Network coordination center"
|
override val myLegalName: String = "Network coordination center"
|
||||||
@ -91,7 +92,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
}
|
}
|
||||||
|
|
||||||
object NotaryNodeFactory : MockNetwork.Factory {
|
object NotaryNodeFactory : MockNetwork.Factory {
|
||||||
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
||||||
require(advertisedServices.contains(com.r3corda.node.services.transactions.SimpleNotaryService.Type))
|
require(advertisedServices.contains(com.r3corda.node.services.transactions.SimpleNotaryService.Type))
|
||||||
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
||||||
@ -106,7 +107,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
}
|
}
|
||||||
|
|
||||||
object RatesOracleFactory : MockNetwork.Factory {
|
object RatesOracleFactory : MockNetwork.Factory {
|
||||||
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
||||||
require(advertisedServices.contains(com.r3corda.node.services.clientapi.NodeInterestRates.Type))
|
require(advertisedServices.contains(com.r3corda.node.services.clientapi.NodeInterestRates.Type))
|
||||||
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
||||||
@ -128,7 +129,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
}
|
}
|
||||||
|
|
||||||
object RegulatorFactory : MockNetwork.Factory {
|
object RegulatorFactory : MockNetwork.Factory {
|
||||||
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNetwork.MockNode {
|
||||||
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
|
||||||
override val myLegalName: String = "Regulator A"
|
override val myLegalName: String = "Regulator A"
|
||||||
@ -152,10 +153,10 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
val networkMap: SimulatedNode
|
val networkMap: SimulatedNode
|
||||||
= network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = com.r3corda.node.services.network.NetworkMapService.Type) as SimulatedNode
|
= network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = com.r3corda.node.services.network.NetworkMapService.Type) as SimulatedNode
|
||||||
val notary: SimulatedNode
|
val notary: SimulatedNode
|
||||||
= network.createNode(networkMap.info, nodeFactory = NotaryNodeFactory, advertisedServices = com.r3corda.node.services.transactions.SimpleNotaryService.Type) as SimulatedNode
|
= network.createNode(networkMap.info.address, nodeFactory = NotaryNodeFactory, advertisedServices = com.r3corda.node.services.transactions.SimpleNotaryService.Type) as SimulatedNode
|
||||||
val regulators: List<SimulatedNode> = listOf(network.createNode(networkMap.info, 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, start = false, nodeFactory = RatesOracleFactory, advertisedServices = com.r3corda.node.services.clientapi.NodeInterestRates.Type) as SimulatedNode
|
= network.createNode(networkMap.info.address, start = false, nodeFactory = RatesOracleFactory, advertisedServices = com.r3corda.node.services.clientapi.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)
|
||||||
|
@ -49,18 +49,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(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNode
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNode
|
||||||
}
|
}
|
||||||
|
|
||||||
object DefaultFactory : Factory {
|
object DefaultFactory : Factory {
|
||||||
override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?,
|
override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNode {
|
advertisedServices: Set<ServiceType>, id: Int, keyPair: KeyPair?): MockNode {
|
||||||
return MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair)
|
return MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class MockNode(dir: Path, config: NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: NodeInfo?,
|
open class MockNode(dir: Path, config: NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceType>, val id: Int, val keyPair: KeyPair?) : com.r3corda.node.internal.AbstractNode(dir, config, networkMapAddr, advertisedServices, TestClock()) {
|
advertisedServices: Set<ServiceType>, val id: Int, val keyPair: KeyPair?) : com.r3corda.node.internal.AbstractNode(dir, 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 =
|
||||||
@ -105,7 +105,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: NodeInfo? = 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,
|
||||||
databasePersistence: Boolean = false, vararg advertisedServices: ServiceType): MockNode {
|
databasePersistence: Boolean = false, vararg advertisedServices: ServiceType): MockNode {
|
||||||
val newNode = forcedID == -1
|
val newNode = forcedID == -1
|
||||||
@ -161,7 +161,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
|||||||
require(nodes.isEmpty())
|
require(nodes.isEmpty())
|
||||||
return Pair(
|
return Pair(
|
||||||
createNode(null, -1, nodeFactory, true, null, notaryKeyPair, false, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type),
|
createNode(null, -1, nodeFactory, true, null, notaryKeyPair, false, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type),
|
||||||
createNode(nodes[0].info, -1, nodeFactory, true, null)
|
createNode(nodes[0].info.address, -1, nodeFactory, true, null)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,11 +178,11 @@ 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 = com.r3corda.node.services.network.NetworkMapService.Type)
|
||||||
val notaryNode = createNode(mapNode.info, nodeFactory = nodeFactory, keyPair = notaryKeyPair,
|
val notaryNode = createNode(mapNode.info.address, nodeFactory = nodeFactory, keyPair = notaryKeyPair,
|
||||||
advertisedServices = com.r3corda.node.services.transactions.SimpleNotaryService.Type)
|
advertisedServices = com.r3corda.node.services.transactions.SimpleNotaryService.Type)
|
||||||
val nodes = ArrayList<MockNode>()
|
val nodes = ArrayList<MockNode>()
|
||||||
repeat(numPartyNodes) {
|
repeat(numPartyNodes) {
|
||||||
nodes += createPartyNode(mapNode.info)
|
nodes += createPartyNode(mapNode.info.address)
|
||||||
}
|
}
|
||||||
return BasketOfNodes(nodes, notaryNode, mapNode)
|
return BasketOfNodes(nodes, notaryNode, mapNode)
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
|||||||
return createNode(null, -1, defaultFactory, true, legalName, keyPair, false, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type)
|
return createNode(null, -1, defaultFactory, true, legalName, keyPair, false, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createPartyNode(networkMapAddr: NodeInfo, legalName: String? = null, keyPair: KeyPair? = null): MockNode {
|
fun createPartyNode(networkMapAddr: SingleMessageRecipient, legalName: String? = null, keyPair: KeyPair? = null): MockNode {
|
||||||
return createNode(networkMapAddr, -1, defaultFactory, true, legalName, keyPair)
|
return createNode(networkMapAddr, -1, defaultFactory, true, legalName, keyPair)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user