def __init__(self, # Ursula rest_host: str, rest_port: int, certificate: Certificate = None, # TODO: from_certificate classmethod instead, use only filepath..? certificate_filepath: str = None, db_name: str = None, # TODO: deprecate db_name, use only filepath.? db_filepath: str = None, is_me: bool = True, interface_signature=None, # Blockchain miner_agent=None, checksum_address: str = None, registry_filepath: str = None, # Character abort_on_learning_error: bool = False, federated_only: bool = False, start_learning_now: bool = None, crypto_power=None, tls_curve: EllipticCurve = None, tls_private_key=None, # TODO: config here. #361 known_nodes: Iterable = None, **character_kwargs ) -> None: self._work_orders = [] Character.__init__(self, is_me=is_me, checksum_address=checksum_address, start_learning_now=start_learning_now, federated_only=federated_only, crypto_power=crypto_power, abort_on_learning_error=abort_on_learning_error, known_nodes=known_nodes, **character_kwargs) if not federated_only: Miner.__init__(self, is_me=is_me, miner_agent=miner_agent, checksum_address=checksum_address, registry_filepath=registry_filepath) blockchain_power = BlockchainPower(blockchain=self.blockchain, account=self.checksum_public_address) self._crypto_power.consume_power_up(blockchain_power) if is_me is True: # TODO: 340 self._stored_treasure_maps = {} if not federated_only: self.substantiate_stamp() if not crypto_power or (TLSHostingPower not in crypto_power._power_ups): # TODO: Maybe we want _power_ups to be public after all? # We'll hook all the TLS stuff up unless the crypto_power was already passed. if is_me: self.suspicious_activities_witnessed = {'vladimirs': [], 'bad_treasure_maps': []} rest_routes = ProxyRESTRoutes( db_name=db_name, db_filepath=db_filepath, network_middleware=self.network_middleware, federated_only=self.federated_only, treasure_map_tracker=self.treasure_maps, node_tracker=self.known_nodes, node_bytes_caster=self.__bytes__, work_order_tracker=self._work_orders, node_recorder=self.remember_node, stamp=self.stamp, verifier=self.verify_from, suspicious_activity_tracker=self.suspicious_activities_witnessed, certificate_dir=self.known_certificates_dir, ) rest_server = ProxyRESTServer( rest_host=rest_host, rest_port=rest_port, routes=rest_routes, ) self.rest_url = rest_server.rest_url self.datastore = rest_routes.datastore # TODO: Maybe organize this better? tls_hosting_keypair = HostingKeypair( common_name=self.checksum_public_address, private_key=tls_private_key, curve=tls_curve, host=rest_host, certificate=certificate, certificate_dir=self.known_certificates_dir) tls_hosting_power = TLSHostingPower(rest_server=rest_server, keypair=tls_hosting_keypair) else: # Unless the caller passed a crypto power, we'll make our own TLSHostingPower for this stranger. rest_server = ProxyRESTServer( rest_host=rest_host, rest_port=rest_port ) if certificate or certificate_filepath: tls_hosting_power = TLSHostingPower(rest_server=rest_server, certificate_filepath=certificate_filepath, certificate=certificate, certificate_dir=self.known_certificates_dir, common_name=self.checksum_public_address,) else: tls_hosting_keypair = HostingKeypair( common_name=self.checksum_public_address, curve=tls_curve, host=rest_host, certificate_filepath=certificate_filepath, certificate_dir=self.known_certificates_dir) tls_hosting_power = TLSHostingPower(rest_server=rest_server, keypair=tls_hosting_keypair) self._crypto_power.consume_power_up(tls_hosting_power) # Make this work for not me for certificate to work else: self.log.info("Not adhering rest_server; we'll use the one on crypto_power..") certificate_filepath = self._crypto_power.power_ups(TLSHostingPower).keypair.certificate_filepath certificate = self._crypto_power.power_ups(TLSHostingPower).keypair.certificate # VerifiableNode.from_tls_hosting_power(tls_hosting_power=self._crypto_power.power_ups(TLSHostingPower)) # TODO: use classmethod VerifiableNode.__init__(self, certificate=certificate, certificate_filepath=certificate_filepath, interface_signature=interface_signature) if is_me: message = "Initialized Self {} | {}".format(self.__class__.__name__, self.checksum_public_address) self.log.info(message) else: message = "Initialized Stranger {} | {}".format(self.__class__.__name__, self.checksum_public_address) self.log.debug(message)
def __init__( self, # Ursula rest_host: str, rest_port: int, domains: Set = ( GLOBAL_DOMAIN, ), # For now, serving and learning domains will be the same. certificate: Certificate = None, certificate_filepath: str = None, db_filepath: str = None, is_me: bool = True, interface_signature=None, timestamp=None, # Blockchain identity_evidence: bytes = constants.NOT_SIGNED, checksum_public_address: str = None, # Character password: str = None, abort_on_learning_error: bool = False, federated_only: bool = False, start_learning_now: bool = None, crypto_power=None, tls_curve: EllipticCurve = None, known_nodes: Iterable = None, **character_kwargs) -> None: # # Character # self._work_orders = list() Character.__init__(self, is_me=is_me, checksum_public_address=checksum_public_address, start_learning_now=start_learning_now, federated_only=federated_only, crypto_power=crypto_power, abort_on_learning_error=abort_on_learning_error, known_nodes=known_nodes, domains=domains, **character_kwargs) # # Self-Ursula # if is_me is True: # TODO: 340 self._stored_treasure_maps = dict() # # Staking Ursula # if not federated_only: Miner.__init__(self, is_me=is_me, checksum_address=checksum_public_address) # Access staking node via node's transacting keys TODO: Better handle ephemeral staking self ursula blockchain_power = BlockchainPower( blockchain=self.blockchain, account=self.checksum_public_address) self._crypto_power.consume_power_up(blockchain_power) # Use blockchain power to substantiate stamp, instead of signing key self.substantiate_stamp( password=password) # TODO: Derive from keyring # # ProxyRESTServer and TLSHostingPower # TODO: Maybe we want _power_ups to be public after all? # if not crypto_power or (TLSHostingPower not in crypto_power._power_ups): # # Ephemeral Self-Ursula # if is_me: self.suspicious_activities_witnessed = { 'vladimirs': [], 'bad_treasure_maps': [] } # # REST Server (Ephemeral Self-Ursula) # rest_app, datastore = make_rest_app( db_filepath=db_filepath, network_middleware=self.network_middleware, federated_only=self.federated_only, # TODO: 466 treasure_map_tracker=self.treasure_maps, node_tracker=self.known_nodes, node_bytes_caster=self.__bytes__, work_order_tracker=self._work_orders, node_recorder=self.remember_node, stamp=self.stamp, verifier=self.verify_from, suspicious_activity_tracker=self. suspicious_activities_witnessed, serving_domains=domains, ) # # TLSHostingPower (Ephemeral Self-Ursula) # tls_hosting_keypair = HostingKeypair( curve=tls_curve, host=rest_host, checksum_public_address=self.checksum_public_address) tls_hosting_power = TLSHostingPower( keypair=tls_hosting_keypair, host=rest_host) self.rest_server = ProxyRESTServer( rest_host=rest_host, rest_port=rest_port, rest_app=rest_app, datastore=datastore, hosting_power=tls_hosting_power) # # Stranger-Ursula # else: # TLSHostingPower if certificate or certificate_filepath: tls_hosting_power = TLSHostingPower( host=rest_host, public_certificate_filepath=certificate_filepath, public_certificate=certificate) else: tls_hosting_keypair = HostingKeypair( curve=tls_curve, host=rest_host, generate_certificate=False) tls_hosting_power = TLSHostingPower( host=rest_host, keypair=tls_hosting_keypair) # REST Server # Unless the caller passed a crypto power we'll make our own TLSHostingPower for this stranger. self.rest_server = ProxyRESTServer( rest_host=rest_host, rest_port=rest_port, hosting_power=tls_hosting_power) # # OK - Now we have a ProxyRestServer and a TLSHostingPower for some Ursula # self._crypto_power.consume_power_up(tls_hosting_power) # Consume! # # Verifiable Node # certificate_filepath = self._crypto_power.power_ups( TLSHostingPower).keypair.certificate_filepath certificate = self._crypto_power.power_ups( TLSHostingPower).keypair.certificate Teacher.__init__( self, domains=domains, certificate=certificate, certificate_filepath=certificate_filepath, interface_signature=interface_signature, timestamp=timestamp, identity_evidence=identity_evidence, substantiate_immediately=is_me and not federated_only, ) # # Logging / Updating # if is_me: self.known_nodes.record_fleet_state( additional_nodes_to_track=[self]) message = "THIS IS YOU: {}: {}".format(self.__class__.__name__, self) self.log.info(message) else: message = "Initialized Stranger {} | {}".format( self.__class__.__name__, self) self.log.debug(message)
def __init__( self, # Ursula rest_host: str, rest_port: int, certificate: Certificate = None, certificate_filepath: str = None, tls_private_key=None, # TODO: Derive from keyring db_name: str = None, db_filepath: str = None, is_me: bool = True, interface_signature=None, timestamp=None, # Blockchain miner_agent=None, checksum_address: str = None, # Character passphrase: str = None, abort_on_learning_error: bool = False, federated_only: bool = False, start_learning_now: bool = None, crypto_power=None, tls_curve: EllipticCurve = None, known_nodes: Iterable = None, **character_kwargs) -> None: # # Character # self._work_orders = list() Character.__init__(self, is_me=is_me, checksum_address=checksum_address, start_learning_now=start_learning_now, federated_only=federated_only, crypto_power=crypto_power, abort_on_learning_error=abort_on_learning_error, known_nodes=known_nodes, **character_kwargs) # # Self-Ursula # if is_me is True: # TODO: 340 self._stored_treasure_maps = dict() if not federated_only: Miner.__init__(self, is_me=is_me, miner_agent=miner_agent, checksum_address=checksum_address) # Access staking node via node's transacting keys blockchain_power = BlockchainPower( blockchain=self.blockchain, account=self.checksum_public_address) self._crypto_power.consume_power_up(blockchain_power) # Use blockchain power to substantiate stamp self.substantiate_stamp(passphrase=passphrase) # # ProxyRESTServer and TLSHostingPower # if not crypto_power or (TLSHostingPower not in crypto_power._power_ups): # TODO: Maybe we want _power_ups to be public after all? # We'll hook all the TLS stuff up unless the crypto_power was already passed. # # Self-Ursula # if is_me: self.suspicious_activities_witnessed = { 'vladimirs': [], 'bad_treasure_maps': [] } # # REST Server # rest_routes = ProxyRESTRoutes( db_name=db_name, db_filepath=db_filepath, network_middleware=self.network_middleware, federated_only=self.federated_only, # TODO: 466 treasure_map_tracker=self.treasure_maps, node_tracker=self.known_nodes, node_bytes_caster=self.__bytes__, work_order_tracker=self._work_orders, node_recorder=self.remember_node, stamp=self.stamp, verifier=self.verify_from, suspicious_activity_tracker=self. suspicious_activities_witnessed, certificate_dir=self.known_certificates_dir, ) rest_server = ProxyRESTServer( rest_host=rest_host, rest_port=rest_port, routes=rest_routes, ) self.rest_url = rest_server.rest_url self.datastore = rest_routes.datastore # TODO: Maybe organize this better? # # TLSHostingPower # tls_hosting_keypair = HostingKeypair( curve=tls_curve, host=rest_host, certificate=certificate, certificate_filepath=certificate_filepath, private_key=tls_private_key) tls_hosting_power = TLSHostingPower( rest_server=rest_server, keypair=tls_hosting_keypair) # # Stranger-Ursula # else: # REST Server # Unless the caller passed a crypto power, # we'll make our own TLSHostingPower for this stranger. rest_server = ProxyRESTServer(rest_host=rest_host, rest_port=rest_port) # # TLSHostingPower # if certificate or certificate_filepath: tls_hosting_power = TLSHostingPower( rest_server=rest_server, certificate_filepath=certificate_filepath, certificate=certificate) else: tls_hosting_keypair = HostingKeypair( curve=tls_curve, host=rest_host, certificate_filepath=certificate_filepath) tls_hosting_power = TLSHostingPower( rest_server=rest_server, keypair=tls_hosting_keypair) # OK - Now we have a ProxyRestServer and a TLSHostingPower for some Ursula self._crypto_power.consume_power_up(tls_hosting_power) # Consume! else: self.log.info( "Not adhering rest_server; Using the one on crypto_power.") # # Verifiable Node # certificate_filepath = self._crypto_power.power_ups( TLSHostingPower).keypair.certificate_filepath certificate = self._crypto_power.power_ups( TLSHostingPower).keypair.certificate VerifiableNode.__init__(self, certificate=certificate, certificate_filepath=certificate_filepath, interface_signature=interface_signature, timestamp=timestamp) # # Logging # if is_me: message = "Initialized Self {} | {}".format( self.__class__.__name__, self.checksum_public_address) self.log.info(message) else: message = "Initialized Stranger {} | {}".format( self.__class__.__name__, self.checksum_public_address) self.log.debug(message)