From d2c7a791602e1d303a72e423a3f447ff40d0b358 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 23 Apr 2024 12:24:16 +0400 Subject: [PATCH 1/2] add checking adnl connection --- modules/__init__.py | 1 + mytoncore/mytoncore.py | 37 +++++++++++++++++++++++++++++++++++++ mytonctrl/mytonctrl.py | 1 + 3 files changed, 39 insertions(+) diff --git a/modules/__init__.py b/modules/__init__.py index a06e0aa5..d7e3cc7d 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -44,6 +44,7 @@ class Setting: 'overlayTelemetryUrl': Setting(None, 'https://telemetry.toncenter.com/report_overlays', 'Overlay telemetry url'), 'duplicateApi': Setting(None, 'sendTelemetry', 'Duplicate external to Toncenter'), 'duplicateApiUrl': Setting(None, 'https://[testnet.]toncenter.com/api/v2/sendBoc', 'Toncenter api url for duplicate'), + 'checkAdnl': Setting(None, 'sendTelemetry', 'Check local udp port and adnl connection'), 'liteclient_timeout': Setting(None, 3, 'Liteclient default timeout'), 'console_timeout': Setting(None, 3, 'Validator console default timeout'), 'fift_timeout': Setting(None, 3, 'Fift default timeout'), diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 9cd98d64..a11a6578 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2707,6 +2707,43 @@ def GetDbSize(self, exceptions="log"): return result #end define + def check_adnl(self): + telemetry = self.local.db.get("sendTelemetry", False) + check_adnl = self.local.db.get("checkAdnl", telemetry) + if not check_adnl: + return + url = 'http://45.129.96.53/adnl_check' + try: + data = self.get_local_adnl_data() + response = requests.post(url, json=data, timeout=3).json() + except Exception as e: + self.local.add_log(f'Failed to check adnl connection: {type(e)}: {e}') + return False + result = response.json().get("ok") + if not result: + self.local.add_log(f'Failed to check adnl connection to local node: {response.get("message")}', 'error') + return result + #end define + + def get_local_adnl_data(self): + + def int2ip(dec): + import socket + return socket.inet_ntoa(struct.pack("!i", dec)) + + vconfig = self.GetValidatorConfig() + + data = {"ip": int2ip(vconfig["addrs"][0]["ip"]), "port": vconfig["addrs"][0]["port"]} + + dht_id = vconfig["dht"][0]["id"] + dht_id_hex = base64.b64decode(dht_id).hex().upper() + + result = self.validatorConsole.Run(f"exportpub {dht_id_hex}") + pubkey = parse(result, "got public key: ", "\n") + data["pubkey"] = base64.b64encode(base64.b64decode(pubkey)[4:]) + return data + #end define + def Result2List(self, text): buff = parse(text, "result:", "\n") if buff is None or "error" in buff: diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 216ac25f..882d4e4c 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -242,6 +242,7 @@ def PreUp(local, ton): CheckMytonctrlUpdate(local) check_installer_user(local) check_vport(local, ton) + ton.check_adnl() warnings(local, ton) # CheckTonUpdate() #end define From e5d00f3e6675f0ed7157cc2e4cbb799efe6a8216 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 23 Apr 2024 12:30:09 +0400 Subject: [PATCH 2/2] bugfix bugfix bugfix --- mytoncore/mytoncore.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index a11a6578..3397ee97 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2715,11 +2715,11 @@ def check_adnl(self): url = 'http://45.129.96.53/adnl_check' try: data = self.get_local_adnl_data() - response = requests.post(url, json=data, timeout=3).json() + response = requests.post(url, json=data, timeout=5).json() except Exception as e: - self.local.add_log(f'Failed to check adnl connection: {type(e)}: {e}') + self.local.add_log(f'Failed to check adnl connection: {type(e)}: {e}', 'error') return False - result = response.json().get("ok") + result = response.get("ok") if not result: self.local.add_log(f'Failed to check adnl connection to local node: {response.get("message")}', 'error') return result @@ -2733,14 +2733,14 @@ def int2ip(dec): vconfig = self.GetValidatorConfig() - data = {"ip": int2ip(vconfig["addrs"][0]["ip"]), "port": vconfig["addrs"][0]["port"]} + data = {"host": int2ip(vconfig["addrs"][0]["ip"]), "port": vconfig["addrs"][0]["port"]} dht_id = vconfig["dht"][0]["id"] dht_id_hex = base64.b64decode(dht_id).hex().upper() result = self.validatorConsole.Run(f"exportpub {dht_id_hex}") pubkey = parse(result, "got public key: ", "\n") - data["pubkey"] = base64.b64encode(base64.b64decode(pubkey)[4:]) + data["pubkey"] = base64.b64encode(base64.b64decode(pubkey)[4:]).decode() return data #end define