Ejemplo n.º 1
0
def make_ursulas(how_many_ursulas: int, ursula_starting_port: int) -> list:
    """
    :param how_many_ursulas: How many Ursulas to create.
    :param ursula_starting_port: The port of the first created Ursula; subsequent Ursulas will increment the port number by 1.
    :return: A list of created Ursulas
    """
    event_loop = asyncio.get_event_loop()

    URSULAS = []
    for _u in range(how_many_ursulas):
        port = ursula_starting_port + _u
        _URSULA = Ursula(dht_port=port,
                         ip_address="127.0.0.1",
                         db_name="test-{}".format(port),
                         rest_port=port +
                         100)  # TODO: Make ports unstupid and more clear.

        class MockDatastoreThreadPool(object):
            def callInThread(self, f, *args, **kwargs):
                return f(*args, **kwargs)

        _URSULA.datastore_threadpool = MockDatastoreThreadPool()
        _URSULA.dht_listen()

        URSULAS.append(_URSULA)

    for _counter, ursula in enumerate(URSULAS):
        event_loop.run_until_complete(
            ursula.server.bootstrap([("127.0.0.1", ursula_starting_port + _c)
                                     for _c in range(how_many_ursulas)]))
        ursula.publish_dht_information()

    return URSULAS
Ejemplo n.º 2
0
from hendrix.deploy.tls import HendrixDeployTLS
from hendrix.facilities.services import ExistingKeyTLSContextFactory
from nkms.characters import Ursula
from OpenSSL.crypto import X509
from OpenSSL.SSL import TLSv1_2_METHOD

from nkms.crypto.api import generate_self_signed_certificate

DB_NAME = "non-mining-proxy-node"

_URSULA = Ursula(dht_port=3501,
                 rest_port=3601,
                 ip_address="localhost",
                 db_name=DB_NAME)
_URSULA.dht_listen()

CURVE = ec.SECP256R1
cert, private_key = generate_self_signed_certificate(
    _URSULA.stamp.fingerprint().decode(), CURVE)

deployer = HendrixDeployTLS("start", {
    "wsgi": _URSULA.rest_app,
    "https_port": _URSULA.rest_port
},
                            key=private_key,
                            cert=X509.from_cryptography(cert),
                            context_factory=ExistingKeyTLSContextFactory,
                            context_factory_kwargs={
                                "curve_name": "prime256v1",
                                "sslmethod": TLSv1_2_METHOD