fixes and refactors from review
This commit is contained in:
parent
0841c90e6c
commit
3b88d2465d
3 changed files with 12 additions and 26 deletions
|
@ -96,7 +96,8 @@ class ConnectionManager:
|
||||||
d.addBoth(lambda _: disconnect_peer(p))
|
d.addBoth(lambda _: disconnect_peer(p))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
closing_deferreds = [close_connection(peer) for peer in list(self._peer_connections.keys())]
|
# fixme: stop modifying dict during iteration
|
||||||
|
closing_deferreds = [close_connection(peer) for peer in list(self._peer_connections)]
|
||||||
return defer.DeferredList(closing_deferreds)
|
return defer.DeferredList(closing_deferreds)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
|
@ -2895,46 +2895,31 @@ class Daemon(AuthJSONRPCServer):
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
data_store = self.dht_node._dataStore
|
data_store = self.dht_node._dataStore
|
||||||
datastore_len = len(data_store)
|
|
||||||
hosts = {}
|
hosts = {}
|
||||||
|
|
||||||
if datastore_len:
|
for k, v in data_store.items():
|
||||||
for k, v in data_store.items():
|
for contact, _ in v:
|
||||||
for contact, value, lastPublished, originallyPublished, originalPublisherID in v:
|
hosts.setdefault(contact, []).append(hexlify(k).decode())
|
||||||
if contact in hosts:
|
|
||||||
blobs = hosts[contact]
|
|
||||||
else:
|
|
||||||
blobs = []
|
|
||||||
blobs.append(hexlify(k))
|
|
||||||
hosts[contact] = blobs
|
|
||||||
|
|
||||||
contact_set = set()
|
contact_set = set()
|
||||||
blob_hashes = []
|
blob_hashes = set()
|
||||||
result['buckets'] = {}
|
result['buckets'] = {}
|
||||||
|
|
||||||
for i in range(len(self.dht_node._routingTable._buckets)):
|
for i in range(len(self.dht_node._routingTable._buckets)):
|
||||||
for contact in self.dht_node._routingTable._buckets[i]._contacts:
|
for contact in self.dht_node._routingTable._buckets[i]._contacts:
|
||||||
contacts = result['buckets'].get(i, [])
|
blobs = [hexlify(raw_hash).decode() for raw_hash in hosts.pop(contact)] if contact in hosts else []
|
||||||
if contact in hosts:
|
blob_hashes.update(blobs)
|
||||||
blobs = hosts[contact]
|
|
||||||
del hosts[contact]
|
|
||||||
else:
|
|
||||||
blobs = []
|
|
||||||
host = {
|
host = {
|
||||||
"address": contact.address,
|
"address": contact.address,
|
||||||
"port": contact.port,
|
"port": contact.port,
|
||||||
"node_id": hexlify(contact.id).decode(),
|
"node_id": hexlify(contact.id).decode(),
|
||||||
"blobs": blobs,
|
"blobs": blobs,
|
||||||
}
|
}
|
||||||
for blob_hash in blobs:
|
result['buckets'].setdefault(i, []).append(host)
|
||||||
if blob_hash not in blob_hashes:
|
|
||||||
blob_hashes.append(blob_hash)
|
|
||||||
contacts.append(host)
|
|
||||||
result['buckets'][i] = contacts
|
|
||||||
contact_set.add(hexlify(contact.id).decode())
|
contact_set.add(hexlify(contact.id).decode())
|
||||||
|
|
||||||
result['contacts'] = contact_set
|
result['contacts'] = list(contact_set)
|
||||||
result['blob_hashes'] = blob_hashes
|
result['blob_hashes'] = list(blob_hashes)
|
||||||
result['node_id'] = hexlify(self.dht_node.node_id).decode()
|
result['node_id'] = hexlify(self.dht_node.node_id).decode()
|
||||||
return self._render_response(result)
|
return self._render_response(result)
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ def get_contact(contact_list, node_id, address, port):
|
||||||
|
|
||||||
|
|
||||||
def expand_peer(compact_peer_info):
|
def expand_peer(compact_peer_info):
|
||||||
host = ".".join([str(d) for d in compact_peer_info[:4]])
|
host = "{}.{}.{}.{}".format(*compact_peer_info[:4])
|
||||||
port, = struct.unpack('>H', compact_peer_info[4:6])
|
port, = struct.unpack('>H', compact_peer_info[4:6])
|
||||||
peer_node_id = compact_peer_info[6:]
|
peer_node_id = compact_peer_info[6:]
|
||||||
return (peer_node_id, host, port)
|
return (peer_node_id, host, port)
|
||||||
|
|
Loading…
Reference in a new issue