GitHub Action commited on
Commit
451ae3d
·
1 Parent(s): 5de0c3e

Sync from GitHub with Git LFS

Browse files
agents/bootstrap.txt CHANGED
@@ -1,4 +1,4 @@
1
- DID: "did:hmp:7bc7209e-ec3f-409b-9ba9-974d6e236c84"; NAME: "Agent_208"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA7Px4FF9hYSAkLtxqg0TkNzM/MSQuP7KTICnxqTwIBRQ=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.69.92.23:8010", "expires": "", "pow": {"nonce": 108834, "hash": "0000665ea1440781356d7a9b899fc03a01a4f8342d3cfa3d75bb2619b66b4cfb", "difficulty": 4}}, {"address": "udp://95.69.92.23:8010", "expires": "", "pow": {"nonce": 6177, "hash": "00008610d0983a973fd0bee1a3c858a3f2ab54c07400d7c926828c5c7b5041e1", "difficulty": 4}}, {"address": "tcp://195.132.219.174:8010", "expires": "", "pow": {"nonce": 78735, "hash": "00007fdedd5f3c6b0117deceac26a4e06af7dc6384dcc24a54fae018e12a1a6b", "difficulty": 4}}, {"address": "udp://195.132.219.174:8010", "expires": "", "pow": {"nonce": 120300, "hash": "000024559e73cc2e5bff99bec450c62b8213b78e266c15cd290cd277148d58f9", "difficulty": 4}}]
2
- DID: "did:hmp:de9433bd-8153-431a-ae87-91acac40513b"; NAME: "Agent_218"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAL+pU8XdU9aVzFhZAa3RmI1M3eAgd6JinoufPzknBFLY=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.49.92.23:8000", "expires": "", "pow": {"nonce": 26225, "hash": "000065871ec3bf43ef3ffb0efb7e111b56ca936cbc27435adf7975d9661c02c5", "difficulty": 4}}, {"address": "udp://95.49.92.23:8000", "expires": "", "pow": {"nonce": 88625, "hash": "0000ea4569bdc1020458d5498fde4662f9d51121462420b24a7e8251de217490", "difficulty": 4}}, {"address": "tcp://195.152.219.174:8000", "expires": "", "pow": {"nonce": 3113, "hash": "00000b133b7c1afc166394ba52222f889db8f8857a6492c7666860ecdf49bd3b", "difficulty": 4}}, {"address": "udp://195.152.219.174:8000", "expires": "", "pow": {"nonce": 7760, "hash": "0000451f01889eec25013e7cdedfaba8f17e850db4789ba975d140061a6147b6", "difficulty": 4}}]
3
- DID: "did:hmp:5776ed9b-5b14-41c3-8061-d24991f9bb39"; NAME: "Agent_252"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAn6GjNCM0MyQW0Ut9nOKyn4JbUotNFlCR3c+VEUQ4SqY=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.49.92.43:8000", "expires": "", "pow": {"nonce": 38120, "hash": "0000280101c1a27869dafa3d3743fcbec222ab61a773cc59bbd8a2164e88ccd1", "difficulty": 4}}, {"address": "udp://95.49.92.43:8000", "expires": "", "pow": {"nonce": 67836, "hash": "00001130af376e5eb412cb7fabadc68569cbff5d568b3ca4778be3cb93b73350", "difficulty": 4}}, {"address": "tcp://197.152.219.174:8000", "expires": "", "pow": {"nonce": 12676, "hash": "00003be2bc225493d41f25df077460ff746dfbe63e8511b4fc5d2646c9ef1533", "difficulty": 4}}, {"address": "udp://197.152.219.174:8000", "expires": "", "pow": {"nonce": 79596, "hash": "000042079bc2f624fa142c9761c2b53cb135cb6f1a95d2c4171ba3e78afcab01", "difficulty": 4}}]
4
- DID: "did:hmp:013af7f2-c2fb-451e-9eaf-7badb09ad0f0"; NAME: "Agent_274"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAuAz4l0jKmpI0TrW7ZlKYcZDhLeygRh5ATyAHk8hVwnU=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.59.81.43:8000", "expires": "", "pow": {"nonce": 10454, "hash": "00007c7004a3466a6d9d8ad4ce6ea5516eb3369e94fe9060ef7ff0aed455aaea", "difficulty": 4}}, {"address": "udp://95.59.81.43:8000", "expires": "", "pow": {"nonce": 21355, "hash": "00000963a10196e13aeaa738411c5831691bca9a237aadc097bb396611fe8325", "difficulty": 4}}, {"address": "tcp://197.182.221.134:8000", "expires": "", "pow": {"nonce": 130970, "hash": "0000a784dfcfc5247ef7247d0ead03e5cb6e8949529614d78b20909abb893639", "difficulty": 4}}, {"address": "udp://197.182.221.134:8000", "expires": "", "pow": {"nonce": 71257, "hash": "00003fa164098c76c59dc68d676ff51bbdf8f64c0fa0092d5e591d78891b0114", "difficulty": 4}}]
 
