Пример #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 SafeTemporaryDirectory() as tmpdir:
            node = Node(nodeName, nodeReg, basedirpath=tmpdir)

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

            looper.add(node)
            node.startKeySharing()
            looper.run()
Пример #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 tdirAndLooper(nodeReg):
    with SafeTemporaryDirectory() as td:
        logger.debug("temporary directory: {}".format(td))
        with Looper() as looper:
            yield td, looper
Пример #4
0
from plenum.common.keygen_utils import initLocalKeys
from plenum.common.temp_file_util import SafeTemporaryDirectory
from plenum.common.types import NodeDetail
from stp_core.types import HA
from plenum.common.util import randomString
from plenum.server.node import Node
from plenum.test.malicious_behaviors_node import faultyReply, makeNodeFaulty

console = getConsole()
console.reinit(verbosity=console.Wordage.terse)
"""
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 SafeTemporaryDirectory() as tmpdir:
    """
    Looper runs an asynchronous message loop that services the nodes and client.
    It's also a context manager, so it cleans up after itself.
    """
    with Looper(debug=False) as looper:
        """
        The nodes need to have the their keys initialized
        """
        initLocalKeys('Alpha', tmpdir, randomString(32), override=True)
        initLocalKeys('AlphaC', tmpdir, randomString(32), override=True)
        initLocalKeys('Beta', tmpdir, randomString(32), override=True)
        initLocalKeys('BetaC', tmpdir, randomString(32), override=True)
        initLocalKeys('Gamma', tmpdir, randomString(32), override=True)
        initLocalKeys('GammaC', tmpdir, randomString(32), override=True)
        initLocalKeys('Delta', tmpdir, randomString(32), override=True)