mirror of https://github.com/nucypher/nucypher.git
Each Ursula in a concat'd bytestring is variable length.
parent
4c9f9108ed
commit
ece4bf2808
|
@ -134,7 +134,7 @@ class RestMiddleware:
|
|||
params = {}
|
||||
|
||||
if announce_nodes:
|
||||
payload = bytes().join(bytes(n) for n in announce_nodes)
|
||||
payload = bytes().join(bytes(VariableLengthBytestring(n)) for n in announce_nodes)
|
||||
response = client.post("https://{}/node_metadata".format(url),
|
||||
verify=certificate_filepath,
|
||||
data=payload, timeout=2, params=params)
|
||||
|
|
|
@ -29,7 +29,7 @@ import OpenSSL
|
|||
import maya
|
||||
import requests
|
||||
import time
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from bytestring_splitter import BytestringSplitter, VariableLengthBytestring
|
||||
from constant_sorrow import constants
|
||||
from cryptography.hazmat.primitives.serialization import Encoding
|
||||
from cryptography.x509 import Certificate, NameOID
|
||||
|
@ -515,7 +515,7 @@ class Learner:
|
|||
if self._crashed:
|
||||
return self._crashed
|
||||
rounds_undertaken = self._learning_round - starting_round
|
||||
if addresses.issubset(self.__known_nodes):
|
||||
if addresses.issubset(self.known_nodes.addresses()):
|
||||
if rounds_undertaken:
|
||||
self.log.info("Learned about all nodes after {} rounds.".format(rounds_undertaken))
|
||||
return True
|
||||
|
@ -638,7 +638,7 @@ class Learner:
|
|||
# TODO: What to do if the teacher improperly signed the node payload?
|
||||
raise
|
||||
|
||||
fleet_state_checksum_bytes, fleet_state_updated_bytes, nodes = FleetStateTracker.snapshot_splitter(node_payload,
|
||||
fleet_state_checksum_bytes, fleet_state_updated_bytes, node_payload = FleetStateTracker.snapshot_splitter(node_payload,
|
||||
return_remainder=True)
|
||||
current_teacher.last_seen = maya.now()
|
||||
# TODO: This is weird - let's get a stranger FleetState going.
|
||||
|
@ -653,7 +653,7 @@ class Learner:
|
|||
if response.status_code == 204:
|
||||
return constants.FLEET_STATES_MATCH
|
||||
|
||||
node_list = Ursula.batch_from_bytes(nodes, federated_only=self.federated_only) # TODO: 466
|
||||
node_list = Ursula.batch_from_bytes(node_payload, federated_only=self.federated_only) # TODO: 466
|
||||
|
||||
new_nodes = []
|
||||
for node in node_list:
|
||||
|
|
|
@ -169,8 +169,9 @@ class ProxyRESTRoutes:
|
|||
def all_known_nodes(self, request: Request):
|
||||
headers = {'Content-Type': 'application/octet-stream'}
|
||||
payload = self._node_tracker.snapshot()
|
||||
ursulas_as_bytes = bytes().join(bytes(n) for n in self._node_tracker)
|
||||
ursulas_as_bytes += self._node_bytes_caster()
|
||||
ursulas_as_vbytes = (VariableLengthBytestring(n) for n in self._node_tracker)
|
||||
ursulas_as_bytes = bytes().join(bytes(u) for u in ursulas_as_vbytes)
|
||||
ursulas_as_bytes += VariableLengthBytestring(self._node_bytes_caster())
|
||||
|
||||
payload += ursulas_as_bytes
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
from apistar import TestClient
|
||||
|
||||
from bytestring_splitter import VariableLengthBytestring
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.crypto.kits import RevocationKit
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
|
@ -118,5 +119,6 @@ class EvilMiddleWare(MockRestMiddleware):
|
|||
mock_client = self._get_mock_client_by_ursula(ursula)
|
||||
response = mock_client.post("http://localhost/node_metadata".format(mock_client),
|
||||
verify=False,
|
||||
data=bytes(shitty_interface_id))
|
||||
data=bytes(VariableLengthBytestring(shitty_interface_id))
|
||||
)
|
||||
return response
|
||||
|
|
|
@ -25,6 +25,7 @@ from twisted.internet.error import CannotListenError
|
|||
from nucypher.cli import cli
|
||||
from nucypher.characters.base import Learner
|
||||
from nucypher.utilities.sandbox.constants import TEST_URSULA_INSECURE_DEVELOPMENT_PASSWORD
|
||||
from nucypher.utilities.sandbox.ursula import UrsulaCommandProtocol
|
||||
|
||||
|
||||
@pytest.mark.skip()
|
||||
|
|
|
@ -16,9 +16,8 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|||
"""
|
||||
from functools import partial
|
||||
|
||||
import maya
|
||||
import pytest
|
||||
import pytest_twisted
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from twisted.internet.threads import deferToThread
|
||||
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
|
@ -62,15 +61,10 @@ def test_get_cert_from_running_seed_node(ursula_federated_test_config):
|
|||
|
||||
def start_lonely_learning_loop():
|
||||
any_other_ursula.start_learning_loop()
|
||||
start = maya.now()
|
||||
while not firstula in any_other_ursula.known_nodes:
|
||||
passed = maya.now() - start
|
||||
if passed.seconds > 2:
|
||||
pytest.fail("Didn't find the seed node.")
|
||||
any_other_ursula.block_until_specific_nodes_are_known(set([firstula.checksum_public_address]), timeout=2)
|
||||
|
||||
yield deferToThread(start_lonely_learning_loop)
|
||||
assert firstula in any_other_ursula.known_nodes
|
||||
|
||||
certificate_as_learned = list(any_other_ursula.known_nodes)[0].certificate
|
||||
assert certificate_as_learned == certificate_as_deployed
|
||||
any_other_ursula.stop_learning_loop()
|
||||
firstula_as_learned = any_other_ursula.known_nodes[firstula.checksum_public_address]
|
||||
assert certificate_as_deployed == firstula_as_learned.certificate
|
||||
|
|
Loading…
Reference in New Issue