Skip to content

Commit d2c7a79

Browse files
committed
add checking adnl connection
1 parent 46b95fd commit d2c7a79

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

modules/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Setting:
4444
'overlayTelemetryUrl': Setting(None, 'https://telemetry.toncenter.com/report_overlays', 'Overlay telemetry url'),
4545
'duplicateApi': Setting(None, 'sendTelemetry', 'Duplicate external to Toncenter'),
4646
'duplicateApiUrl': Setting(None, 'https://[testnet.]toncenter.com/api/v2/sendBoc', 'Toncenter api url for duplicate'),
47+
'checkAdnl': Setting(None, 'sendTelemetry', 'Check local udp port and adnl connection'),
4748
'liteclient_timeout': Setting(None, 3, 'Liteclient default timeout'),
4849
'console_timeout': Setting(None, 3, 'Validator console default timeout'),
4950
'fift_timeout': Setting(None, 3, 'Fift default timeout'),

mytoncore/mytoncore.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,43 @@ def GetDbSize(self, exceptions="log"):
27072707
return result
27082708
#end define
27092709

2710+
def check_adnl(self):
2711+
telemetry = self.local.db.get("sendTelemetry", False)
2712+
check_adnl = self.local.db.get("checkAdnl", telemetry)
2713+
if not check_adnl:
2714+
return
2715+
url = 'http://45.129.96.53/adnl_check'
2716+
try:
2717+
data = self.get_local_adnl_data()
2718+
response = requests.post(url, json=data, timeout=3).json()
2719+
except Exception as e:
2720+
self.local.add_log(f'Failed to check adnl connection: {type(e)}: {e}')
2721+
return False
2722+
result = response.json().get("ok")
2723+
if not result:
2724+
self.local.add_log(f'Failed to check adnl connection to local node: {response.get("message")}', 'error')
2725+
return result
2726+
#end define
2727+
2728+
def get_local_adnl_data(self):
2729+
2730+
def int2ip(dec):
2731+
import socket
2732+
return socket.inet_ntoa(struct.pack("!i", dec))
2733+
2734+
vconfig = self.GetValidatorConfig()
2735+
2736+
data = {"ip": int2ip(vconfig["addrs"][0]["ip"]), "port": vconfig["addrs"][0]["port"]}
2737+
2738+
dht_id = vconfig["dht"][0]["id"]
2739+
dht_id_hex = base64.b64decode(dht_id).hex().upper()
2740+
2741+
result = self.validatorConsole.Run(f"exportpub {dht_id_hex}")
2742+
pubkey = parse(result, "got public key: ", "\n")
2743+
data["pubkey"] = base64.b64encode(base64.b64decode(pubkey)[4:])
2744+
return data
2745+
#end define
2746+
27102747
def Result2List(self, text):
27112748
buff = parse(text, "result:", "\n")
27122749
if buff is None or "error" in buff:

mytonctrl/mytonctrl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def PreUp(local, ton):
242242
CheckMytonctrlUpdate(local)
243243
check_installer_user(local)
244244
check_vport(local, ton)
245+
ton.check_adnl()
245246
warnings(local, ton)
246247
# CheckTonUpdate()
247248
#end define

0 commit comments

Comments
 (0)