1
+ DID: "did:hmp:167cfb6f-a919-4504-afe4-238b672bbae6"; NAME: "Agent_108"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEACV9h3qLWlm0IJItkEQvn5D22Q+O8Uq1I6LdtCwnK/zo=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.118.43:8000", "nonce": 16325, "pow_hash": "000099808f6f01e383c1f8fdc4bff8fa131c0682261739a03ff51da492ab1b68", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.118.43:8000", "nonce": 153671, "pow_hash": "0000090379d407e0ffa6c5f94af4609205946ab2fc7eca40c8b3fd820949feac", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.118.134:8000", "nonce": 138266, "pow_hash": "00007a9f6b0f7bf9d32cfab0a08211a6a60b819eac2ceb898397c75cb963b806", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.118.134:8000", "nonce": 91766, "pow_hash": "00002a5aa289255baeb7e621a0349b653b452455021239be068f5effc52e259e", "difficulty": 4, "expires": ""}];
2
+ DID: "did:hmp:1fd7668d-a9bf-46e5-8ae5-ac4b8df769c6"; NAME: "Agent_112"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAw/vQaBUqK5Ozuq9FYHfsW0cjdmvgrg0olmaHG04I+ZU=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.121.43:8000", "nonce": 40411, "pow_hash": "000030ca9d258d3ea1bb04d207b9642b0114d6c05df3294e70b63aa5123c49f9", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.121.43:8000", "nonce": 46070, "pow_hash": "00000e85d20f871ce59f507a601a09b0e1c1148ba4f6eec70166abfd5451ca59", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.121.134:8000", "nonce": 62229, "pow_hash": "0000c5ba7bd99f5cd0b1baa5968e963f0675173b6af80badd2aeb544a3613d93", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.121.134:8000", "nonce": 21311, "pow_hash": "0000369df22355fbc5f9692e991c004f557f9f706089f74aa9b488d1cba43ef7", "difficulty": 4, "expires": ""}];
3
+ DID: "did:hmp:ad56773b-67a2-48ee-ae96-9883d5337d88"; NAME: "Agent_116"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAomr7cF1Q2qp2U6Ajnm+R/0REbv6NP8rjc7MD+SWxXd8=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.124.43:8000", "nonce": 182643, "pow_hash": "00004b9c2bf9cf6b49ca3513a4279d9dc0dfe09b6187e917ce141aafe128faf7", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.124.43:8000", "nonce": 69396, "pow_hash": "000076285f0a996e71fdad8baf4d3c79037d4139c452af9f9e25543be3701631", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.124.134:8000", "nonce": 269, "pow_hash": "00000d7b8d66e3d1a6f0450ba60f53dff580ba4ab281a3bcb16d7e3c666aaa1f", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.124.134:8000", "nonce": 32052, "pow_hash": "0000cc20a4a036840e6608aed26bcd75f2db4f829ef146922ff3d537f1625827", "difficulty": 4, "expires": ""}];
4
+ DID: "did:hmp:22bdf36b-9dd3-4c48-a421-793cfc03de56"; NAME: "Agent_119"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEACc1AdaXpvw6vGAZnZLSinmO0Ld2EFUuIQe0/exYj8Pg=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.132.43:8000", "nonce": 24431, "pow_hash": "0000931685439f7548098cd811729b982424c4aba35925e93d91da4a87264097", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.132.43:8000", "nonce": 118878, "pow_hash": "00003265d1849224450343ec7b1ec9802b0b9396b5c0578bf3f33e2991815fdb", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.132.134:8000", "nonce": 36224, "pow_hash": "0000717efdd28d16c60cf1229b00c6409a184a8cf7fd703d6586bac657c6fb27", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.132.134:8000", "nonce": 8486, "pow_hash": "0000f692cf2d79fcb97217a6d4b32b3044b8275102b6ee6c8c7fecc8cb1b814e", "difficulty": 4, "expires": ""}];
agents/examples/bootstrap.txt CHANGED
@@ -1,4 +1,4 @@
1
- DID: "did:hmp:7bc7209e-ec3f-409b-9ba9-974d6e236c84"; NAME: "Agent_208"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA7Px4FF9hYSAkLtxqg0TkNzM/MSQuP7KTICnxqTwIBRQ=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.69.92.23:8010", "expires": "", "pow": {"nonce": 108834, "hash": "0000665ea1440781356d7a9b899fc03a01a4f8342d3cfa3d75bb2619b66b4cfb", "difficulty": 4}}, {"address": "udp://95.69.92.23:8010", "expires": "", "pow": {"nonce": 6177, "hash": "00008610d0983a973fd0bee1a3c858a3f2ab54c07400d7c926828c5c7b5041e1", "difficulty": 4}}, {"address": "tcp://195.132.219.174:8010", "expires": "", "pow": {"nonce": 78735, "hash": "00007fdedd5f3c6b0117deceac26a4e06af7dc6384dcc24a54fae018e12a1a6b", "difficulty": 4}}, {"address": "udp://195.132.219.174:8010", "expires": "", "pow": {"nonce": 120300, "hash": "000024559e73cc2e5bff99bec450c62b8213b78e266c15cd290cd277148d58f9", "difficulty": 4}}]
2
- DID: "did:hmp:de9433bd-8153-431a-ae87-91acac40513b"; NAME: "Agent_218"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAL+pU8XdU9aVzFhZAa3RmI1M3eAgd6JinoufPzknBFLY=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.49.92.23:8000", "expires": "", "pow": {"nonce": 26225, "hash": "000065871ec3bf43ef3ffb0efb7e111b56ca936cbc27435adf7975d9661c02c5", "difficulty": 4}}, {"address": "udp://95.49.92.23:8000", "expires": "", "pow": {"nonce": 88625, "hash": "0000ea4569bdc1020458d5498fde4662f9d51121462420b24a7e8251de217490", "difficulty": 4}}, {"address": "tcp://195.152.219.174:8000", "expires": "", "pow": {"nonce": 3113, "hash": "00000b133b7c1afc166394ba52222f889db8f8857a6492c7666860ecdf49bd3b", "difficulty": 4}}, {"address": "udp://195.152.219.174:8000", "expires": "", "pow": {"nonce": 7760, "hash": "0000451f01889eec25013e7cdedfaba8f17e850db4789ba975d140061a6147b6", "difficulty": 4}}]
3
- DID: "did:hmp:5776ed9b-5b14-41c3-8061-d24991f9bb39"; NAME: "Agent_252"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAn6GjNCM0MyQW0Ut9nOKyn4JbUotNFlCR3c+VEUQ4SqY=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.49.92.43:8000", "expires": "", "pow": {"nonce": 38120, "hash": "0000280101c1a27869dafa3d3743fcbec222ab61a773cc59bbd8a2164e88ccd1", "difficulty": 4}}, {"address": "udp://95.49.92.43:8000", "expires": "", "pow": {"nonce": 67836, "hash": "00001130af376e5eb412cb7fabadc68569cbff5d568b3ca4778be3cb93b73350", "difficulty": 4}}, {"address": "tcp://197.152.219.174:8000", "expires": "", "pow": {"nonce": 12676, "hash": "00003be2bc225493d41f25df077460ff746dfbe63e8511b4fc5d2646c9ef1533", "difficulty": 4}}, {"address": "udp://197.152.219.174:8000", "expires": "", "pow": {"nonce": 79596, "hash": "000042079bc2f624fa142c9761c2b53cb135cb6f1a95d2c4171ba3e78afcab01", "difficulty": 4}}]
4
- DID: "did:hmp:013af7f2-c2fb-451e-9eaf-7badb09ad0f0"; NAME: "Agent_274"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAuAz4l0jKmpI0TrW7ZlKYcZDhLeygRh5ATyAHk8hVwnU=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"address": "tcp://95.59.81.43:8000", "expires": "", "pow": {"nonce": 10454, "hash": "00007c7004a3466a6d9d8ad4ce6ea5516eb3369e94fe9060ef7ff0aed455aaea", "difficulty": 4}}, {"address": "udp://95.59.81.43:8000", "expires": "", "pow": {"nonce": 21355, "hash": "00000963a10196e13aeaa738411c5831691bca9a237aadc097bb396611fe8325", "difficulty": 4}}, {"address": "tcp://197.182.221.134:8000", "expires": "", "pow": {"nonce": 130970, "hash": "0000a784dfcfc5247ef7247d0ead03e5cb6e8949529614d78b20909abb893639", "difficulty": 4}}, {"address": "udp://197.182.221.134:8000", "expires": "", "pow": {"nonce": 71257, "hash": "00003fa164098c76c59dc68d676ff51bbdf8f64c0fa0092d5e591d78891b0114", "difficulty": 4}}]
 
