Example #1
0
    def handle_addr(self, message_header, message):
        """
		This method will handle incoming inventories of network 
		peers.
		Args:
			message_header: The message header
			message: The list of peers
		"""
        db = open_db(peer_db_path, self.logger)
        wb = writebatch()
        self.logger.info("Unpacking new peers from {0}".format(self.peerip))
        try:
            for peer in message.addresses:
                _p = db.get("{0}:{1}".format(peer.ip_address, str(peer.port)))
                if _p is None:
                    wb.put("{0}:{1}".format(peer.ip_address, str(peer.port)),
                           "{0}.{1}".format(str(0), str(int(0))))
                try:
                    infiniti_rpc._CONNECTION.addnode(
                        "{0}:{1}".format(peer.ip_address, str(peer.port)),
                        'add')
                except:
                    pass
            db.write(wb)
        except Exception as e:
            self.stop(e.errno, 'handle_addr')
Example #2
0
 def save(self,db):
     db = open_db(BLOCK_PATH)
     db.put(self.calculate_hash(),self.timestamp)
     db = None # trigger garbage collection
     n = 0
     for tx in self.txns:
         tx.save(self.calculate_hash(),n)
         n += 1
Example #3
0
 def save(self,block_hash,pos):
     db = open_db(TRANSACTION_PATH)
     db.put(block_hash + "_" + str(pos), self.calculate_hash() )
     db = None # trigger garbage collection
     n = 0
     for txout in self.tx_out:
         txout.save(self.calculate_hash())
         n += 1
     n = 0
     for txin in self.tx_in:
         txin.save(self.calculate_hash())
         n += 1
Example #4
0
 def save(self,tx_hash,pos):
     db = open_db(TXOUT_PATH)
     db.put(tx_hash + "_" + pos, self.serialize())
Example #5
0
 def touch_peer(self, value):
     db = open_db(peer_db_path, self.logger)
     timestr = str(int(time.time()))
     valuestr = str(int(value))
     db.put("{0}:{1}".format(self.peerip, str(self.port)),
            "{0}.{1}".format(valuestr, timestr))
Example #6
0
 def error_peer(self, errno):
     db = open_db(peer_db_path)
     db.put(self.peerip + ":" + str(self.port), str(errno))
Example #7
0
 def touch_peer(self):
     db = open_db(peer_db_path)
     db.put(self.peerip + ":" + str(self.port), str(int(time.time())))
Example #8
0
 def save(self, tx_hash, pos):
     db = open_db(TXOUT_PATH)
     db.put("{0}_{1}".format(tx_hash, str(pos)), self.serialize())