From f9a9bb19a7cc6d202446890e4e11bebd4a118cf3 Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Fri, 18 May 2018 15:01:24 +0530 Subject: [PATCH] CONTRIBUTION - Network bootstrapper check for duplicate node names (#3182) --- CONTRIBUTORS.md | 20 +++++++++++----- .../internal/network/NetworkBootstrapper.kt | 24 ++++++++++++++++++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 5fa0f16e1c..f7c0f465f0 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,11 +1,12 @@ # List of Contributors -We'd like to thank the following people for contributing ideas to Corda, -either during architecture review sessions of the R3 Architecture Working Group, -or in design reviews since Corda has been open-sourced. Some people have moved to -a different organisation since their contribution. Please forgive any omissions, and -create a pull request, or email , if you wish to see -changes to this list. +We'd like to thank the following people for contributing to Corda, either by +contributing to the design of Corda during the architecture review sessions of the +R3 Architecture Working Group and during design reviews since Corda has been +open-sourced, or by contributing code via pull requests. Some people have +moved to a different organisation since their contribution. Please forgive any +omissions, and create a pull request, or email , if you wish to +see changes to this list. * Alberto Arri (R3) * Andras Slemmer (R3) @@ -122,6 +123,8 @@ changes to this list. * Shams Asari (R3) * Simon Taylor (Barclays) * Sofus Mortensen (Digital Asset Holdings) +* stevenroose +* Stanly Johnson (Servntire Global) * Szymon Sztuka (R3) * Stephen Lane-Smith (BMO) * Thomas O'Donnell (Macquarie) @@ -132,6 +135,11 @@ changes to this list. * Tim Swanson (R3) * Timothy Smith (Credit Suisse) * Tommy Lillehagen (R3) +* tomtau +* Tudor Malene (R3) +* Tushar Singh Bora +* varunkm +* verymahler * Viktor Kolomeyko (R3) * Wawrzek Niewodniczanski (R3) * Wei Wu Zhang (Commonwealth Bank of Australia) diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/network/NetworkBootstrapper.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/network/NetworkBootstrapper.kt index 15b139b390..b0143f988a 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/network/NetworkBootstrapper.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/network/NetworkBootstrapper.kt @@ -38,6 +38,10 @@ import java.time.Instant import java.util.concurrent.Executors import java.util.concurrent.TimeoutException import kotlin.streams.toList +import kotlin.collections.HashSet +import kotlin.collections.component1 +import kotlin.collections.component2 +import kotlin.collections.set /** * Class to bootstrap a local network of Corda nodes on the same filesystem. @@ -77,7 +81,9 @@ class NetworkBootstrapper { try { println("Waiting for all nodes to generate their node-info files...") val nodeInfoFiles = gatherNodeInfoFiles(processes, nodeDirs) - println("Distributing all node info-files to all nodes") + println("Checking for duplicate nodes") + checkForDuplicateLegalNames(nodeInfoFiles) + println("Distributing all node-info files to all nodes") distributeNodeInfos(nodeDirs, nodeInfoFiles) println("Gathering notary identities") val notaryInfos = gatherNotaryInfos(nodeInfoFiles) @@ -158,6 +164,22 @@ class NetworkBootstrapper { } } + /*the function checks for duplicate myLegalName in the all the *_node.conf files + All the myLegalName values are added to a HashSet - this helps detect duplicate values. + If a duplicate name is found the process is aborted with an error message + */ + private fun checkForDuplicateLegalNames(nodeInfoFiles: List) { + val legalNames = HashSet() + for (nodeInfoFile in nodeInfoFiles) { + val nodeConfig = ConfigFactory.parseFile((nodeInfoFile.parent / "node.conf").toFile()) + val legalName = nodeConfig.getString("myLegalName") + if(!legalNames.add(legalName)){ + println("Duplicate Node Found - ensure every node has a unique legal name"); + throw IllegalArgumentException("Duplicate Node Found - $legalName"); + } + } + } + private fun gatherNotaryInfos(nodeInfoFiles: List): List { return nodeInfoFiles.mapNotNull { nodeInfoFile -> // The config contains the notary type