def unreg_from_bs(self): query = query_builder("UNREG", data=[self.udp_ip, self.udp_port, self.username]) res = udp_send_recv(self.bs_ip, self.bs_port, query) try: res_type, res = query_parser(res) except Exception as e: pass
def disconnect_from_network(self): for ip, port in self.routing_table.get(): query = query_builder("LEAVE", data=[self.udp_ip, self.udp_port]) data = udp_send_recv(ip, port, query) try: res_type, data = query_parser(data) except Exception as e: print("Error:", str(e)) else: if res_type == "LEAVEOK": pass
def connect_to_network(self): for ip, port in self.routing_table.get(): query = query_builder("JOIN", data=[self.udp_ip, self.udp_port]) data = udp_send_recv(ip, port, query) try: res_type, data = query_parser(data) except Exception as e: print("Error:", str(e)) self.routing_table.remove((ip, port)) else: if res_type == "JOINOK": pass
def reg_in_bs(self): query = query_builder("REG", data=[self.udp_ip, self.udp_port, self.username]) data = udp_send_recv(self.bs_ip, self.bs_port, query) try: res_type, data = query_parser(data) except Exception as e: print("Error:", str(e)) sys.exit("Exiting, Couldn't connect to BS") else: if res_type == "REGOK": for i in range(0, len(data), 2): self.routing_table.add(data[i], data[i + 1]) else: print("Error: Invalid response from BS") sys.exit("Exiting, Couldn't connect to BS")