mirror of https://github.com/nucypher/nucypher.git
Marking and expanding some DHT value parsing logic. See #172.
parent
14a4bf1634
commit
c9d518beac
|
@ -75,6 +75,7 @@ class NuCypherHashProtocol(KademliaProtocol):
|
|||
self.welcomeIfNewNode(source)
|
||||
self.log.debug("got a store request from %s" % str(sender))
|
||||
|
||||
# TODO: Why is this logic here? This is madness. See #172.
|
||||
if value.startswith(BYTESTRING_IS_URSULA_IFACE_INFO) or value.startswith(
|
||||
BYTESTRING_IS_TREASURE_MAP):
|
||||
header, signature, sender_pubkey_sig, hrac, message = dht_value_splitter(
|
||||
|
|
|
@ -276,3 +276,22 @@ class ProxyRESTServer(object):
|
|||
return Response(content=treasure_map_bytes,
|
||||
content_type="application/octet-stream")
|
||||
|
||||
def receive_treasure_map(self, treasure_map_id_as_hex, request: http.Request):
|
||||
# TODO: This function is the epitome of #172.
|
||||
treasure_map_id = binascii.unhexlify(treasure_map_id_as_hex)
|
||||
|
||||
header, signature_for_ursula, pubkey_sig_alice, hrac, tmap_message_kit = \
|
||||
dht_value_splitter(request.body, return_remainder=True)
|
||||
# TODO: This next line is possibly the worst in the entire codebase at the moment. #172.
|
||||
# Also TODO: TTL?
|
||||
do_store = self.server.protocol.determine_legality_of_dht_key(signature_for_ursula, pubkey_sig_alice, tmap_message_kit,
|
||||
hrac, digest(treasure_map_id), request.body)
|
||||
if do_store:
|
||||
# TODO: Stop storing things in the protocol storage. Do this better.
|
||||
# TODO: Propagate to other nodes.
|
||||
self.server.protocol.storage[digest(treasure_map_id)] = request.body
|
||||
return # TODO: Proper response here.
|
||||
else:
|
||||
# TODO: Make this a proper 500 or whatever.
|
||||
assert False
|
||||
|
||||
|
|
|
@ -179,9 +179,11 @@ class Policy(object):
|
|||
|
||||
Our public key (which everybody knows) and the hrac above.
|
||||
"""
|
||||
return self.hash(bytes(self.alice.stamp) + self.hrac())
|
||||
return keccak_digest(bytes(self.alice.stamp) + self.hrac())
|
||||
|
||||
def publish_treasure_map(self):
|
||||
def publish_treasure_map(self, networky_stuff=None, use_dht=True):
|
||||
if networky_stuff is None and use_dht is False:
|
||||
raise ValueError("Can't engage the REST swarm without networky stuff.")
|
||||
tmap_message_kit, signature_for_bob = self.alice.encrypt_for(
|
||||
self.bob,
|
||||
self.treasure_map.packed_payload())
|
||||
|
@ -189,13 +191,21 @@ class Policy(object):
|
|||
|
||||
# In order to know this is safe to propagate, Ursula needs to see a signature, our public key,
|
||||
# and, reasons explained in treasure_map_dht_key above, the uri_hash.
|
||||
dht_value = signature_for_ursula + self.alice.stamp + self.hrac() + tmap_message_kit.to_bytes()
|
||||
dht_key = self.treasure_map_dht_key()
|
||||
# TODO: Clean this up. See #172.
|
||||
map_payload = signature_for_ursula + self.alice.stamp + self.hrac() + tmap_message_kit.to_bytes()
|
||||
map_id = self.treasure_map_dht_key()
|
||||
|
||||
setter = self.alice.server.set(dht_key, BYTESTRING_IS_TREASURE_MAP + dht_value)
|
||||
event_loop = asyncio.get_event_loop()
|
||||
event_loop.run_until_complete(setter)
|
||||
return tmap_message_kit, dht_value, signature_for_bob, signature_for_ursula
|
||||
if use_dht:
|
||||
setter = self.alice.server.set(map_id, BYTESTRING_IS_TREASURE_MAP + map_payload)
|
||||
event_loop = asyncio.get_event_loop()
|
||||
event_loop.run_until_complete(setter)
|
||||
else:
|
||||
for node in self.alice.known_nodes.values():
|
||||
response = networky_stuff.push_treasure_map_to_node(node, map_id, BYTESTRING_IS_TREASURE_MAP + map_payload)
|
||||
# TODO: Do something here based on success or failure
|
||||
if response.status_code == 204:
|
||||
pass
|
||||
return tmap_message_kit, map_payload, signature_for_bob, signature_for_ursula
|
||||
|
||||
def enact(self, networky_stuff):
|
||||
for contract in self._accepted_contracts.values():
|
||||
|
|
Loading…
Reference in New Issue