discv5/handler/
request_call.rs1pub use crate::node_info::NodeContact;
2use crate::{
3 packet::Packet,
4 rpc::{Request, RequestBody},
5};
6
7use super::HandlerReqId;
8
9#[derive(Debug)]
11pub(super) struct RequestCall {
12 contact: NodeContact,
13 packet: Packet,
15 request_id: HandlerReqId,
17 request: RequestBody,
19 handshake_sent: bool,
21 retries: u8,
23 remaining_responses: Option<u64>,
26 initiating_session: bool,
29}
30
31impl RequestCall {
32 pub fn new(
33 contact: NodeContact,
34 packet: Packet,
35 request_id: HandlerReqId,
36 request: RequestBody,
37 initiating_session: bool,
38 ) -> Self {
39 RequestCall {
40 contact,
41 packet,
42 request_id,
43 request,
44 handshake_sent: false,
45 retries: 1,
46 remaining_responses: None,
47 initiating_session,
48 }
49 }
50
51 pub fn contact(&self) -> &NodeContact {
53 &self.contact
54 }
55
56 pub fn id(&self) -> &HandlerReqId {
58 &self.request_id
59 }
60
61 pub fn body(&self) -> &RequestBody {
63 &self.request
64 }
65
66 pub fn packet(&self) -> &Packet {
68 &self.packet
69 }
70
71 pub fn encode(&self) -> Vec<u8> {
72 match &self.request_id {
73 HandlerReqId::Internal(id) | HandlerReqId::External(id) => {
74 let request = Request {
75 id: id.clone(),
76 body: self.request.clone(),
77 };
78 request.encode()
79 }
80 }
81 }
82
83 pub fn retries(&self) -> u8 {
85 self.retries
86 }
87
88 pub fn increment_retries(&mut self) {
90 self.retries += 1;
91 }
92
93 pub fn handshake_sent(&self) -> bool {
95 self.handshake_sent
96 }
97
98 pub fn set_handshake_sent(&mut self) {
100 self.handshake_sent = true;
101 }
102
103 pub fn set_initiating_session(&mut self, state: bool) {
105 self.initiating_session = state;
106 }
107
108 pub fn initiating_session(&self) -> bool {
110 self.initiating_session
111 }
112
113 pub fn update_packet(&mut self, packet: Packet) {
115 self.packet = packet;
116 }
117
118 pub fn remaining_responses_mut(&mut self) -> &mut Option<u64> {
120 &mut self.remaining_responses
121 }
122}