diff --git a/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt b/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt index f89c6c173e..248dcb0d1a 100644 --- a/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt +++ b/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt @@ -6,7 +6,8 @@ import com.r3corda.core.crypto.generateKeyPair import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.services.ServiceType import com.r3corda.node.services.config.NodeConfiguration -import com.r3corda.node.services.messaging.ArtemisMessagingService +import com.r3corda.node.services.messaging.ArtemisMessagingClient +import com.r3corda.node.services.messaging.ArtemisMessagingComponent import com.r3corda.node.services.network.InMemoryNetworkMapCache import com.r3corda.node.services.network.NetworkMapService import java.net.Socket @@ -98,24 +99,25 @@ class DriverDSL(private var portCounter: Int, val baseDirectory: String, val qua fun nextLocalHostAndPort() = HostAndPort.fromParts("localhost", nextPort()) - val messagingService = ArtemisMessagingService( + val networkMapCache = InMemoryNetworkMapCache(null) + private val networkMapName = "NetworkMapService" + private val networkMapAddress = nextLocalHostAndPort() + private lateinit var networkMapNodeInfo: NodeInfo + private val registeredProcesses = LinkedList() + + val messagingService = ArtemisMessagingClient( Paths.get(baseDirectory, "driver-artemis"), - nextLocalHostAndPort(), object : NodeConfiguration { override val myLegalName = "driver-artemis" override val exportJMXto = "" override val nearestCity = "Zion" override val keyStorePassword = "keypass" override val trustStorePassword = "trustpass" - } + }, + serverHostPort = networkMapAddress, + myHostPort = nextLocalHostAndPort() ) - val networkMapCache = InMemoryNetworkMapCache(null) - private val networkMapName = "NetworkMapService" - private val networkMapAddress = nextLocalHostAndPort() - private lateinit var networkMapNodeInfo: NodeInfo - private val registeredProcesses = LinkedList() - private fun nextPort(): Int { val nextPort = portCounter portCounter++ @@ -177,9 +179,28 @@ class DriverDSL(private var portCounter: Int, val baseDirectory: String, val qua } internal fun start() { + startNetworkMapService() messagingService.configureWithDevSSLCertificate() messagingService.start() - startNetworkMapService() + // 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 nodeInfo = NodeInfo( + address = ArtemisMessagingClient.makeRecipient(networkMapAddress), + identity = Party( + name = networkMapName, + owningKey = generateKeyPair().public + ), + advertisedServices = setOf(NetworkMapService.Type) + ) + networkMapCache.addMapService(messagingService, nodeInfo, true) + networkMapNodeInfo = poll { + networkMapCache.partyNodes.forEach { + if (it.identity.name == networkMapName) { + return@poll it + } + } + null + } } private fun startNetworkMapService() { @@ -196,25 +217,6 @@ class DriverDSL(private var portCounter: Int, val baseDirectory: String, val qua ) println("Starting network-map-service") registerProcess(startNode(driverCliParams, quasarPath)) - // 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 nodeInfo = NodeInfo( - address = ArtemisMessagingService.makeRecipient(networkMapAddress), - identity = Party( - name = networkMapName, - owningKey = generateKeyPair().public - ), - advertisedServices = setOf(NetworkMapService.Type) - ) - networkMapCache.addMapService(messagingService, nodeInfo, true) - networkMapNodeInfo = poll { - networkMapCache.partyNodes.forEach { - if (it.identity.name == networkMapName) { - return@poll it - } - } - null - } } companion object { diff --git a/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt b/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt index 896111ce5d..1fa733aec3 100644 --- a/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt +++ b/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt @@ -2,13 +2,13 @@ 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.crypto.toPublicKey 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.messaging.ArtemisMessagingService +import com.r3corda.node.services.messaging.ArtemisMessagingClient import com.r3corda.node.services.network.NetworkMapService import joptsimple.ArgumentAcceptingOptionSpec import joptsimple.OptionParser @@ -31,7 +31,7 @@ class NodeRunner { val networkMapNodeInfo = if (networkMapName != null && networkMapPublicKey != null && networkMapAddress != null) { NodeInfo( - address = ArtemisMessagingService.makeRecipient(networkMapAddress), + address = ArtemisMessagingClient.makeRecipient(networkMapAddress), identity = Party( name = networkMapName, owningKey = networkMapPublicKey @@ -106,7 +106,7 @@ class NodeRunner { throw IllegalArgumentException("Must provide at least one --services") } val networkMapName = optionSet.valueOf(networkMapName) - val networkMapPublicKey = optionSet.valueOf(networkMapPublicKey)?.toPublicKey() + val networkMapPublicKey = optionSet.valueOf(networkMapPublicKey)?.let { parsePublicKeyBase58(it) } val networkMapAddress = optionSet.valueOf(networkMapAddress) val messagingAddress = requiredArgument(optionSet, messagingAddress) val apiAddress = requiredArgument(optionSet, apiAddress) diff --git a/node/src/main/kotlin/com/r3corda/node/services/messaging/ArtemisMessagingComponent.kt b/node/src/main/kotlin/com/r3corda/node/services/messaging/ArtemisMessagingComponent.kt index cb190f0af2..39231d4e09 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/messaging/ArtemisMessagingComponent.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/messaging/ArtemisMessagingComponent.kt @@ -23,7 +23,7 @@ abstract class ArtemisMessagingComponent(val directory: Path, val config: NodeCo private val trustStorePath = directory.resolve("certificates").resolve("truststore.jks") // In future: can contain onion routing info, etc. - protected data class Address(val hostAndPort: HostAndPort) : SingleMessageRecipient + data class Address(val hostAndPort: HostAndPort) : SingleMessageRecipient protected enum class ConnectionDirection { INBOUND, OUTBOUND } diff --git a/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt index 1c34558226..8af22c0e43 100644 --- a/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt @@ -1,6 +1,6 @@ package com.r3corda.node.driver -import com.r3corda.node.services.messaging.ArtemisMessagingService +import com.r3corda.node.services.messaging.ArtemisMessagingComponent import com.r3corda.node.services.transactions.NotaryService import org.junit.Test import java.net.Socket @@ -23,7 +23,7 @@ class DriverTests { } } // Check that the port is bound - val address = notaryNodeInfo.address as ArtemisMessagingService.Address + val address = notaryNodeInfo.address as ArtemisMessagingComponent.Address poll { try { Socket(address.hostAndPort.hostText, address.hostAndPort.port).close()