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')
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
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
def save(self,tx_hash,pos): db = open_db(TXOUT_PATH) db.put(tx_hash + "_" + pos, self.serialize())
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))
def error_peer(self, errno): db = open_db(peer_db_path) db.put(self.peerip + ":" + str(self.port), str(errno))
def touch_peer(self): db = open_db(peer_db_path) db.put(self.peerip + ":" + str(self.port), str(int(time.time())))
def save(self, tx_hash, pos): db = open_db(TXOUT_PATH) db.put("{0}_{1}".format(tx_hash, str(pos)), self.serialize())