#1961: scanning no longer happens every timestep - the scan is all done in one timestep after the required timestep countdown is complete

This commit is contained in:
Czar.Echavez
2023-10-30 15:34:13 +00:00
parent 1ddf400d6f
commit 98ca33e994
5 changed files with 150 additions and 73 deletions

View File

@@ -929,6 +929,15 @@ class Node(SimComponent):
is_resetting: bool = False
"If true, the node will try turning itself off then back on again."
node_scan_duration: int = 10
"How many timesteps until the whole node is scanned. Default 10 time steps."
node_scan_countdown: int = 0
"Time steps until scan is complete"
red_scan_countdown: int = 0
"Time steps until reveal to red scan is complete."
def __init__(self, **kwargs):
"""
Initialize the Node with various components and managers.
@@ -1098,8 +1107,47 @@ class Node(SimComponent):
self.is_resetting = False
self.power_on()
# apply time step to node components
# time steps which require the node to be on
if self.operating_state == NodeOperatingState.ON:
# node scanning
if self.node_scan_countdown > 0:
self.node_scan_countdown -= 1
if self.node_scan_countdown == 0:
# scan everything!
for process_id in self.processes:
self.processes[process_id].scan()
# scan services
for service_id in self.services:
self.services[service_id].scan()
# scan applications
for application_id in self.applications:
self.applications[application_id].scan()
# scan file system
self.file_system.scan(instant_scan=True)
if self.red_scan_countdown > 0:
self.red_scan_countdown -= 1
if self.red_scan_countdown == 0:
# scan processes
for process_id in self.processes:
self.processes[process_id].reveal_to_red()
# scan services
for service_id in self.services:
self.services[service_id].reveal_to_red()
# scan applications
for application_id in self.applications:
self.applications[application_id].reveal_to_red()
# scan file system
self.file_system.reveal_to_red(instant_scan=True)
for process_id in self.processes:
self.processes[process_id].apply_timestep(timestep=timestep)
@@ -1124,20 +1172,7 @@ class Node(SimComponent):
to the red agent.
"""
# scan processes
for process_id in self.processes:
self.processes[process_id].scan()
# scan services
for service_id in self.services:
self.services[service_id].scan()
# scan applications
for application_id in self.applications:
self.applications[application_id].scan()
# scan file system
self.file_system.scan()
self.node_scan_countdown = self.node_scan_duration
def reveal_to_red(self) -> None:
"""
@@ -1152,20 +1187,7 @@ class Node(SimComponent):
`revealed_to_red` to `True`.
"""
# scan processes
for process_id in self.processes:
self.processes[process_id].reveal_to_red()
# scan services
for service_id in self.services:
self.services[service_id].reveal_to_red()
# scan applications
for application_id in self.applications:
self.applications[application_id].reveal_to_red()
# scan file system
self.file_system.reveal_to_red()
self.red_scan_countdown = self.node_scan_duration
def power_on(self):
"""Power on the Node, enabling its NICs if it is in the OFF state."""