From 8dad1fc4aab5d10dd81ac071f99e46bf78b1a4ce Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Sat, 25 Feb 2017 21:31:32 -0600 Subject: [PATCH] Do not send events to their originators, or to any event not specified in the "to" list. --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9420474..dc2bd6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,8 +86,30 @@ impl Tenquestionmarks { loop { match main_receiver.recv() { Ok(envelope) => { + /* + * Check if the target module is a valid destination for the envelope. + * We want to deliver this envelope if all of the following are true: + * 1. The target module is not the originator of the envelope + * 2. The envelope's list of allowed recipients is empty, or specifically + * names the target module. + */ let arc_envelope = Arc::new(envelope); for (key, sender) in &module_senders { + let from_this = String::from(*key); + if Some(from_this.clone()) == arc_envelope.from { + debug!("Refusing to transmit event to its originator ({:?})", from_this); + continue; + } + else if !(arc_envelope.to.is_empty() || !arc_envelope.to.contains(&from_this)) { + debug!( + "Refusing to transmit envelope from {:?} to {:?} since it is not on the list of allowed recipients ({:?})", + arc_envelope.from, + from_this, + arc_envelope.to + ); + continue; + } + match sender.send(arc_envelope.clone()) { Err(err) => debug!("Failed to dispatch event to module \"{}\": {:?}", key, err), Ok(_) => {}