Allow ephemeral node and node storage default in Finnegans Wake demo.

pull/677/head
Kieran Prasch 2019-01-21 12:58:06 -08:00
parent 1663eb78d6
commit 06d689f45b
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
1 changed files with 16 additions and 31 deletions

View File

@ -1,15 +1,15 @@
import datetime
import os import os
import shutil
import datetime
import maya import maya
import shutil
from twisted.logger import globalLogPublisher from twisted.logger import globalLogPublisher
from umbral.keys import UmbralPublicKey
from nucypher.characters.lawful import Alice, Bob, Ursula from nucypher.characters.lawful import Alice, Bob, Ursula
from nucypher.data_sources import DataSource as Enrico from nucypher.data_sources import DataSource as Enrico
from nucypher.network.middleware import RestMiddleware from nucypher.network.middleware import RestMiddleware
from nucypher.utilities.logging import simpleObserver from nucypher.utilities.logging import SimpleObserver
from umbral.keys import UmbralPublicKey
###################### ######################
# Boring setup stuff # # Boring setup stuff #
@ -19,18 +19,7 @@ from umbral.keys import UmbralPublicKey
BOOK_PATH = os.path.join('.', 'finnegans-wake.txt') BOOK_PATH = os.path.join('.', 'finnegans-wake.txt')
# Twisted Logger # Twisted Logger
globalLogPublisher.addObserver(simpleObserver) globalLogPublisher.addObserver(SimpleObserver())
# Temporary file storage
TEMP_FILES_DIR = "{}/examples-runtime-cruft".format(os.path.dirname(os.path.abspath(__file__)))
TEMP_DEMO_DIR = "{}/finnegans-wake-demo".format(TEMP_FILES_DIR)
TEMP_CERTIFICATE_DIR = "{}/certs".format(TEMP_DEMO_DIR)
# Remove previous demo files and create new ones
shutil.rmtree(TEMP_FILES_DIR, ignore_errors=True)
os.mkdir(TEMP_FILES_DIR)
os.mkdir(TEMP_DEMO_DIR)
os.mkdir(TEMP_CERTIFICATE_DIR)
####################################### #######################################
@ -38,13 +27,12 @@ os.mkdir(TEMP_CERTIFICATE_DIR)
# (will fail with bad connection) ##### # (will fail with bad connection) #####
####################################### #######################################
TESTNET_LOAD_BALANCER = "eu-federated-balancer-40be4480ec380cd7.elb.eu-central-1.amazonaws.com" SEEDNODE_URI = "https://localhost:11501"
############################################## ##############################################
# Ursula, the Untrusted Re-Encryption Proxy # # Ursula, the Untrusted Re-Encryption Proxy #
############################################## ##############################################
ursula = Ursula.from_seed_and_stake_info(host=TESTNET_LOAD_BALANCER, ursula = Ursula.from_seed_and_stake_info(seed_uri=SEEDNODE_URI,
certificates_directory=TEMP_CERTIFICATE_DIR,
federated_only=True, federated_only=True,
minimum_stake=0) minimum_stake=0)
@ -60,8 +48,7 @@ label = b"secret/files/and/stuff"
ALICE = Alice(network_middleware=RestMiddleware(), ALICE = Alice(network_middleware=RestMiddleware(),
known_nodes=[ursula], known_nodes=[ursula],
learn_on_same_thread=True, learn_on_same_thread=True,
federated_only=True, federated_only=True)
known_certificates_dir=TEMP_CERTIFICATE_DIR)
# Alice can get the public key even before creating the policy. # Alice can get the public key even before creating the policy.
# From this moment on, any Data Source that knows the public key # From this moment on, any Data Source that knows the public key
@ -69,13 +56,11 @@ ALICE = Alice(network_middleware=RestMiddleware(),
# any Bob that Alice grants access. # any Bob that Alice grants access.
policy_pubkey = ALICE.get_policy_pubkey_from_label(label) policy_pubkey = ALICE.get_policy_pubkey_from_label(label)
BOB = Bob( BOB = Bob(known_nodes=[ursula],
known_nodes=[ursula],
network_middleware=RestMiddleware(), network_middleware=RestMiddleware(),
federated_only=True, federated_only=True,
start_learning_now=True, start_learning_now=True,
learn_on_same_thread=True, learn_on_same_thread=True)
known_certificates_dir=TEMP_CERTIFICATE_DIR)
ALICE.start_learning_loop(now=True) ALICE.start_learning_loop(now=True)
@ -127,9 +112,9 @@ for counter, plaintext in enumerate(finnegans_wake):
# single passage from James Joyce's Finnegan's Wake. # single passage from James Joyce's Finnegan's Wake.
# The matter of whether encryption makes the passage more or less readable # The matter of whether encryption makes the passage more or less readable
# is left to the reader to determine. # is left to the reader to determine.
single_passage_ciphertext, _signature = enciro.encrypt_message(plaintext) single_passage_ciphertext, _signature = enrico.encrypt_message(plaintext)
data_source_public_key = bytes(enciro.stamp) data_source_public_key = bytes(enrico.stamp)
del enciro del enrico
############### ###############
# Back to Bob # # Back to Bob #