add config
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s

This commit is contained in:
2026-03-07 10:44:45 +01:00
parent 8e6c759cb8
commit c19fab4d32
8 changed files with 140 additions and 21 deletions

View File

@@ -12,6 +12,7 @@ import threading
from pathlib import Path
from typing import Iterable, Optional
from src.config import settings
from src.utilities.packet_tracker import packet_tracker
logger = logging.getLogger("bridge_telemetry")
@@ -87,14 +88,14 @@ class BridgeTelemetryManager:
if process is not None and process.poll() is None:
try:
process.send_signal(signal.SIGTERM)
process.wait(timeout=3)
process.wait(timeout=settings.telemetry_process_stop_timeout_seconds)
except subprocess.TimeoutExpired:
process.kill()
except Exception:
logger.exception("Failed to stop bridge telemetry collector cleanly")
if reader is not None and reader.is_alive():
reader.join(timeout=2)
reader.join(timeout=settings.telemetry_reader_join_timeout_seconds)
def _read_loop(self, process: subprocess.Popen[str]) -> None:
stdout = process.stdout

View File

@@ -15,6 +15,8 @@ from typing import Any, Dict, Optional, Tuple
from scapy.all import IP, IPv6, TCP, UDP # type: ignore
from src.config import settings
logger = logging.getLogger("ndpi_classifier")
ndpi = None # type: ignore
@@ -52,9 +54,9 @@ class NDPIClassifier:
def __init__(self) -> None:
self._engine = None
self._flows: Dict[Tuple[Any, ...], _FlowState] = {}
self._max_flows = 200_000
self._flow_ttl_seconds = 120.0
self._cleanup_interval_packets = 10_000
self._max_flows = settings.ndpi_max_flows
self._flow_ttl_seconds = settings.ndpi_flow_ttl_seconds
self._cleanup_interval_packets = settings.ndpi_cleanup_interval_packets
self._packet_counter = 0
self._initialized = False

View File

@@ -12,6 +12,7 @@ from typing import Any, Dict, List, Optional
import src.shared_objects as shared_objects
from src.Models.etherType import EtherTypeEnum, ethertype_from_int
from src.Models.ip_protocol import protocol_from_number
from src.config import settings
from src.utilities.packet_identity import build_packet_uid
logger = logging.getLogger("packet_tracker")
@@ -41,7 +42,7 @@ class PacketTracker:
def stop(self) -> None:
self._stop_event.set()
self._thread.join(timeout=2)
self._thread.join(timeout=settings.packet_tracker_stop_join_timeout_seconds)
def observe_packet(self, pkt_info: Dict[str, Any]) -> str:
"""Merge parsed packet information into a pending packet entry."""
@@ -221,7 +222,7 @@ class PacketTracker:
if not src_ip or not dst_ip or protocol_raw is None:
return None
cutoff = time.time() - 1.0
cutoff = time.time() - settings.packet_tracker_reject_correlation_window_seconds
for entry in self._entries.values():
payload = entry["payload"]
if entry["last_observed_at"] < cutoff:
@@ -292,7 +293,7 @@ class PacketTracker:
try:
fut = asyncio.run_coroutine_threadsafe(web_db.upsert_packet(payload), web_loop)
fut.result(timeout=2.0)
fut.result(timeout=settings.packet_tracker_persist_timeout_seconds)
with self._lock:
current = self._entries.get(entry["packet_uid"])
if current is not None:
@@ -303,4 +304,8 @@ class PacketTracker:
logger.exception("Failed to persist packet %s", entry["packet_uid"])
packet_tracker = PacketTracker()
packet_tracker = PacketTracker(
finalize_delay_seconds=settings.packet_tracker_finalize_delay_seconds,
retention_seconds=settings.packet_tracker_retention_seconds,
min_flush_interval_seconds=settings.packet_tracker_min_flush_interval_seconds,
)