Merge branch 'feature/clean-chainstate' into feature/blockstackd-subdomain-indexing

This commit is contained in:
Jude Nelson
2018-02-08 17:02:32 -05:00
3 changed files with 130 additions and 13 deletions

View File

@@ -45,7 +45,7 @@ from .client import \
ping as blockstack_ping, \
getinfo as blockstack_getinfo, \
get_zonefile_inventory as blockstack_get_zonefile_inventory, \
get_atlas_peers as blockstack_get_atlas_peers, \
atlas_peer_exchange as blockstack_atlas_peer_exchange, \
get_zonefiles as blockstack_get_zonefiles, \
put_zonefiles as blockstack_put_zonefiles, \
json_is_error
@@ -2288,9 +2288,9 @@ def atlas_peer_get_neighbors( my_hostport, peer_hostport, timeout=None, peer_tab
assert not atlas_peer_table_is_locked_by_me()
try:
peer_list = blockstack_get_atlas_peers( peer_hostport, timeout=timeout, my_hostport=my_hostport, proxy=rpc )
peer_list = blockstack_atlas_peer_exchange( peer_hostport, my_hostport, timeout=timeout, proxy=rpc )
except (socket.timeout, socket.gaierror, socket.herror, socket.error), se:
atlas_log_socket_error( "get_atlas_peers(%s)" % peer_hostport, peer_hostport, se)
atlas_log_socket_error( "atlas_peer_exchange(%s)" % peer_hostport, peer_hostport, se)
log.error("Socket error in response from '%s'" % peer_hostport)
except Exception, e:

View File

@@ -520,6 +520,8 @@ def get_atlas_peers(hostport, timeout=30, my_hostport=None, proxy=None):
],
}
log.warning("DEPRECATED call to atlas_get_peers()")
schema = json_response_schema( peers_schema )
if proxy is None:
@@ -557,6 +559,67 @@ def get_atlas_peers(hostport, timeout=30, my_hostport=None, proxy=None):
return peers
def atlas_peer_exchange(hostport, my_hostport, timeout=30, proxy=None):
"""
Get an atlas peer's neighbors, and list ourselves as a possible peer.
Return {'status': True, 'peers': [peers]} on success.
Return {'error': ...} on error
"""
assert hostport or proxy, 'need either hostport or proxy'
peers_schema = {
'type': 'object',
'properties': {
'peers': {
'type': 'array',
'items': {
'type': 'string',
'pattern': '^([^:]+):([1-9][0-9]{1,4})$',
},
},
},
'required': [
'peers'
],
}
schema = json_response_schema( peers_schema )
if proxy is None:
proxy = connect_hostport(hostport)
peers = None
try:
peer_list_resp = proxy.atlas_peer_exchange(my_hostport)
peer_list_resp = json_validate(schema, peer_list_resp)
if json_is_error(peer_list_resp):
return peer_list_resp
# verify that all strings are host:ports
for peer_hostport in peer_list_resp['peers']:
peer_host, peer_port = url_to_host_port(peer_hostport)
if peer_host is None or peer_port is None:
return {'error': 'Invalid peer listing'}
peers = peer_list_resp
except (ValidationError, AssertionError) as e:
if BLOCKSTACK_DEBUG:
log.exception(e)
peers = json_traceback()
except Exception as ee:
if BLOCKSTACK_DEBUG:
log.exception(ee)
log.error("Caught exception while connecting to Blockstack node: {}".format(ee))
resp = {'error': 'Failed to contact Blockstack node {}. Try again with `--debug`.'.format(hostport)}
return resp
return peers
def get_zonefiles(hostport, zonefile_hashes, timeout=30, my_hostport=None, proxy=None):
"""
Get a set of zonefiles from the given server.