mirror of
https://github.com/corda/corda.git
synced 2025-06-23 01:19:00 +00:00
Make Node override configuration and use FullNodeConfiguration so that no casting is needed
This commit is contained in:
@ -72,7 +72,7 @@ import kotlin.reflect.KClass
|
|||||||
// TODO: Where this node is the initial network map service, currently no networkMapService is provided.
|
// TODO: Where this node is the initial network map service, currently no networkMapService is provided.
|
||||||
// In theory the NodeInfo for the node should be passed in, instead, however currently this is constructed by the
|
// In theory the NodeInfo for the node should be passed in, instead, however currently this is constructed by the
|
||||||
// AbstractNode. It should be possible to generate the NodeInfo outside of AbstractNode, so it can be passed in.
|
// AbstractNode. It should be possible to generate the NodeInfo outside of AbstractNode, so it can be passed in.
|
||||||
abstract class AbstractNode(val configuration: NodeConfiguration, val networkMapService: SingleMessageRecipient?,
|
abstract class AbstractNode(open val configuration: NodeConfiguration, val networkMapService: SingleMessageRecipient?,
|
||||||
val advertisedServices: Set<ServiceInfo>, val platformClock: Clock) : SingletonSerializeAsToken() {
|
val advertisedServices: Set<ServiceInfo>, val platformClock: Clock) : SingletonSerializeAsToken() {
|
||||||
companion object {
|
companion object {
|
||||||
val PRIVATE_KEY_FILE_NAME = "identity-private-key"
|
val PRIVATE_KEY_FILE_NAME = "identity-private-key"
|
||||||
|
@ -9,7 +9,6 @@ import com.r3corda.core.utilities.loggerFor
|
|||||||
import com.r3corda.node.serialization.NodeClock
|
import com.r3corda.node.serialization.NodeClock
|
||||||
import com.r3corda.node.services.api.MessagingServiceInternal
|
import com.r3corda.node.services.api.MessagingServiceInternal
|
||||||
import com.r3corda.node.services.config.FullNodeConfiguration
|
import com.r3corda.node.services.config.FullNodeConfiguration
|
||||||
import com.r3corda.node.services.config.NodeConfiguration
|
|
||||||
import com.r3corda.node.services.messaging.ArtemisMessagingServer
|
import com.r3corda.node.services.messaging.ArtemisMessagingServer
|
||||||
import com.r3corda.node.services.messaging.CordaRPCOps
|
import com.r3corda.node.services.messaging.CordaRPCOps
|
||||||
import com.r3corda.node.services.messaging.NodeMessagingClient
|
import com.r3corda.node.services.messaging.NodeMessagingClient
|
||||||
@ -60,7 +59,7 @@ class ConfigurationException(message: String) : Exception(message)
|
|||||||
* @param messagingServerAddr The address of the Artemis broker instance. If not provided the node will run one locally.
|
* @param messagingServerAddr The address of the Artemis broker instance. If not provided the node will run one locally.
|
||||||
*/
|
*/
|
||||||
class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
|
class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
|
||||||
configuration: NodeConfiguration, networkMapAddress: SingleMessageRecipient?,
|
override val configuration: FullNodeConfiguration, networkMapAddress: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceInfo>, clock: Clock = NodeClock(),
|
advertisedServices: Set<ServiceInfo>, clock: Clock = NodeClock(),
|
||||||
val messagingServerAddr: HostAndPort? = null) : AbstractNode(configuration, networkMapAddress, advertisedServices, clock) {
|
val messagingServerAddr: HostAndPort? = null) : AbstractNode(configuration, networkMapAddress, advertisedServices, clock) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -163,7 +162,7 @@ class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
|
|||||||
|
|
||||||
val server = Server()
|
val server = Server()
|
||||||
|
|
||||||
if (configuration is FullNodeConfiguration && configuration.useHTTPS) {
|
if (configuration.useHTTPS) {
|
||||||
val httpsConfiguration = HttpConfiguration()
|
val httpsConfiguration = HttpConfiguration()
|
||||||
httpsConfiguration.outputBufferSize = 32768
|
httpsConfiguration.outputBufferSize = 32768
|
||||||
httpsConfiguration.addCustomizer(SecureRequestCustomizer())
|
httpsConfiguration.addCustomizer(SecureRequestCustomizer())
|
||||||
|
@ -11,5 +11,6 @@ dataSourceProperties = {
|
|||||||
"dataSource.password" = ""
|
"dataSource.password" = ""
|
||||||
}
|
}
|
||||||
devMode = true
|
devMode = true
|
||||||
|
hostNotaryServiceLocally = false
|
||||||
certificateSigningService = "https://cordaci-netperm.corda.r3cev.com"
|
certificateSigningService = "https://cordaci-netperm.corda.r3cev.com"
|
||||||
useHTTPS = false
|
useHTTPS = false
|
@ -437,7 +437,7 @@ private fun runUploadRates(host: HostAndPort): ListenableFuture<Int> {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNodeConfig(cliParams: CliParams.RunNode): NodeConfiguration {
|
private fun getNodeConfig(cliParams: CliParams.RunNode): FullNodeConfiguration {
|
||||||
if (!Files.exists(cliParams.dir)) {
|
if (!Files.exists(cliParams.dir)) {
|
||||||
throw NotSetupException("Missing config directory. Please run node setup before running the node")
|
throw NotSetupException("Missing config directory. Please run node setup before running the node")
|
||||||
}
|
}
|
||||||
@ -450,7 +450,7 @@ private fun getNodeConfig(cliParams: CliParams.RunNode): NodeConfiguration {
|
|||||||
return loadConfigFile(cliParams.dir, configFile, cliParams.defaultLegalName)
|
return loadConfigFile(cliParams.dir, configFile, cliParams.defaultLegalName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadConfigFile(baseDir: Path, configFile: Path, defaultLegalName: String): NodeConfiguration {
|
private fun loadConfigFile(baseDir: Path, configFile: Path, defaultLegalName: String): FullNodeConfiguration {
|
||||||
if (!Files.exists(configFile)) {
|
if (!Files.exists(configFile)) {
|
||||||
createDefaultConfigFile(configFile, defaultLegalName)
|
createDefaultConfigFile(configFile, defaultLegalName)
|
||||||
log.warn("Default config created at $configFile.")
|
log.warn("Default config created at $configFile.")
|
||||||
|
@ -10,17 +10,15 @@ import com.r3corda.core.utilities.Emoji
|
|||||||
import com.r3corda.core.utilities.LogHelper
|
import com.r3corda.core.utilities.LogHelper
|
||||||
import com.r3corda.demos.api.NodeInterestRates
|
import com.r3corda.demos.api.NodeInterestRates
|
||||||
import com.r3corda.node.internal.Node
|
import com.r3corda.node.internal.Node
|
||||||
|
import com.r3corda.node.services.config.FullNodeConfiguration
|
||||||
import com.r3corda.node.services.config.NodeConfiguration
|
import com.r3corda.node.services.config.NodeConfiguration
|
||||||
import com.r3corda.node.services.messaging.NodeMessagingClient
|
import com.r3corda.node.services.messaging.NodeMessagingClient
|
||||||
import com.r3corda.protocols.RatesFixProtocol
|
import com.r3corda.protocols.RatesFixProtocol
|
||||||
import com.r3corda.testing.node.makeTestDataSourceProperties
|
|
||||||
import joptsimple.OptionParser
|
import joptsimple.OptionParser
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.nio.file.Path
|
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
private val log: Logger = LoggerFactory.getLogger("RatesFixDemo")
|
private val log: Logger = LoggerFactory.getLogger("RatesFixDemo")
|
||||||
@ -60,25 +58,21 @@ fun main(args: Array<String>) {
|
|||||||
val advertisedServices: Set<ServiceInfo> = emptySet()
|
val advertisedServices: Set<ServiceInfo> = emptySet()
|
||||||
val myNetAddr = HostAndPort.fromString(options.valueOf(networkAddressArg))
|
val myNetAddr = HostAndPort.fromString(options.valueOf(networkAddressArg))
|
||||||
|
|
||||||
// TODO: create a base class that provides a default implementation
|
|
||||||
val config = object : NodeConfiguration {
|
|
||||||
override val basedir: Path = dir
|
|
||||||
override val myLegalName: String = "Rate fix demo node"
|
|
||||||
override val nearestCity: String = "Atlantis"
|
|
||||||
override val emailAddress: String = ""
|
|
||||||
override val devMode: Boolean = true
|
|
||||||
override val exportJMXto: String = "http"
|
|
||||||
override val keyStorePassword: String = "cordacadevpass"
|
|
||||||
override val trustStorePassword: String = "trustpass"
|
|
||||||
override val dataSourceProperties: Properties = makeTestDataSourceProperties()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
val apiAddr = HostAndPort.fromParts(myNetAddr.hostText, myNetAddr.port + 1)
|
val apiAddr = HostAndPort.fromParts(myNetAddr.hostText, myNetAddr.port + 1)
|
||||||
|
|
||||||
|
val config = NodeConfiguration.loadConfig(
|
||||||
|
baseDirectoryPath = dir,
|
||||||
|
allowMissingConfig = true,
|
||||||
|
configOverrides = mapOf(
|
||||||
|
"myLegalName" to "Rate fix demo node",
|
||||||
|
"basedir" to dir.normalize().toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val nodeConfiguration = FullNodeConfiguration(config)
|
||||||
|
|
||||||
val node = logElapsedTime("Node startup") {
|
val node = logElapsedTime("Node startup") {
|
||||||
Node(myNetAddr, apiAddr, config, networkMapAddr,
|
Node(myNetAddr, apiAddr, nodeConfiguration, networkMapAddr, advertisedServices, DemoClock()).setup().start()
|
||||||
advertisedServices, DemoClock()).setup().start()
|
|
||||||
}
|
}
|
||||||
node.networkMapRegistrationFuture.get()
|
node.networkMapRegistrationFuture.get()
|
||||||
val notaryNode = node.services.networkMapCache.notaryNodes[0]
|
val notaryNode = node.services.networkMapCache.notaryNodes[0]
|
||||||
|
Reference in New Issue
Block a user