GitHub Action
commited on
Commit
·
93df710
1
Parent(s):
1444024
Sync from GitHub with Git LFS
Browse files- agents/tools/storage.py +50 -40
agents/tools/storage.py
CHANGED
|
@@ -946,7 +946,6 @@ class Storage:
|
|
| 946 |
"""
|
| 947 |
import requests
|
| 948 |
|
| 949 |
-
# Абсолютный путь к bootstrap.txt в корне проекта
|
| 950 |
base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
| 951 |
bootstrap_path = os.path.join(base_path, bootstrap_file)
|
| 952 |
|
|
@@ -964,50 +963,61 @@ class Storage:
|
|
| 964 |
if addr is None:
|
| 965 |
continue
|
| 966 |
|
|
|
|
|
|
|
| 967 |
proto, hostport = addr.split("://")
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
|
| 1008 |
except Exception as e:
|
| 1009 |
print(f"[Bootstrap] Ошибка парсинга {line}: {e}")
|
| 1010 |
|
|
|
|
| 1011 |
# Утил��ты
|
| 1012 |
def close(self):
|
| 1013 |
self.conn.close()
|
|
|
|
| 946 |
"""
|
| 947 |
import requests
|
| 948 |
|
|
|
|
| 949 |
base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
| 950 |
bootstrap_path = os.path.join(base_path, bootstrap_file)
|
| 951 |
|
|
|
|
| 963 |
if addr is None:
|
| 964 |
continue
|
| 965 |
|
| 966 |
+
# Разворачиваем any:// на tcp и udp
|
| 967 |
+
addrs_to_register = []
|
| 968 |
proto, hostport = addr.split("://")
|
| 969 |
+
if proto == "any":
|
| 970 |
+
addrs_to_register.append(f"tcp://{hostport}")
|
| 971 |
+
addrs_to_register.append(f"udp://{hostport}")
|
| 972 |
+
else:
|
| 973 |
+
addrs_to_register.append(addr)
|
| 974 |
+
|
| 975 |
+
for a in addrs_to_register:
|
| 976 |
+
proto2, hostport2 = a.split("://")
|
| 977 |
+
|
| 978 |
+
# TCP → проверяем /identity
|
| 979 |
+
if proto2 == "tcp":
|
| 980 |
+
try:
|
| 981 |
+
url = f"http://{hostport2}/identity"
|
| 982 |
+
r = requests.get(url, timeout=3)
|
| 983 |
+
if r.status_code == 200:
|
| 984 |
+
info = r.json()
|
| 985 |
+
peer_id = info.get("id")
|
| 986 |
+
name = info.get("name", "unknown")
|
| 987 |
+
pubkey = info.get("pubkey")
|
| 988 |
+
capabilities = info.get("capabilities", {})
|
| 989 |
+
|
| 990 |
+
self.add_or_update_peer(
|
| 991 |
+
peer_id=peer_id,
|
| 992 |
+
name=name,
|
| 993 |
+
addresses=[a],
|
| 994 |
+
source="bootstrap",
|
| 995 |
+
status="online",
|
| 996 |
+
pubkey=pubkey,
|
| 997 |
+
capabilities=capabilities,
|
| 998 |
+
)
|
| 999 |
+
print(f"[Bootstrap] Добавлен узел {peer_id} ({a})")
|
| 1000 |
+
else:
|
| 1001 |
+
print(f"[Bootstrap] {a} недоступен (HTTP {r.status_code})")
|
| 1002 |
+
except Exception as e:
|
| 1003 |
+
print(f"[Bootstrap] Ошибка при подключении к {a}: {e}")
|
| 1004 |
+
|
| 1005 |
+
# UDP → просто регистрируем
|
| 1006 |
+
elif proto2 == "udp":
|
| 1007 |
+
peer_id = str(uuid.uuid4())
|
| 1008 |
+
self.add_or_update_peer(
|
| 1009 |
+
peer_id=peer_id,
|
| 1010 |
+
name="unknown",
|
| 1011 |
+
addresses=[a],
|
| 1012 |
+
source="bootstrap",
|
| 1013 |
+
status="unknown"
|
| 1014 |
+
)
|
| 1015 |
+
print(f"[Bootstrap] Добавлен адрес (без проверки): {a}")
|
| 1016 |
|
| 1017 |
except Exception as e:
|
| 1018 |
print(f"[Bootstrap] Ошибка парсинга {line}: {e}")
|
| 1019 |
|
| 1020 |
+
|
| 1021 |
# Утил��ты
|
| 1022 |
def close(self):
|
| 1023 |
self.conn.close()
|