Пример #1
0
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:
            clientName = '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(clientName, seed)
            assert signer.verkey == b'cffbb88a142be2f62d1b408818e21a2f' \
                                    b'887c4442ae035a260d4cc2ec28ae24d6'

            client_address = ('127.0.0.1', 8000)

            client = Client(clientName,
                            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_DEPRECATED(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
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 SafeTemporaryDirectory() as tmpdir:
            clientName = '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(clientName, seed)
            assert signer.verkey == b'cffbb88a142be2f62d1b408818e21a2f' \
                                    b'887c4442ae035a260d4cc2ec28ae24d6'

            client_address = ('127.0.0.1', 8000)

            client = Client(clientName,
                            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_DEPRECATED(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))
Пример #3
0
def run_node():

    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.
        config = getConfig()
        basedirpath = config.baseDir
        cliNodeReg = {k: v[0] for k, v in config.cliNodeReg.items()}
        clientName = 'Alice'

        # 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'22222222222222222222222222222222'
        assert len(seed) == 32
        signer = SimpleSigner(clientName, seed)

        client_address = ('0.0.0.0', 9700)

        client = Client(clientName,
                        cliNodeReg,
                        ha=client_address,
                        signer=signer,
                        basedirpath=basedirpath)
        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_DEPRECATED(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))
Пример #4
0
def run_node():

    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.
        config = getConfig()
        basedirpath = config.baseDir
        cliNodeReg = {k: v[0] for k, v in config.cliNodeReg.items()}
        clientName = 'Alice'

        # 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'22222222222222222222222222222222'
        assert len(seed) == 32
        signer = SimpleSigner(clientName, seed)

        client_address = ('0.0.0.0', 9700)

        client = Client(clientName,
                        cliNodeReg,
                        ha=client_address,
                        signer=signer,
                        basedirpath=basedirpath)
        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_DEPRECATED(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))
Пример #5
0
def repeatsRequest(client: Client, count: int) -> Client:
    """
    Client sends count number of requests for each operation.
    Different requestIds will be generated for the same operation.

    :param client: the client to make faulty
    :param count: the number of requests to send for each operation.
    :return: the faulty client
    """
    def evilSubmit(self, *operations: Mapping) -> List[Request]:
        requests = []
        logger.debug(
            "EVIL: client creates {} requests for each operation".format(
                count))
        for op in operations:
            for _ in range(count):
                request = self.createRequest(op)
                self.nodestack.send(request)
                requests.append(request)
        return requests

    client.submit_DEPRECATED = types.MethodType(evilSubmit, client)
    return client