Adapt demo's doctor.py to latest changes; Use default temporary node storage in examples

pull/665/head
David Núñez 2019-01-13 19:45:15 +01:00 committed by Kieran Prasch
parent f4a849938b
commit d148d075cb
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
2 changed files with 20 additions and 24 deletions

View File

@ -23,12 +23,10 @@ POLICY_FILENAME = "policy-metadata.json"
# # Twisted Logger
globalLogPublisher.addObserver(SimpleObserver())
#
# # Temporary file storage
TEMP_ALICE_DIR = "{}/alicia-files".format(os.path.dirname(os.path.abspath(__file__)))
TEMP_URSULA_CERTIFICATE_DIR = "{}/ursula-certs".format(TEMP_ALICE_DIR)
TEMP_ALICE_DIR = "alicia-files".format(os.path.dirname(os.path.abspath(__file__)))
# We expect the url of the seednode as the first argument.
SEEDNODE_URL = sys.argv[1]
SEEDNODE_URL = 'localhost:11500'
#######################################
@ -37,9 +35,11 @@ SEEDNODE_URL = sys.argv[1]
# We get a persistent Alice.
# If we had an existing Alicia in disk, let's get it from there
passphrase = "TEST_ALICIA_INSECURE_DEVELOPMENT_PASSWORD"
try: # If we had an existing Alicia in disk, let's get it from there
alice_config_file = os.path.join(TEMP_ALICE_DIR, "config_root", "alice.config")
try:
alice_config_file = os.path.join(TEMP_ALICE_DIR, "alice.config")
new_alice_config = AliceConfiguration.from_configuration_file(
filepath=alice_config_file,
network_middleware=RestMiddleware(),
@ -47,25 +47,29 @@ try: # If we had an existing Alicia in disk, let's get it from there
save_metadata=False,
)
alicia = new_alice_config(passphrase=passphrase)
except: # If anything fails, let's create Alicia from scratch
except:
# If anything fails, let's create Alicia from scratch
# Remove previous demo files and create new ones
shutil.rmtree(TEMP_ALICE_DIR, ignore_errors=True)
os.mkdir(TEMP_ALICE_DIR)
os.mkdir(TEMP_URSULA_CERTIFICATE_DIR)
ursula = Ursula.from_seed_and_stake_info(seed_uri=SEEDNODE_URL,
federated_only=True,
minimum_stake=0)
alice_config = AliceConfiguration(
config_root=os.path.join(TEMP_ALICE_DIR, "config_root"),
config_root=os.path.join(TEMP_ALICE_DIR),
is_me=True,
known_nodes={ursula},
start_learning_now=False,
federated_only=True,
learn_on_same_thread=True,
)
alice_config.initialize(password=passphrase)
alice_config.keyring.unlock(password=passphrase)
alicia = alice_config.produce()

View File

@ -9,9 +9,9 @@ from timeit import default_timer as timer
from nucypher.characters.lawful import Bob, Ursula
from nucypher.crypto.kits import UmbralMessageKit
from nucypher.crypto.powers import EncryptingPower, SigningPower
from nucypher.crypto.powers import DecryptingPower, SigningPower
from nucypher.data_sources import DataSource
from nucypher.keystore.keypairs import EncryptingKeypair, SigningKeypair
from nucypher.keystore.keypairs import DecryptingKeypair, SigningKeypair
from nucypher.network.middleware import RestMiddleware
from umbral.keys import UmbralPublicKey
@ -21,22 +21,15 @@ from umbral.keys import UmbralPublicKey
# Boring setup stuff #
######################
SEEDNODE_URL = sys.argv[1]
SEEDNODE_URL = 'localhost:11501'
# TODO: path joins?
TEMP_DOCTOR_DIR = "{}/doctor-files".format(os.path.dirname(os.path.abspath(__file__)))
TEMP_URSULA_CERTIFICATE_DIR = "{}/ursula-certs".format(TEMP_DOCTOR_DIR)
TEMP_DOCTOR_CERTIFICATE_DIR = "{}/doctor-certs".format(TEMP_DOCTOR_DIR)
# Remove previous demo files and create new ones
shutil.rmtree(TEMP_DOCTOR_DIR, ignore_errors=True)
os.mkdir(TEMP_DOCTOR_DIR)
os.mkdir(TEMP_URSULA_CERTIFICATE_DIR)
os.mkdir(TEMP_DOCTOR_CERTIFICATE_DIR)
ursula = Ursula.from_seed_and_stake_info(host=SEEDNODE_URL,
certificates_directory=TEMP_URSULA_CERTIFICATE_DIR,
ursula = Ursula.from_seed_and_stake_info(seed_uri=SEEDNODE_URL,
federated_only=True,
minimum_stake=0)
@ -44,9 +37,9 @@ ursula = Ursula.from_seed_and_stake_info(host=SEEDNODE_URL,
from doctor_keys import get_doctor_privkeys
doctor_keys = get_doctor_privkeys()
bob_enc_keypair = EncryptingKeypair(private_key=doctor_keys["enc"])
bob_enc_keypair = DecryptingKeypair(private_key=doctor_keys["enc"])
bob_sig_keypair = SigningKeypair(private_key=doctor_keys["sig"])
enc_power = EncryptingPower(keypair=bob_enc_keypair)
enc_power = DecryptingPower(keypair=bob_enc_keypair)
sig_power = SigningPower(keypair=bob_sig_keypair)
power_ups = [enc_power, sig_power]
@ -57,7 +50,6 @@ doctor = Bob(
federated_only=True,
crypto_power_ups=power_ups,
start_learning_now=True,
known_certificates_dir=TEMP_DOCTOR_CERTIFICATE_DIR,
abort_on_learning_error=True,
known_nodes=[ursula],
save_metadata=False,