Skip to content

Commit

Permalink
Maintain sender information for NetworkActor
Browse files Browse the repository at this point in the history
  • Loading branch information
Bathtor committed Sep 29, 2019
1 parent 5704e2b commit 595a625
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ pub trait NetworkActor: ComponentLogging {
type Deserialiser: Deserialiser<Self::Message>;

/// 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<ActorPath>, msg: Self::Message) -> ();

fn on_error(&mut self, error: UnpackError<NetMessage>) -> () {
warn!(
Expand All @@ -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::<_, <Self as NetworkActor>::Deserialiser>() {
Ok(m) => self.receive(m),
Ok(m) => self.receive(Some(sender), m),
Err(e) => self.on_error(e),
}
}
Expand Down

0 comments on commit 595a625

Please sign in to comment.