mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-12 16:09:29 -05:00
Box all messages in enum
The messages are very different, best to box them and save size on the stack as an enum takes as much space on the stack than its bigger variant.
This commit is contained in:
parent
d2a1937f51
commit
a910bc2046
@ -19,20 +19,18 @@ const BUF_SIZE: usize = 1024 * 1024;
|
||||
// Codec for each Message and a macro that implements them.
|
||||
|
||||
/// Messages Bob sends to Alice.
|
||||
// TODO: Remove this once network changes are done
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum BobToAlice {
|
||||
SwapRequest(bob::SwapRequest),
|
||||
SwapRequest(Box<bob::SwapRequest>),
|
||||
Message0(Box<bob::Message0>),
|
||||
Message1(bob::Message1),
|
||||
Message2(bob::Message2),
|
||||
Message1(Box<bob::Message1>),
|
||||
Message2(Box<bob::Message2>),
|
||||
}
|
||||
|
||||
/// Messages Alice sends to Bob.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum AliceToBob {
|
||||
SwapResponse(alice::SwapResponse),
|
||||
SwapResponse(Box<alice::SwapResponse>),
|
||||
Message0(Box<alice::Message0>),
|
||||
Message1(Box<alice::Message1>),
|
||||
Message2,
|
||||
|
@ -93,7 +93,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
|
||||
} => {
|
||||
if let BobToAlice::Message1(msg) = request {
|
||||
debug!("Received Message1");
|
||||
self.events.push_back(OutEvent::Msg { msg, channel });
|
||||
self.events.push_back(OutEvent::Msg { msg: *msg, channel });
|
||||
}
|
||||
}
|
||||
RequestResponseEvent::Message {
|
||||
|
@ -79,7 +79,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
|
||||
if let BobToAlice::Message2(msg) = request {
|
||||
debug!("Received Message 2");
|
||||
self.events.push_back(OutEvent::Msg {
|
||||
msg,
|
||||
msg: *msg,
|
||||
bob_peer_id: peer,
|
||||
});
|
||||
// Send back empty response so that the request/response protocol completes.
|
||||
|
@ -45,7 +45,7 @@ pub struct Behaviour {
|
||||
impl Behaviour {
|
||||
/// Alice always sends her messages as a response to a request from Bob.
|
||||
pub fn send(&mut self, channel: ResponseChannel<AliceToBob>, msg: SwapResponse) {
|
||||
let msg = AliceToBob::SwapResponse(msg);
|
||||
let msg = AliceToBob::SwapResponse(Box::new(msg));
|
||||
self.rr.send_response(channel, msg);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
|
||||
} => {
|
||||
if let BobToAlice::SwapRequest(msg) = request {
|
||||
debug!("Received swap request");
|
||||
self.events.push_back(OutEvent { msg, channel })
|
||||
self.events.push_back(OutEvent { msg: *msg, channel })
|
||||
}
|
||||
}
|
||||
RequestResponseEvent::Message {
|
||||
|
@ -41,7 +41,7 @@ pub struct Behaviour {
|
||||
|
||||
impl Behaviour {
|
||||
pub fn send(&mut self, alice: PeerId, msg: Message1) {
|
||||
let msg = BobToAlice::Message1(msg);
|
||||
let msg = BobToAlice::Message1(Box::new(msg));
|
||||
let _id = self.rr.send_request(&alice, msg);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub struct Behaviour {
|
||||
|
||||
impl Behaviour {
|
||||
pub fn send(&mut self, alice: PeerId, msg: Message2) {
|
||||
let msg = BobToAlice::Message2(msg);
|
||||
let msg = BobToAlice::Message2(Box::new(msg));
|
||||
let _id = self.rr.send_request(&alice, msg);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ pub struct Behaviour {
|
||||
|
||||
impl Behaviour {
|
||||
pub fn send(&mut self, alice: PeerId, swap_request: SwapRequest) -> Result<RequestId> {
|
||||
let msg = BobToAlice::SwapRequest(swap_request);
|
||||
let msg = BobToAlice::SwapRequest(Box::new(swap_request));
|
||||
let id = self.rr.send_request(&alice, msg);
|
||||
|
||||
Ok(id)
|
||||
@ -92,7 +92,9 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
|
||||
} => {
|
||||
if let AliceToBob::SwapResponse(swap_response) = response {
|
||||
debug!("Received swap response");
|
||||
self.events.push_back(OutEvent { swap_response });
|
||||
self.events.push_back(OutEvent {
|
||||
swap_response: *swap_response,
|
||||
});
|
||||
}
|
||||
}
|
||||
RequestResponseEvent::InboundFailure { error, .. } => {
|
||||
|
Loading…
Reference in New Issue
Block a user