mirror of https://github.com/nucypher/nucypher.git
Whew! Redline this entire method; it happens just-in-time now.
parent
e2cf9b3214
commit
49c3b767b9
|
@ -810,88 +810,7 @@ class Learner:
|
||||||
else:
|
else:
|
||||||
raise self.InvalidSignature("No signature provided -- signature presumed invalid.")
|
raise self.InvalidSignature("No signature provided -- signature presumed invalid.")
|
||||||
|
|
||||||
def parse_and_maybe_validate_fleet_bytes(self, node_payload, verify_now=False):
|
def learn_from_teacher_node(self, eager=False):
|
||||||
from nucypher.characters.lawful import Ursula
|
|
||||||
node_list = Ursula.batch_from_bytes(node_payload,
|
|
||||||
registry=self.registry,
|
|
||||||
federated_only=self.federated_only) # TODO: 466
|
|
||||||
|
|
||||||
new_nodes = []
|
|
||||||
for node in node_list:
|
|
||||||
if not set(self.learning_domains).intersection(set(node.serving_domains)):
|
|
||||||
self.log.debug(
|
|
||||||
f"Teacher {node} is serving {node.serving_domains}, but we're only learning {self.learning_domains}.")
|
|
||||||
continue # This node is not serving any of our domains.
|
|
||||||
|
|
||||||
# First, determine if this is an outdated representation of an already known node.
|
|
||||||
# TODO: #1032
|
|
||||||
with suppress(KeyError):
|
|
||||||
already_known_node = self.known_nodes[node.checksum_address]
|
|
||||||
if not node.timestamp > already_known_node.timestamp:
|
|
||||||
self.log.debug("Skipping already known node {}".format(already_known_node))
|
|
||||||
# This node is already known. We can safely continue to the next.
|
|
||||||
continue
|
|
||||||
|
|
||||||
#
|
|
||||||
# Verify Node
|
|
||||||
#
|
|
||||||
|
|
||||||
certificate_filepath = self.node_storage.store_node_certificate(certificate=node.certificate)
|
|
||||||
try:
|
|
||||||
if verify_now:
|
|
||||||
node.verify_node(self.network_middleware,
|
|
||||||
registry=self.registry,
|
|
||||||
certificate_filepath=certificate_filepath)
|
|
||||||
self.log.debug("Verified node: {}".format(node.checksum_address))
|
|
||||||
|
|
||||||
else:
|
|
||||||
node.validate_metadata(registry=self.registry)
|
|
||||||
|
|
||||||
#
|
|
||||||
# Report Failure
|
|
||||||
#
|
|
||||||
|
|
||||||
except NodeSeemsToBeDown:
|
|
||||||
self.log.info(f"Verification Failed - "
|
|
||||||
f"Cannot establish connection to {node}.")
|
|
||||||
|
|
||||||
except node.StampNotSigned:
|
|
||||||
self.log.warn(f'Verification Failed - '
|
|
||||||
f'{node} stamp is unsigned.')
|
|
||||||
|
|
||||||
except node.NotStaking:
|
|
||||||
self.log.warn(f'Verification Failed - '
|
|
||||||
f'{node} has no active stakes in the current period '
|
|
||||||
f'({self.staking_agent.get_current_period()}')
|
|
||||||
|
|
||||||
except node.InvalidWorkerSignature:
|
|
||||||
self.log.warn(f'Verification Failed - '
|
|
||||||
f'{node} has an invalid wallet signature for {node.decentralized_identity_evidence}')
|
|
||||||
|
|
||||||
except node.DetachedWorker:
|
|
||||||
self.log.warn(f'Verification Failed - '
|
|
||||||
f'{node} is not bonded to a Staker.')
|
|
||||||
|
|
||||||
except node.InvalidNode:
|
|
||||||
self.log.warn(node.invalid_metadata_message.format(node))
|
|
||||||
|
|
||||||
except node.SuspiciousActivity:
|
|
||||||
message = f"Suspicious Activity: Discovered node with bad signature: {node}." \
|
|
||||||
f"Propagated by: {current_teacher}"
|
|
||||||
self.log.warn(message)
|
|
||||||
|
|
||||||
#
|
|
||||||
# Success
|
|
||||||
#
|
|
||||||
|
|
||||||
else:
|
|
||||||
new = self.remember_node(node, record_fleet_state=False)
|
|
||||||
if new:
|
|
||||||
new_nodes.append(node)
|
|
||||||
self._adjust_learning(new_nodes)
|
|
||||||
return node_list, new_nodes
|
|
||||||
|
|
||||||
def learn_from_teacher_node(self, eager=True):
|
|
||||||
"""
|
"""
|
||||||
Sends a request to node_url to find out about known nodes.
|
Sends a request to node_url to find out about known nodes.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue