ockam_core/routing/message/relay_message.rs
1use crate::{Address, LocalMessage, Route};
2
3/// A message addressed to the relay responsible for delivery of the
4/// wrapped [`LocalMessage`]
5#[derive(Clone, Debug)]
6pub struct RelayMessage {
7 source: Address,
8 destination: Address,
9 local_msg: LocalMessage,
10}
11
12impl RelayMessage {
13 /// Construct a new message addressed to a user worker
14 pub fn new(source: Address, destination: Address, local_msg: LocalMessage) -> Self {
15 Self {
16 source,
17 destination,
18 local_msg,
19 }
20 }
21
22 /// The sender address of the wrapped `LocalMessage`
23 /// Note that this may be different from the first hop in the return_route
24 /// This address is always equal to the address of the `Context` instance used to
25 /// send or forward the message
26 pub fn source(&self) -> &Address {
27 &self.source
28 }
29
30 /// The recipient address for the wrapped `LocalMessage`
31 /// Note that this may be different from the first hop in the onward_route, for example while
32 /// sending a message to an External address (e.g. TCP) first message will be delivered to the
33 /// the TCP Router (and destination address will be the address of the TCP Router), and only
34 /// then to the individual connection worker
35 pub fn destination(&self) -> &Address {
36 &self.destination
37 }
38
39 /// Onward route
40 pub fn onward_route(&self) -> &Route {
41 self.local_msg.onward_route()
42 }
43
44 /// Return route
45 pub fn return_route(&self) -> &Route {
46 self.local_msg.return_route()
47 }
48
49 /// Payload
50 pub fn payload(&self) -> &[u8] {
51 self.local_msg.payload()
52 }
53
54 /// Local message
55 pub fn local_message(&self) -> &LocalMessage {
56 &self.local_msg
57 }
58
59 /// Take local message
60 pub fn into_local_message(self) -> LocalMessage {
61 self.local_msg
62 }
63}