Do not send events to their originators, or to any event not specified in the "to" list.

This commit is contained in:
Adrian Malacoda 2017-02-25 21:31:32 -06:00
parent 1fbba2554d
commit 8dad1fc4aa

View File

@ -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(_) => {}