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"]))
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
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
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"]))
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"]))
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"]))