コード例 #1
0
ファイル: simple_client.py プロジェクト: SmithSamuelM/plenum
def run_node():

    cliNodeReg = OrderedDict([
        ('AlphaC', ('127.0.0.1', 8002)),
        ('BetaC', ('127.0.0.1', 8004)),
        ('GammaC', ('127.0.0.1', 8006)),
        ('DeltaC', ('127.0.0.1', 8008))])

    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 clean.
        with TemporaryDirectory() as tmpdir:
            clientId = 'Joe'

            # this seed is used by the signer to deterministically generate
            # a signature verification key that is shared out of band with the
            # consensus pool
            seed = b'a 32 byte super secret seed.....'
            assert len(seed) == 32
            signer = SimpleSigner(clientId, seed)
            assert signer.verkey == b'cffbb88a142be2f62d1b408818e21a2f' \
                                    b'887c4442ae035a260d4cc2ec28ae24d6'

            client_address = ('127.0.0.1', 8000)

            client = Client(clientId,
                            cliNodeReg,
                            ha=client_address,
                            signer=signer,
                            basedirpath=tmpdir)
            looper.add(client)

            # give the client time to connect
            looper.runFor(3)

            # a simple message
            msg = {'life_answer': 42}

            # submit the request to the pool
            request, = client.submit(msg)

            # allow time for the request to be executed
            looper.runFor(3)

            reply, status = client.getReply(request.reqId)
            print('')
            print('Reply: {}\n'.format(reply))
            print('Status: {}\n'.format(status))
コード例 #2
0
ファイル: tutorial.py プロジェクト: SmithSamuelM/plenum
        msg = {'life_answer': 42}

        """
        And submit it to the pool.
        """
        request, = client.submit(msg)

        """
        Allow some time for the request to be executed.
        """
        looper.runFor(3)

        """
        Let's get the reply.
        """
        reply, status = client.getReply(request.reqId)

        """
        Check the reply and see if consensus has been reached.
        """
        print("Reply: {}\n".format(reply))
        print("Status: {}\n".format(status))

        """
        See the reply details of a request.
        """
        client.showReplyDetails(request.reqId)

        """
        As we are using 4 nodes, we have an f-value of 1, which means that
        consensus can be still achieved with one faulty node. In this example,