mirror of
https://github.com/corda/corda.git
synced 2025-04-07 19:34:41 +00:00
node: Expose ArtemisMessagingService.Address
This commit is contained in:
parent
3bc62fdb95
commit
8cf635cf74
@ -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<Process>()
|
||||
|
||||
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<Process>()
|
||||
|
||||
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 {
|
||||
|
@ -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)
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user