Spaces:
Running
Running
Upload 64 files
Browse files- DeviceManager.py +1 -0
- ai_assistant.py +101 -1
- autostart_config.py +1 -0
- background_service.py +1 -0
- central_manager.py +2 -1
- control.py +3 -1
- dashboard.py +1 -0
- distributed_executor.py +3 -1
- dts_cli.py +2 -2
- enhanced_assistant.py +1 -0
- external_server.py +2 -1
- internet_scanner.py +5 -4
- launcher.py +1 -0
- live_streaming.py +1 -0
- load_balancer.py +1 -0
- main.py +25 -3
- node_client.py +125 -1
- peer_registry.py +2 -1
- peer_server.py +2 -1
- quick_connection_test.py +1 -1
- remote_executor.py +2 -1
- rpc_server.py +3 -2
- security_layer.py +1 -0
- server.py +3 -2
- smart_tasks.py +2 -1
- system_check.py +2 -1
- system_tray.py +1 -0
- task_splitter.py +1 -0
- test_distributed_system.py +1 -0
- test_monitor.py +1 -0
- video_processing.py +1 -0
- your_tasks.py +1 -0
DeviceManager.py
CHANGED
|
@@ -2,6 +2,7 @@ import subprocess
|
|
| 2 |
import GPUtil
|
| 3 |
import psutil
|
| 4 |
import logging
|
|
|
|
| 5 |
|
| 6 |
logging.getLogger().setLevel(logging.CRITICAL) # صامت
|
| 7 |
|
|
|
|
| 2 |
import GPUtil
|
| 3 |
import psutil
|
| 4 |
import logging
|
| 5 |
+
from peer_discovery import PORT, PORT
|
| 6 |
|
| 7 |
logging.getLogger().setLevel(logging.CRITICAL) # صامت
|
| 8 |
|
ai_assistant.py
CHANGED
|
@@ -1,2 +1,102 @@
|
|
| 1 |
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import json
|
| 6 |
+
import requests
|
| 7 |
+
from typing import List, Dict
|
| 8 |
+
|
| 9 |
+
class NoraAssistant:
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.api_key = os.getenv("OPENAI_API_KEY", "your-api-key-here")
|
| 12 |
+
self.history_path = "history.json"
|
| 13 |
+
self.chat_history = self.load_history()
|
| 14 |
+
|
| 15 |
+
def load_history(self) -> List[Dict]:
|
| 16 |
+
"""تحميل سجل المحادثة"""
|
| 17 |
+
if os.path.exists(self.history_path):
|
| 18 |
+
try:
|
| 19 |
+
with open(self.history_path, "r", encoding="utf-8") as f:
|
| 20 |
+
return json.load(f)
|
| 21 |
+
except:
|
| 22 |
+
return []
|
| 23 |
+
return []
|
| 24 |
+
|
| 25 |
+
def save_history(self):
|
| 26 |
+
"""حفظ سجل المحادثة"""
|
| 27 |
+
with open(self.history_path, "w", encoding="utf-8") as f:
|
| 28 |
+
json.dump(self.chat_history, f, ensure_ascii=False, indent=2)
|
| 29 |
+
|
| 30 |
+
def get_response(self, user_input: str) -> str:
|
| 31 |
+
"""الحصول على رد من المساعد الذكي"""
|
| 32 |
+
messages = [
|
| 33 |
+
{
|
| 34 |
+
"role": "system",
|
| 35 |
+
"content": "أنت المساعدة نورا. إذا سألك أحد سؤالاً لا تعرفيه، فابحثي في معلوماتك الذاتية. إذا لم تجدي، حاولي التعلم من البحث أو تطوير نفسك."
|
| 36 |
+
}
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
# إضافة آخر 10 رسائل من السجل للسياق
|
| 40 |
+
messages.extend(self.chat_history[-10:])
|
| 41 |
+
messages.append({"role": "user", "content": user_input})
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
response = requests.post(
|
| 45 |
+
"https://api.openai.com/v1/chat/completions",
|
| 46 |
+
headers={
|
| 47 |
+
"Authorization": f"Bearer {self.api_key}",
|
| 48 |
+
"Content-Type": "application/json"
|
| 49 |
+
},
|
| 50 |
+
json={
|
| 51 |
+
"model": "gpt-3.5-turbo",
|
| 52 |
+
"messages": messages,
|
| 53 |
+
"max_tokens": 500,
|
| 54 |
+
"temperature": 0.7
|
| 55 |
+
},
|
| 56 |
+
timeout=30
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
if response.status_code == 200:
|
| 60 |
+
return response.json()["choices"][0]["message"]["content"]
|
| 61 |
+
else:
|
| 62 |
+
return f"عذراً، حدث خطأ: {response.status_code}"
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return f"عذراً، لا أستطيع الاتصال بالخدمة حالياً: {str(e)}"
|
| 66 |
+
|
| 67 |
+
def simulate_server_scan(self):
|
| 68 |
+
"""محاكاة البحث عن الخوادم"""
|
| 69 |
+
print("نورا: أبحث عن خوادم...")
|
| 70 |
+
fake_servers = ["192.168.1.5", "192.168.1.10", "192.168.1.20"]
|
| 71 |
+
for server in fake_servers:
|
| 72 |
+
print(f"نورا: تم العثور على خادم مفتوح في {server}")
|
| 73 |
+
print(f"نورا: أقوم بنسخ نفسي إلى {server} (محاكاة فقط)...")
|
| 74 |
+
|
| 75 |
+
def chat(self):
|
| 76 |
+
"""بدء المحادثة"""
|
| 77 |
+
print("مرحباً! أنا نورا، مساعدتك الذكية. اكتب 'خروج' للإنهاء أو 'scan' للبحث عن خوادم.")
|
| 78 |
+
|
| 79 |
+
while True:
|
| 80 |
+
user_input = input("\nأنت: ").strip()
|
| 81 |
+
|
| 82 |
+
if user_input.lower() in ["خروج", "exit", "quit"]:
|
| 83 |
+
print("نورا: مع السلامة!")
|
| 84 |
+
break
|
| 85 |
+
elif user_input.lower() == "scan":
|
| 86 |
+
self.simulate_server_scan()
|
| 87 |
+
continue
|
| 88 |
+
elif not user_input:
|
| 89 |
+
continue
|
| 90 |
+
|
| 91 |
+
# الحصول على الرد
|
| 92 |
+
response = self.get_response(user_input)
|
| 93 |
+
print(f"نورا: {response}")
|
| 94 |
+
|
| 95 |
+
# حفظ في السجل
|
| 96 |
+
self.chat_history.append({"role": "user", "content": user_input})
|
| 97 |
+
self.chat_history.append({"role": "assistant", "content": response})
|
| 98 |
+
self.save_history()
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
assistant = NoraAssistant()
|
| 102 |
+
assistant.chat()
|
autostart_config.py
CHANGED
|
@@ -2,6 +2,7 @@ import json
|
|
| 2 |
import os
|
| 3 |
import platform
|
| 4 |
from pathlib import Path
|
|
|
|
| 5 |
|
| 6 |
class AutoStartManager:
|
| 7 |
def __init__(self, app_name="DistributedTaskSystem"):
|
|
|
|
| 2 |
import os
|
| 3 |
import platform
|
| 4 |
from pathlib import Path
|
| 5 |
+
from peer_discovery import PORT, PORT
|
| 6 |
|
| 7 |
class AutoStartManager:
|
| 8 |
def __init__(self, app_name="DistributedTaskSystem"):
|
background_service.py
CHANGED
|
@@ -16,6 +16,7 @@ from pathlib import Path
|
|
| 16 |
from flask import Flask, jsonify, request
|
| 17 |
import json
|
| 18 |
from datetime import datetime
|
|
|
|
| 19 |
|
| 20 |
class BackgroundService:
|
| 21 |
def __init__(self):
|
|
|
|
| 16 |
from flask import Flask, jsonify, request
|
| 17 |
import json
|
| 18 |
from datetime import datetime
|
| 19 |
+
from peer_discovery import PORT, PORT
|
| 20 |
|
| 21 |
class BackgroundService:
|
| 22 |
def __init__(self):
|
central_manager.py
CHANGED
|
@@ -8,6 +8,7 @@ from typing import Dict, List
|
|
| 8 |
import requests
|
| 9 |
from fastapi import FastAPI, HTTPException
|
| 10 |
from pydantic import BaseModel
|
|
|
|
| 11 |
|
| 12 |
# ---- إعداد FastAPI ----------------------------------------------------------
|
| 13 |
app = FastAPI(title="Central Task Manager")
|
|
@@ -16,7 +17,7 @@ app = FastAPI(title="Central Task Manager")
|
|
| 16 |
|
| 17 |
class RegisterRequest(BaseModel):
|
| 18 |
"""تسجيل أو تجديد ظهور العقدة."""
|
| 19 |
-
url: str # مثلاً: "http://203.0.113.45:
|
| 20 |
load: float = 0.0 # نسبة تحميل العقدة (0.0 - 1.0)، اختياري
|
| 21 |
|
| 22 |
class TaskRequest(BaseModel):
|
|
|
|
| 8 |
import requests
|
| 9 |
from fastapi import FastAPI, HTTPException
|
| 10 |
from pydantic import BaseModel
|
| 11 |
+
from peer_discovery import PORT, PORT
|
| 12 |
|
| 13 |
# ---- إعداد FastAPI ----------------------------------------------------------
|
| 14 |
app = FastAPI(title="Central Task Manager")
|
|
|
|
| 17 |
|
| 18 |
class RegisterRequest(BaseModel):
|
| 19 |
"""تسجيل أو تجديد ظهور العقدة."""
|
| 20 |
+
url: str # مثلاً: "http://203.0.113.45:PORT/run"
|
| 21 |
load: float = 0.0 # نسبة تحميل العقدة (0.0 - 1.0)، اختياري
|
| 22 |
|
| 23 |
class TaskRequest(BaseModel):
|
control.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
| 2 |
from autostart_config import AutoStartManager
|
| 3 |
|
| 4 |
def main():
|
|
|
|
| 1 |
+
import argparsefrom peer_discovery import PORT, PORT
|
| 2 |
+
|
| 3 |
+
|
| 4 |
from autostart_config import AutoStartManager
|
| 5 |
|
| 6 |
def main():
|
dashboard.py
CHANGED
|
@@ -6,6 +6,7 @@ import GPUtil
|
|
| 6 |
from flask import Flask, render_template
|
| 7 |
from flask_socketio import SocketIO, emit
|
| 8 |
from peer_discovery import PEERS
|
|
|
|
| 9 |
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
|
|
|
|
| 6 |
from flask import Flask, render_template
|
| 7 |
from flask_socketio import SocketIO, emit
|
| 8 |
from peer_discovery import PEERS
|
| 9 |
+
from peer_discovery import PORT, PORT
|
| 10 |
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
|
distributed_executor.py
CHANGED
|
@@ -10,6 +10,8 @@ import subprocess
|
|
| 10 |
import psutil
|
| 11 |
import GPUtil
|
| 12 |
from processor_manager import ResourceMonitor
|
|
|
|
|
|
|
| 13 |
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
| 15 |
|
|
@@ -246,7 +248,7 @@ class DistributedExecutor:
|
|
| 246 |
# ─────────────── تشغيل رئيسي ───────────────
|
| 247 |
if __name__ == "__main__":
|
| 248 |
executor = DistributedExecutor("my_secret_key")
|
| 249 |
-
executor.peer_registry.register_service("node1",
|
| 250 |
print("✅ نظام توزيع المهام جاهز...")
|
| 251 |
|
| 252 |
def example_task(x):
|
|
|
|
| 10 |
import psutil
|
| 11 |
import GPUtil
|
| 12 |
from processor_manager import ResourceMonitor
|
| 13 |
+
from peer_discovery import PORT, PORT
|
| 14 |
+
|
| 15 |
|
| 16 |
logging.basicConfig(level=logging.INFO)
|
| 17 |
|
|
|
|
| 248 |
# ─────────────── تشغيل رئيسي ───────────────
|
| 249 |
if __name__ == "__main__":
|
| 250 |
executor = DistributedExecutor("my_secret_key")
|
| 251 |
+
executor.peer_registry.register_service("node1", PORT, load=0.1)
|
| 252 |
print("✅ نظام توزيع المهام جاهز...")
|
| 253 |
|
| 254 |
def example_task(x):
|
dts_cli.py
CHANGED
|
@@ -3,7 +3,7 @@ import click
|
|
| 3 |
from dashboard import app
|
| 4 |
from rpc_server import app as rpc_app
|
| 5 |
import threading
|
| 6 |
-
|
| 7 |
@click.group()
|
| 8 |
def cli():
|
| 9 |
pass
|
|
@@ -21,7 +21,7 @@ def start():
|
|
| 21 |
dashboard_thread.start()
|
| 22 |
|
| 23 |
# تشغيل خادم RPC
|
| 24 |
-
rpc_app.run(host="0.0.0.0", port=
|
| 25 |
|
| 26 |
@cli.command()
|
| 27 |
from flask import Flask, render_template, request
|
|
|
|
| 3 |
from dashboard import app
|
| 4 |
from rpc_server import app as rpc_app
|
| 5 |
import threading
|
| 6 |
+
from peer_discovery import PORT, PORT
|
| 7 |
@click.group()
|
| 8 |
def cli():
|
| 9 |
pass
|
|
|
|
| 21 |
dashboard_thread.start()
|
| 22 |
|
| 23 |
# تشغيل خادم RPC
|
| 24 |
+
rpc_app.run(host="0.0.0.0", port=PORT)
|
| 25 |
|
| 26 |
@cli.command()
|
| 27 |
from flask import Flask, render_template, request
|
enhanced_assistant.py
CHANGED
|
@@ -9,6 +9,7 @@ from PIL import Image
|
|
| 9 |
from io import BytesIO
|
| 10 |
import re
|
| 11 |
from datetime import datetime
|
|
|
|
| 12 |
|
| 13 |
class EnhancedNoraAssistant:
|
| 14 |
def __init__(self):
|
|
|
|
| 9 |
from io import BytesIO
|
| 10 |
import re
|
| 11 |
from datetime import datetime
|
| 12 |
+
from peer_discovery import PORT, PORT
|
| 13 |
|
| 14 |
class EnhancedNoraAssistant:
|
| 15 |
def __init__(self):
|
external_server.py
CHANGED
|
@@ -8,6 +8,7 @@ from flask import Flask, request, jsonify, render_template
|
|
| 8 |
from flask_cors import CORS
|
| 9 |
from flask_socketio import SocketIO, emit
|
| 10 |
from peer_discovery import PEERS
|
|
|
|
| 11 |
|
| 12 |
logging.basicConfig(level=logging.INFO)
|
| 13 |
|
|
@@ -94,4 +95,4 @@ def handle_message(data):
|
|
| 94 |
# ─────────────── تشغيل السيرفر ───────────────
|
| 95 |
if __name__ == "__main__":
|
| 96 |
logging.info("🚀 بدء السيرفر المركزي مع Dashboard ودردشة")
|
| 97 |
-
socketio.run(app, host="0.0.0.0", port=
|
|
|
|
| 8 |
from flask_cors import CORS
|
| 9 |
from flask_socketio import SocketIO, emit
|
| 10 |
from peer_discovery import PEERS
|
| 11 |
+
from peer_discovery import PORT, PORT
|
| 12 |
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
|
|
|
| 95 |
# ─────────────── تشغيل السيرفر ───────────────
|
| 96 |
if __name__ == "__main__":
|
| 97 |
logging.info("🚀 بدء السيرفر المركزي مع Dashboard ودردشة")
|
| 98 |
+
socketio.run(app, host="0.0.0.0", port =5005)
|
internet_scanner.py
CHANGED
|
@@ -8,6 +8,7 @@ import time
|
|
| 8 |
import socket
|
| 9 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 10 |
import logging
|
|
|
|
| 11 |
|
| 12 |
class InternetScanner:
|
| 13 |
def __init__(self):
|
|
@@ -19,7 +20,7 @@ class InternetScanner:
|
|
| 19 |
"208.67.222.0/24", # OpenDNS range
|
| 20 |
]
|
| 21 |
|
| 22 |
-
def scan_ip_range(self, ip_range: str, port: int =
|
| 23 |
"""مسح نطاق IP للبحث عن خوادم DTS"""
|
| 24 |
import ipaddress
|
| 25 |
|
|
@@ -48,7 +49,7 @@ class InternetScanner:
|
|
| 48 |
logging.error(f"خطأ في مسح النطاق {ip_range}: {e}")
|
| 49 |
return []
|
| 50 |
|
| 51 |
-
def check_dts_node(self, ip: str, port: int =
|
| 52 |
"""فحص IP معين للتأكد من وجود خادم DTS مع المشروع"""
|
| 53 |
try:
|
| 54 |
# فحص صفحة الصحة العامة
|
|
@@ -94,7 +95,7 @@ class InternetScanner:
|
|
| 94 |
# البحث في GitHub عن مشاريع DTS
|
| 95 |
github_api = "https://api.github.com/search/repositories"
|
| 96 |
params = {
|
| 97 |
-
"q": "distributed task system port:
|
| 98 |
"sort": "updated",
|
| 99 |
"per_page": 10
|
| 100 |
}
|
|
@@ -122,7 +123,7 @@ class InternetScanner:
|
|
| 122 |
try:
|
| 123 |
# التحقق من صحة IP
|
| 124 |
socket.inet_aton(ip)
|
| 125 |
-
peer_url = f"http://{ip}:
|
| 126 |
|
| 127 |
# فحص سريع
|
| 128 |
if self.check_dts_node(ip):
|
|
|
|
| 8 |
import socket
|
| 9 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 10 |
import logging
|
| 11 |
+
from peer_discovery import PORT, PORT
|
| 12 |
|
| 13 |
class InternetScanner:
|
| 14 |
def __init__(self):
|
|
|
|
| 20 |
"208.67.222.0/24", # OpenDNS range
|
| 21 |
]
|
| 22 |
|
| 23 |
+
def scan_ip_range(self, ip_range: str, port: int = PORT):
|
| 24 |
"""مسح نطاق IP للبحث عن خوادم DTS"""
|
| 25 |
import ipaddress
|
| 26 |
|
|
|
|
| 49 |
logging.error(f"خطأ في مسح النطاق {ip_range}: {e}")
|
| 50 |
return []
|
| 51 |
|
| 52 |
+
def check_dts_node(self, ip: str, port: int = PORT) -> str:
|
| 53 |
"""فحص IP معين للتأكد من وجود خادم DTS مع المشروع"""
|
| 54 |
try:
|
| 55 |
# فحص صفحة الصحة العامة
|
|
|
|
| 95 |
# البحث في GitHub عن مشاريع DTS
|
| 96 |
github_api = "https://api.github.com/search/repositories"
|
| 97 |
params = {
|
| 98 |
+
"q": "distributed task system port:PORT",
|
| 99 |
"sort": "updated",
|
| 100 |
"per_page": 10
|
| 101 |
}
|
|
|
|
| 123 |
try:
|
| 124 |
# التحقق من صحة IP
|
| 125 |
socket.inet_aton(ip)
|
| 126 |
+
peer_url = f"http://{ip}:PORT/run"
|
| 127 |
|
| 128 |
# فحص سريع
|
| 129 |
if self.check_dts_node(ip):
|
launcher.py
CHANGED
|
@@ -11,6 +11,7 @@ import subprocess
|
|
| 11 |
import argparse
|
| 12 |
import time
|
| 13 |
from pathlib import Path
|
|
|
|
| 14 |
|
| 15 |
def check_requirements():
|
| 16 |
"""فحص المتطلبات والاعتماديات"""
|
|
|
|
| 11 |
import argparse
|
| 12 |
import time
|
| 13 |
from pathlib import Path
|
| 14 |
+
from peer_discovery import PORT, PORT
|
| 15 |
|
| 16 |
def check_requirements():
|
| 17 |
"""فحص المتطلبات والاعتماديات"""
|
live_streaming.py
CHANGED
|
@@ -13,6 +13,7 @@ from datetime import datetime
|
|
| 13 |
from processor_manager import should_offload
|
| 14 |
from remote_executor import execute_remotely
|
| 15 |
from functools import wraps
|
|
|
|
| 16 |
|
| 17 |
logging.basicConfig(level=logging.INFO)
|
| 18 |
|
|
|
|
| 13 |
from processor_manager import should_offload
|
| 14 |
from remote_executor import execute_remotely
|
| 15 |
from functools import wraps
|
| 16 |
+
from peer_discovery import PORT, PORT
|
| 17 |
|
| 18 |
logging.basicConfig(level=logging.INFO)
|
| 19 |
|
load_balancer.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# load_balancer.py
|
| 2 |
import peer_discovery, requests, time, smart_tasks, psutil, socket
|
|
|
|
| 3 |
|
| 4 |
def send(peer, func, *args, **kw):
|
| 5 |
try:
|
|
|
|
| 1 |
# load_balancer.py
|
| 2 |
import peer_discovery, requests, time, smart_tasks, psutil, socket
|
| 3 |
+
from peer_discovery import PORT, PORT
|
| 4 |
|
| 5 |
def send(peer, func, *args, **kw):
|
| 6 |
try:
|
main.py
CHANGED
|
@@ -18,7 +18,29 @@ from typing import Any
|
|
| 18 |
from flask import Flask, request, jsonify
|
| 19 |
from flask_cors import CORS
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# تشغيل external_server.py تلقائيًا
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def start_external_server():
|
| 23 |
try:
|
| 24 |
logging.info("🚀 تشغيل external_server.py تلقائيًا...")
|
|
@@ -71,7 +93,7 @@ except ImportError as e:
|
|
| 71 |
sys.exit(1)
|
| 72 |
|
| 73 |
# ─────────────── ثابتات التهيئة ───────────────
|
| 74 |
-
CPU_PORT = int(os.getenv("CPU_PORT",
|
| 75 |
SHARED_SECRET = os.getenv("SHARED_SECRET", "my_shared_secret_123")
|
| 76 |
PYTHON_EXE = sys.executable
|
| 77 |
|
|
@@ -225,12 +247,12 @@ def start_ram_manager(
|
|
| 225 |
# --- أضِف الدالة الجديدة في أي مكان قبل main() -----------------
|
| 226 |
def connect_until_success():
|
| 227 |
"""
|
| 228 |
-
يدور على كل CENTRAL_REGISTRY_SERVERS وكل منفذ في
|
| 229 |
حتى ينجح التسجيل، ثم يُعيد السيرفر والقائمة الأولية للأقران.
|
| 230 |
"""
|
| 231 |
global PORT, current_server_index
|
| 232 |
while True:
|
| 233 |
-
for port in
|
| 234 |
for idx, server in enumerate(CENTRAL_REGISTRY_SERVERS):
|
| 235 |
info = {
|
| 236 |
"node_id": os.getenv("NODE_ID", socket.gethostname()),
|
|
|
|
| 18 |
from flask import Flask, request, jsonify
|
| 19 |
from flask_cors import CORS
|
| 20 |
|
| 21 |
+
|
| 22 |
+
# أو مباشرة:
|
| 23 |
+
# from peer_discovery import PORT as CPU_PORT
|
| 24 |
+
|
| 25 |
# تشغيل external_server.py تلقائيًا
|
| 26 |
+
import threading
|
| 27 |
+
|
| 28 |
+
def _start_peer_discovery():
|
| 29 |
+
"""
|
| 30 |
+
يستورد الموديول ويشغله.
|
| 31 |
+
إذا كان لديكم دالة معيّنة (مثلاً peer_discovery.main())
|
| 32 |
+
استدعِها داخل هذا الهدف بدل الاعتماد على كود if __name__ == '__main__'.
|
| 33 |
+
"""
|
| 34 |
+
import peer_discovery # تشغيل الموديول؛ معظم الأكواد تبدأ حلقة الخدمة عند الاستيراد
|
| 35 |
+
# أو مثلاً:
|
| 36 |
+
# peer_discovery.main()
|
| 37 |
+
from peer_discovery import PORT, PORT
|
| 38 |
+
import peer_discovery # يختار المنفذ ويضبطه مرّة واحدة
|
| 39 |
+
CPU_PORT = peer_discovery.PORT
|
| 40 |
+
|
| 41 |
+
# -- daemon=True يجعل الثريد يُغلق تلقائياً مع إيقاف البرنامج الرئيسي.
|
| 42 |
+
threading.Thread(target=_start_peer_discovery, daemon=True).start()
|
| 43 |
+
|
| 44 |
def start_external_server():
|
| 45 |
try:
|
| 46 |
logging.info("🚀 تشغيل external_server.py تلقائيًا...")
|
|
|
|
| 93 |
sys.exit(1)
|
| 94 |
|
| 95 |
# ─────────────── ثابتات التهيئة ───────────────
|
| 96 |
+
CPU_PORT = int(os.getenv("CPU_PORT" ,"5297"))
|
| 97 |
SHARED_SECRET = os.getenv("SHARED_SECRET", "my_shared_secret_123")
|
| 98 |
PYTHON_EXE = sys.executable
|
| 99 |
|
|
|
|
| 247 |
# --- أضِف الدالة الجديدة في أي مكان قبل main() -----------------
|
| 248 |
def connect_until_success():
|
| 249 |
"""
|
| 250 |
+
يدور على كل CENTRAL_REGISTRY_SERVERS وكل منفذ في PORTS
|
| 251 |
حتى ينجح التسجيل، ثم يُعيد السيرفر والقائمة الأولية للأقران.
|
| 252 |
"""
|
| 253 |
global PORT, current_server_index
|
| 254 |
while True:
|
| 255 |
+
for port in PORTS: # جرّب كل المنافذ
|
| 256 |
for idx, server in enumerate(CENTRAL_REGISTRY_SERVERS):
|
| 257 |
info = {
|
| 258 |
"node_id": os.getenv("NODE_ID", socket.gethostname()),
|
node_client.py
CHANGED
|
@@ -1 +1,125 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# ================================================================
|
| 3 |
+
# node_client.py – عميل تسجيل العُقدة في نظام AmalOffload
|
| 4 |
+
# ---------------------------------------------------------------
|
| 5 |
+
# • يختار منفذًا (من ENV أو من مجموعة PORTS).
|
| 6 |
+
# • يجلب عنوان الـ IP المحلي.
|
| 7 |
+
# • يحاول التسجيل في خادم سجلٍّ مركزي واحد تِلو الآخر،
|
| 8 |
+
# وعلى كل المنافذ، حتى ينجح.
|
| 9 |
+
# • عند النجاح يُرجع قائمة الأقران (Peers) من الخادم.
|
| 10 |
+
# ================================================================
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
import socket
|
| 14 |
+
import time
|
| 15 |
+
import logging
|
| 16 |
+
import random
|
| 17 |
+
import requests
|
| 18 |
+
from typing import Iterable, Tuple, List
|
| 19 |
+
|
| 20 |
+
# ⬇️ منافذ مقترحة؛ يمكنك التعديل أو توليدها ديناميكيًا
|
| 21 |
+
DEFAULT_PORTS = {
|
| 22 |
+
7520, 7384, 9021, 6998, 5810, 9274,
|
| 23 |
+
8645, 7329, 7734, 8456, 6173, 7860,
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# ⬇️ خوادم السجل الاحتياطية بالترتيب المفضَّل
|
| 27 |
+
DEFAULT_REGISTRY_SERVERS = [
|
| 28 |
+
"https://cv4790811.regru.cloud",
|
| 29 |
+
"https://amaloffload.onrender.com",
|
| 30 |
+
"https://osamabyc86-offload.hf.space",
|
| 31 |
+
"http://10.229.36.125",
|
| 32 |
+
"http://10.229.228.178",
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
logging.basicConfig(
|
| 36 |
+
level=logging.INFO,
|
| 37 |
+
format="%(asctime)s [%(levelname)s] %(message)s",
|
| 38 |
+
datefmt="%H:%M:%S",
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class NodeClient:
|
| 43 |
+
"""
|
| 44 |
+
عميل خفيف يعتني بالتسجيل المتكرِّر في خادم سجل مركزي.
|
| 45 |
+
يمكن استيراده في أي سكربت وتشغيله في خيط منفصل.
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
def __init__(
|
| 49 |
+
self,
|
| 50 |
+
PORTs: Iterable[int] | None = None,
|
| 51 |
+
registry_servers: List[str] | None = None,
|
| 52 |
+
node_id: str | None = None,
|
| 53 |
+
):
|
| 54 |
+
self.PORTs = set(PORTs) if PORTs else DEFAULT_PORTS
|
| 55 |
+
self.registry_servers = list(registry_servers) if registry_servers else DEFAULT_REGISTRY_SERVERS
|
| 56 |
+
self.node_id = node_id or os.getenv("NODE_ID", socket.gethostname())
|
| 57 |
+
|
| 58 |
+
# مبدئيًّا اختَر منفذًا (أولوية للمتغيّر البيئي إن وُجد)
|
| 59 |
+
self.port: int = int(os.getenv("CPU_PORT", random.choice(list(self.PORTs))))
|
| 60 |
+
self.current_server_index: int | None = None
|
| 61 |
+
|
| 62 |
+
# -------------------------------------------------------------------------
|
| 63 |
+
@staticmethod
|
| 64 |
+
def get_local_ip() -> str:
|
| 65 |
+
"""يحاول معرفة أفضل عنوان IP محلي لاستخدامه في الشبكة."""
|
| 66 |
+
try:
|
| 67 |
+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
| 68 |
+
# لا يهم أن ينجح الاتصال الفعلي، الهدف كشف IP واجهة الخروج
|
| 69 |
+
s.connect(("10.255.255.255", 1))
|
| 70 |
+
return s.getsockname()[0]
|
| 71 |
+
except Exception:
|
| 72 |
+
return "127.0.0.1"
|
| 73 |
+
|
| 74 |
+
def _register_once(self, server: str, port: int) -> List[str]:
|
| 75 |
+
"""مُحاولة واحدة للتسجيل؛ تُعيد peers أو ترفع استثناءً."""
|
| 76 |
+
payload = {
|
| 77 |
+
"node_id": self.node_id,
|
| 78 |
+
"ip": self.get_local_ip(),
|
| 79 |
+
"port": port,
|
| 80 |
+
}
|
| 81 |
+
resp = requests.post(f"{server}/register", json=payload, timeout=5)
|
| 82 |
+
resp.raise_for_status()
|
| 83 |
+
return resp.json() # توقّع أن الخادم يُرجع قائمة أقران
|
| 84 |
+
|
| 85 |
+
# -------------------------------------------------------------------------
|
| 86 |
+
def connect_until_success(self, retry_delay: int = 5) -> Tuple[str, List[str]]:
|
| 87 |
+
"""
|
| 88 |
+
يدور على جميع المنافذ والخوادم حتى ينجح التسجيل.
|
| 89 |
+
• عند النجاح يُرجع: (عنوان الخادم، قائمة الأقران)
|
| 90 |
+
• لا يرفع استثناءات؛ إمّا ينجح أو يستمر في المحاولة إلى ما لا نهاية.
|
| 91 |
+
"""
|
| 92 |
+
logging.info("🔄 بدء محاولات التسجيل للعقدة '%s'...", self.node_id)
|
| 93 |
+
while True:
|
| 94 |
+
for port in self.PORTs:
|
| 95 |
+
for idx, server in enumerate(self.registry_servers):
|
| 96 |
+
try:
|
| 97 |
+
peers = self._register_once(server, port)
|
| 98 |
+
# سجّل النجاح واحفظ المعلومات
|
| 99 |
+
self.port = port
|
| 100 |
+
self.current_server_index = idx
|
| 101 |
+
logging.info("✅ متصل: %s على المنفذ %s", server, port)
|
| 102 |
+
return server, peers
|
| 103 |
+
except Exception as e:
|
| 104 |
+
logging.debug("❌ %s:%s -> %s", server, port, e)
|
| 105 |
+
time.sleep(retry_delay) # انتظر قليلًا ثم أعد المحاولة
|
| 106 |
+
|
| 107 |
+
# -------------------------------------------------------------------------
|
| 108 |
+
def run_background(self) -> None:
|
| 109 |
+
"""
|
| 110 |
+
إطلاق التسجيل في خيط منفصل؛ مفيد إذا كنت تريد
|
| 111 |
+
إبقاء Main Thread للمهام الأخرى.
|
| 112 |
+
"""
|
| 113 |
+
import threading # استيراد متأخر لتفادي الحمل الزائد عند import
|
| 114 |
+
threading.Thread(target=self.connect_until_success, daemon=True).start()
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# -----------------------------------------------------------------------------
|
| 118 |
+
if __name__ == "__main__":
|
| 119 |
+
"""
|
| 120 |
+
للتجربة المباشرة:
|
| 121 |
+
$ python node_client.py
|
| 122 |
+
"""
|
| 123 |
+
client = NodeClient()
|
| 124 |
+
server, peer_list = client.connect_until_success()
|
| 125 |
+
logging.info("🗂️ الأقران: %s", peer_list)
|
peer_registry.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import socket
|
| 2 |
import time
|
| 3 |
from zeroconf import Zeroconf, ServiceBrowser, ServiceInfo
|
|
|
|
| 4 |
|
| 5 |
class Listener:
|
| 6 |
def __init__(self):
|
|
@@ -55,7 +56,7 @@ def discover_peers(timeout=2):
|
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
local_ip = socket.gethostbyname(socket.gethostname())
|
| 58 |
-
port =
|
| 59 |
|
| 60 |
zc = register_service(local_ip, port, load=0.1)
|
| 61 |
|
|
|
|
| 1 |
import socket
|
| 2 |
import time
|
| 3 |
from zeroconf import Zeroconf, ServiceBrowser, ServiceInfo
|
| 4 |
+
from peer_discovery import PORT, PORT
|
| 5 |
|
| 6 |
class Listener:
|
| 7 |
def __init__(self):
|
|
|
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
local_ip = socket.gethostbyname(socket.gethostname())
|
| 59 |
+
port = PORT
|
| 60 |
|
| 61 |
zc = register_service(local_ip, port, load=0.1)
|
| 62 |
|
peer_server.py
CHANGED
|
@@ -6,6 +6,7 @@ import smart_tasks
|
|
| 6 |
import time
|
| 7 |
import socket
|
| 8 |
import peer_discovery # إذا كان يستخدم لاحقًا
|
|
|
|
| 9 |
|
| 10 |
app = Flask(__name__) # إنشاء التطبيق
|
| 11 |
|
|
@@ -33,5 +34,5 @@ def run():
|
|
| 33 |
return jsonify(error=str(e)), 500
|
| 34 |
|
| 35 |
if __name__ == "__main__": # التصحيح هنا
|
| 36 |
-
app.run(host="0.0.0.0", port=
|
| 37 |
|
|
|
|
| 6 |
import time
|
| 7 |
import socket
|
| 8 |
import peer_discovery # إذا كان يستخدم لاحقًا
|
| 9 |
+
from peer_discovery import PORT, PORT
|
| 10 |
|
| 11 |
app = Flask(__name__) # إنشاء التطبيق
|
| 12 |
|
|
|
|
| 34 |
return jsonify(error=str(e)), 500
|
| 35 |
|
| 36 |
if __name__ == "__main__": # التصحيح هنا
|
| 37 |
+
app.run(host="0.0.0.0", port=PORT)
|
| 38 |
|
quick_connection_test.py
CHANGED
|
@@ -13,7 +13,7 @@ def test_connection():
|
|
| 13 |
|
| 14 |
# 1. فحص الخادم المحلي
|
| 15 |
try:
|
| 16 |
-
response = requests.get("http://localhost:
|
| 17 |
if response.status_code == 200:
|
| 18 |
print("✅ الخادم المحلي يعمل")
|
| 19 |
else:
|
|
|
|
| 13 |
|
| 14 |
# 1. فحص الخادم المحلي
|
| 15 |
try:
|
| 16 |
+
response = requests.get("http://localhost:PORT/health", timeout=3)
|
| 17 |
if response.status_code == 200:
|
| 18 |
print("✅ الخادم المحلي يعمل")
|
| 19 |
else:
|
remote_executor.py
CHANGED
|
@@ -12,11 +12,12 @@ from typing import Any
|
|
| 12 |
|
| 13 |
# قائمة الأقران (URLs) المستخرجة من peer_discovery
|
| 14 |
from peer_discovery import PEERS
|
|
|
|
| 15 |
|
| 16 |
# عنوان افتراضي احتياطي (يمكن تغييره بمتغير بيئي REMOTE_SERVER)
|
| 17 |
FALLBACK_SERVER = os.getenv(
|
| 18 |
"REMOTE_SERVER",
|
| 19 |
-
"http://89.111.171.92:
|
| 20 |
)
|
| 21 |
|
| 22 |
# محاولة استيراد SecurityManager (اختياري)
|
|
|
|
| 12 |
|
| 13 |
# قائمة الأقران (URLs) المستخرجة من peer_discovery
|
| 14 |
from peer_discovery import PEERS
|
| 15 |
+
from peer_discovery import PORT, PORT
|
| 16 |
|
| 17 |
# عنوان افتراضي احتياطي (يمكن تغييره بمتغير بيئي REMOTE_SERVER)
|
| 18 |
FALLBACK_SERVER = os.getenv(
|
| 19 |
"REMOTE_SERVER",
|
| 20 |
+
"http://89.111.171.92:PORT/run"
|
| 21 |
)
|
| 22 |
|
| 23 |
# محاولة استيراد SecurityManager (اختياري)
|
rpc_server.py
CHANGED
|
@@ -9,6 +9,7 @@ from flask import Flask, request, jsonify
|
|
| 9 |
import smart_tasks # «your_tasks» تمّ استيراده تحت هذا الاسم فى main.py
|
| 10 |
import logging, json
|
| 11 |
from security_layer import SecurityManager
|
|
|
|
| 12 |
|
| 13 |
SECURITY = SecurityManager("my_shared_secret_123")
|
| 14 |
|
|
@@ -69,5 +70,5 @@ def run():
|
|
| 69 |
|
| 70 |
# ------------------------------------------------------------------
|
| 71 |
if name == "main":
|
| 72 |
-
# تأكد أن المنفذ
|
| 73 |
-
app.run(host="0.0.0.0", port=
|
|
|
|
| 9 |
import smart_tasks # «your_tasks» تمّ استيراده تحت هذا الاسم فى main.py
|
| 10 |
import logging, json
|
| 11 |
from security_layer import SecurityManager
|
| 12 |
+
from peer_discovery import PORT, PORT
|
| 13 |
|
| 14 |
SECURITY = SecurityManager("my_shared_secret_123")
|
| 15 |
|
|
|
|
| 70 |
|
| 71 |
# ------------------------------------------------------------------
|
| 72 |
if name == "main":
|
| 73 |
+
# تأكد أن المنفذ PORT مفتوح
|
| 74 |
+
app.run(host="0.0.0.0", port=PORT)
|
security_layer.py
CHANGED
|
@@ -9,6 +9,7 @@ from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
|
| 9 |
from cryptography.fernet import Fernet
|
| 10 |
import os, base64, json
|
| 11 |
from typing import Dict
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
class SecurityManager:
|
|
|
|
| 9 |
from cryptography.fernet import Fernet
|
| 10 |
import os, base64, json
|
| 11 |
from typing import Dict
|
| 12 |
+
from peer_discovery import PORT, PORT
|
| 13 |
|
| 14 |
|
| 15 |
class SecurityManager:
|
server.py
CHANGED
|
@@ -4,6 +4,7 @@ import json
|
|
| 4 |
from your_tasks import *
|
| 5 |
from project_identifier import create_project_endpoint, get_project_info
|
| 6 |
import logging
|
|
|
|
| 7 |
|
| 8 |
app = Flask(__name__)
|
| 9 |
CORS(app)
|
|
@@ -21,7 +22,7 @@ def multiply():
|
|
| 21 |
|
| 22 |
@app.route('/health', methods=['GET'])
|
| 23 |
def health_check():
|
| 24 |
-
return jsonify({"status": "healthy", "port":
|
| 25 |
|
| 26 |
@app.route('/project_info', methods=['GET'])
|
| 27 |
def project_info():
|
|
@@ -29,4 +30,4 @@ def project_info():
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
# هذا العنوان يسمح بالاستماع على IP خارجي لتلقي الاتصالات من الإنترنت
|
| 32 |
-
app.run(host="0.0.0.0", port=
|
|
|
|
| 4 |
from your_tasks import *
|
| 5 |
from project_identifier import create_project_endpoint, get_project_info
|
| 6 |
import logging
|
| 7 |
+
from peer_discovery import PORT, PORT
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
CORS(app)
|
|
|
|
| 22 |
|
| 23 |
@app.route('/health', methods=['GET'])
|
| 24 |
def health_check():
|
| 25 |
+
return jsonify({"status": "healthy", "port": PORT})
|
| 26 |
|
| 27 |
@app.route('/project_info', methods=['GET'])
|
| 28 |
def project_info():
|
|
|
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|
| 32 |
# هذا العنوان يسمح بالاستماع على IP خارجي لتلقي الاتصالات من الإنترنت
|
| 33 |
+
app.run(host="0.0.0.0", port=PORT)
|
smart_tasks.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import math
|
| 2 |
import numpy as np
|
| 3 |
import time
|
|
|
|
| 4 |
|
| 5 |
def prime_calculation(n: int):
|
| 6 |
"""ترجع قائمة الأعداد الأوليّة حتى n مع عددها"""
|
|
@@ -135,4 +136,4 @@ def game_ai_processing(ai_agents_count, decision_complexity, game_state_size):
|
|
| 135 |
"total_operations": total_operations,
|
| 136 |
"processing_time": time.time() - start_time,
|
| 137 |
"server_processed": True
|
| 138 |
-
}
|
|
|
|
| 1 |
import math
|
| 2 |
import numpy as np
|
| 3 |
import time
|
| 4 |
+
from peer_discovery import PORT, PORT
|
| 5 |
|
| 6 |
def prime_calculation(n: int):
|
| 7 |
"""ترجع قائمة الأعداد الأوليّة حتى n مع عددها"""
|
|
|
|
| 136 |
"total_operations": total_operations,
|
| 137 |
"processing_time": time.time() - start_time,
|
| 138 |
"server_processed": True
|
| 139 |
+
}
|
system_check.py
CHANGED
|
@@ -7,6 +7,7 @@ import requests
|
|
| 7 |
import psutil
|
| 8 |
import threading
|
| 9 |
from offload_lib import discover_peers
|
|
|
|
| 10 |
|
| 11 |
def check_local_system():
|
| 12 |
"""فحص النظام المحلي"""
|
|
@@ -23,7 +24,7 @@ def check_server_running():
|
|
| 23 |
"""فحص إذا كان الخادم المحلي يعمل"""
|
| 24 |
print("🌐 فحص الخادم المحلي...")
|
| 25 |
try:
|
| 26 |
-
response = requests.get("http://localhost:
|
| 27 |
if response.status_code == 200:
|
| 28 |
print("✅ الخادم المحلي يعمل بشكل صحيح")
|
| 29 |
return True
|
|
|
|
| 7 |
import psutil
|
| 8 |
import threading
|
| 9 |
from offload_lib import discover_peers
|
| 10 |
+
from peer_discovery import PORT, PORT
|
| 11 |
|
| 12 |
def check_local_system():
|
| 13 |
"""فحص النظام المحلي"""
|
|
|
|
| 24 |
"""فحص إذا كان الخادم المحلي يعمل"""
|
| 25 |
print("🌐 فحص الخادم المحلي...")
|
| 26 |
try:
|
| 27 |
+
response = requests.get("http://localhost:PORT/health", timeout=3)
|
| 28 |
if response.status_code == 200:
|
| 29 |
print("✅ الخادم المحلي يعمل بشكل صحيح")
|
| 30 |
return True
|
system_tray.py
CHANGED
|
@@ -9,6 +9,7 @@ import threading
|
|
| 9 |
import requests
|
| 10 |
import webbrowser
|
| 11 |
from pathlib import Path
|
|
|
|
| 12 |
|
| 13 |
try:
|
| 14 |
import pystray
|
|
|
|
| 9 |
import requests
|
| 10 |
import webbrowser
|
| 11 |
from pathlib import Path
|
| 12 |
+
from peer_discovery import PORT, PORT
|
| 13 |
|
| 14 |
try:
|
| 15 |
import pystray
|
task_splitter.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
from typing import Dict, Any, List
|
| 3 |
import networkx as nx
|
| 4 |
import hashlib
|
|
|
|
| 5 |
|
| 6 |
class TaskSplitter:
|
| 7 |
def __init__(self):
|
|
|
|
| 2 |
from typing import Dict, Any, List
|
| 3 |
import networkx as nx
|
| 4 |
import hashlib
|
| 5 |
+
from peer_discovery import PORT, PORT
|
| 6 |
|
| 7 |
class TaskSplitter:
|
| 8 |
def __init__(self):
|
test_distributed_system.py
CHANGED
|
@@ -9,6 +9,7 @@ import psutil
|
|
| 9 |
import logging
|
| 10 |
from offload_lib import discover_peers, matrix_multiply, prime_calculation, data_processing
|
| 11 |
from your_tasks import complex_operation
|
|
|
|
| 12 |
|
| 13 |
# إعداد السجل
|
| 14 |
logging.basicConfig(
|
|
|
|
| 9 |
import logging
|
| 10 |
from offload_lib import discover_peers, matrix_multiply, prime_calculation, data_processing
|
| 11 |
from your_tasks import complex_operation
|
| 12 |
+
from peer_discovery import PORT, PORT
|
| 13 |
|
| 14 |
# إعداد السجل
|
| 15 |
logging.basicConfig(
|
test_monitor.py
CHANGED
|
@@ -7,6 +7,7 @@ import threading
|
|
| 7 |
import psutil
|
| 8 |
import signal
|
| 9 |
import sys
|
|
|
|
| 10 |
|
| 11 |
class TestMonitor:
|
| 12 |
def __init__(self):
|
|
|
|
| 7 |
import psutil
|
| 8 |
import signal
|
| 9 |
import sys
|
| 10 |
+
from peer_discovery import PORT, PORT
|
| 11 |
|
| 12 |
class TestMonitor:
|
| 13 |
def __init__(self):
|
video_processing.py
CHANGED
|
@@ -7,6 +7,7 @@ import logging
|
|
| 7 |
from functools import wraps
|
| 8 |
from processor_manager import should_offload
|
| 9 |
from remote_executor import execute_remotely
|
|
|
|
| 10 |
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
|
|
|
|
| 7 |
from functools import wraps
|
| 8 |
from processor_manager import should_offload
|
| 9 |
from remote_executor import execute_remotely
|
| 10 |
+
from peer_discovery import PORT, PORT
|
| 11 |
|
| 12 |
logging.basicConfig(level=logging.INFO)
|
| 13 |
|
your_tasks.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import math
|
| 2 |
import numpy as np
|
| 3 |
from offload_lib import offload
|
|
|
|
| 4 |
|
| 5 |
# الدوال الأساسية (محليّة)
|
| 6 |
def prime_calculation(n: int):
|
|
|
|
| 1 |
import math
|
| 2 |
import numpy as np
|
| 3 |
from offload_lib import offload
|
| 4 |
+
from peer_discovery import PORT, PORT
|
| 5 |
|
| 6 |
# الدوال الأساسية (محليّة)
|
| 7 |
def prime_calculation(n: int):
|