Fix #204: Instantiate and inject CaptureBus in Engine
- Engine.__init__ now initializes self.capture_bus = None - Engine.start_all() instantiates CaptureBus before starting modules - CaptureBus uses resolved interface from config - Inject capture_bus into configs of all modules with requires_capture_bus=True - Engine.stop_all() properly stops CaptureBus after stopping modules - CaptureBus instantiation includes error handling with fallback
This commit is contained in:
@@ -225,6 +225,7 @@ class Engine:
|
|||||||
if actual_iface:
|
if actual_iface:
|
||||||
self.config.setdefault("network", {})["primary_interface"] = actual_iface
|
self.config.setdefault("network", {})["primary_interface"] = actual_iface
|
||||||
logger.debug("Resolved auto interface to: %s", actual_iface)
|
logger.debug("Resolved auto interface to: %s", actual_iface)
|
||||||
|
self.capture_bus = None
|
||||||
self._lock = multiprocessing.Lock()
|
self._lock = multiprocessing.Lock()
|
||||||
logger.info("Engine initialized (tier=%s, phase=%s)", self._tier, self._phase)
|
logger.info("Engine initialized (tier=%s, phase=%s)", self._tier, self._phase)
|
||||||
|
|
||||||
@@ -342,6 +343,24 @@ class Engine:
|
|||||||
def start_all(self) -> dict[str, bool]:
|
def start_all(self) -> dict[str, bool]:
|
||||||
"""Start all registered modules in dependency order."""
|
"""Start all registered modules in dependency order."""
|
||||||
order = _topo_sort(self._modules)
|
order = _topo_sort(self._modules)
|
||||||
|
|
||||||
|
# Instantiate and start CaptureBus for passive modules
|
||||||
|
iface = self.config.get("network", {}).get("primary_interface")
|
||||||
|
if iface:
|
||||||
|
try:
|
||||||
|
from core.capture_bus import CaptureBus
|
||||||
|
self.capture_bus = CaptureBus(interface=iface)
|
||||||
|
self.capture_bus.start()
|
||||||
|
logger.info("CaptureBus started on %s", iface)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Failed to start CaptureBus: %s", e)
|
||||||
|
self.capture_bus = None
|
||||||
|
|
||||||
|
# Inject capture_bus into module configs for passive modules
|
||||||
|
for name, entry in self._modules.items():
|
||||||
|
if getattr(entry.module_class, "requires_capture_bus", False):
|
||||||
|
entry.config["capture_bus"] = self.capture_bus
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
for name in order:
|
for name in order:
|
||||||
results[name] = self.start(name)
|
results[name] = self.start(name)
|
||||||
@@ -352,6 +371,14 @@ class Engine:
|
|||||||
order = _topo_sort(self._modules)
|
order = _topo_sort(self._modules)
|
||||||
for name in reversed(order):
|
for name in reversed(order):
|
||||||
self.stop(name, timeout=timeout)
|
self.stop(name, timeout=timeout)
|
||||||
|
|
||||||
|
# Stop CaptureBus after all modules
|
||||||
|
if self.capture_bus:
|
||||||
|
try:
|
||||||
|
self.capture_bus.stop()
|
||||||
|
self.capture_bus = None
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Failed to stop CaptureBus: %s", e)
|
||||||
|
|
||||||
def get_status(self, name: str = None) -> dict:
|
def get_status(self, name: str = None) -> dict:
|
||||||
"""Get status of one module or all modules."""
|
"""Get status of one module or all modules."""
|
||||||
|
|||||||
Reference in New Issue
Block a user