Skip to content

refactor checking local adnl con #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2600,24 +2600,6 @@ 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):
Expand Down
35 changes: 34 additions & 1 deletion mytonctrl/mytonctrl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf_8 -*-
import base64
import random
import subprocess
import json
import psutil
Expand All @@ -10,6 +11,8 @@

from functools import partial

import requests

from mypylib.mypylib import (
int2ip,
get_git_author_and_repo,
Expand Down Expand Up @@ -218,7 +221,6 @@ def PreUp(local: MyPyClass, ton: MyTonCore):
CheckMytonctrlUpdate(local)
check_installer_user(local)
check_vport(local, ton)
ton.check_adnl()
warnings(local, ton)
# CheckTonUpdate()
#end define
Expand Down Expand Up @@ -484,9 +486,40 @@ def check_slashed(local, ton):
print_warning(local, "slashed_warning")
#end define

def check_adnl(local, ton):
telemetry = ton.local.db.get("sendTelemetry", False)
check_adnl = ton.local.db.get("checkAdnl", telemetry)
local.add_log('Checking ADNL connection to local node', 'info')
if not check_adnl:
return
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', '103.106.3.171']
hosts = random.sample(hosts, k=3)
data = ton.get_local_adnl_data()
error = ''
ok = True
for host in hosts:
url = f'http://{host}/adnl_check'
try:
response = requests.post(url, json=data, timeout=5).json()
except Exception as e:
ok = False
error = f'{{red}}Failed to check ADNL connection to local node: {type(e)}: {e}{{endc}}'
continue
result = response.get("ok")
if result:
ok = True
break
if not result:
ok = False
error = f'{{red}}Failed to check ADNL connection to local node: {response.get("message")}{{endc}}'
if not ok:
print_warning(local, error)
#end define

def warnings(local, ton):
local.try_function(check_disk_usage, args=[local, ton])
local.try_function(check_sync, args=[local, ton])
local.try_function(check_adnl, args=[local, ton])
local.try_function(check_validator_balance, args=[local, ton])
local.try_function(check_vps, args=[local, ton])
local.try_function(check_tg_channel, args=[local, ton])
Expand Down