mirror of https://github.com/nucypher/nucypher.git
Introducing named DBs per Ursula.
parent
cdc39c67eb
commit
7e567c24f6
|
@ -7,7 +7,7 @@
|
|||
|
||||
from nkms.characters import Ursula
|
||||
|
||||
_URSULA = Ursula(dht_port=3501, dht_interface="localhost")
|
||||
_URSULA = Ursula(dht_port=3501, dht_interface="localhost", db_name="non-mining-proxy-node")
|
||||
_URSULA.listen()
|
||||
|
||||
from hendrix.deploy.base import HendrixDeploy
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
import asyncio
|
||||
import logging
|
||||
|
||||
from kademlia.network import Server
|
||||
from nkms.network.server import NuCypherSeedOnlyDHTServer
|
||||
|
||||
key = "llamas"
|
||||
value = "tons_of_things_keyed_llamas"
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.set_debug(True)
|
||||
|
||||
server = NuCypherSeedOnlyDHTServer()
|
||||
server.listen(8469)
|
||||
loop.run_until_complete(server.bootstrap([("127.0.0.1", 8468)]))
|
||||
set = server.set(key, value)
|
||||
loop.run_until_complete(set)
|
||||
server.stop()
|
||||
loop.close()
|
|
@ -492,13 +492,13 @@ class Ursula(Character, ProxyRESTServer):
|
|||
_default_crypto_powerups = [SigningPower, EncryptingPower]
|
||||
|
||||
def __init__(self, dht_port=None, dht_interface=None, dht_ttl=0,
|
||||
rest_address=None, rest_port=None,
|
||||
rest_address=None, rest_port=None, db_name=None,
|
||||
*args, **kwargs):
|
||||
self.dht_port = dht_port
|
||||
self.dht_interface = dht_interface
|
||||
self.dht_ttl = 0
|
||||
self._work_orders = []
|
||||
ProxyRESTServer.__init__(self, rest_address, rest_port)
|
||||
ProxyRESTServer.__init__(self, rest_address, rest_port, db_name)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
|
@ -540,7 +540,7 @@ class Ursula(Character, ProxyRESTServer):
|
|||
id = digest(secure_random(32))
|
||||
|
||||
super().attach_server(ksize, alpha, id, storage)
|
||||
self.attach_rest_server()
|
||||
self.attach_rest_server(db_name=self.db_name)
|
||||
|
||||
def listen(self):
|
||||
return self.server.listen(self.dht_port, self.dht_interface)
|
||||
|
|
|
@ -99,12 +99,13 @@ class NuCypherSeedOnlyDHTServer(NuCypherDHTServer):
|
|||
|
||||
class ProxyRESTServer(object):
|
||||
|
||||
def __init__(self, rest_address, rest_port):
|
||||
def __init__(self, rest_address, rest_port, db_name):
|
||||
self.rest_address = rest_address
|
||||
self.rest_port = rest_port
|
||||
self.db_name = db_name
|
||||
self._rest_app = None
|
||||
|
||||
def attach_rest_server(self):
|
||||
def attach_rest_server(self, db_name):
|
||||
|
||||
routes = [
|
||||
Route('/kFrag/{hrac_as_hex}',
|
||||
|
@ -127,14 +128,17 @@ class ProxyRESTServer(object):
|
|||
]
|
||||
|
||||
self._rest_app = App(routes=routes)
|
||||
self.start_datastore()
|
||||
self.start_datastore(db_name)
|
||||
|
||||
def start_datastore(self, db_name):
|
||||
if not db_name:
|
||||
raise TypeError("In order to start a datastore, you need to supply a db_name.")
|
||||
|
||||
def start_datastore(self):
|
||||
from nkms.keystore import keystore
|
||||
from nkms.keystore.db import Base
|
||||
from sqlalchemy.engine import create_engine
|
||||
|
||||
engine = create_engine('sqlite:///test.db', echo=True)
|
||||
engine = create_engine('sqlite:///{}'.format(db_name))
|
||||
Base.metadata.create_all(engine)
|
||||
self.datastore = keystore.KeyStore(engine)
|
||||
self.db_engine = engine
|
||||
|
|
|
@ -70,6 +70,10 @@ def bob(alice, ursulas):
|
|||
def ursulas():
|
||||
URSULAS = make_ursulas(NUMBER_OF_URSULAS_IN_NETWORK, URSULA_PORT)
|
||||
yield URSULAS
|
||||
# Remove the DBs that have been sprayed hither and yon.
|
||||
for _u in range(NUMBER_OF_URSULAS_IN_NETWORK):
|
||||
port = URSULA_PORT + _u
|
||||
os.remove("test-{}".format(port))
|
||||
blockchain_client._ursulas_on_blockchain.clear()
|
||||
|
||||
|
||||
|
|
|
@ -30,15 +30,14 @@ def make_ursulas(how_many_ursulas: int, ursula_starting_port: int) -> list:
|
|||
|
||||
URSULAS = []
|
||||
for _u in range(how_many_ursulas):
|
||||
_URSULA = Ursula(dht_port=ursula_starting_port + _u, dht_interface="127.0.0.1")
|
||||
_URSULA.attach_server()
|
||||
port = ursula_starting_port + _u
|
||||
_URSULA = Ursula(dht_port=port, dht_interface="127.0.0.1", db_name="test-{}".format(port))
|
||||
|
||||
class MockDatastoreThreadPool(object):
|
||||
def callInThread(self, f, *args, **kwargs):
|
||||
return f(*args, **kwargs)
|
||||
|
||||
_URSULA.datastore_threadpool = MockDatastoreThreadPool()
|
||||
_URSULA.start_datastore()
|
||||
_URSULA.listen()
|
||||
|
||||
URSULAS.append(_URSULA)
|
||||
|
|
Loading…
Reference in New Issue