URI: 
       tdownload headers chunks - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 7204dceeac7de39a15c240ad97422ae6255bd3ef
   DIR parent 7c2ac013063eb1c80ec53cff9c623e4b7681f511
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Tue,  3 Sep 2013 07:29:44 +0200
       
       download headers chunks
       
       Diffstat:
         M lib/blockchain.py                   |      37 ++++++++++++++++++++++++++++++-
       
       1 file changed, 36 insertions(+), 1 deletion(-)
       ---
   DIR diff --git a/lib/blockchain.py b/lib/blockchain.py
       t@@ -166,13 +166,42 @@ class BlockchainVerifier(threading.Thread):
                return True
        
        
       +    def get_chunks(self, i, header, height):
       +        requested_chunks = []
       +        min_index = (self.local_height + 1)/2016
       +        max_index = (height + 1)/2016
       +        for n in range(min_index, max_index + 1):
       +            print_error( "requesting chunk", n )
       +            i.send([ ('blockchain.block.get_chunk',[n])], 'get_header')
       +            requested_chunks.append(n)
       +            break
       +
       +        while requested_chunks:
       +            try:
       +                r = i.get_response('get_header',timeout=1)
       +            except Queue.Empty:
       +                continue
       +            if not r: continue
       +
       +            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_chunk':
       +                index = params[0]
       +                self.verify_chunk(index, result)
       +                requested_chunks.remove(index)
        
        
            def verify_chunk(self, index, hexdata):
                data = hexdata.decode('hex')
                height = index*2016
                num = len(data)/80
       -        print_error("validating headers %d"%height)
        
                if index == 0:  
                    previous_hash = ("0"*64)
       t@@ -196,6 +225,7 @@ class BlockchainVerifier(threading.Thread):
                    previous_hash = _hash 
        
                self.save_chunk(index, data)
       +        print_error("validated chunk %d"%height)
        
        
            def verify_header(self, header):
       t@@ -371,7 +401,12 @@ class BlockchainVerifier(threading.Thread):
                    
                    height = header.get('block_height')
        
       +            if height > self.local_height + 50:
       +                self.get_chunks(i, header, height)
       +
       +
                    if height > self.local_height:
       +
                        # get missing parts from interface (until it connects to my chain)
                        chain = self.get_chain( i, header )