node: Expose ArtemisMessagingService.Address

This commit is contained in:
Andras Slemmer
2016-08-01 14:08:51 +01:00
parent 3bc62fdb95
commit 8cf635cf74
4 changed files with 39 additions and 37 deletions

View File

@ -6,7 +6,8 @@ import com.r3corda.core.crypto.generateKeyPair
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.services.config.NodeConfiguration 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.InMemoryNetworkMapCache
import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NetworkMapService
import java.net.Socket 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()) 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<Process>()
val messagingService = ArtemisMessagingClient(
Paths.get(baseDirectory, "driver-artemis"), Paths.get(baseDirectory, "driver-artemis"),
nextLocalHostAndPort(),
object : NodeConfiguration { object : NodeConfiguration {
override val myLegalName = "driver-artemis" override val myLegalName = "driver-artemis"
override val exportJMXto = "" override val exportJMXto = ""
override val nearestCity = "Zion" override val nearestCity = "Zion"
override val keyStorePassword = "keypass" override val keyStorePassword = "keypass"
override val trustStorePassword = "trustpass" 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<Process>()
private fun nextPort(): Int { private fun nextPort(): Int {
val nextPort = portCounter val nextPort = portCounter
portCounter++ portCounter++
@ -177,9 +179,28 @@ class DriverDSL(private var portCounter: Int, val baseDirectory: String, val qua
} }
internal fun start() { internal fun start() {
startNetworkMapService()
messagingService.configureWithDevSSLCertificate() messagingService.configureWithDevSSLCertificate()
messagingService.start() 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() { private fun startNetworkMapService() {
@ -196,25 +217,6 @@ class DriverDSL(private var portCounter: Int, val baseDirectory: String, val qua
) )
println("Starting network-map-service") println("Starting network-map-service")
registerProcess(startNode(driverCliParams, quasarPath)) 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 { companion object {

View File

@ -2,13 +2,13 @@ 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.Party
import com.r3corda.core.crypto.parsePublicKeyBase58
import com.r3corda.core.crypto.toBase58String import com.r3corda.core.crypto.toBase58String
import com.r3corda.core.crypto.toPublicKey
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
import com.r3corda.node.services.config.NodeConfiguration 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 com.r3corda.node.services.network.NetworkMapService
import joptsimple.ArgumentAcceptingOptionSpec import joptsimple.ArgumentAcceptingOptionSpec
import joptsimple.OptionParser import joptsimple.OptionParser
@ -31,7 +31,7 @@ class NodeRunner {
val networkMapNodeInfo = val networkMapNodeInfo =
if (networkMapName != null && networkMapPublicKey != null && networkMapAddress != null) { if (networkMapName != null && networkMapPublicKey != null && networkMapAddress != null) {
NodeInfo( NodeInfo(
address = ArtemisMessagingService.makeRecipient(networkMapAddress), address = ArtemisMessagingClient.makeRecipient(networkMapAddress),
identity = Party( identity = Party(
name = networkMapName, name = networkMapName,
owningKey = networkMapPublicKey owningKey = networkMapPublicKey
@ -106,7 +106,7 @@ class NodeRunner {
throw IllegalArgumentException("Must provide at least one --services") throw IllegalArgumentException("Must provide at least one --services")
} }
val networkMapName = optionSet.valueOf(networkMapName) 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 networkMapAddress = optionSet.valueOf(networkMapAddress)
val messagingAddress = requiredArgument(optionSet, messagingAddress) val messagingAddress = requiredArgument(optionSet, messagingAddress)
val apiAddress = requiredArgument(optionSet, apiAddress) val apiAddress = requiredArgument(optionSet, apiAddress)

View File

@ -23,7 +23,7 @@ abstract class ArtemisMessagingComponent(val directory: Path, val config: NodeCo
private val trustStorePath = directory.resolve("certificates").resolve("truststore.jks") private val trustStorePath = directory.resolve("certificates").resolve("truststore.jks")
// In future: can contain onion routing info, etc. // 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 } protected enum class ConnectionDirection { INBOUND, OUTBOUND }

View File

@ -1,6 +1,6 @@
package com.r3corda.node.driver 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 com.r3corda.node.services.transactions.NotaryService
import org.junit.Test import org.junit.Test
import java.net.Socket import java.net.Socket
@ -23,7 +23,7 @@ class DriverTests {
} }
} }
// Check that the port is bound // Check that the port is bound
val address = notaryNodeInfo.address as ArtemisMessagingService.Address val address = notaryNodeInfo.address as ArtemisMessagingComponent.Address
poll { poll {
try { try {
Socket(address.hostAndPort.hostText, address.hostAndPort.port).close() Socket(address.hostAndPort.hostText, address.hostAndPort.port).close()