|
1 | | -import base64 |
2 | 1 | import json |
3 | | -import os |
| 2 | +import random |
4 | 3 | import subprocess |
5 | 4 | import time |
6 | 5 |
|
| 6 | +import requests |
| 7 | + |
7 | 8 | from mypylib.mypylib import color_print, print_table, color_text, timeago, bcolors |
8 | 9 | from modules.module import MtcModule |
9 | 10 |
|
@@ -335,6 +336,35 @@ def print_validator_list(self, args): |
335 | 336 | print_table(table) |
336 | 337 | # end define |
337 | 338 |
|
| 339 | + def check_adnl_connection(self): |
| 340 | + telemetry = self.ton.local.db.get("sendTelemetry", False) |
| 341 | + check_adnl = self.ton.local.db.get("checkAdnl", telemetry) |
| 342 | + if not check_adnl: |
| 343 | + return True, '' |
| 344 | + self.local.add_log('Checking ADNL connection to local node', 'info') |
| 345 | + hosts = ['45.129.96.53', '5.154.181.153', '2.56.126.137', '91.194.11.68', '45.12.134.214', '138.124.184.27', |
| 346 | + '103.106.3.171'] |
| 347 | + hosts = random.sample(hosts, k=3) |
| 348 | + data = self.ton.get_local_adnl_data() |
| 349 | + error = '' |
| 350 | + ok = True |
| 351 | + for host in hosts: |
| 352 | + url = f'http://{host}/adnl_check' |
| 353 | + try: |
| 354 | + response = requests.post(url, json=data, timeout=5).json() |
| 355 | + except Exception as e: |
| 356 | + ok = False |
| 357 | + error = f'{{red}}Failed to check ADNL connection to local node: {type(e)}: {e}{{endc}}' |
| 358 | + continue |
| 359 | + result = response.get("ok") |
| 360 | + if result: |
| 361 | + ok = True |
| 362 | + break |
| 363 | + if not result: |
| 364 | + ok = False |
| 365 | + error = f'{{red}}Failed to check ADNL connection to local node: {response.get("message")}{{endc}}' |
| 366 | + return ok, error |
| 367 | + |
338 | 368 | def add_console_commands(self, console): |
339 | 369 | console.AddItem("vas", self.view_account_status, self.local.translate("vas_cmd")) |
340 | 370 | console.AddItem("vah", self.view_account_history, self.local.translate("vah_cmd")) |
|
0 commit comments