mirror of
https://github.com/corda/corda.git
synced 2025-03-27 22:28:55 +00:00
Extract common name from legal name to determine path in Driver (#613)
Rewrote node name to extract common name to use as the node path for samples, to work around characters being incorrectly treated as separators.
This commit is contained in:
parent
5d0bbfa6b5
commit
89a45b3ce2
@ -9,6 +9,8 @@ import com.typesafe.config.ConfigRenderOptions
|
|||||||
import net.corda.client.rpc.CordaRPCClient
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
import net.corda.core.ThreadBox
|
import net.corda.core.ThreadBox
|
||||||
import net.corda.core.crypto.Party
|
import net.corda.core.crypto.Party
|
||||||
|
import net.corda.core.crypto.X509Utilities
|
||||||
|
import net.corda.core.crypto.commonName
|
||||||
import net.corda.core.div
|
import net.corda.core.div
|
||||||
import net.corda.core.flatMap
|
import net.corda.core.flatMap
|
||||||
import net.corda.core.map
|
import net.corda.core.map
|
||||||
@ -30,6 +32,7 @@ import net.corda.nodeapi.config.SSLConfiguration
|
|||||||
import net.corda.nodeapi.config.parseAs
|
import net.corda.nodeapi.config.parseAs
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import org.bouncycastle.asn1.x500.X500Name
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.*
|
import java.net.*
|
||||||
@ -58,6 +61,23 @@ private val log: Logger = loggerFor<DriverDSL>()
|
|||||||
* This is the interface that's exposed to DSL users.
|
* This is the interface that's exposed to DSL users.
|
||||||
*/
|
*/
|
||||||
interface DriverDSLExposedInterface {
|
interface DriverDSLExposedInterface {
|
||||||
|
/**
|
||||||
|
* Starts a [net.corda.node.internal.Node] in a separate process.
|
||||||
|
*
|
||||||
|
* @param providedName Name of the node, which will be its legal name in [Party].
|
||||||
|
* Note that this must be unique as the driver uses it as a primary key!
|
||||||
|
* @param advertisedServices The set of services to be advertised by the node. Defaults to empty set.
|
||||||
|
* @param verifierType The type of transaction verifier to use. See: [VerifierType]
|
||||||
|
* @param rpcUsers List of users who are authorised to use the RPC system. Defaults to empty list.
|
||||||
|
* @return The [NodeInfo] of the started up node retrieved from the network map service.
|
||||||
|
*/
|
||||||
|
@Deprecated("To be removed once X500Name is used as legal name everywhere")
|
||||||
|
fun startNode(providedName: String?,
|
||||||
|
advertisedServices: Set<ServiceInfo> = emptySet(),
|
||||||
|
rpcUsers: List<User> = emptyList(),
|
||||||
|
verifierType: VerifierType = VerifierType.InMemory,
|
||||||
|
customOverrides: Map<String, Any?> = emptyMap()): ListenableFuture<NodeHandle>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a [net.corda.node.internal.Node] in a separate process.
|
* Starts a [net.corda.node.internal.Node] in a separate process.
|
||||||
*
|
*
|
||||||
@ -68,7 +88,7 @@ interface DriverDSLExposedInterface {
|
|||||||
* @param rpcUsers List of users who are authorised to use the RPC system. Defaults to empty list.
|
* @param rpcUsers List of users who are authorised to use the RPC system. Defaults to empty list.
|
||||||
* @return The [NodeInfo] of the started up node retrieved from the network map service.
|
* @return The [NodeInfo] of the started up node retrieved from the network map service.
|
||||||
*/
|
*/
|
||||||
fun startNode(providedName: String? = null,
|
fun startNode(providedName: X500Name? = null,
|
||||||
advertisedServices: Set<ServiceInfo> = emptySet(),
|
advertisedServices: Set<ServiceInfo> = emptySet(),
|
||||||
rpcUsers: List<User> = emptyList(),
|
rpcUsers: List<User> = emptyList(),
|
||||||
verifierType: VerifierType = VerifierType.InMemory,
|
verifierType: VerifierType = VerifierType.InMemory,
|
||||||
@ -416,19 +436,31 @@ class DriverDSL(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun startNode(
|
override fun startNode(
|
||||||
providedName: String?,
|
providedName: X500Name?,
|
||||||
advertisedServices: Set<ServiceInfo>,
|
advertisedServices: Set<ServiceInfo>,
|
||||||
rpcUsers: List<User>,
|
rpcUsers: List<User>,
|
||||||
verifierType: VerifierType,
|
verifierType: VerifierType,
|
||||||
customOverrides: Map<String, Any?>
|
customOverrides: Map<String, Any?>
|
||||||
): ListenableFuture<NodeHandle> {
|
): ListenableFuture<NodeHandle> {
|
||||||
|
return startNode(providedName?.toString(), advertisedServices, rpcUsers, verifierType, customOverrides)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun startNode(providedName: String?,
|
||||||
|
advertisedServices: Set<ServiceInfo>,
|
||||||
|
rpcUsers: List<User>,
|
||||||
|
verifierType: VerifierType,
|
||||||
|
customOverrides: Map<String, Any?>): ListenableFuture<NodeHandle> {
|
||||||
val p2pAddress = portAllocation.nextHostAndPort()
|
val p2pAddress = portAllocation.nextHostAndPort()
|
||||||
val rpcAddress = portAllocation.nextHostAndPort()
|
val rpcAddress = portAllocation.nextHostAndPort()
|
||||||
val webAddress = portAllocation.nextHostAndPort()
|
val webAddress = portAllocation.nextHostAndPort()
|
||||||
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
|
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
|
||||||
val name = providedName ?: "${pickA(name)}-${p2pAddress.port}"
|
val name = providedName.toString() ?: X509Utilities.getDevX509Name("${pickA(name).commonName}-${p2pAddress.port}").toString()
|
||||||
|
val commonName = try {
|
||||||
val baseDirectory = driverDirectory / name
|
X500Name(name).commonName
|
||||||
|
} catch(ex: IllegalArgumentException) {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
val baseDirectory = driverDirectory / commonName
|
||||||
val configOverrides = mapOf(
|
val configOverrides = mapOf(
|
||||||
"myLegalName" to name,
|
"myLegalName" to name,
|
||||||
"p2pAddress" to p2pAddress.toString(),
|
"p2pAddress" to p2pAddress.toString(),
|
||||||
@ -475,7 +507,7 @@ class DriverDSL(
|
|||||||
verifierType: VerifierType,
|
verifierType: VerifierType,
|
||||||
rpcUsers: List<User>
|
rpcUsers: List<User>
|
||||||
): ListenableFuture<Pair<Party, List<NodeHandle>>> {
|
): ListenableFuture<Pair<Party, List<NodeHandle>>> {
|
||||||
val nodeNames = (1..clusterSize).map { "${DUMMY_NOTARY.name} $it" }
|
val nodeNames = (1..clusterSize).map { "Notary Node $it" }
|
||||||
val paths = nodeNames.map { driverDirectory / it }
|
val paths = nodeNames.map { driverDirectory / it }
|
||||||
ServiceIdentityGenerator.generateToDisk(paths, type.id, notaryName)
|
ServiceIdentityGenerator.generateToDisk(paths, type.id, notaryName)
|
||||||
|
|
||||||
@ -533,7 +565,12 @@ class DriverDSL(
|
|||||||
override fun startNetworkMapService() {
|
override fun startNetworkMapService() {
|
||||||
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
|
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
|
||||||
val apiAddress = portAllocation.nextHostAndPort().toString()
|
val apiAddress = portAllocation.nextHostAndPort().toString()
|
||||||
val baseDirectory = driverDirectory / networkMapLegalName
|
val nodeDirectoryName = try {
|
||||||
|
X500Name(networkMapLegalName).commonName
|
||||||
|
} catch(ex: IllegalArgumentException) {
|
||||||
|
networkMapLegalName
|
||||||
|
}
|
||||||
|
val baseDirectory = driverDirectory / nodeDirectoryName
|
||||||
val config = ConfigHelper.loadConfig(
|
val config = ConfigHelper.loadConfig(
|
||||||
baseDirectory = baseDirectory,
|
baseDirectory = baseDirectory,
|
||||||
allowMissingConfig = true,
|
allowMissingConfig = true,
|
||||||
@ -554,9 +591,9 @@ class DriverDSL(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val name = arrayOf(
|
val name = arrayOf(
|
||||||
ALICE.name,
|
X500Name(ALICE.name),
|
||||||
BOB.name,
|
X500Name(BOB.name),
|
||||||
DUMMY_BANK_A.name
|
X500Name(DUMMY_BANK_A.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun <A> pickA(array: Array<A>): A = array[Math.abs(Random().nextInt()) % array.size]
|
fun <A> pickA(array: Array<A>): A = array[Math.abs(Random().nextInt()) % array.size]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user