Get rid of the fake NodeInfo used to identify the NetworkMapService node.

Remove old comment
This commit is contained in:
Matthew Nesbit 2016-09-06 16:23:47 +01:00
parent c6fd467fb5
commit 2e1952a8a7
21 changed files with 89 additions and 152 deletions

View File

@ -4,6 +4,7 @@ import com.google.common.util.concurrent.ListenableFuture
import com.r3corda.core.contracts.Contract
import com.r3corda.core.crypto.Party
import com.r3corda.core.messaging.MessagingService
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo
import org.slf4j.LoggerFactory
import java.security.PublicKey
@ -73,12 +74,12 @@ interface NetworkMapCache {
* updates.
*
* @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 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.
*/
fun addMapService(net: MessagingService, service: NodeInfo,
fun addMapService(net: MessagingService, networkMapAddress: SingleMessageRecipient,
subscribe: Boolean, ifChangedSinceVer: Int? = null): ListenableFuture<Unit>
/**

View File

@ -300,8 +300,6 @@ class DriverDSL(
val driverCliParams = NodeRunner.CliParams(
services = advertisedServices,
networkMapName = networkMapNodeInfo!!.identity.name,
networkMapPublicKey = networkMapNodeInfo!!.identity.owningKey,
networkMapAddress = networkMapAddress,
messagingAddress = messagingAddress,
apiAddress = apiAddress,
@ -386,17 +384,8 @@ class DriverDSL(
override fun start() {
startNetworkMapService()
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
// the network map service itself.
val fakeNodeInfo = NodeInfo(
address = ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress),
identity = Party(
name = networkMapName,
owningKey = generateKeyPair().public
),
advertisedServices = setOf(NetworkMapService.Type)
)
networkMapCache.addMapService(networkMapClient, fakeNodeInfo, true)
val networkMapAddr = ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress)
networkMapCache.addMapService(networkMapClient, networkMapAddr, true)
networkMapNodeInfo = poll("network map cache for $networkMapName") {
networkMapCache.partyNodes.forEach {
if (it.identity.name == networkMapName) {
@ -423,8 +412,6 @@ class DriverDSL(
val driverCliParams = NodeRunner.CliParams(
services = setOf(NetworkMapService.Type),
networkMapName = null,
networkMapPublicKey = null,
networkMapAddress = null,
messagingAddress = networkMapAddress,
apiAddress = apiAddress,

View File

@ -1,16 +1,11 @@
package com.r3corda.node.driver
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.node.internal.Node
import com.r3corda.node.services.config.NodeConfiguration
import com.r3corda.node.services.config.NodeConfigurationFromConfig
import com.r3corda.node.services.messaging.ArtemisMessagingClient
import com.r3corda.node.services.network.NetworkMapService
import joptsimple.ArgumentAcceptingOptionSpec
import joptsimple.OptionParser
import joptsimple.OptionSet
@ -18,7 +13,6 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.file.Path
import java.nio.file.Paths
import java.security.PublicKey
import java.util.*
private val log: Logger = LoggerFactory.getLogger(NodeRunner::class.java)
@ -33,15 +27,8 @@ class NodeRunner {
with(cliParams) {
val networkMapNodeInfo =
if (networkMapName != null && networkMapPublicKey != null && networkMapAddress != null) {
NodeInfo(
address = ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress),
identity = Party(
name = networkMapName,
owningKey = networkMapPublicKey
),
advertisedServices = setOf(NetworkMapService.Type)
)
if (networkMapAddress != null) {
ArtemisMessagingClient.makeNetworkMapAddress(networkMapAddress)
} else {
null
}
@ -70,8 +57,6 @@ class NodeRunner {
class CliParams (
val services: Set<ServiceType>,
val networkMapName: String?,
val networkMapPublicKey: PublicKey?,
val networkMapAddress: HostAndPort?,
val messagingAddress: HostAndPort,
val apiAddress: HostAndPort,
@ -82,10 +67,6 @@ class NodeRunner {
val parser = OptionParser()
val services =
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 =
parser.accepts("network-map-address").withOptionalArg().ofType(String::class.java)
val messagingAddress =
@ -100,8 +81,6 @@ class NodeRunner {
fun parse(optionSet: OptionSet): CliParams {
val services = optionSet.valuesOf(services)
val networkMapName = optionSet.valueOf(networkMapName)
val networkMapPublicKey = optionSet.valueOf(networkMapPublicKey)?.run { parsePublicKeyBase58(this) }
val networkMapAddress = optionSet.valueOf(networkMapAddress)
val messagingAddress = requiredArgument(optionSet, messagingAddress)
val apiAddress = requiredArgument(optionSet, apiAddress)
@ -112,8 +91,6 @@ class NodeRunner {
messagingAddress = HostAndPort.fromString(messagingAddress),
apiAddress = HostAndPort.fromString(apiAddress),
baseDirectory = baseDirectory,
networkMapName = networkMapName,
networkMapPublicKey = networkMapPublicKey,
networkMapAddress = networkMapAddress?.let { HostAndPort.fromString(it) }
)
}
@ -125,14 +102,6 @@ class NodeRunner {
cliArguments.add("--services")
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) {
cliArguments.add("--network-map-address")
cliArguments.add(networkMapAddress.toString())

View File

@ -6,6 +6,7 @@ import com.google.common.util.concurrent.MoreExecutors
import com.google.common.util.concurrent.SettableFuture
import com.r3corda.core.RunOnCallerThread
import com.r3corda.core.crypto.Party
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.messaging.runOnNextMessage
import com.r3corda.core.node.CityDatabase
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.
// 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.
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() {
companion object {
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.
*/
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"
}
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.
// TODO: Return a future so the caller knows these operations may not have completed yet, and can monitor if needed
updateRegistration(networkMapService, AddOrRemove.ADD)
@ -291,7 +292,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
if (inNodeNetworkMapService == null)
return noNetworkMapConfigured()
// 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 */
@ -301,7 +302,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
"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
val expires = platformClock.instant() + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
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 ->
future.set(message.data.deserialize())
}
net.send(message, serviceInfo.address)
net.send(message, networkMapAddr)
return future
}
@ -339,8 +340,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
protected open fun makeIdentityService(): IdentityService {
val service = InMemoryIdentityService()
if (networkMapService != null)
service.registerIdentity(networkMapService.identity)
service.registerIdentity(storage.myLegalIdentity)
services.networkMapCache.partyNodes.forEach { service.registerIdentity(it.identity) }

View File

@ -2,6 +2,7 @@ package com.r3corda.node.internal
import com.codahale.metrics.JmxReporter
import com.google.common.net.HostAndPort
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.ServiceHub
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.
*/
class Node(dir: Path, val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
configuration: NodeConfiguration, networkMapAddress: NodeInfo?,
configuration: NodeConfiguration, networkMapAddress: SingleMessageRecipient?,
advertisedServices: Set<ServiceType>, clock: Clock = NodeClock(),
val messagingServerAddr: HostAndPort? = null) : AbstractNode(dir, configuration, networkMapAddress, advertisedServices, clock) {
companion object {

View File

@ -3,6 +3,7 @@ package com.r3corda.node.services.config
import com.google.common.net.HostAndPort
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.generateKeyPair
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.ServiceType
import com.r3corda.node.internal.Node
@ -122,9 +123,8 @@ class FullNodeConfiguration(conf: Config) : NodeConfiguration {
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: NodeInfo? = if (mapService.hostServiceLocally) null else NodeInfo(networkMapTarget, networkMapBootstrapIdentity, setOf(NetworkMapService.Type))
val networkMapAddress: SingleMessageRecipient? = if (mapService.hostServiceLocally) null else networkMapTarget
return Node(basedir.toAbsolutePath().normalize(),
artemisAddress,
webAddress,

View File

@ -3,6 +3,7 @@ package com.r3corda.node.services.messaging
import com.google.common.net.HostAndPort
import com.r3corda.core.ThreadBox
import com.r3corda.core.crypto.newSecureRandom
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.NetworkMapCache
import com.r3corda.core.utilities.loggerFor
@ -67,8 +68,8 @@ class ArtemisMessagingServer(directory: Path,
running = false
}
fun bridgeToNetworkMapService(networkMapService: NodeInfo?) {
if ((networkMapService != null) && (networkMapService.address is NetworkMapAddress)) {
fun bridgeToNetworkMapService(networkMapService: SingleMessageRecipient?) {
if ((networkMapService != null) && (networkMapService is NetworkMapAddress)) {
val query = activeMQServer.queueQuery(NETWORK_MAP_ADDRESS)
if (!query.isExists) {
activeMQServer.createQueue(NETWORK_MAP_ADDRESS, NETWORK_MAP_ADDRESS, null, true, false)
@ -87,7 +88,7 @@ class ArtemisMessagingServer(directory: Path,
val query = activeMQServer.queueQuery(queueName)
if (query.isExists) {
// 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)
if (query.isExists) {
// Deploy new bridge
maybeDeployBridgeForAddress(queueName, change.node)
maybeDeployBridgeForAddress(queueName, change.node.address)
}
}
@ -135,7 +136,7 @@ class ArtemisMessagingServer(directory: Path,
if (identity != null) {
val nodeInfo = networkMapCache.getNodeByPublicKey(identity)
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
* is that of a remote party
*/
private fun maybeDeployBridgeForAddress(name: SimpleString, nodeInfo: NodeInfo) {
val hostAndPort = toHostAndPort(nodeInfo.address)
private fun maybeDeployBridgeForAddress(name: SimpleString, address: SingleMessageRecipient) {
val hostAndPort = toHostAndPort(address)
if (hostAndPort == myHostPort) {
return

View File

@ -6,6 +6,7 @@ import com.google.common.util.concurrent.SettableFuture
import com.r3corda.core.contracts.Contract
import com.r3corda.core.crypto.Party
import com.r3corda.core.messaging.MessagingService
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.messaging.runOnNextMessage
import com.r3corda.core.messaging.send
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 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> {
if (subscribe && !registeredForPush) {
// 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) }
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
}

View File

@ -3,6 +3,7 @@ package com.r3corda.node.messaging
import com.r3corda.core.contracts.Attachment
import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.crypto.sha256
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.ServiceType
import com.r3corda.core.serialization.OpaqueBytes
@ -87,7 +88,7 @@ class AttachmentTests {
fun `malicious response`() {
// Make a node that doesn't do sanity checking at load time.
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 {
return object : MockNetwork.MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair) {
override fun start(): MockNetwork.MockNode {
@ -98,7 +99,7 @@ class AttachmentTests {
}
}
}, 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.
val id = n0.storage.attachments.importAttachment(ByteArrayInputStream(fakeAttachment()))

View File

@ -5,6 +5,7 @@ package com.r3corda.node.messaging
import com.r3corda.core.messaging.Message
import com.r3corda.core.messaging.TopicStringValidator
import com.r3corda.core.node.services.DEFAULT_SESSION_ID
import com.r3corda.node.services.network.NetworkMapService
import com.r3corda.testing.node.MockNetwork
import org.junit.Before
import org.junit.Test
@ -38,9 +39,9 @@ class InMemoryMessagingTests {
@Test
fun basics() {
val node1 = network.createNode()
val node2 = network.createNode()
val node3 = network.createNode()
val node1 = network.createNode(advertisedServices = NetworkMapService.Type)
val node2 = network.createNode(networkMapAddress = node1.info.address)
val node3 = network.createNode(networkMapAddress = node1.info.address)
val bits = "test-content".toByteArray()
var finalDelivery: Message? = null
@ -67,9 +68,9 @@ class InMemoryMessagingTests {
@Test
fun broadcast() {
val node1 = network.createNode()
val node2 = network.createNode()
val node3 = network.createNode()
val node1 = network.createNode(advertisedServices = NetworkMapService.Type)
val node2 = network.createNode(networkMapAddress = node1.info.address)
val node3 = network.createNode(networkMapAddress = node1.info.address)
val bits = "test-content".toByteArray()
@ -86,8 +87,8 @@ class InMemoryMessagingTests {
*/
@Test
fun `skip unhandled messages`() {
val node1 = network.createNode()
val node2 = network.createNode()
val node1 = network.createNode(advertisedServices = NetworkMapService.Type)
val node2 = network.createNode(networkMapAddress = node1.info.address)
var received: Int = 0
node1.net.addMessageHandler("valid_message") { msg, reg ->

View File

@ -8,6 +8,7 @@ import com.r3corda.core.contracts.*
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.days
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.ServiceHub
import com.r3corda.core.node.services.ServiceType
@ -93,8 +94,8 @@ class TwoPartyTradeProtocolTests {
ledger {
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
val aliceNode = net.createPartyNode(notaryNode.info, ALICE.name, ALICE_KEY)
val bobNode = net.createPartyNode(notaryNode.info, BOB.name, BOB_KEY)
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name, ALICE_KEY)
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name, BOB_KEY)
bobNode.services.fillWithSomeTestCash(2000.DOLLARS)
val alicesFakePaper = fillUpForSeller(false, aliceNode.storage.myLegalIdentity.owningKey,
@ -139,11 +140,11 @@ class TwoPartyTradeProtocolTests {
fun `shutdown and restore`() {
ledger {
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
val aliceNode = net.createPartyNode(notaryNode.info, ALICE.name, ALICE_KEY)
var bobNode = net.createPartyNode(notaryNode.info, BOB.name, BOB_KEY)
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name, ALICE_KEY)
var bobNode = net.createPartyNode(notaryNode.info.address, BOB.name, BOB_KEY)
val bobAddr = bobNode.net.myAddress as InMemoryMessagingNetwork.Handle
val networkMapAddr = notaryNode.info
val networkMapAddr = notaryNode.info.address
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
// that Bob was waiting on before the reboot occurred.
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 {
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
// 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 ...
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 {
return object : MockNetwork.MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair) {
// That constructs the storage service object in a customised way ...
@ -250,8 +251,8 @@ class TwoPartyTradeProtocolTests {
@Test
fun `check dependencies of sale asset are resolved`() {
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
val aliceNode = makeNodeWithTracking(notaryNode.info, ALICE.name, ALICE_KEY)
val bobNode = makeNodeWithTracking(notaryNode.info, BOB.name, BOB_KEY)
val aliceNode = makeNodeWithTracking(notaryNode.info.address, ALICE.name, ALICE_KEY)
val bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name, BOB_KEY)
ledger(aliceNode.services) {
@ -371,8 +372,8 @@ class TwoPartyTradeProtocolTests {
expectedMessageSubstring: String
) {
val notaryNode = net.createNotaryNode(DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
val aliceNode = net.createPartyNode(notaryNode.info, ALICE.name, ALICE_KEY)
val bobNode = net.createPartyNode(notaryNode.info, BOB.name, BOB_KEY)
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name, ALICE_KEY)
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name, BOB_KEY)
val issuer = MEGA_CORP.ref(1, 2, 3)
val bobKey = bobNode.keyManagement.freshKey()

View File

@ -16,7 +16,7 @@ class InMemoryNetworkMapCacheTest {
fun registerWithNetwork() {
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()
future.get()
}

View File

@ -37,9 +37,9 @@ class NotaryChangeTests {
legalName = DUMMY_NOTARY.name,
keyPair = DUMMY_NOTARY_KEY,
advertisedServices = *arrayOf(NetworkMapService.Type, SimpleNotaryService.Type))
clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info)
clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info)
newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info, advertisedServices = SimpleNotaryService.Type)
clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info.address)
clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info.address)
newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info.address, advertisedServices = SimpleNotaryService.Type)
net.runNetwork() // Clear network map registration messages
}

View File

@ -32,7 +32,7 @@ class NotaryServiceTests {
keyPair = DUMMY_NOTARY_KEY,
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
}

View File

@ -32,7 +32,7 @@ class ValidatingNotaryServiceTests {
keyPair = DUMMY_NOTARY_KEY,
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
}

View File

@ -3,7 +3,7 @@ package com.r3corda.node.services.statemachine
import co.paralleluniverse.fibers.Fiber
import co.paralleluniverse.fibers.Suspendable
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.random63BitValue
import com.r3corda.testing.node.MockNetwork
@ -55,12 +55,13 @@ class StateMachineManagerTests {
node2.smm.add("test", ReceiveProtocol(topic, sessionID))
net.runNetwork()
node2.stop()
val restoredProtocol = node2.restartAndGetRestoredProtocol<ReceiveProtocol>(node1.info)
val restoredProtocol = node2.restartAndGetRestoredProtocol<ReceiveProtocol>(node1.info.address)
assertThat(restoredProtocol.receivedPayload).isEqualTo(payload)
}
private inline fun <reified P : NonTerminatingProtocol> MockNode.restartAndGetRestoredProtocol(networkMapAddress: NodeInfo? = null): P {
val node = mockNet.createNode(networkMapAddress, id)
private inline fun <reified P : NonTerminatingProtocol> MockNode.restartAndGetRestoredProtocol(networkMapAddress: SingleMessageRecipient? = null): P {
val servicesArray = advertisedServices.toTypedArray()
val node = mockNet.createNode(networkMapAddress, id, advertisedServices = *servicesArray)
return node.smm.findStateMachines(P::class.java).single().first
}

View File

@ -85,7 +85,6 @@ sealed class CliParams {
val networkAddress: HostAndPort,
val apiAddress: HostAndPort,
val mapAddress: String,
val identityFile: Path,
val tradeWithIdentities: List<Path>,
val uploadRates: Boolean,
val defaultLegalName: String,
@ -166,11 +165,6 @@ sealed class CliParams {
CliParamsSpec.apiAddressArg.defaultsTo("localhost:${defaultApiPort(node)}")
)),
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)) {
options.valuesOf(CliParamsSpec.fakeTradeWithIdentityFile).map { Paths.get(it) }
} else {
@ -264,9 +258,6 @@ object CliParamsSpec {
val baseDirectoryArg =
parser.accepts("base-directory", "The directory to put all files under")
.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 =
parser.accepts("network-map-address", "The address of the network map")
.withRequiredArg().defaultsTo("localhost")
@ -411,7 +402,7 @@ private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipi
}
IRSDemoNode.NodeB -> {
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 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> {
// 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"))

View File

@ -38,7 +38,6 @@ fun main(args: Array<String>) {
val networkAddressArg = parser.accepts("network-address").withRequiredArg().required()
val dirArg = parser.accepts("directory").withRequiredArg().defaultsTo("rate-fix-demo-data")
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 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 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 expectedRate = BigDecimal(options.valueOf(expectedRateArg))
@ -77,7 +74,7 @@ fun main(args: Array<String>) {
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() }
node.networkMapRegistrationFuture.get()
val notaryNode = node.services.networkMapCache.notaryNodes[0]

View File

@ -134,14 +134,8 @@ fun main(args: Array<String>) {
advertisedServices = setOf(NetworkMapService.Type, SimpleNotaryService.Type)
null
} 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()
NodeInfo(ArtemisMessagingClient.makeNetworkMapAddress(theirNetAddr), party, setOf(NetworkMapService.Type))
ArtemisMessagingClient.makeNetworkMapAddress(theirNetAddr)
}
// And now construct then start the node object. It takes a little while.

View File

@ -2,6 +2,7 @@ package com.r3corda.simulation
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
import com.r3corda.core.messaging.SingleMessageRecipient
import com.r3corda.core.node.CityDatabase
import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.PhysicalLocation
@ -45,7 +46,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
// 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) {
override fun findMyLocation(): PhysicalLocation? = CityDatabase[configuration.nearestCity]
}
@ -53,7 +54,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
inner class BankFactory : MockNetwork.Factory {
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 {
val letter = 'A' + counter
val city = bankLocations[counter++ % bankLocations.size]
@ -69,14 +70,14 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
}
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()
object NetworkMapNodeFactory : MockNetwork.Factory {
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))
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
override val myLegalName: String = "Network coordination center"
@ -91,7 +92,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
}
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 {
require(advertisedServices.contains(com.r3corda.node.services.transactions.SimpleNotaryService.Type))
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
@ -106,7 +107,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
}
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 {
require(advertisedServices.contains(com.r3corda.node.services.clientapi.NodeInterestRates.Type))
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
@ -128,7 +129,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
}
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 {
val cfg = object : com.r3corda.node.services.config.NodeConfiguration {
override val myLegalName: String = "Regulator A"
@ -152,10 +153,10 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
val networkMap: SimulatedNode
= network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = com.r3corda.node.services.network.NetworkMapService.Type) as SimulatedNode
val notary: SimulatedNode
= network.createNode(networkMap.info, 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)
= 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.address, start = false, nodeFactory = RegulatorFactory) as 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.
val serviceProviders: List<SimulatedNode> = listOf(notary, ratesOracle, networkMap)

View File

@ -49,18 +49,18 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
/** Allows customisation of how nodes are created. */
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
}
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 {
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()) {
override val log: Logger = loggerFor<MockNode>()
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. */
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,
databasePersistence: Boolean = false, vararg advertisedServices: ServiceType): MockNode {
val newNode = forcedID == -1
@ -161,7 +161,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
require(nodes.isEmpty())
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(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 {
require(nodes.isEmpty())
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)
val nodes = ArrayList<MockNode>()
repeat(numPartyNodes) {
nodes += createPartyNode(mapNode.info)
nodes += createPartyNode(mapNode.info.address)
}
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)
}
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)
}