diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index 12fd93b3b4..4e983e37ee 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -129,18 +129,9 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo } } - val info: NodeInfo by lazy { - val services = mutableListOf() - for (service in advertisedServices) { - val identity = obtainKeyPair(configuration.basedir, service.type.id + "-private-key", service.type.id + "-public", service.type.id).first - services += ServiceEntry(service, identity) - } - val legalIdentity = obtainLegalIdentity() - NodeInfo(net.myAddress, legalIdentity, services, findMyLocation()) - } - open fun findMyLocation(): PhysicalLocation? = CityDatabase[configuration.nearestCity] + lateinit var info: NodeInfo lateinit var storage: TxWritableStorageService lateinit var checkpointStorage: CheckpointStorage lateinit var smm: StateMachineManager @@ -202,8 +193,8 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo schemas = makeSchemaService() vault = makeVaultService() + info = makeInfo() identity = makeIdentityService() - // Place the long term identity key in the KMS. Eventually, this is likely going to be separated again because // the KMS is meant for derived temporary keys used in transactions, and we're not supposed to sign things with // the identity key. But the infrastructure to make that easy isn't here yet. @@ -264,6 +255,25 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo return this } + private fun makeInfo(): NodeInfo { + val services = makeServiceEntries() + val legalIdentity = obtainLegalIdentity() + return NodeInfo(net.myAddress, legalIdentity, services, findMyLocation()) + } + + /** + * A service entry contains the advertised [ServiceInfo] along with the service identity. The identity *name* is + * taken from the configuration or, if non specified, generated by combining the node's legal name and the service id. + */ + private fun makeServiceEntries(): List { + return advertisedServices.map { + val serviceId = it.type.id + val serviceName = it.name ?: "$serviceId|${configuration.myLegalName}" + val identity = obtainKeyPair(configuration.basedir, serviceId + "-private-key", serviceId + "-public", serviceName).first + ServiceEntry(it, identity) + } + } + @VisibleForTesting protected open fun acceptableLiveFiberCountOnStop(): Int = 0 @@ -446,12 +456,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo val checkpointStorage = DBCheckpointStorage() val transactionStorage = DBTransactionStorage() _servicesThatAcceptUploads += attachments - // Populate the partyKeys set. - obtainKeyPair(dir, PRIVATE_KEY_FILE_NAME, PUBLIC_IDENTITY_FILE_NAME) - for (service in advertisedServices) { - // Ensure all required keys exist. - obtainKeyPair(configuration.basedir, service.type.id + "-private-key", service.type.id + "-public", service.type.id) - } val stateMachineTransactionMappingStorage = DBTransactionMappingStorage() return Pair( constructStorageService(attachments, transactionStorage, stateMachineTransactionMappingStorage), @@ -475,7 +479,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, val netwo // the legal name is actually validated in some way. val privKeyFile = dir / privateKeyFileName val pubIdentityFile = dir / publicKeyFileName - val identityName = if (serviceName == null) configuration.myLegalName else configuration.myLegalName + "|" + serviceName + val identityName = serviceName ?: configuration.myLegalName val identityAndKey = if (!privKeyFile.exists()) { log.info("Identity key not found, generating fresh key!")