elo-node 0.4.1__tar.gz → 0.4.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {elo_node-0.4.1 → elo_node-0.4.3}/PKG-INFO +1 -1
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/__init__.py +1 -1
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/node.py +78 -5
- {elo_node-0.4.1 → elo_node-0.4.3}/elo_node.egg-info/PKG-INFO +1 -1
- {elo_node-0.4.1 → elo_node-0.4.3}/pyproject.toml +1 -1
- {elo_node-0.4.1 → elo_node-0.4.3}/README.md +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/__main__.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/security.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/transport/__init__.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/transport/protocol.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/transport/routing.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/transport/tcp.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/transport/tracker.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo/types.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo_node.egg-info/SOURCES.txt +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo_node.egg-info/dependency_links.txt +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo_node.egg-info/entry_points.txt +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo_node.egg-info/requires.txt +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/elo_node.egg-info/top_level.txt +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/setup.cfg +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/tests/test_security.py +0 -0
- {elo_node-0.4.1 → elo_node-0.4.3}/tests/test_unit.py +0 -0
|
@@ -78,7 +78,7 @@ class Node:
|
|
|
78
78
|
peers: list[str] | None = None,
|
|
79
79
|
tracker: str = "public",
|
|
80
80
|
allowlist: list[str] | None = None,
|
|
81
|
-
version: str = "0.4.
|
|
81
|
+
version: str = "0.4.3",
|
|
82
82
|
identity: EphemeralIdentity | None = None,
|
|
83
83
|
verify_peers: bool = True,
|
|
84
84
|
heartbeat_interval_s: int = 30,
|
|
@@ -293,11 +293,42 @@ class Node:
|
|
|
293
293
|
# ── descoberta ─────────────────────────────────────────────
|
|
294
294
|
|
|
295
295
|
async def discover_peers(self) -> list[dict[str, Any]]:
|
|
296
|
-
|
|
296
|
+
"""Return all known peers with capabilities.
|
|
297
|
+
|
|
298
|
+
Merges data from TCP connections (live) and InterestTable (registered).
|
|
299
|
+
"""
|
|
300
|
+
result: dict[str, dict[str, Any]] = {}
|
|
301
|
+
|
|
302
|
+
# From TCP connections — live peers
|
|
297
303
|
for addr in self._tcp.peer_addresses:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
304
|
+
result[addr] = {"addr": addr, "connected": True, "caps": [], "via": "tcp"}
|
|
305
|
+
|
|
306
|
+
# From InterestTable — peers that completed HELLO handshake
|
|
307
|
+
for addr in self._routing.known_peers:
|
|
308
|
+
caps = list(self._routing.get_peer_caps(addr).get("caps", set()))
|
|
309
|
+
if addr in result:
|
|
310
|
+
result[addr]["caps"] = caps
|
|
311
|
+
result[addr]["via"] = "both"
|
|
312
|
+
else:
|
|
313
|
+
result[addr] = {"addr": addr, "connected": False, "caps": caps, "via": "routing"}
|
|
314
|
+
|
|
315
|
+
return list(result.values())
|
|
316
|
+
|
|
317
|
+
def get_known_peers(self) -> list[dict[str, Any]]:
|
|
318
|
+
"""Return peers registered in InterestTable (completed HELLO handshake).
|
|
319
|
+
|
|
320
|
+
More reliable than discover_peers() — only includes peers that
|
|
321
|
+
completed the full handshake (HELLO + HELLO_ACK).
|
|
322
|
+
Meant for tracker/discovery use cases.
|
|
323
|
+
"""
|
|
324
|
+
result = []
|
|
325
|
+
for addr in self._routing.known_peers:
|
|
326
|
+
info = self._routing.get_peer_caps(addr)
|
|
327
|
+
result.append({
|
|
328
|
+
"addr": addr,
|
|
329
|
+
"caps": list(info.get("caps", set())),
|
|
330
|
+
"interests": list(info.get("interests", set())),
|
|
331
|
+
})
|
|
301
332
|
return result
|
|
302
333
|
|
|
303
334
|
# ── run loop ──────────────────────────────────────────────
|
|
@@ -448,6 +479,48 @@ class Node:
|
|
|
448
479
|
async def _on_bye(self, peer_addr: str, msg: dict) -> None:
|
|
449
480
|
self._routing.remove_peer(peer_addr)
|
|
450
481
|
|
|
482
|
+
# ── relay via tracker ───────────────────────────────────
|
|
483
|
+
|
|
484
|
+
async def send_task_via_tracker(
|
|
485
|
+
self,
|
|
486
|
+
tracker_node: str,
|
|
487
|
+
target: str,
|
|
488
|
+
capability: str,
|
|
489
|
+
payload: dict[str, Any],
|
|
490
|
+
*,
|
|
491
|
+
ttl_s: int = 60,
|
|
492
|
+
) -> Result:
|
|
493
|
+
"""Send a task via tracker relay (for peers behind NAT/Docker).
|
|
494
|
+
|
|
495
|
+
Args:
|
|
496
|
+
tracker_node: node_id or addr of tracker (empty = auto)
|
|
497
|
+
target: node_id prefix or name of the destination
|
|
498
|
+
capability: capability to invoke on destination
|
|
499
|
+
payload: task payload
|
|
500
|
+
"""
|
|
501
|
+
task_id = str(uuid.uuid4())
|
|
502
|
+
relay_payload = {
|
|
503
|
+
"target": target,
|
|
504
|
+
"capability": capability,
|
|
505
|
+
"payload": payload,
|
|
506
|
+
"ttl_s": ttl_s,
|
|
507
|
+
}
|
|
508
|
+
task_dict = p2p_task_msg(
|
|
509
|
+
task_id, tracker_node or "", self._node_id, "relay", relay_payload
|
|
510
|
+
)
|
|
511
|
+
task_dict.pop("signature", None)
|
|
512
|
+
task_dict["signature"] = self._identity.sign(task_dict)
|
|
513
|
+
|
|
514
|
+
peer = tracker_node or self._routing.find_peer_for("relay")
|
|
515
|
+
if peer:
|
|
516
|
+
try:
|
|
517
|
+
await self._tcp.send_to(peer, task_dict)
|
|
518
|
+
return await self._wait_for_result(task_id, peer)
|
|
519
|
+
except Exception as e:
|
|
520
|
+
return Result.make_error(task_id, "RELAY_ERROR", str(e))
|
|
521
|
+
|
|
522
|
+
return Result.make_error(task_id, "NO_TRACKER", "No tracker peer found")
|
|
523
|
+
|
|
451
524
|
# ── helpers ───────────────────────────────────────────────
|
|
452
525
|
|
|
453
526
|
async def _wait_for_result(self, task_id: str, peer_addr: str) -> Result:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|