espresso_node/request_response/
mod.rs1use std::future::Future;
2
3use data_source::DataSource;
4use derive_more::derive::Deref;
5use espresso_types::{PubKey, traits::SequencerPersistence};
6use hotshot_types::signature_key::BLSPrivKey;
7use network::Sender;
8use recipient_source::RecipientSource;
9use request::{Request, Response};
10use request_response::{RequestError, RequestResponse, RequestResponseConfig, network::Bytes};
11use tokio::sync::mpsc::Receiver;
12
13pub mod catchup;
14pub mod data_source;
15pub mod network;
16pub mod recipient_source;
17pub mod request;
18
19#[derive(Clone, Deref)]
22pub struct RequestResponseProtocol<P: SequencerPersistence> {
23 #[deref]
24 #[allow(clippy::type_complexity)]
25 inner: RequestResponse<
27 Sender,
28 Receiver<Bytes>,
29 Request,
30 RecipientSource<P>,
31 DataSource<P>,
32 PubKey,
33 >,
34
35 config: RequestResponseConfig,
38
39 public_key: PubKey,
41 private_key: BLSPrivKey,
43}
44
45impl<P: SequencerPersistence> RequestResponseProtocol<P> {
46 pub fn new(
48 config: RequestResponseConfig,
50 sender: Sender,
52 receiver: Receiver<Bytes>,
54 recipient_source: RecipientSource<P>,
57 data_source: DataSource<P>,
60 public_key: PubKey,
62 private_key: BLSPrivKey,
64 ) -> Self {
65 Self {
66 inner: RequestResponse::new(
67 config.clone(),
68 sender,
69 receiver,
70 recipient_source,
71 data_source,
72 ),
73 config,
74 public_key,
75 private_key,
76 }
77 }
78}
79
80impl<P: SequencerPersistence> RequestResponseProtocol<P> {
81 pub async fn request_indefinitely<F, Fut, O>(
82 &self,
83 request: Request,
85 response_validation_fn: F,
87 ) -> std::result::Result<O, RequestError>
88 where
89 F: Fn(&Request, Response) -> Fut + Send + Sync + 'static + Clone,
90 Fut: Future<Output = anyhow::Result<O>> + Send + Sync + 'static,
91 O: Send + Sync + 'static + Clone,
92 {
93 self.inner
95 .request_indefinitely(
96 &self.public_key,
97 &self.private_key,
98 self.config.incoming_request_ttl,
99 request,
100 response_validation_fn,
101 )
102 .await
103 }
104}