mirror of https://github.com/nucypher/nucypher.git
More hacking and slashing on the DHT removal and config sanity.
parent
a8dba1b738
commit
4413dc952c
21
cli/main.py
21
cli/main.py
|
@ -12,11 +12,10 @@ from nucypher.blockchain.eth.actors import Miner
|
|||
from nucypher.blockchain.eth.chains import Blockchain, TesterBlockchain
|
||||
from nucypher.blockchain.eth.deployers import NucypherTokenDeployer, MinerEscrowDeployer, PolicyManagerDeployer
|
||||
from nucypher.characters import Ursula
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_ROOT, DEFAULT_SIMULATION_PORT, \
|
||||
DEFAULT_SIMULATION_REGISTRY_FILEPATH, DEFAULT_INI_FILEPATH, DEFAULT_REST_PORT, DEFAULT_DB_NAME, \
|
||||
BASE_DIR
|
||||
from nucypher.config.characters import UrsulaConfiguration
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_FILE_LOCATION, DEFAULT_CONFIG_ROOT, DEFAULT_REST_PORT
|
||||
from nucypher.config.node import DEFAULT_CONFIG_ROOT
|
||||
from nucypher.config.parsers import parse_nucypher_ini_config, parse_running_modes
|
||||
from nucypher.network.nodes import collect_stored_nodes
|
||||
from nucypher.utilities.sandbox import UrsulaProcessProtocol
|
||||
|
||||
__version__ = '0.1.0-alpha.0'
|
||||
|
@ -41,7 +40,7 @@ from twisted.internet import reactor
|
|||
|
||||
from nucypher.blockchain.eth.agents import MinerAgent, PolicyAgent, NucypherTokenAgent
|
||||
from nucypher.utilities.blockchain import token_airdrop
|
||||
from nucypher.config.utils import validate_nucypher_ini_config, initialize_configuration
|
||||
from nucypher.config.utils import validate_nucypher_ini_config
|
||||
|
||||
root = logging.getLogger()
|
||||
root.setLevel(logging.DEBUG)
|
||||
|
@ -125,7 +124,7 @@ uses_config = click.make_pass_decorator(NucypherClickConfig, ensure=True)
|
|||
@click.group()
|
||||
@click.option('--version', help="Prints the installed version.", is_flag=True)
|
||||
@click.option('--verbose', help="Enable verbose mode.", is_flag=True)
|
||||
@click.option('--config-file', help="Specify a custom config filepath.", type=click.Path(), default=DEFAULT_INI_FILEPATH)
|
||||
@click.option('--config-file', help="Specify a custom config filepath.", type=click.Path(), default="cool winnebago")
|
||||
@uses_config
|
||||
def cli(config, verbose, version, config_file):
|
||||
"""Configure and manage a nucypher nodes"""
|
||||
|
@ -147,7 +146,7 @@ def cli(config, verbose, version, config_file):
|
|||
@cli.command()
|
||||
@click.argument('action')
|
||||
@click.option('--dev', is_flag=True)
|
||||
@click.option('--config-file', help="Specify a custom .ini configuration filepath", default=DEFAULT_INI_FILEPATH)
|
||||
@click.option('--config-file', help="Specify a custom .ini configuration filepath", default=DEFAULT_CONFIG_FILE_LOCATION)
|
||||
@click.option('--config-root', help="Specify a custom installation location", default=DEFAULT_CONFIG_ROOT)
|
||||
def config(action, config_file, config_root, dev):
|
||||
"""Manage the nucypher .ini configuration file"""
|
||||
|
@ -443,7 +442,7 @@ def simulate(config, action, nodes, federated_only):
|
|||
policy_manager_deployer = PolicyManagerDeployer(miner_agent=miner_agent, deployer_address=etherbase)
|
||||
policy_manager_deployer.arm()
|
||||
policy_manager_deployer.deploy()
|
||||
policy_agent = policy_manager_deployer.make_agent()
|
||||
policy_agent = policy_manager_deployer.make_agent()
|
||||
click.echo("Deployed {}:{}".format(policy_agent.contract_name, policy_agent.contract_address))
|
||||
|
||||
airdrop_amount = 1000000 * int(constants.M)
|
||||
|
@ -676,12 +675,12 @@ def status(config, provider, contracts, network):
|
|||
@click.option('--federated-only', is_flag=True, default=False)
|
||||
@click.option('--dev', is_flag=True, default=False)
|
||||
@click.option('--rest-host', type=str, default='localhost')
|
||||
@click.option('--rest-port', type=int, default=DEFAULT_REST_PORT)
|
||||
@click.option('--db-name', type=str, default=DEFAULT_DB_NAME)
|
||||
@click.option('--rest-port', type=int, default=UrsulaConfiguration.DEFAULT_REST_PORT)
|
||||
@click.option('--db-name', type=str, default=UrsulaConfiguration.DEFAULT_DB_NAME)
|
||||
@click.option('--checksum-address', type=str)
|
||||
@click.option('--teacher-uri', type=str)
|
||||
@click.option('--node-dir', type=click.Path(), default=DEFAULT_CONFIG_ROOT)
|
||||
@click.option('--config-file', type=click.Path(), default=DEFAULT_INI_FILEPATH)
|
||||
@click.option('--config-file', type=click.Path(), default=DEFAULT_CONFIG_FILE_LOCATION)
|
||||
def run_ursula(rest_port,
|
||||
rest_host,
|
||||
db_name,
|
||||
|
|
|
@ -12,7 +12,7 @@ from eth_tester import EthereumTester
|
|||
from eth_tester import PyEVMBackend
|
||||
from nucypher.blockchain.eth.registry import EthereumContractRegistry
|
||||
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
|
||||
from nucypher.config.config import NodeConfiguration
|
||||
from nucypher.config.node import NodeConfiguration
|
||||
from nucypher.config.parsers import parse_blockchain_config
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ import tempfile
|
|||
|
||||
from constant_sorrow import constants
|
||||
|
||||
from nucypher.config.config import DEFAULT_CONFIG_ROOT, NodeConfiguration
|
||||
from nucypher.config.parsers import parse_blockchain_config
|
||||
# from nucypher.config.config import DEFAULT_CONFIG_ROOT, NodeConfiguration
|
||||
# from nucypher.config.parsers import parse_blockchain_config
|
||||
|
||||
|
||||
class EthereumContractRegistry:
|
||||
|
@ -17,7 +17,7 @@ class EthereumContractRegistry:
|
|||
WARNING: Unless you are developing NuCypher, you most likely won't ever need
|
||||
to use this.
|
||||
"""
|
||||
__default_registry_path = os.path.join(DEFAULT_CONFIG_ROOT, 'registry.json')
|
||||
# __default_registry_path = os.path.join(DEFAULT_CONFIG_ROOT, 'registry.json')
|
||||
|
||||
class RegistryError(Exception):
|
||||
pass
|
||||
|
@ -32,7 +32,7 @@ class EthereumContractRegistry:
|
|||
self.__registry_filepath = registry_filepath or self.__default_registry_path
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: NodeConfiguration) -> 'EthereumContractRegistry':
|
||||
def from_config(cls, config) -> 'EthereumContractRegistry':
|
||||
if config.temp_registry is True: # In memory only
|
||||
registry = TemporaryEthereumContractRegistry()
|
||||
else:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import os
|
||||
import random
|
||||
from collections import OrderedDict, defaultdict
|
||||
from collections import deque
|
||||
|
@ -28,8 +27,8 @@ from twisted.internet import task, threads
|
|||
from nucypher.blockchain.eth.actors import PolicyAuthor, Miner, only_me
|
||||
from nucypher.blockchain.eth.agents import MinerAgent
|
||||
from nucypher.blockchain.eth.constants import datetime_to_period
|
||||
from nucypher.config.characters import UrsulaConfiguration
|
||||
|
||||
from nucypher.config.config import NodeConfiguration, UrsulaConfiguration
|
||||
from nucypher.config.parsers import parse_alice_config, parse_character_config
|
||||
from nucypher.crypto.api import keccak_digest, encrypt_and_sign
|
||||
from nucypher.crypto.constants import PUBLIC_ADDRESS_LENGTH, PUBLIC_KEY_LENGTH
|
||||
|
@ -795,7 +794,7 @@ class Bob(Character):
|
|||
self._saved_work_orders = WorkOrderHistory()
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, filepath=DEFAULT_INI_FILEPATH, overrides: dict = None) -> 'Bob':
|
||||
def from_config(cls, filepath, overrides: dict = None) -> 'Bob':
|
||||
payload = parse_character_config(filepath=filepath)
|
||||
if overrides is not None:
|
||||
payload.update(overrides)
|
||||
|
@ -1066,6 +1065,8 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
|
||||
VerifiableNode.__init__(self, interface_signature=interface_signature)
|
||||
|
||||
self._work_orders = []
|
||||
|
||||
Character.__init__(self, is_me=is_me,
|
||||
checksum_address=checksum_address,
|
||||
always_be_learning=always_be_learning,
|
||||
|
@ -1185,8 +1186,8 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
#
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: UrsulaConfiguration) -> 'Ursula': # TODO
|
||||
instance = cls()
|
||||
def from_config(cls, config) -> 'Ursula': # TODO
|
||||
instance = cls() # Holy shit, that's a cool winnebago. My uncle used to have one just like it.
|
||||
return instance
|
||||
|
||||
@classmethod
|
||||
|
@ -1291,7 +1292,7 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
# Utilities
|
||||
#
|
||||
|
||||
def write_node_metadata(self, node_metadata_dir: str = DEFAULT_KNOWN_NODE_DIR) -> str:
|
||||
def write_node_metadata(self, node_metadata_dir: str) -> str:
|
||||
|
||||
try:
|
||||
filename = "node-metadata-{}".format(self.rest_information()[0].port)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
DEFAULT_CONFIG_FILE_LOCATION = "cool winnebago"
|
||||
DEFAULT_CONFIG_ROOT = "my uncle has one just like it."
|
||||
DEFAULT_REST_PORT = 9151
|
|
@ -4,7 +4,7 @@ from glob import glob
|
|||
from os.path import abspath
|
||||
from typing import Union, Tuple
|
||||
|
||||
from nucypher.config.config import NodeConfiguration
|
||||
from nucypher.config.node import NodeConfiguration
|
||||
|
||||
|
||||
def collect_stored_nodes(known_metadata_dir=None) -> set:
|
||||
|
|
|
@ -16,8 +16,6 @@ from cryptography.hazmat.primitives import hashes
|
|||
from cryptography.hazmat.primitives.asymmetric import ec
|
||||
from cryptography.x509.oid import NameOID
|
||||
|
||||
from nucypher.config.constants import DEFAULT_TLS_CERTIFICATE_FILEPATH, DEFAULT_KNOWN_CERTIFICATES_DIR
|
||||
from nucypher.config.utils import NucypherConfigurationError
|
||||
from umbral import pre
|
||||
from umbral.keys import UmbralPrivateKey, UmbralPublicKey
|
||||
|
||||
|
@ -117,10 +115,11 @@ def ecdsa_verify(
|
|||
|
||||
|
||||
def _save_tls_certificate(certificate: Certificate,
|
||||
certificate_dir: str,
|
||||
common_name: str = None,
|
||||
is_me: bool = False,
|
||||
force: bool = True,
|
||||
certificate_dir: str = DEFAULT_KNOWN_CERTIFICATES_DIR) -> str:
|
||||
) -> str:
|
||||
|
||||
if is_me is False and not common_name:
|
||||
raise NucypherConfigurationError('A common name must be passed to save another node\'s certificate.')
|
||||
|
@ -174,7 +173,7 @@ def generate_self_signed_certificate(common_name,
|
|||
cert = cert.sign(private_key, hashes.SHA512(), default_backend())
|
||||
|
||||
if save_to_disk is True:
|
||||
tls_certificate_filepath = _save_tls_certificate(cert, common_name)
|
||||
tls_certificate_filepath = _save_tls_certificate(cert, common_name=common_name)
|
||||
else:
|
||||
tls_certificate_filepath = constants.CERTIFICATE_NOT_SAVED
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ class HostingKeypair(Keypair):
|
|||
certificate=None,
|
||||
curve=None,
|
||||
generate_keys_if_needed=True,
|
||||
save_cert_to_disk=False,
|
||||
):
|
||||
|
||||
self.curve = curve or self._DEFAULT_CURVE
|
||||
|
@ -143,10 +144,11 @@ class HostingKeypair(Keypair):
|
|||
super().__init__(private_key=private_key)
|
||||
|
||||
elif certificate:
|
||||
self.certificate_filepath = _save_tls_certificate(certificate,
|
||||
common_name=common_name,
|
||||
is_me=False,
|
||||
force=False)
|
||||
if save_cert_to_disk:
|
||||
self.certificate_filepath = _save_tls_certificate(certificate,
|
||||
common_name=common_name,
|
||||
is_me=False,
|
||||
force=False)
|
||||
self.certificate = certificate
|
||||
super().__init__(public_key=certificate.public_key())
|
||||
|
||||
|
@ -158,7 +160,8 @@ class HostingKeypair(Keypair):
|
|||
self.certificate, private_key, self.tls_certificate_filepath = generate_self_signed_certificate(common_name=common_name,
|
||||
private_key=private_key,
|
||||
curve=self.curve,
|
||||
host=host)
|
||||
host=host,
|
||||
save_to_disk=save_cert_to_disk)
|
||||
super().__init__(private_key=private_key)
|
||||
else:
|
||||
raise TypeError("You didn't provide a cert, but also told us not to generate keys. Not sure what to do.")
|
||||
|
|
|
@ -2,7 +2,6 @@ import requests
|
|||
|
||||
from bytestring_splitter import BytestringSplitter, VariableLengthBytestring
|
||||
|
||||
from nucypher.config.constants import DEFAULT_TLS_CERTIFICATE_FILEPATH
|
||||
from nucypher.crypto.api import load_tls_certificate
|
||||
from umbral.fragments import CapsuleFrag
|
||||
|
||||
|
|
|
@ -324,8 +324,8 @@ class ProxyRESTRoutes:
|
|||
|
||||
if do_store:
|
||||
self.log.info("{} storing TreasureMap {}".format(self, treasure_map_id))
|
||||
self.dht_server.set_now(binascii.unhexlify(treasure_map_id),
|
||||
constants.BYTESTRING_IS_TREASURE_MAP + bytes(treasure_map))
|
||||
# self.dht_server.set_now(binascii.unhexlify(treasure_map_id), # TODO: Now that the DHT is retired, let's do this another way.
|
||||
# constants.BYTESTRING_IS_TREASURE_MAP + bytes(treasure_map))
|
||||
|
||||
# TODO 341 - what if we already have this TreasureMap?
|
||||
self._treasure_map_tracker[digest(treasure_map_id)] = treasure_map
|
||||
|
|
|
@ -86,8 +86,6 @@ def make_ursulas(ether_addresses: list,
|
|||
ether_address = None
|
||||
ursula = Ursula(is_me=True,
|
||||
checksum_address=ether_address,
|
||||
dht_host="localhost",
|
||||
dht_port=port,
|
||||
db_name="test-{}".format(port),
|
||||
rest_host="localhost",
|
||||
rest_port=port + 100,
|
||||
|
@ -101,7 +99,6 @@ def make_ursulas(ether_addresses: list,
|
|||
return f(*args, **kwargs)
|
||||
|
||||
ursula.datastore_threadpool = MockDatastoreThreadPool()
|
||||
ursula.dht_listen()
|
||||
|
||||
if miners is True:
|
||||
# TODO: 309
|
||||
|
@ -129,11 +126,6 @@ def make_ursulas(ether_addresses: list,
|
|||
for ursula_to_learn_about in ursulas:
|
||||
ursula_to_teach.remember_node(ursula_to_learn_about)
|
||||
|
||||
event_loop.run_until_complete(
|
||||
ursula.dht_server.bootstrap(
|
||||
[("localhost", starting_port + _c) for _c in range(len(ursulas))]))
|
||||
# ursula.publish_dht_information()
|
||||
|
||||
return ursulas
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ from tempfile import NamedTemporaryFile
|
|||
from click.testing import CliRunner
|
||||
|
||||
from cli.main import cli
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_ROOT, DEFAULT_INI_FILEPATH, APP_DIRS, PROJECT_ROOT
|
||||
|
||||
|
||||
def test_config():
|
||||
|
|
|
@ -15,6 +15,8 @@ from nucypher.blockchain.eth.interfaces import BlockchainDeployerInterface
|
|||
from nucypher.blockchain.eth.registry import TemporaryEthereumContractRegistry
|
||||
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
|
||||
from nucypher.characters import Alice, Bob
|
||||
from nucypher.config.characters import UrsulaConfiguration
|
||||
from nucypher.config.node import NodeConfiguration, BASE_DIR
|
||||
from nucypher.data_sources import DataSource
|
||||
from nucypher.keystore import keystore
|
||||
from nucypher.keystore.db import Base
|
||||
|
@ -24,8 +26,6 @@ from nucypher.keystore.keypairs import SigningKeypair
|
|||
# Setup
|
||||
#
|
||||
|
||||
|
||||
from cli.main import BASE_DIR
|
||||
from nucypher.utilities.blockchain import token_airdrop
|
||||
from nucypher.utilities.sandbox import MockRestMiddleware, make_ursulas
|
||||
|
||||
|
|
Loading…
Reference in New Issue