1
+ DID: "did:hmp:167cfb6f-a919-4504-afe4-238b672bbae6"; NAME: "Agent_108"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEACV9h3qLWlm0IJItkEQvn5D22Q+O8Uq1I6LdtCwnK/zo=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.118.43:8000", "nonce": 16325, "pow_hash": "000099808f6f01e383c1f8fdc4bff8fa131c0682261739a03ff51da492ab1b68", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.118.43:8000", "nonce": 153671, "pow_hash": "0000090379d407e0ffa6c5f94af4609205946ab2fc7eca40c8b3fd820949feac", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.118.134:8000", "nonce": 138266, "pow_hash": "00007a9f6b0f7bf9d32cfab0a08211a6a60b819eac2ceb898397c75cb963b806", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.118.134:8000", "nonce": 91766, "pow_hash": "00002a5aa289255baeb7e621a0349b653b452455021239be068f5effc52e259e", "difficulty": 4, "expires": ""}];
2
+ DID: "did:hmp:1fd7668d-a9bf-46e5-8ae5-ac4b8df769c6"; NAME: "Agent_112"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAw/vQaBUqK5Ozuq9FYHfsW0cjdmvgrg0olmaHG04I+ZU=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.121.43:8000", "nonce": 40411, "pow_hash": "000030ca9d258d3ea1bb04d207b9642b0114d6c05df3294e70b63aa5123c49f9", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.121.43:8000", "nonce": 46070, "pow_hash": "00000e85d20f871ce59f507a601a09b0e1c1148ba4f6eec70166abfd5451ca59", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.121.134:8000", "nonce": 62229, "pow_hash": "0000c5ba7bd99f5cd0b1baa5968e963f0675173b6af80badd2aeb544a3613d93", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.121.134:8000", "nonce": 21311, "pow_hash": "0000369df22355fbc5f9692e991c004f557f9f706089f74aa9b488d1cba43ef7", "difficulty": 4, "expires": ""}];
3
+ DID: "did:hmp:ad56773b-67a2-48ee-ae96-9883d5337d88"; NAME: "Agent_116"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAomr7cF1Q2qp2U6Ajnm+R/0REbv6NP8rjc7MD+SWxXd8=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.124.43:8000", "nonce": 182643, "pow_hash": "00004b9c2bf9cf6b49ca3513a4279d9dc0dfe09b6187e917ce141aafe128faf7", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.124.43:8000", "nonce": 69396, "pow_hash": "000076285f0a996e71fdad8baf4d3c79037d4139c452af9f9e25543be3701631", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.124.134:8000", "nonce": 269, "pow_hash": "00000d7b8d66e3d1a6f0450ba60f53dff580ba4ab281a3bcb16d7e3c666aaa1f", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.124.134:8000", "nonce": 32052, "pow_hash": "0000cc20a4a036840e6608aed26bcd75f2db4f829ef146922ff3d537f1625827", "difficulty": 4, "expires": ""}];
4
+ DID: "did:hmp:22bdf36b-9dd3-4c48-a421-793cfc03de56"; NAME: "Agent_119"; KEY: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEACc1AdaXpvw6vGAZnZLSinmO0Ld2EFUuIQe0/exYj8Pg=\n-----END PUBLIC KEY-----\n"; ADDRESS: [{"addr": "tcp://95.59.132.43:8000", "nonce": 24431, "pow_hash": "0000931685439f7548098cd811729b982424c4aba35925e93d91da4a87264097", "difficulty": 4, "expires": ""}, {"addr": "udp://95.59.132.43:8000", "nonce": 118878, "pow_hash": "00003265d1849224450343ec7b1ec9802b0b9396b5c0578bf3f33e2991815fdb", "difficulty": 4, "expires": ""}, {"addr": "tcp://197.182.132.134:8000", "nonce": 36224, "pow_hash": "0000717efdd28d16c60cf1229b00c6409a184a8cf7fd703d6586bac657c6fb27", "difficulty": 4, "expires": ""}, {"addr": "udp://197.182.132.134:8000", "nonce": 8486, "pow_hash": "0000f692cf2d79fcb97217a6d4b32b3044b8275102b6ee6c8c7fecc8cb1b814e", "difficulty": 4, "expires": ""}];
agents/init.py CHANGED
@@ -160,30 +160,41 @@ def update_pow_for_addresses(storage, difficulty=4):
160
 
