def ondemand_create_connection(self, uid, send_req): logging.debug("idle peers {0}".format(self.idle_peers)) peer = self.idle_peers[uid] fpr_len = len(self.ipop_state["_fpr"]) fpr = peer["data"][:fpr_len] cas = peer["data"][fpr_len + 1:] ip4 = self.uid_ip_table[peer["uid"]] logging.debug("Start mutual creating connection") if send_req: il.do_send_msg(self.sock, "send_msg", 1, uid, fpr) self.create_connection(peer["uid"], fpr, 1, CONFIG["sec"], cas, ip4)
def trim_connections(self): for k, v in self.peers.iteritems(): # Trim TinCan link if the peer is offline if "fpr" in v and v["status"] == "offline": if v["last_time"] > CONFIG["wait_time"] * 2: il.do_send_msg(self.sock, "send_msg", 1, k, "destroy" + self.ipop_state["_uid"]) il.do_trim_link(self.sock, k) # Trim TinCan link if the On Demand Inactive Timeout occurs if CONFIG["on-demand_connection"] and v["status"] == "online": if v["last_active"] + CONFIG["on-demand_inactive_timeout"]\ < time.time(): logging.debug("Inactive, trimming node:{0}".format(k)) il.do_send_msg(self.sock, 1, "send_msg", k, "destroy" + self.ipop_state["_uid"]) il.do_trim_link(self.sock, k)