From 0386bfadf07d1913187e7328ee4555933f24b91a Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 31 May 2018 12:01:07 -0400 Subject: [PATCH] update seed script --- scripts/seed_node.py | 46 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/scripts/seed_node.py b/scripts/seed_node.py index 3f3268130..c94d55de0 100644 --- a/scripts/seed_node.py +++ b/scripts/seed_node.py @@ -48,13 +48,30 @@ def format_contact(contact): return { "node_id": contact.id.encode('hex'), "address": contact.address, - "port": contact.port, + "nodePort": contact.port, "lastReplied": contact.lastReplied, "lastRequested": contact.lastRequested, - "failedRPCs": contact.failedRPCs + "failedRPCs": contact.failedRPCs, + "lastFailed": None if not contact.failures else contact.failures[-1] } +def format_datastore(node): + datastore = deepcopy(node._dataStore._dict) + result = {} + for key, values in datastore.iteritems(): + contacts = [] + for (contact, value, last_published, originally_published, original_publisher_id) in values: + contact_dict = format_contact(contact) + contact_dict['peerPort'] = struct.unpack('>H', value[4:6])[0] + contact_dict['lastPublished'] = last_published + contact_dict['originallyPublished'] = originally_published + contact_dict['originalPublisherID'] = original_publisher_id.encode('hex') + contacts.append(contact_dict) + result[key.encode('hex')] = contacts + return result + + class MultiSeedRPCServer(AuthJSONRPCServer): def __init__(self, starting_node_port, nodes, rpc_port): AuthJSONRPCServer.__init__(self, False) @@ -103,27 +120,18 @@ class MultiSeedRPCServer(AuthJSONRPCServer): return defer.succeed([node.node_id.encode('hex') for node in self._nodes]) def jsonrpc_node_datastore(self, node_id): - def format_datastore(node): - datastore = deepcopy(node._dataStore._dict) - result = {} - for key, values in datastore.iteritems(): - contacts = [] - for (value, last_published, originally_published, original_publisher_id) in values: - host = ".".join([str(ord(d)) for d in value[:4]]) - port, = struct.unpack('>H', value[4:6]) - peer_node_id = value[6:] - contact_dict = format_contact(node.contact_manager.make_contact(peer_node_id, host, port)) - contact_dict['lastPublished'] = last_published - contact_dict['originallyPublished'] = originally_published - contact_dict['originalPublisherID'] = original_publisher_id - contacts.append(contact_dict) - result[key.encode('hex')] = contacts - return result - for node in self._nodes: if node.node_id == node_id.decode('hex'): return defer.succeed(format_datastore(node)) + def jsonrpc_get_nodes_who_stored(self, blob_hash): + storing_nodes = {} + for node in self._nodes: + datastore = format_datastore(node) + if blob_hash in datastore: + storing_nodes[node.node_id.encode('hex')] = datastore[blob_hash] + return defer.succeed(storing_nodes) + def jsonrpc_node_routing_table(self, node_id): def format_bucket(bucket): return {