From 4b962eeb1f64dbc65afe8edc5e098a33a602a438 Mon Sep 17 00:00:00 2001 From: Andras Slemmer Date: Mon, 11 Jul 2016 15:56:53 +0100 Subject: [PATCH 1/5] irsdemo: Remove unused --fake-trade-with-address --- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 27 +++++--------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index a7a5c50931..052edf90a6 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -82,7 +82,6 @@ sealed class CliParams { val apiAddress: HostAndPort, val mapAddress: String, val identityFile: Path, - val tradeWithAddrs: List, val tradeWithIdentities: List, val uploadRates: Boolean, val defaultLegalName: String, @@ -156,11 +155,6 @@ sealed class CliParams { } else { dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME) }, - tradeWithAddrs = if (options.has(CliParamsSpec.fakeTradeWithAddr)) { - options.valuesOf(CliParamsSpec.fakeTradeWithAddr) - } else { - listOf("localhost:${defaultNetworkPort(node.other)}") - }, tradeWithIdentities = if (options.has(CliParamsSpec.fakeTradeWithIdentityFile)) { options.valuesOf(CliParamsSpec.fakeTradeWithIdentityFile).map { Paths.get(it) } } else { @@ -236,7 +230,6 @@ object CliParamsSpec { val baseDirectoryArg = parser.accepts("base-directory").withOptionalArg().defaultsTo(CliParams.defaultBaseDirectory) val networkMapIdentityFile = parser.accepts("network-map-identity-file").withOptionalArg() val networkMapNetAddr = parser.accepts("network-map-address").withRequiredArg().defaultsTo("localhost") - val fakeTradeWithAddr = parser.accepts("fake-trade-with-address").withOptionalArg() val fakeTradeWithIdentityFile = parser.accepts("fake-trade-with-identity-file").withOptionalArg() val nonOptions = parser.nonOptions() } @@ -306,11 +299,8 @@ private fun runNode(cliParams: CliParams.RunNode): Int { try { val networkMap = createRecipient(cliParams.mapAddress) - val destinations = cliParams.tradeWithAddrs.map({ - createRecipient(it) - }) - val node = startNode(cliParams, networkMap, destinations) + val node = startNode(cliParams, networkMap) // Register handlers for the demo AutoOfferProtocol.Handler.register(node) UpdateBusinessDayProtocol.Handler.register(node) @@ -366,7 +356,7 @@ private fun createRecipient(addr: String) : SingleMessageRecipient { return ArtemisMessagingService.makeRecipient(hostAndPort) } -private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipient, recipients: List) : Node { +private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipient) : Node { val config = getNodeConfig(params) val advertisedServices: Set val networkMapId = @@ -387,21 +377,18 @@ private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipi // TODO: This should all be replaced by the identity service being updated // as the network map changes. - if (params.tradeWithAddrs.size != params.tradeWithIdentities.size) { - throw IllegalArgumentException("Different number of peer addresses (${params.tradeWithAddrs.size}) and identities (${params.tradeWithIdentities.size})") - } - for ((recipient, identityFile) in recipients.zip(params.tradeWithIdentities)) { - val peerId = nodeInfo(recipient, identityFile) - node.services.identityService.registerIdentity(peerId.identity) + for (identityFile in params.tradeWithIdentities) { + node.services.identityService.registerIdentity(parsePartyFromFile(identityFile)) } return node } +private fun parsePartyFromFile(path: Path) = Files.readAllBytes(path).deserialize() + private fun nodeInfo(recipient: SingleMessageRecipient, identityFile: Path, advertisedServices: Set = emptySet()): NodeInfo { try { - val path = identityFile - val party = Files.readAllBytes(path).deserialize() + val party = parsePartyFromFile(identityFile) return NodeInfo(recipient, party, advertisedServices) } catch (e: Exception) { println("Could not find identify file $identityFile.") From 144f88e0d046cf2152df9da4680e8ee7f6ce19f5 Mon Sep 17 00:00:00 2001 From: Andras Slemmer Date: Mon, 11 Jul 2016 15:57:41 +0100 Subject: [PATCH 2/5] irsdemo: Print more helpful error message when no role is specified (was NPE) --- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index 052edf90a6..a3e5a1321f 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -197,7 +197,7 @@ sealed class CliParams { } fun parse(options: OptionSet): CliParams { - val role = options.valueOf(CliParamsSpec.roleArg)!! + val role: IRSDemoRole = options.valueOf(CliParamsSpec.roleArg) ?: throw IllegalArgumentException("Please provide a role") return when (role) { IRSDemoRole.SetupNodeA -> parseSetupNode(options, IRSDemoNode.NodeA) IRSDemoRole.SetupNodeB -> parseSetupNode(options, IRSDemoNode.NodeB) From 6da1a702bff1c482f2f9c93ccade80c47afba4f0 Mon Sep 17 00:00:00 2001 From: Andras Slemmer Date: Mon, 11 Jul 2016 15:58:17 +0100 Subject: [PATCH 3/5] irsdemo: Give descriptions of cli arguments --- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 30 ++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index a3e5a1321f..2fc92bd0be 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -224,13 +224,26 @@ enum class IRSDemoNode { object CliParamsSpec { val parser = OptionParser() - val roleArg = parser.accepts("role").withRequiredArg().ofType(IRSDemoRole::class.java) - val networkAddressArg = parser.accepts("network-address").withOptionalArg().ofType(String::class.java) - val apiAddressArg = parser.accepts("api-address").withOptionalArg().ofType(String::class.java) - val baseDirectoryArg = parser.accepts("base-directory").withOptionalArg().defaultsTo(CliParams.defaultBaseDirectory) - val networkMapIdentityFile = parser.accepts("network-map-identity-file").withOptionalArg() - val networkMapNetAddr = parser.accepts("network-map-address").withRequiredArg().defaultsTo("localhost") - val fakeTradeWithIdentityFile = parser.accepts("fake-trade-with-identity-file").withOptionalArg() + val roleArg = parser.accepts("role") + .withRequiredArg().ofType(IRSDemoRole::class.java) + val networkAddressArg = + parser.accepts("network-address", "The p2p networking address to use") + .withOptionalArg().ofType(String::class.java) + val apiAddressArg = + parser.accepts("api-address", "The address to expose the HTTP API on") + .withOptionalArg().ofType(String::class.java) + val baseDirectoryArg = + parser.accepts("base-directory", "The directory to put all files under") + .withOptionalArg().defaultsTo(CliParams.defaultBaseDirectory) + val networkMapIdentityFile = + parser.accepts("network-map-identity-file", "The file containing the Party info of the network map") + .withOptionalArg() + val networkMapNetAddr = + parser.accepts("network-map-address", "The address of the network map") + .withRequiredArg().defaultsTo("localhost") + val fakeTradeWithIdentityFile = + parser.accepts("fake-trade-with-identity-file", "Extra identities to be registered with the identity service") + .withOptionalArg() val nonOptions = parser.nonOptions() } @@ -453,8 +466,9 @@ private fun createDefaultConfigFile(configFile: File, legalName: String) { } private fun printHelp(parser: OptionParser) { + val roleList = IRSDemoRole.values().joinToString(separator = "|") {it.toString()} println(""" - Usage: irsdemo --role [NodeA|NodeB|Trade|Date] [|] [options] + Usage: irsdemo --role $roleList [|] [options] Please refer to the documentation in docs/build/index.html for more info. """.trimIndent()) From 38af91dc48da52d7797d2ab3cd4d83a4f70acc49 Mon Sep 17 00:00:00 2001 From: Andras Slemmer Date: Mon, 11 Jul 2016 18:33:02 +0100 Subject: [PATCH 4/5] irsdemo: add --help --- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index 2fc92bd0be..fd60e2251c 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -104,6 +104,11 @@ sealed class CliParams { val dateString: String ) : CliParams() + /** + * Corresponds to --help. + */ + object Help : CliParams() + companion object { val defaultBaseDirectory = "./build/irs-demo" @@ -197,6 +202,9 @@ sealed class CliParams { } fun parse(options: OptionSet): CliParams { + if (options.has(CliParamsSpec.help)) { + return Help + } val role: IRSDemoRole = options.valueOf(CliParamsSpec.roleArg) ?: throw IllegalArgumentException("Please provide a role") return when (role) { IRSDemoRole.SetupNodeA -> parseSetupNode(options, IRSDemoNode.NodeA) @@ -245,6 +253,7 @@ object CliParamsSpec { parser.accepts("fake-trade-with-identity-file", "Extra identities to be registered with the identity service") .withOptionalArg() val nonOptions = parser.nonOptions() + val help = parser.accepts("help", "Prints this help").forHelp() } class IRSDemoPluginRegistry : CordaPluginRegistry { @@ -280,6 +289,10 @@ fun runIRSDemo(args: Array): Int { is CliParams.RunNode -> runNode(cliParams) is CliParams.Trade -> runTrade(cliParams) is CliParams.DateChange -> runDateChange(cliParams) + is CliParams.Help -> { + printHelp(CliParamsSpec.parser) + 0 + } } } From 53725af318fd8d6e5eddc0cd8f91f45ee34d2ee2 Mon Sep 17 00:00:00 2001 From: Andras Slemmer Date: Tue, 12 Jul 2016 15:42:08 +0100 Subject: [PATCH 5/5] irsdemo: Add spaces in closure --- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index fd60e2251c..4056eea3d7 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -479,7 +479,7 @@ private fun createDefaultConfigFile(configFile: File, legalName: String) { } private fun printHelp(parser: OptionParser) { - val roleList = IRSDemoRole.values().joinToString(separator = "|") {it.toString()} + val roleList = IRSDemoRole.values().joinToString(separator = "|") { it.toString() } println(""" Usage: irsdemo --role $roleList [|] [options] Please refer to the documentation in docs/build/index.html for more info.