24 lines
975 B
Python
24 lines
975 B
Python
import os
|
|
import importlib
|
|
import logging
|
|
|
|
class BaseProtocol:
|
|
name = "Base"
|
|
def encode(self, text: str) -> bytes: raise NotImplementedError
|
|
def decode(self, data: bytes) -> str: raise NotImplementedError
|
|
def generate_service_signal(self, signal_type: str) -> bytes: raise NotImplementedError
|
|
def detect_service_signal(self, data: bytes) -> str: raise NotImplementedError
|
|
|
|
def load_protocols():
|
|
plugins = {}
|
|
for f in os.listdir('./protocols'):
|
|
if f.endswith('.py') and f != '__init__.py':
|
|
mod_name = f[:-3]
|
|
try:
|
|
mod = importlib.import_module(f'protocols.{mod_name}')
|
|
if hasattr(mod, 'ProtocolPlugin'):
|
|
instance = mod.ProtocolPlugin()
|
|
plugins[instance.name] = {"instance": instance, "enabled": True, "failed": False}
|
|
except Exception as e:
|
|
logging.error(f"Failed to load protocol {mod_name}: {e}")
|
|
return plugins |