mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
Node: get artemisAddress and webAddress from the config rather than constructor parameters
This commit is contained in:
parent
e5c0c975bd
commit
727c3ac5fc
@ -1,7 +1,6 @@
|
||||
package com.r3corda.node.internal
|
||||
|
||||
import com.codahale.metrics.JmxReporter
|
||||
import com.google.common.net.HostAndPort
|
||||
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||
import com.r3corda.core.node.ServiceHub
|
||||
import com.r3corda.core.node.services.ServiceInfo
|
||||
@ -58,10 +57,8 @@ class ConfigurationException(message: String) : Exception(message)
|
||||
* @param clock The clock used within the node and by all protocols etc.
|
||||
* @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,
|
||||
override val configuration: FullNodeConfiguration, networkMapAddress: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, clock: Clock = NodeClock(),
|
||||
val messagingServerAddr: HostAndPort? = null) : AbstractNode(configuration, networkMapAddress, advertisedServices, clock) {
|
||||
class Node(override val configuration: FullNodeConfiguration, networkMapAddress: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, clock: Clock = NodeClock()) : AbstractNode(configuration, networkMapAddress, advertisedServices, clock) {
|
||||
companion object {
|
||||
/** The port that is used by default if none is specified. As you know, 31337 is the most elite number. */
|
||||
@JvmField
|
||||
@ -119,9 +116,9 @@ class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
|
||||
private var shutdownThread: Thread? = null
|
||||
|
||||
override fun makeMessagingService(): MessagingServiceInternal {
|
||||
val serverAddr = messagingServerAddr ?: {
|
||||
messageBroker = ArtemisMessagingServer(configuration, p2pAddr, services.networkMapCache)
|
||||
p2pAddr
|
||||
val serverAddr = configuration.messagingServerAddress ?: {
|
||||
messageBroker = ArtemisMessagingServer(configuration, configuration.artemisAddress, services.networkMapCache)
|
||||
configuration.artemisAddress
|
||||
}()
|
||||
val myIdentityOrNullIfNetworkMapService = if (networkMapService != null) services.storageService.myLegalIdentityKey.public else null
|
||||
return NodeMessagingClient(configuration, serverAddr, myIdentityOrNullIfNetworkMapService, serverThread,
|
||||
@ -177,13 +174,13 @@ class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
|
||||
sslContextFactory.setExcludeCipherSuites(".*NULL.*", ".*RC4.*", ".*MD5.*", ".*DES.*", ".*DSS.*")
|
||||
sslContextFactory.setIncludeCipherSuites(".*AES.*GCM.*")
|
||||
val sslConnector = ServerConnector(server, SslConnectionFactory(sslContextFactory, "http/1.1"), HttpConnectionFactory(httpsConfiguration))
|
||||
sslConnector.port = webServerAddr.port
|
||||
sslConnector.port = configuration.webAddress.port
|
||||
server.connectors = arrayOf<Connector>(sslConnector)
|
||||
} else {
|
||||
val httpConfiguration = HttpConfiguration()
|
||||
httpConfiguration.outputBufferSize = 32768
|
||||
val httpConnector = ServerConnector(server, HttpConnectionFactory(httpConfiguration))
|
||||
httpConnector.port = webServerAddr.port
|
||||
httpConnector.port = configuration.webAddress.port
|
||||
server.connectors = arrayOf<Connector>(httpConnector)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import com.r3corda.core.div
|
||||
import com.r3corda.core.messaging.SingleMessageRecipient
|
||||
import com.r3corda.core.node.services.ServiceInfo
|
||||
import com.r3corda.node.internal.Node
|
||||
import com.r3corda.node.serialization.NodeClock
|
||||
import com.r3corda.node.services.messaging.NodeMessagingClient
|
||||
import com.r3corda.node.services.network.NetworkMapService
|
||||
import com.typesafe.config.Config
|
||||
@ -18,7 +17,6 @@ import java.net.URL
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.util.*
|
||||
@ -133,13 +131,12 @@ class FullNodeConfiguration(conf: Config) : NodeConfiguration {
|
||||
override val trustStorePassword: String by conf
|
||||
override val dataSourceProperties: Properties by conf
|
||||
override val devMode: Boolean by conf.getOrElse { false }
|
||||
val networkMapAddress: HostAndPort? = if (conf.hasPath("networkMapAddress")) HostAndPort.fromString(conf.getString("networkMapAddress")) else null
|
||||
val useHTTPS: Boolean by conf
|
||||
val artemisAddress: HostAndPort by conf
|
||||
val webAddress: HostAndPort by conf
|
||||
val messagingServerAddress: HostAndPort? = if (conf.hasPath("messagingServerAddress")) HostAndPort.fromString(conf.getString("messagingServerAddress")) else null
|
||||
val networkMapAddress: HostAndPort? = if (conf.hasPath("networkMapAddress")) HostAndPort.fromString(conf.getString("networkMapAddress")) else null
|
||||
val extraAdvertisedServiceIds: String by conf
|
||||
val clock: Clock = NodeClock()
|
||||
|
||||
fun createNode(): Node {
|
||||
val advertisedServices = mutableSetOf<ServiceInfo>()
|
||||
@ -150,14 +147,7 @@ class FullNodeConfiguration(conf: Config) : NodeConfiguration {
|
||||
}
|
||||
if (networkMapAddress == null) advertisedServices.add(ServiceInfo(NetworkMapService.Type))
|
||||
val networkMapMessageAddress: SingleMessageRecipient? = if (networkMapAddress == null) null else NodeMessagingClient.makeNetworkMapAddress(networkMapAddress)
|
||||
return Node(artemisAddress,
|
||||
webAddress,
|
||||
this,
|
||||
networkMapMessageAddress,
|
||||
advertisedServices,
|
||||
clock,
|
||||
messagingServerAddress
|
||||
)
|
||||
return Node(this, networkMapMessageAddress, advertisedServices)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ private fun setup(params: CliParams.SetupNode): Int {
|
||||
}
|
||||
|
||||
val configFile = params.dir.resolve("config")
|
||||
val config = loadConfigFile(params.dir, configFile, params.defaultLegalName)
|
||||
val config = loadConfigFile(params.dir, configFile, emptyMap(), params.defaultLegalName)
|
||||
if (!Files.exists(params.dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))) {
|
||||
createIdentities(config)
|
||||
}
|
||||
@ -406,7 +406,7 @@ private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipi
|
||||
}
|
||||
|
||||
val node = logElapsedTime("Node startup", log) {
|
||||
Node(params.networkAddress, params.apiAddress, config, networkMapId, advertisedServices, DemoClock()).setup().start()
|
||||
Node(config, networkMapId, advertisedServices, DemoClock()).setup().start()
|
||||
}
|
||||
|
||||
return node
|
||||
@ -447,15 +447,19 @@ private fun getNodeConfig(cliParams: CliParams.RunNode): FullNodeConfiguration {
|
||||
}
|
||||
|
||||
val configFile = cliParams.dir.resolve("config")
|
||||
return loadConfigFile(cliParams.dir, configFile, cliParams.defaultLegalName)
|
||||
val configOverrides = mapOf(
|
||||
"artemisAddress" to cliParams.networkAddress.toString(),
|
||||
"webAddress" to cliParams.apiAddress.toString()
|
||||
)
|
||||
return loadConfigFile(cliParams.dir, configFile, configOverrides, cliParams.defaultLegalName)
|
||||
}
|
||||
|
||||
private fun loadConfigFile(baseDir: Path, configFile: Path, defaultLegalName: String): FullNodeConfiguration {
|
||||
private fun loadConfigFile(baseDir: Path, configFile: Path, configOverrides: Map<String, String>, defaultLegalName: String): FullNodeConfiguration {
|
||||
if (!Files.exists(configFile)) {
|
||||
createDefaultConfigFile(configFile, defaultLegalName)
|
||||
log.warn("Default config created at $configFile.")
|
||||
}
|
||||
return FullNodeConfiguration(NodeConfiguration.loadConfig(baseDir, configFileOverride = configFile))
|
||||
return FullNodeConfiguration(NodeConfiguration.loadConfig(baseDir, configFileOverride = configFile, configOverrides = configOverrides))
|
||||
}
|
||||
|
||||
private fun createIdentities(nodeConf: NodeConfiguration) {
|
||||
|
@ -65,14 +65,16 @@ fun main(args: Array<String>) {
|
||||
allowMissingConfig = true,
|
||||
configOverrides = mapOf(
|
||||
"myLegalName" to "Rate fix demo node",
|
||||
"basedir" to dir.normalize().toString()
|
||||
"basedir" to dir.normalize().toString(),
|
||||
"artemisAddress" to myNetAddr.toString(),
|
||||
"webAddress" to apiAddr.toString()
|
||||
)
|
||||
)
|
||||
|
||||
val nodeConfiguration = FullNodeConfiguration(config)
|
||||
|
||||
val node = logElapsedTime("Node startup") {
|
||||
Node(myNetAddr, apiAddr, nodeConfiguration, networkMapAddr, advertisedServices, DemoClock()).setup().start()
|
||||
Node(nodeConfiguration, networkMapAddr, advertisedServices, DemoClock()).setup().start()
|
||||
}
|
||||
node.networkMapRegistrationFuture.get()
|
||||
val notaryNode = node.services.networkMapCache.notaryNodes[0]
|
||||
|
@ -122,7 +122,12 @@ fun main(args: Array<String>) {
|
||||
Role.BUYER -> "Bank A"
|
||||
Role.SELLER -> "Bank B"
|
||||
}
|
||||
FullNodeConfiguration(NodeConfiguration.loadConfig(directory, allowMissingConfig = true, configOverrides = mapOf("myLegalName" to myLegalName)))
|
||||
val configOverrides = mapOf(
|
||||
"myLegalName" to myLegalName,
|
||||
"artemisAddress" to myNetAddr.toString(),
|
||||
"webAddress" to apiNetAddr.toString()
|
||||
)
|
||||
FullNodeConfiguration(NodeConfiguration.loadConfig(directory, allowMissingConfig = true, configOverrides = configOverrides))
|
||||
}
|
||||
|
||||
// Which services will this instance of the node provide to the network?
|
||||
@ -141,7 +146,7 @@ fun main(args: Array<String>) {
|
||||
|
||||
// And now construct then start the node object. It takes a little while.
|
||||
val node = logElapsedTime("Node startup", log) {
|
||||
Node(myNetAddr, apiNetAddr, config, networkMapId, advertisedServices).setup().start()
|
||||
Node(config, networkMapId, advertisedServices).setup().start()
|
||||
}
|
||||
|
||||
// What happens next depends on the role. The buyer sits around waiting for a trade to start. The seller role
|
||||
|
Loading…
Reference in New Issue
Block a user