def get_status(): config = get_configs() if config is None or "guid" not in config: return { "success": False, "localerror": True, "error": "You have no guid!", } ip_list = get_local_tracker_list() for ip in ip_list: try: r = requests.get( f"http://{ip}:{constants.TRACKER_PORT}/peer_status/{config['guid']}", timeout=constants.REQUEST_TIMEOUT, ) r.raise_for_status() return r.json() except (requests.HTTPError, requests.ConnectionError, requests.Timeout, ValueError): continue return { "success": False, "localerror": True, "error": "Can't connect to any tracker", }
def choose_tracker(): print("Choose tracker") tracker_list = get_tracker_list.get_local_tracker_list() ui.tracker_list.clear() ui.tracker_list.addItems(tracker_list) choose_tracker_index = 1 ui.ui_stack.setCurrentIndex(choose_tracker_index) return
def choose_tracker_add(): new_ip = ui.tracker_ip_box.text() print("Add ip {} to list".format(new_ip)) # need error stuff here if (not get_tracker_list.add_tracker_ip_local(new_ip)): show_popup(ERROR_TITLE, "Failed to add ip") return ui.tracker_ip_box.clear() tracker_list = get_tracker_list.get_local_tracker_list() ui.tracker_list.clear() ui.tracker_list.addItems(tracker_list) return
def get_file_info(fhash): tracker_ips = get_local_tracker_list() for tracker_ip in tracker_ips: try: r = requests.get( f"http://{tracker_ip}:{constants.TRACKER_PORT}/file_by_hash/{fhash}", timeout=constants.REQUEST_TIMEOUT, ) r.raise_for_status() return r.json() except (requests.HTTPError, requests.ConnectionError, requests.Timeout, ValueError): continue return { "success": False, "error": "No trackers available", }
def send_request(data): ip_list = get_local_tracker_list() for ip in ip_list: try: r = requests.post( f"http://{ip}:{constants.TRACKER_PORT}/add_file", timeout=constants.REQUEST_TIMEOUT, json=data, ) r.raise_for_status() return r.json() except (requests.HTTPError, requests.ConnectionError, requests.Timeout, ValueError): continue return { "success": False, "error": "No trackers available", }
def _send_keepalive(self, data): tracker_ips = get_local_tracker_list() for tracker_ip in tracker_ips: try: r = requests.put( f"http://{tracker_ip}:{constants.TRACKER_PORT}/keep_alive", json=data, timeout=constants.REQUEST_TIMEOUT, ) r.raise_for_status() return r.json() except (requests.HTTPError, requests.ConnectionError, requests.Timeout, ValueError): continue return { "success": False, "error": "No trackers available", }