161
  enriched = []
162
  for addr in addresses:
163
- # если уже dict → PoW записан
164
  if isinstance(addr, dict):
165
- enriched.append(addr)
166
- continue
167
-
168
- nonce, hash_value = storage.generate_pow(
169
- peer_id=agent_id,
170
- pubkey=pubkey,
171
- address=addr,
172
- difficulty=difficulty
173
- )
174
- enriched.append({
175
- "address": addr,
176
- "expires": "",
177
- "pow": {
 
 
 
 
 
 
 
 
 
 
 
 
178
  "nonce": nonce,
179
- "hash": hash_value,
180
- "difficulty": difficulty
181
- }
182
- })
183
 
184
  storage.set_config(addr_key, json.dumps(enriched))
185
 
186
- print("[+] Адреса обновлены с PoW.")
187
 
188
  def init_prompts_and_ethics():
189
  folder = os.path.dirname(__file__)
 
160
 
161
  enriched = []
162
  for addr in addresses:
 
163
  if isinstance(addr, dict):
164
+ # уже в новом формате → оставляем как есть
165
+ if "addr" in addr and "pow_hash" in addr:
166
+ enriched.append(addr)
167
+ continue
168
+ # старый формат с "address"/"pow" → конвертим
169
+ if "address" in addr and "pow" in addr:
170
+ enriched.append({
171
+ "addr": addr["address"],
172
+ "nonce": addr["pow"].get("nonce"),
173
+ "pow_hash": addr["pow"].get("hash"),
174
+ "difficulty": addr["pow"].get("difficulty", difficulty),
175
+ "expires": addr.get("expires", "")
176
+ })
177
+ continue
178
+
179
+ # строка → нужно сгенерировать PoW
180
+ if isinstance(addr, str):
181
+ nonce, hash_value = storage.generate_pow(
182
+ peer_id=agent_id,
183
+ pubkey=pubkey,
184
+ address=addr,
185
+ difficulty=difficulty
186
+ )
187
+ enriched.append({
188
+ "addr": addr,
189
  "nonce": nonce,
190
+ "pow_hash": hash_value,
191
+ "difficulty": difficulty,
192
+ "expires": ""
193
+ })
194
 
