GitHub Action commited on
Commit ·
a37a248
1
Parent(s): 451ae3d
Sync from GitHub with Git LFS
Browse files- agents/peer_sync.py +33 -12
agents/peer_sync.py
CHANGED
|
@@ -29,8 +29,6 @@ print(f"[PeerSync] Local ports: {local_ports}")
|
|
| 29 |
# ---------------------------
|
| 30 |
# Загрузка bootstrap
|
| 31 |
# ---------------------------
|
| 32 |
-
import json
|
| 33 |
-
|
| 34 |
def load_bootstrap_peers(filename="bootstrap.txt"):
|
| 35 |
try:
|
| 36 |
with open(filename, "r", encoding="utf-8") as f:
|
|
@@ -74,23 +72,46 @@ def load_bootstrap_peers(filename="bootstrap.txt"):
|
|
| 74 |
print(f"[Bootstrap] Failed to parse JSON addresses: {line} ({e})")
|
| 75 |
continue
|
| 76 |
|
| 77 |
-
# Расширяем any:// в tcp/udp
|
| 78 |
expanded_addresses = []
|
| 79 |
for addr in addresses:
|
| 80 |
if isinstance(addr, dict):
|
| 81 |
-
|
| 82 |
-
if
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
expanded_addresses.append(addr)
|
| 88 |
-
|
|
|
|
| 89 |
if addr.startswith("any://"):
|
| 90 |
hostport = addr[len("any://"):]
|
| 91 |
-
expanded_addresses.extend([
|
|
|
|
|
|
|
|
|
|
| 92 |
else:
|
| 93 |
-
expanded_addresses.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# Сохраняем в storage
|
| 96 |
storage.add_or_update_peer(
|
|
|
|
| 29 |
# ---------------------------
|
| 30 |
# Загрузка bootstrap
|
| 31 |
# ---------------------------
|
|
|
|
|
|
|
| 32 |
def load_bootstrap_peers(filename="bootstrap.txt"):
|
| 33 |
try:
|
| 34 |
with open(filename, "r", encoding="utf-8") as f:
|
|
|
|
| 72 |
print(f"[Bootstrap] Failed to parse JSON addresses: {line} ({e})")
|
| 73 |
continue
|
| 74 |
|
| 75 |
+
# Расширяем any:// в tcp/udp и приводим к новому формату
|
| 76 |
expanded_addresses = []
|
| 77 |
for addr in addresses:
|
| 78 |
if isinstance(addr, dict):
|
| 79 |
+
# старый формат с address/pow → конвертим
|
| 80 |
+
if "address" in addr:
|
| 81 |
+
addr_str = addr["address"]
|
| 82 |
+
if addr_str.startswith("any://"):
|
| 83 |
+
hostport = addr_str[len("any://"):]
|
| 84 |
+
variants = [f"tcp://{hostport}", f"udp://{hostport}"]
|
| 85 |
+
else:
|
| 86 |
+
variants = [addr_str]
|
| 87 |
+
|
| 88 |
+
for v in variants:
|
| 89 |
+
expanded_addresses.append({
|
| 90 |
+
"addr": v,
|
| 91 |
+
"nonce": addr.get("pow", {}).get("nonce"),
|
| 92 |
+
"pow_hash": addr.get("pow", {}).get("hash"),
|
| 93 |
+
"difficulty": addr.get("pow", {}).get("difficulty"),
|
| 94 |
+
"expires": addr.get("expires", "")
|
| 95 |
+
})
|
| 96 |
+
# уже новый формат → оставляем как есть
|
| 97 |
+
elif "addr" in addr:
|
| 98 |
expanded_addresses.append(addr)
|
| 99 |
+
|
| 100 |
+
elif isinstance(addr, str):
|
| 101 |
if addr.startswith("any://"):
|
| 102 |
hostport = addr[len("any://"):]
|
| 103 |
+
expanded_addresses.extend([
|
| 104 |
+
{"addr": f"tcp://{hostport}", "nonce": None, "pow_hash": None, "difficulty": None, "expires": ""},
|
| 105 |
+
{"addr": f"udp://{hostport}", "nonce": None, "pow_hash": None, "difficulty": None, "expires": ""}
|
| 106 |
+
])
|
| 107 |
else:
|
| 108 |
+
expanded_addresses.append({
|
| 109 |
+
"addr": addr,
|
| 110 |
+
"nonce": None,
|
| 111 |
+
"pow_hash": None,
|
| 112 |
+
"difficulty": None,
|
| 113 |
+
"expires": ""
|
| 114 |
+
})
|
| 115 |
|
| 116 |
# Сохраняем в storage
|
| 117 |
storage.add_or_update_peer(
|