Esempio n. 1
0
def run_node():

    nodeReg = OrderedDict([
        ('Alpha', ('127.0.0.1', 9701)),
        ('Beta', ('127.0.0.1', 9703)),
        ('Gamma', ('127.0.0.1', 9705)),
        ('Delta', ('127.0.0.1', 9707))])

    # the first argument should be the node name
    try:
        nodeName = sys.argv[1]
    except IndexError:
        names = list(nodeReg.keys())
        print("Please supply a node name (one of {}) as the first argument.".
              format(", ".join(names)))
        print("For example:")
        print("    {} {}".format(sys.argv[0], names[0]))
        return

    with Looper(debug=False) as looper:
        # Nodes persist keys when bootstrapping to other nodes and reconnecting
        # using an ephemeral temporary directory when proving a concept is a
        # nice way to keep things tidy.
        with TemporaryDirectory() as tmpdir:
            node = Node(nodeName, nodeReg, basedirpath=tmpdir)

            # see simple_client.py
            joe_verkey = b'cffbb88a142be2f62d1b408818e21a2f' \
                         b'887c4442ae035a260d4cc2ec28ae24d6'
            node.clientAuthNr.addClient("Joe", joe_verkey)

            looper.add(node)
            node.startKeySharing()
            looper.run()
Esempio n. 2
0
def testNodesConnectWhenTheyAllStartAtOnce():
    with TemporaryDirectory() as td:
        with Looper() as looper:
            nodes = []
            for name in nodeReg:
                node = Node(name, nodeReg, basedirpath=td)
                looper.add(node)
                node.startKeySharing()
                nodes.append(node)
            looper.run(checkNodesConnected(nodes))
Esempio n. 3
0
def testNodesComingUpAtDifferentTimes():
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    with TemporaryDirectory() as td:
        print("temporary directory: {}".format(td))
        with Looper() as looper:
            nodes = []

            names = list(nodeReg.keys())
            shuffle(names)
            waits = [randint(1, 10) for _ in names]
            rwaits = [randint(1, 10) for _ in names]

            for i, name in enumerate(names):
                node = Node(name, nodeReg, basedirpath=td)
                looper.add(node)
                node.startKeySharing()
                nodes.append(node)
                looper.runFor(waits[i])
            looper.run(checkNodesConnected(nodes,
                                           overrideTimeout=10))
            print("connects")
            print("node order: {}".format(names))
            print("waits: {}".format(waits))

            for n in nodes:
                n.stop()
            for i, n in enumerate(nodes):
                n.start()
                looper.runFor(rwaits[i])
            looper.runFor(3)
            looper.run(checkNodesConnected(nodes,
                                           overrideTimeout=10))
            print("reconnects")
            print("node order: {}".format(names))
            print("rwaits: {}".format(rwaits))
Esempio n. 4
0
    def newNode(self, nodeName: str):
        opVerifiers = self.plugins['VERIFICATION'] if self.plugins else []
        if nodeName in self.nodes:
            self.print("Node {} already exists.".format(nodeName))
            return

        if nodeName == "all":
            names = set(self.nodeReg.keys()) - set(self.nodes.keys())
        elif nodeName not in self.nodeReg:
            tokens = [
                (Token.Error, "Invalid node name '{}'. ".format(nodeName))]
            self.printTokens(tokens)
            self.showValidNodes()
            return
        else:
            names = [nodeName]
        for name in names:
            node = Node(name, self.nodeReg, basedirpath=self.tmpdir,
                        opVerifiers=opVerifiers)
            self.nodes[name] = node
            self.looper.add(node)
            node.startKeySharing()
            for client in self.clients.values():
                self.bootstrapClientKey(client, node)
Esempio n. 5
0
 def create(name):
     node = Node(name, nodeReg, basedirpath=td)
     looper.add(node)
     node.startKeySharing()
     nodes.append(node)
Esempio n. 6
0
            NodeDetail(HA('127.0.0.1', 7566), "DeltaC", HA('127.0.0.1', 7567))
        }
        """
        Create a node called Alpha
        """
        alpha = Node('Alpha', nodeReg, basedirpath=tmpdir)
        """
        Add the Alpha node to the looper, so it can be serviced.
        """
        looper.add(alpha)
        """
        Start key sharing among nodes. Key sharing is a way to bootstrap a
        consensus pool when you don't want to manually construct keys
        beforehand. See the github wiki for more details on key sharing.
        """
        alpha.startKeySharing()
        """
        Do the same process for the other nodes. Ordinarily, we would never have
        more than one node on a machine, but this is for demonstration purposes.
        """
        beta = Node('Beta', nodeReg, basedirpath=tmpdir)
        looper.add(beta)
        beta.startKeySharing()

        gamma = Node('Gamma', nodeReg, basedirpath=tmpdir)
        looper.add(gamma)
        gamma.startKeySharing()

        delta = Node('Delta', nodeReg, basedirpath=tmpdir)
        looper.add(delta)
        delta.startKeySharing()
Esempio n. 7
0
        """
        Create a node called Alpha
        """
        alpha = Node('Alpha', nodeReg, basedirpath=tmpdir)

        """
        Add the Alpha node to the looper, so it can be serviced.
        """
        looper.add(alpha)

        """
        Start key sharing among nodes. Key sharing is a way to bootstrap a
        consensus pool when you don't want to manually construct keys
        beforehand. See the github wiki for more details on key sharing.
        """
        alpha.startKeySharing()

        """
        Do the same process for the other nodes. Ordinarily, we would never have
        more than one node on a machine, but this is for demonstration purposes.
        """
        beta = Node('Beta', nodeReg, basedirpath=tmpdir)
        looper.add(beta)
        beta.startKeySharing()

        gamma = Node('Gamma', nodeReg, basedirpath=tmpdir)
        looper.add(gamma)
        gamma.startKeySharing()

        delta = Node('Delta', nodeReg, basedirpath=tmpdir)
        looper.add(delta)