Download core/flow_controller.py from digitview/the-organism: direct link, hf CLI and curl.
- Browser
- Download file 2.48 kB
-
https://huggingface.co/digitview/the-organism/resolve/main/core/flow_controller.py
- Command line
-
hf download hf://digitview/the-organism/core/flow_controller.py
-
curl -L -o flow_controller.py https://huggingface.co/digitview/the-organism/resolve/main/core/flow_controller.py
2.48 kB
| # File: C:\Users\leonk\Documents\AI_Projects\ai_workspace\core\flow_controller.py | |
| # Signature: [LK] | |
| import time | |
| import queue | |
| import threading | |
| class LegacyFlowController: | |
| """ | |
| The Organism: Adaptive Legacy Flow Controller [LK] | |
| Throttles and paces telemetry handoffs to match the exact ingestion | |
| speed of legacy hard drives and SIEM systems, preventing backpressure. | |
| """ | |
| def __init__(self, max_batch_size: int = 50, flush_interval_seconds: float = 5.0): | |
| self._lock = threading.Lock() | |
| self._outbox_queue = queue.Queue() | |
| self._max_batch_size = max_batch_size | |
| self._flush_interval = flush_interval_seconds | |
| self._last_flush_time = time.time() | |
| def enqueue_for_legacy_accountant(self, legacy_formatted_msg: str, priority: int = 2) -> None: | |
| """Enqueues formatted legacy messages (Syslog/CEF) for paced delivery.""" | |
| with self._lock: | |
| self._outbox_queue.put((priority, time.time(), legacy_formatted_msg)) | |
| def get_next_batch(self) -> list: | |
| """ | |
| Releases data strictly at a controlled pace matching legacy speeds, | |
| protecting slow hard drives and traditional log collectors from flooding. | |
| """ | |
| current_time = time.time() | |
| batch = [] | |
| with self._lock: | |
| if (current_time - self._last_flush_time >= self._flush_interval) or self._outbox_queue.qsize() >= self._max_batch_size: | |
| while not self._outbox_queue.empty() and len(batch) < self._max_batch_size: | |
| priority, timestamp, msg = self._outbox_queue.get() | |
| batch.append(msg) | |
| self._last_flush_time = current_time | |
| return batch | |
| if __name__ == "__main__": | |
| controller = LegacyFlowController(max_batch_size=3, flush_interval_seconds=1.0) | |
| print("=== THE ORGANISM: LEGACY FLOW CONTROLLER INITIALIZED [LK] ===") | |
| # Simulate high-speed bouncer output being paced for a slow accountant | |
| controller.enqueue_for_legacy_accountant("CEF:0|Digitview|TheOrganism|1.0|SIG01|PROBE|5|src=127.0.0.1") | |
| controller.enqueue_for_legacy_accountant("CEF:0|Digitview|TheOrganism|1.0|SIG02|PROBE|5|src=127.0.0.1") | |
| controller.enqueue_for_legacy_accountant("CEF:0|Digitview|TheOrganism|1.0|SIG03|CRITICAL|10|src=127.0.0.1") | |
| print("Batch 1 (Immediate check):", controller.get_next_batch()) | |
| time.sleep(1.1) | |
| print("Batch 2 (After flow interval):", controller.get_next_batch()) | |