Extra touch

This commit is contained in:
NikolajDanger
2023-05-29 19:51:01 +02:00
parent afa764ad67
commit 4723482dbc
2 changed files with 19 additions and 1 deletions

View File

@ -2,6 +2,8 @@ import sys
import socket
import threading
import tempfile
from os import unlink
from time import time
from typing import Any, Dict, List
@ -92,6 +94,8 @@ class NetworkMonitor(BaseMonitor):
implemented by any child process. Depending on the nature of the
monitor, this may wish to directly call apply_retroactive_rules before
starting."""
self.temp_files = []
self.ports = set(
rule.pattern.triggering_port for rule in self._rules.values()
)
@ -105,6 +109,7 @@ class NetworkMonitor(BaseMonitor):
self._rules_lock.acquire()
try:
self.temp_files.append(event["tmp file"])
for rule in self._rules.values():
# Match event port against rule ports
hit = event["triggering port"]
@ -129,12 +134,19 @@ class NetworkMonitor(BaseMonitor):
self._rules_lock.release()
def _delete_temp_files(self):
for file in self.temp_files:
unlink(file)
self.temp_files = []
def stop(self)->None:
"""Function to stop the monitor as an ongoing process/thread. Must be
implemented by any child process"""
for listener in self.listeners:
listener.stop()
self._delete_temp_files()
def _is_valid_recipes(self, recipes:Dict[str,BaseRecipe])->None:
"""Validation check for 'recipes' variable from main constructor. Is
automatically called during initialisation."""