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..3397ee97 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=5).json() + except Exception as e: + self.local.add_log(f'Failed to check adnl connection: {type(e)}: {e}', 'error') + return False + 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 + #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 = {"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:]).decode() + 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