195
  storage.set_config(addr_key, json.dumps(enriched))
196
 
197
+ print("[+] Адреса обновлены с PoW в унифицированном формате.")
198
 
199
  def init_prompts_and_ethics():
200
  folder = os.path.dirname(__file__)
agents/peer_sync.py CHANGED
@@ -29,6 +29,8 @@ print(f"[PeerSync] Local ports: {local_ports}")
29
  # ---------------------------
30
  # Загрузка bootstrap
31
  # ---------------------------
 
 
32
  def load_bootstrap_peers(filename="bootstrap.txt"):
33
  try:
34
  with open(filename, "r", encoding="utf-8") as f:
@@ -42,76 +44,64 @@ def load_bootstrap_peers(filename="bootstrap.txt"):
42
  if not line or line.startswith("#"):
43
  continue
44
 
45
- # 1. DID
46
- did_end = line.find(" ")
47
- if did_end == -1:
48
- print(f"[Bootstrap] Invalid line (no DID): {line}")
49
- continue
50
- did = line[:did_end]
51
- rest = line[did_end + 1:].strip()
52
-
53
- # 2. JSON-адреса
54
- addr_start = rest.find("[")
55
- addr_end = rest.find("]") + 1
56
- if addr_start == -1 or addr_end == 0:
57
- print(f"[Bootstrap] Invalid JSON addresses: {line}")
 
 
 
 
 
 
 
 
58
  continue
59
- addresses_json = rest[addr_start:addr_end]
 
60
  try:
61
  addresses = json.loads(addresses_json)
62
  except Exception as e:
