示例#1
0
 def remove_node(self, node, block_updates = False, txid = 0):
     self.nodes.remove(node)
     if block_updates:
         node["txid"] = txid
         node["block"] = time.time()
         self.blocked.append(node)
     self.database.pop("{ip},{po}".format(ip = node["ipv4"], po = node["port"]))
     tools.dbg_print("Removed node: {ip}:{po}\n- - - - - - - - - -".format(ip = node["ipv4"], po = node["port"]))
示例#2
0
 def get_oldest_echo(self):
     current_time = time.time()
     bye_time = current_time - 12
     oldest_node = current_time
     with self.node_lock:
         for n in self.nodes:
             if n["echo"] <= bye_time:
                 tools.dbg_print("Node timed out: {ip}:{po}\n- - - - - - - - - -".format(ip = n["ipv4"], po = n["port"]))
                 self.remove_node(n)
             elif n["echo"] < oldest_node:
                 oldest_node = n["echo"]
     return oldest_node
示例#3
0
 def get_oldest_hello(self):
     current_time = time.time()
     bye_time = current_time - 30
     oldest_peer = current_time
     with self.peer_lock:
         for p in self.peers:
             if p["hello"] <= bye_time:
                 tools.dbg_print("Peer timed out: {}\n- - - - - - - - - -".format(p["username"]))
                 self.remove_peer(p)
             elif p["hello"] < oldest_peer:
                 oldest_peer = p["hello"]
     return oldest_peer
示例#4
0
 def remove_peer(self, peer):
     self.peers.remove(peer)
     self.update_event.set()
     self.update_event.clear()
     tools.dbg_print("Removed peer: {}\n- - - - - - - - - -".format(peer["username"]))
示例#5
0
 def add_peer(self, peer):
     self.peers.append(peer)
     self.update_event.set()
     self.update_event.clear()
     tools.dbg_print("Added new peer: {}\n- - - - - - - - - -".format(peer["username"]))
示例#6
0
 def add_node(self, node, db):
     self.nodes.append(node)
     self.database["{ip},{po}".format(ip = node["ipv4"], po = node["port"])] = db
     tools.dbg_print("Added new node: {ip}:{po}\n- - - - - - - - - -".format(ip = node["ipv4"], po = node["port"]))