1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
pub mod primary_to_primary_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use anemo::codegen::*;
#[derive(Debug, Clone)]
pub struct PrimaryToPrimaryClient<T> {
inner: anemo::rpc::client::Rpc<T>,
}
impl<T> PrimaryToPrimaryClient<T>
where
T: Service<Request<Bytes>, Response = Response<Bytes>>,
T::Error: Into<BoxError>,
{
pub fn new(inner: T) -> Self {
let inner = anemo::rpc::client::Rpc::new(inner);
Self { inner }
}
pub async fn send_message(
&mut self,
request: impl anemo::types::request::IntoRequest<crate::PrimaryMessage>,
) -> Result<anemo::Response<()>, anemo::rpc::Status> {
self.inner
.ready()
.await
.map_err(|e| {
anemo::rpc::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = anemo::rpc::codec::BincodeCodec::default();
let mut request = request.into_request();
*request.route_mut() = "/narwhal.PrimaryToPrimary/SendMessage".into();
self.inner.unary(request, codec).await
}
}
}
pub mod primary_to_primary_server {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use anemo::codegen::*;
#[async_trait]
pub trait PrimaryToPrimary: Send + Sync + 'static {
async fn send_message(
&self,
request: anemo::Request<crate::PrimaryMessage>,
) -> Result<anemo::Response<()>, anemo::rpc::Status>;
}
#[derive(Debug)]
pub struct PrimaryToPrimaryServer<T: PrimaryToPrimary> {
inner: Arc<T>,
}
impl<T: PrimaryToPrimary> PrimaryToPrimaryServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
Self { inner }
}
}
impl<T> anemo::codegen::Service<anemo::Request<Bytes>> for PrimaryToPrimaryServer<T>
where
T: PrimaryToPrimary,
{
type Response = anemo::Response<Bytes>;
type Error = std::convert::Infallible;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: anemo::Request<Bytes>) -> Self::Future {
let inner = self.inner.clone();
match req.route() {
"/narwhal.PrimaryToPrimary/SendMessage" => {
#[allow(non_camel_case_types)]
struct SendMessageSvc<T: PrimaryToPrimary>(pub Arc<T>);
impl<
T: PrimaryToPrimary,
> anemo::rpc::server::UnaryService<crate::PrimaryMessage>
for SendMessageSvc<T> {
type Response = ();
type Future = BoxFuture<
'static,
Result<anemo::Response<Self::Response>, anemo::rpc::Status>,
>;
fn call(
&mut self,
request: anemo::Request<crate::PrimaryMessage>,
) -> Self::Future {
let inner = self.0.clone();
let fut = async move {
(*inner).send_message(request).await
};
Box::pin(fut)
}
}
let inner = self.inner.clone();
let fut = async move {
let method = SendMessageSvc(inner);
let codec = anemo::rpc::codec::BincodeCodec::default();
let mut rpc = anemo::rpc::server::Rpc::new(codec);
let res = rpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
Ok(anemo::types::response::StatusCode::NotFound.into_response())
})
}
}
}
}
impl<T: PrimaryToPrimary> Clone for PrimaryToPrimaryServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self { inner }
}
}
impl<T: PrimaryToPrimary> anemo::rpc::RpcService for PrimaryToPrimaryServer<T> {
const SERVICE_NAME: &'static str = "narwhal.PrimaryToPrimary";
}
}