Spaces:
Paused
Paused
Update engine.py
Browse files
engine.py
CHANGED
|
@@ -459,7 +459,16 @@ settings = {
|
|
| 459 |
ses = lt.session(settings)
|
| 460 |
|
| 461 |
|
| 462 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
|
| 464 |
@app.route('/inject_peers', methods=['POST'])
|
| 465 |
def inject_peers():
|
|
@@ -619,19 +628,31 @@ def process_and_queue(filepath, target_u_id, start_chunk, end_chunk, chunk_size,
|
|
| 619 |
flush_batch(batch_state, f"Vaulting 4.5GB dynamic meta batch")
|
| 620 |
|
| 621 |
def continuous_peer_pulse(u_id, info_hash, trackers, handle, peer_id):
|
| 622 |
-
"""Silently tops off the peer list every
|
| 623 |
while True:
|
| 624 |
-
time.sleep(
|
| 625 |
try:
|
| 626 |
# Stop pulsing if the download is finished, killed, or stalled
|
| 627 |
if u_id not in active_vaults or handle.status().state in [lt.torrent_status.seeding, lt.torrent_status.finished]:
|
| 628 |
break
|
| 629 |
|
| 630 |
-
print(f"[PULSE]
|
|
|
|
|
|
|
| 631 |
force_inject_peers(info_hash, trackers, handle, peer_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
except Exception:
|
| 633 |
break
|
| 634 |
|
|
|
|
| 635 |
def do_archive(u_id, info_hash, part=1, total=1, is_series=False, priority_idx=-1):
|
| 636 |
handle = None
|
| 637 |
scout_status[u_id] = "active"
|
|
@@ -934,4 +955,4 @@ def delete_season(imdb_id, season_name):
|
|
| 934 |
|
| 935 |
|
| 936 |
if __name__ == "__main__":
|
| 937 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 459 |
ses = lt.session(settings)
|
| 460 |
|
| 461 |
|
| 462 |
+
@app.route('/get_peers/<u_id>')
|
| 463 |
+
def get_peers(u_id):
|
| 464 |
+
"""Exposes connected peers so other engines can scrape them."""
|
| 465 |
+
handle = active_handles.get(u_id)
|
| 466 |
+
if not handle: return jsonify({"peers": []})
|
| 467 |
+
|
| 468 |
+
# Extract the raw IP and Port of every connected peer
|
| 469 |
+
peer_list = [{"ip": p.ip[0], "port": p.ip[1]} for p in handle.get_peer_info()]
|
| 470 |
+
return jsonify({"peers": peer_list})
|
| 471 |
+
|
| 472 |
|
| 473 |
@app.route('/inject_peers', methods=['POST'])
|
| 474 |
def inject_peers():
|
|
|
|
| 628 |
flush_batch(batch_state, f"Vaulting 4.5GB dynamic meta batch")
|
| 629 |
|
| 630 |
def continuous_peer_pulse(u_id, info_hash, trackers, handle, peer_id):
|
| 631 |
+
"""Silently tops off the peer list every 60 seconds and syncs with the cluster!"""
|
| 632 |
while True:
|
| 633 |
+
time.sleep(120) # ⚡ Sped up to 60 seconds for Cross-Engine Sync
|
| 634 |
try:
|
| 635 |
# Stop pulsing if the download is finished, killed, or stalled
|
| 636 |
if u_id not in active_vaults or handle.status().state in [lt.torrent_status.seeding, lt.torrent_status.finished]:
|
| 637 |
break
|
| 638 |
|
| 639 |
+
print(f"[PULSE] 🧠 Syncing Swarm Brain for {u_id[:8]}...", flush=True)
|
| 640 |
+
|
| 641 |
+
# 1. Standard Tracker Pulse
|
| 642 |
force_inject_peers(info_hash, trackers, handle, peer_id)
|
| 643 |
+
|
| 644 |
+
# 2. ⚡ THE SWARM BRAIN: Fetch peers from sibling engines
|
| 645 |
+
for url in ENGINE_URLS:
|
| 646 |
+
try:
|
| 647 |
+
res = requests.get(f"{url}/get_peers/{u_id}", timeout=2).json()
|
| 648 |
+
for p in res.get("peers", []):
|
| 649 |
+
try: handle.connect_peer((p['ip'], int(p['port'])), 1)
|
| 650 |
+
except: pass
|
| 651 |
+
except: pass
|
| 652 |
except Exception:
|
| 653 |
break
|
| 654 |
|
| 655 |
+
|
| 656 |
def do_archive(u_id, info_hash, part=1, total=1, is_series=False, priority_idx=-1):
|
| 657 |
handle = None
|
| 658 |
scout_status[u_id] = "active"
|
|
|
|
| 955 |
|
| 956 |
|
| 957 |
if __name__ == "__main__":
|
| 958 |
+
app.run(host="0.0.0.0", port=7860, threaded=True)
|