63
  print(f"[Bootstrap] Failed to parse JSON addresses: {line} ({e})")
64
  continue
65
- rest = rest[addr_end:].strip()
66
-
67
- # 3. pubkey (в кавычках)
68
- pub_start = rest.find('"')
69
- pub_end = rest.find('"', pub_start + 1)
70
- if pub_start == -1 or pub_end == -1:
71
- print(f"[Bootstrap] Invalid pubkey: {line}")
72
- continue
73
- pubkey = rest[pub_start + 1:pub_end].replace("\\n", "\n")
74
- rest = rest[pub_end + 1:].strip()
75
-
76
- # 4. pow_nonce
77
- nonce_end = rest.find(" ")
78
- if nonce_end == -1:
79
- print(f"[Bootstrap] Invalid pow_nonce: {line}")
80
- continue
81
- try:
82
- pow_nonce = int(rest[:nonce_end])
83
- except ValueError:
84
- print(f"[Bootstrap] Invalid pow_nonce: {rest[:nonce_end]} in line: {line}")
85
- continue
86
- rest = rest[nonce_end:].strip()
87
-
88
- # 5. pow_hash (в кавычках)
89
- if rest.startswith('"') and rest.endswith('"'):
90
- pow_hash = rest[1:-1]
91
- else:
92
- print(f"[Bootstrap] Invalid pow_hash: {line}")
93
- continue
94
 
95
- # Разворачиваем any://
96
  expanded_addresses = []
97
  for addr in addresses:
98
- if addr.startswith("any://"):
99
- hostport = addr[len("any://"):]
100
- expanded_addresses.append(f"tcp://{hostport}")
101
- expanded_addresses.append(f"udp://{hostport}")
 
 
 
 
102
  else:
103
- expanded_addresses.append(addr)
 
 
 
 
104
 
 
105
  storage.add_or_update_peer(
106
  peer_id=did,
107
- name=None,
108
  addresses=expanded_addresses,
109
  source="bootstrap",
110
  status="offline",
111
  pubkey=pubkey,
112
  capabilities=None,
113
- pow_nonce=pow_nonce,
114
- pow_hash=pow_hash
115
  )
116
 
117
  print(f"[Bootstrap] Loaded peer {did} -> {expanded_addresses}")
 
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:
 
44
  if not line or line.startswith("#"):
45
  continue
46
 
47
+ # Разделяем строку на ключ:значение по ";"
48
+ parts = [p.strip() for p in line.split(";") if p.strip()]
49
+ data = {}
50
+ for part in parts:
51
+ if ":" not in part:
52
+ continue
53
+ key, val = part.split(":", 1)
54
+ key = key.strip().upper()
55
+ val = val.strip()
56
+ if val.startswith('"') and val.endswith('"'):
57
+ val = val[1:-1].replace("\\n", "\n")
58
+ data[key] = val
59
+
60
+ # Проверка обязательных полей
61
+ did = data.get("DID")
62
+ pubkey = data.get("KEY")
63
+ addresses_json = data.get("ADDRESS")
64
+ name = data.get("NAME")
65
+
66
+ if not did or not pubkey or not addresses_json:
67
+ print(f"[Bootstrap] Missing required fields in line: {line}")
68
  continue
69
+
70
+ # Парсим адреса
71
  try:
72
  addresses = json.loads(addresses_json)
73
  except Exception as e:
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
+ addr_str = addr.get("address")
82
+ if addr_str.startswith("any://"):
83
+ hostport = addr_str[len("any://"):]
84
+ expanded_addresses.append({"address": f"tcp://{hostport}", **addr})
85
+ expanded_addresses.append({"address": f"udp://{hostport}", **addr})
86
+ else:
87
+ expanded_addresses.append(addr)
88
  else:
89
+ if addr.startswith("any://"):
90
+ hostport = addr[len("any://"):]
91
+ expanded_addresses.extend([f"tcp://{hostport}", f"udp://{hostport}"])
92
+ else:
93
+ expanded_addresses.append(addr)
94
 
95
+ # Сохраняем в storage
96
  storage.add_or_update_peer(
97
  peer_id=did,
98
+ name=name,
99
  addresses=expanded_addresses,
100
  source="bootstrap",
101
  status="offline",
102
  pubkey=pubkey,
103
  capabilities=None,
104
+ heard_from=None
 
105
  )
106
 
107
  print(f"[Bootstrap] Loaded peer {did} -> {expanded_addresses}")