mirror of https://github.com/nucypher/nucypher.git
Scrap `suspicious_activities_witnessed` from Ursula
We're not doing anything with it (until #567 is implemented), and it's clogging the memory over time.pull/2820/head
parent
cc51564966
commit
181e6bd3f1
|
@ -271,8 +271,6 @@ class Learner:
|
|||
|
||||
self.log = Logger("learning-loop") # type: Logger
|
||||
|
||||
self.suspicious_activities_witnessed = defaultdict(list) # TODO: Combine with buckets / node labeling
|
||||
|
||||
self.learning_deferred = Deferred()
|
||||
self.domain = domain
|
||||
if not self.federated_only:
|
||||
|
@ -815,7 +813,7 @@ class Learner:
|
|||
unresponsive_nodes.add(current_teacher) # This does nothing.
|
||||
self.known_nodes.mark_as(current_teacher.InvalidNode, current_teacher)
|
||||
self.log.warn(f"Teacher {str(current_teacher)} is invalid (hex={bytes(current_teacher.metadata()).hex()}):{e}.")
|
||||
self.suspicious_activities_witnessed['vladimirs'].append(current_teacher)
|
||||
# TODO (#567): bucket the node as suspicious
|
||||
return
|
||||
except RuntimeError as e:
|
||||
if canceller and canceller.stop_now:
|
||||
|
@ -859,8 +857,7 @@ class Learner:
|
|||
try:
|
||||
metadata.verify(current_teacher.stamp.as_umbral_pubkey())
|
||||
except InvalidSignature:
|
||||
self.suspicious_activities_witnessed['vladimirs'].append(
|
||||
('Node payload improperly signed', response.content))
|
||||
# TODO (#567): bucket the node as suspicious
|
||||
self.log.warn(
|
||||
f"Invalid signature received from teacher {current_teacher} for MetadataResponse {response.content}")
|
||||
return
|
||||
|
|
|
@ -190,7 +190,7 @@ def _make_rest_app(datastore: Datastore, this_node, domain: str, log: Logger) ->
|
|||
except Exception as e:
|
||||
message = f'{bob_identity_message} Invalid EncryptedKeyFrag: {e}.'
|
||||
log.info(message)
|
||||
this_node.suspicious_activities_witnessed['unauthorized'].append(message)
|
||||
# TODO (#567): bucket the node as suspicious
|
||||
return Response(message, status=HTTPStatus.BAD_REQUEST)
|
||||
|
||||
# Verify KFrag Authorization (offchain)
|
||||
|
@ -200,7 +200,7 @@ def _make_rest_app(datastore: Datastore, this_node, domain: str, log: Logger) ->
|
|||
except InvalidSignature as e:
|
||||
message = f'{bob_identity_message} Invalid signature for KeyFrag: {e}.'
|
||||
log.info(message)
|
||||
this_node.suspicious_activities_witnessed['unauthorized'].append(message)
|
||||
# TODO (#567): bucket the node as suspicious
|
||||
return Response(message, status=HTTPStatus.UNAUTHORIZED) # 401 - Unauthorized
|
||||
except Exception as e:
|
||||
message = f'{bob_identity_message} Invalid KeyFrag: {e}.'
|
||||
|
@ -215,7 +215,7 @@ def _make_rest_app(datastore: Datastore, this_node, domain: str, log: Logger) ->
|
|||
except Policy.Unpaid:
|
||||
message = f"{bob_identity_message} Policy {hrac} is unpaid."
|
||||
record = (publisher_verifying_key, message)
|
||||
this_node.suspicious_activities_witnessed['freeriders'].append(record)
|
||||
# TODO (#567): bucket the node as suspicious
|
||||
return Response(message, status=HTTPStatus.PAYMENT_REQUIRED)
|
||||
except Policy.Unknown:
|
||||
message = f"{bob_identity_message} Policy {hrac} is not a published policy."
|
||||
|
|
|
@ -58,10 +58,6 @@ def test_policy_simple_sinpa(blockchain_ursulas,
|
|||
alice_verifying_key=amonia.stamp.as_umbral_pubkey(),
|
||||
encrypted_treasure_map=bupkiss_policy.treasure_map)
|
||||
|
||||
for ursula in blockchain_ursulas:
|
||||
# Reset the Ursula for the next test.
|
||||
ursula.suspicious_activities_witnessed['freeriders'] = []
|
||||
|
||||
|
||||
def test_try_to_post_free_service_by_hacking_enact(blockchain_ursulas,
|
||||
blockchain_alice,
|
||||
|
|
|
@ -79,8 +79,15 @@ def test_blockchain_ursula_stamp_verification_tolerance(blockchain_ursulas, mock
|
|||
return bytes(response)
|
||||
|
||||
mocker.patch.object(blockchain_teacher, 'bytestring_of_known_nodes', bad_bytestring_of_known_nodes)
|
||||
|
||||
globalLogPublisher.addObserver(warning_trapper)
|
||||
lonely_blockchain_learner.learn_from_teacher_node(eager=True)
|
||||
assert len(lonely_blockchain_learner.suspicious_activities_witnessed['vladimirs']) == 1
|
||||
globalLogPublisher.removeObserver(warning_trapper)
|
||||
|
||||
assert len(warnings) == 2
|
||||
warning = warnings[1]['log_format']
|
||||
assert str(blockchain_teacher) in warning
|
||||
assert "Invalid signature received from teacher" in warning # TODO: Cleanup logging templates
|
||||
|
||||
|
||||
@pytest.mark.skip("See Issue #1075") # TODO: Issue #1075
|
||||
|
|
|
@ -20,6 +20,7 @@ import datetime
|
|||
|
||||
import maya
|
||||
import pytest
|
||||
from twisted.logger import LogLevel, globalLogPublisher
|
||||
|
||||
from nucypher.blockchain.eth.agents import ContractAgency, StakingEscrowAgent
|
||||
from nucypher.acumen.nicknames import Nickname
|
||||
|
@ -67,6 +68,14 @@ def test_vladimir_illegal_interface_key_does_not_propagate(blockchain_ursulas):
|
|||
check will catch it and Ursula will refuse to propagate it and also record Vladimir's
|
||||
details.
|
||||
"""
|
||||
|
||||
warnings = []
|
||||
|
||||
def warning_trapper(event):
|
||||
if event['log_level'] == LogLevel.warn:
|
||||
warnings.append(event)
|
||||
|
||||
|
||||
ursulas = list(blockchain_ursulas)
|
||||
ursula_whom_vladimir_will_imitate, other_ursula = ursulas[0], ursulas[1]
|
||||
|
||||
|
@ -76,10 +85,12 @@ def test_vladimir_illegal_interface_key_does_not_propagate(blockchain_ursulas):
|
|||
# This Ursula is totally legit...
|
||||
ursula_whom_vladimir_will_imitate.verify_node(MockRestMiddleware())
|
||||
|
||||
globalLogPublisher.addObserver(warning_trapper)
|
||||
vladimir.network_middleware.propagate_shitty_interface_id(other_ursula, vladimir.metadata())
|
||||
globalLogPublisher.removeObserver(warning_trapper)
|
||||
|
||||
# So far, Ursula hasn't noticed any Vladimirs.
|
||||
assert other_ursula.suspicious_activities_witnessed['vladimirs'] == []
|
||||
assert len(warnings) == 0
|
||||
|
||||
# ...but now, Ursula will now try to learn about Vladimir on a different thread.
|
||||
other_ursula.block_until_specific_nodes_are_known([vladimir.checksum_address])
|
||||
|
@ -87,12 +98,18 @@ def test_vladimir_illegal_interface_key_does_not_propagate(blockchain_ursulas):
|
|||
|
||||
# OK, so cool, let's see what happens when Ursula tries to learn with Vlad as the teacher.
|
||||
other_ursula._current_teacher_node = vladimir_as_learned
|
||||
|
||||
globalLogPublisher.addObserver(warning_trapper)
|
||||
result = other_ursula.learn_from_teacher_node()
|
||||
globalLogPublisher.removeObserver(warning_trapper)
|
||||
|
||||
# FIXME: These two asserts are missing, restoring them leads to failure
|
||||
# Indeed, Ursula noticed that something was up.
|
||||
# assert vladimir in other_ursula.suspicious_activities_witnessed['vladimirs']
|
||||
assert len(warnings) == 1
|
||||
warning = warnings[0]['log_format']
|
||||
assert "Teacher " + str(vladimir_as_learned) + " is invalid" in warning
|
||||
assert "Metadata signature is invalid" in warning # TODO: Cleanup logging templates
|
||||
|
||||
# TODO (#567)
|
||||
# ...and booted him from known_nodes
|
||||
# assert vladimir not in other_ursula.known_nodes
|
||||
|
||||
|
|
Loading…
Reference in New Issue