From 595a625ee3127b4567a382d96e74659da4ce49b3 Mon Sep 17 00:00:00 2001 From: Lars Kroll Date: Sun, 29 Sep 2019 14:33:54 +0200 Subject: [PATCH] Maintain sender information for NetworkActor --- core/src/actors/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/actors/mod.rs b/core/src/actors/mod.rs index 3e59a5b7..18415200 100644 --- a/core/src/actors/mod.rs +++ b/core/src/actors/mod.rs @@ -87,7 +87,9 @@ pub trait NetworkActor: ComponentLogging { type Deserialiser: Deserialiser; /// Handles all messages, after deserialisation. - fn receive(&mut self, msg: Self::Message) -> (); + /// + /// `sender` will only be supplied if the original message was a [NetMessage](crate::messaging::NetMessage). + fn receive(&mut self, sender: Option, msg: Self::Message) -> (); fn on_error(&mut self, error: UnpackError) -> () { warn!( @@ -109,13 +111,14 @@ where #[inline(always)] fn receive_local(&mut self, msg: Self::Message) -> () { - self.receive(msg) + self.receive(None, msg) } #[inline(always)] fn receive_network(&mut self, msg: NetMessage) -> () { + let sender = msg.sender().clone(); match msg.try_deserialise::<_, ::Deserialiser>() { - Ok(m) => self.receive(m), + Ok(m) => self.receive(Some(sender), m), Err(e) => self.on_error(e), } }