Do not send events to their originators, or to any event not specified in the "to" list.
This commit is contained in:
parent
1fbba2554d
commit
8dad1fc4aa
22
src/lib.rs
22
src/lib.rs
@ -86,8 +86,30 @@ impl Tenquestionmarks {
|
|||||||
loop {
|
loop {
|
||||||
match main_receiver.recv() {
|
match main_receiver.recv() {
|
||||||
Ok(envelope) => {
|
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);
|
let arc_envelope = Arc::new(envelope);
|
||||||
for (key, sender) in &module_senders {
|
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()) {
|
match sender.send(arc_envelope.clone()) {
|
||||||
Err(err) => debug!("Failed to dispatch event to module \"{}\": {:?}", key, err),
|
Err(err) => debug!("Failed to dispatch event to module \"{}\": {:?}", key, err),
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user