コード例 #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
    def inner(client: Client) -> Client:
        if nodeName:
            skipIds = [client.nodestack.getRemote(nn).uid for nn in nodeName]
            ovrdRids = [rid for rid in client.nodestack.remotes.keys()
                        if rid not in skipIds]
        else:
            ovrdRids = client.nodestack.remotes.keys()[skipCount:]

        def evilSend(self, msg: Any, *rids: int) -> None:
            logger.debug("EVIL: sending to less nodes {}, ignoring passed "
                         "rids {} and sending to {} instead.".
                         format(msg, rids, ovrdRids))
            for r in ovrdRids:
                self._enqueue(msg, r)

        client.send = types.MethodType(evilSend, client)
        return client
コード例 #3
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.send(request)
                requests.append(request)
        return requests

    client.submit = types.MethodType(evilSubmit, client)
    return client
コード例 #4
0
ファイル: helper.py プロジェクト: SmithSamuelM/plenum
def sendRandomRequest(client: Client):
    return client.submit(randomOperation())[0]
コード例 #5
0
ファイル: tutorial.py プロジェクト: SmithSamuelM/plenum
            'BetaC': ('127.0.0.1', 7563),
            'GammaC': ('127.0.0.1', 7565),
            'DeltaC': ('127.0.0.1', 7567)}

        """
        A bi-directional connection is made from the client. This is the ip
        address and port for the client's interfact to the nodes.
        """
        client_addr = ("127.0.0.1", 8000)

        """
        Create a client.
        """
        clientId = "my_client_id"
        client = Client(clientId=clientId,
                        ha=client_addr,
                        nodeReg=cliNodeReg,
                        basedirpath=tmpdir)
        looper.add(client)

        """
        A client signs its requests. By default, a simple yet secure signing
        mechanism is created for a client.
        """
        idAndKey = client.signer.identifier, client.signer.verkey

        """
        A client's signature verification key must be bootstrapped out of band
        into the consensus pool. For demonstration, we'll add it directly to
        each node.
        """
        for node in alpha, beta, gamma, delta: