remove interface.synchronous_get
This commit is contained in:
@@ -291,32 +291,16 @@ class Blockchain(threading.Thread):
|
|||||||
print_error("requesting header %d from %s"%(h, i.server))
|
print_error("requesting header %d from %s"%(h, i.server))
|
||||||
i.send_request({'method':'blockchain.block.get_header', 'params':[h]}, queue)
|
i.send_request({'method':'blockchain.block.get_header', 'params':[h]}, queue)
|
||||||
|
|
||||||
def retrieve_header(self, i, queue):
|
def retrieve_request(self, queue):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
ir = queue.get(timeout=1)
|
ir = queue.get(timeout=1)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
print_error('retrieve_header: timeout', i.server)
|
print_error('blockchain: request timeout')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not ir:
|
|
||||||
continue
|
|
||||||
|
|
||||||
i, r = ir
|
i, r = ir
|
||||||
|
|
||||||
if r.get('error'):
|
|
||||||
print_error('Verifier received an error:', r)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 3. handle response
|
|
||||||
method = r['method']
|
|
||||||
params = r['params']
|
|
||||||
result = r['result']
|
result = r['result']
|
||||||
|
return result
|
||||||
if method == 'blockchain.block.get_header':
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_chain(self, interface, final_header):
|
def get_chain(self, interface, final_header):
|
||||||
|
|
||||||
@@ -328,7 +312,7 @@ class Blockchain(threading.Thread):
|
|||||||
while self.is_running():
|
while self.is_running():
|
||||||
|
|
||||||
if requested_header:
|
if requested_header:
|
||||||
header = self.retrieve_header(interface, queue)
|
header = self.retrieve_request(queue)
|
||||||
if not header: return
|
if not header: return
|
||||||
chain = [ header ] + chain
|
chain = [ header ] + chain
|
||||||
requested_header = False
|
requested_header = False
|
||||||
@@ -361,9 +345,8 @@ class Blockchain(threading.Thread):
|
|||||||
n = min_index
|
n = min_index
|
||||||
while n < max_index + 1:
|
while n < max_index + 1:
|
||||||
print_error( "Requesting chunk:", n )
|
print_error( "Requesting chunk:", n )
|
||||||
r = i.synchronous_get([ ('blockchain.block.get_chunk',[n])])[0]
|
i.send_request({'method':'blockchain.block.get_chunk', 'params':[n]}, queue)
|
||||||
if not r:
|
r = self.retrieve_request(queue)
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
self.verify_chunk(n, r)
|
self.verify_chunk(n, r)
|
||||||
n = n + 1
|
n = n + 1
|
||||||
|
|||||||
@@ -341,21 +341,6 @@ class Interface(threading.Thread):
|
|||||||
# print_error( "change status", self.server, self.is_connected)
|
# print_error( "change status", self.server, self.is_connected)
|
||||||
self.response_queue.put((self, None))
|
self.response_queue.put((self, None))
|
||||||
|
|
||||||
def synchronous_get(self, requests, timeout=100000000):
|
|
||||||
queue = Queue.Queue()
|
|
||||||
ids = self.send(requests, lambda i,r: queue.put(r))
|
|
||||||
id2 = ids[:]
|
|
||||||
res = {}
|
|
||||||
while ids:
|
|
||||||
r = queue.get(True, timeout)
|
|
||||||
_id = r.get('id')
|
|
||||||
if _id in ids:
|
|
||||||
ids.remove(_id)
|
|
||||||
res[_id] = r.get('result')
|
|
||||||
out = []
|
|
||||||
for _id in id2:
|
|
||||||
out.append(res[_id])
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
class HTTP_Interface(Interface):
|
class HTTP_Interface(Interface):
|
||||||
|
|||||||
@@ -447,11 +447,6 @@ class Network(threading.Thread):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
return self.running
|
return self.running
|
||||||
|
|
||||||
|
|
||||||
def synchronous_get(self, requests, timeout=100000000):
|
|
||||||
return self.interface.synchronous_get(requests)
|
|
||||||
|
|
||||||
|
|
||||||
def get_header(self, tx_height):
|
def get_header(self, tx_height):
|
||||||
return self.blockchain.read_header(tx_height)
|
return self.blockchain.read_header(tx_height)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user