From 2439de214b7372b21ef4a51a1206f4f508d93522 Mon Sep 17 00:00:00 2001 From: Russell Gilbert Date: Sat, 14 Mar 2026 09:50:54 +0000 Subject: [PATCH] RustyLee: Validates organ responses before command processing Ensures the brain only processes commands from organs that return an 'Ok' response. Specifically, the 'Waken' command now requires an 'Ok' response to transition the brain to the 'Awake' state, improving the robustness of inter-organ communication. --- src/rustylee/src/brain.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/rustylee/src/brain.rs b/src/rustylee/src/brain.rs index 4fb2710..f090f80 100644 --- a/src/rustylee/src/brain.rs +++ b/src/rustylee/src/brain.rs @@ -4,7 +4,7 @@ use crate::lifecycle::{LifeState, LifecycleCommand, LifecycleCommandResponse, Li use crate::lifecycle::LifeState::{Dying, Buried, Genisys, Dead}; use crate::organs::organ_factory::OrganFactory; use crate::organs::organ_socket::OrganSocket; -use crate::protocols::{BrainMessage, OrganCommand, OrganCommandEnvelope}; +use crate::protocols::{BrainMessage, OrganCommand, OrganCommandEnvelope, OrganResponse}; use crate::system::time::Time; pub struct Brain { @@ -155,9 +155,20 @@ impl Brain { fn process_message_from_organ(&mut self, message: BrainMessage) { debug!("organ message received: {:?}.", message); - if let OrganCommand::Waken = message.organ_command.command { - self.state = LifeState::Awake; - } + if let OrganResponse::Ok = message.response{ + match message.organ_command.command { + OrganCommand::Waken => { + self.state = LifeState::Awake; + } + + _ => { + debug!("organ message received, no action taken: {:?}.", message.organ_command); + } + } + + if let OrganCommand::Waken = message.organ_command.command { + } + }; } }