Browse Source

remove interface.synchronous_get

283
ThomasV 11 years ago
parent
commit
ed8f9666df
  1. 29
      lib/blockchain.py
  2. 15
      lib/interface.py
  3. 5
      lib/network.py

29
lib/blockchain.py

@ -291,32 +291,16 @@ class Blockchain(threading.Thread):
print_error("requesting header %d from %s"%(h, i.server))
i.send_request({'method':'blockchain.block.get_header', 'params':[h]}, queue)
def retrieve_header(self, i, queue):
def retrieve_request(self, queue):
while True:
try:
ir = queue.get(timeout=1)
except Queue.Empty:
print_error('retrieve_header: timeout', i.server)
print_error('blockchain: request timeout')
continue
if not ir:
continue
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']
if method == 'blockchain.block.get_header':
return result
return result
def get_chain(self, interface, final_header):
@ -328,7 +312,7 @@ class Blockchain(threading.Thread):
while self.is_running():
if requested_header:
header = self.retrieve_header(interface, queue)
header = self.retrieve_request(queue)
if not header: return
chain = [ header ] + chain
requested_header = False
@ -361,9 +345,8 @@ class Blockchain(threading.Thread):
n = min_index
while n < max_index + 1:
print_error( "Requesting chunk:", n )
r = i.synchronous_get([ ('blockchain.block.get_chunk',[n])])[0]
if not r:
continue
i.send_request({'method':'blockchain.block.get_chunk', 'params':[n]}, queue)
r = self.retrieve_request(queue)
try:
self.verify_chunk(n, r)
n = n + 1

15
lib/interface.py

@ -341,21 +341,6 @@ class Interface(threading.Thread):
# print_error( "change status", self.server, self.is_connected)
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):

5
lib/network.py

@ -447,11 +447,6 @@ class Network(threading.Thread):
with self.lock:
return self.running
def synchronous_get(self, requests, timeout=100000000):
return self.interface.synchronous_get(requests)
def get_header(self, tx_height):
return self.blockchain.read_header(tx_height)

Loading…
Cancel
Save