Skip to main content

danube_core/proto/
danube.raft.rs

1// This file is @generated by prost-build.
2#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
3pub struct RaftRequest {
4    #[prost(bytes = "vec", tag = "1")]
5    pub data: ::prost::alloc::vec::Vec<u8>,
6}
7#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
8pub struct RaftReply {
9    #[prost(bytes = "vec", tag = "1")]
10    pub data: ::prost::alloc::vec::Vec<u8>,
11    #[prost(string, tag = "2")]
12    pub error: ::prost::alloc::string::String,
13}
14#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
15pub struct Empty {}
16#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
17pub struct NodeInfoReply {
18    #[prost(uint64, tag = "1")]
19    pub node_id: u64,
20    #[prost(string, tag = "2")]
21    pub raft_addr: ::prost::alloc::string::String,
22    #[prost(bool, tag = "3")]
23    pub has_leader: bool,
24}
25#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
26pub struct ClientWriteRequest {
27    /// bincode-serialized RaftCommand
28    #[prost(bytes = "vec", tag = "1")]
29    pub data: ::prost::alloc::vec::Vec<u8>,
30}
31#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
32pub struct ClientWriteReply {
33    /// bincode-serialized RaftResponse
34    #[prost(bytes = "vec", tag = "1")]
35    pub data: ::prost::alloc::vec::Vec<u8>,
36    /// non-empty on failure
37    #[prost(string, tag = "2")]
38    pub error: ::prost::alloc::string::String,
39}
40/// Generated client implementations.
41pub mod raft_transport_client {
42    #![allow(
43        unused_variables,
44        dead_code,
45        missing_docs,
46        clippy::wildcard_imports,
47        clippy::let_unit_value,
48    )]
49    use tonic::codegen::*;
50    use tonic::codegen::http::Uri;
51    #[derive(Debug, Clone)]
52    pub struct RaftTransportClient<T> {
53        inner: tonic::client::Grpc<T>,
54    }
55    impl RaftTransportClient<tonic::transport::Channel> {
56        /// Attempt to create a new client by connecting to a given endpoint.
57        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
58        where
59            D: TryInto<tonic::transport::Endpoint>,
60            D::Error: Into<StdError>,
61        {
62            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
63            Ok(Self::new(conn))
64        }
65    }
66    impl<T> RaftTransportClient<T>
67    where
68        T: tonic::client::GrpcService<tonic::body::Body>,
69        T::Error: Into<StdError>,
70        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
71        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
72    {
73        pub fn new(inner: T) -> Self {
74            let inner = tonic::client::Grpc::new(inner);
75            Self { inner }
76        }
77        pub fn with_origin(inner: T, origin: Uri) -> Self {
78            let inner = tonic::client::Grpc::with_origin(inner, origin);
79            Self { inner }
80        }
81        pub fn with_interceptor<F>(
82            inner: T,
83            interceptor: F,
84        ) -> RaftTransportClient<InterceptedService<T, F>>
85        where
86            F: tonic::service::Interceptor,
87            T::ResponseBody: Default,
88            T: tonic::codegen::Service<
89                http::Request<tonic::body::Body>,
90                Response = http::Response<
91                    <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
92                >,
93            >,
94            <T as tonic::codegen::Service<
95                http::Request<tonic::body::Body>,
96            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
97        {
98            RaftTransportClient::new(InterceptedService::new(inner, interceptor))
99        }
100        /// Compress requests with the given encoding.
101        ///
102        /// This requires the server to support it otherwise it might respond with an
103        /// error.
104        #[must_use]
105        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
106            self.inner = self.inner.send_compressed(encoding);
107            self
108        }
109        /// Enable decompressing responses.
110        #[must_use]
111        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
112            self.inner = self.inner.accept_compressed(encoding);
113            self
114        }
115        /// Limits the maximum size of a decoded message.
116        ///
117        /// Default: `4MB`
118        #[must_use]
119        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
120            self.inner = self.inner.max_decoding_message_size(limit);
121            self
122        }
123        /// Limits the maximum size of an encoded message.
124        ///
125        /// Default: `usize::MAX`
126        #[must_use]
127        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
128            self.inner = self.inner.max_encoding_message_size(limit);
129            self
130        }
131        pub async fn append_entries(
132            &mut self,
133            request: impl tonic::IntoRequest<super::RaftRequest>,
134        ) -> std::result::Result<tonic::Response<super::RaftReply>, tonic::Status> {
135            self.inner
136                .ready()
137                .await
138                .map_err(|e| {
139                    tonic::Status::unknown(
140                        format!("Service was not ready: {}", e.into()),
141                    )
142                })?;
143            let codec = tonic_prost::ProstCodec::default();
144            let path = http::uri::PathAndQuery::from_static(
145                "/danube.raft.RaftTransport/AppendEntries",
146            );
147            let mut req = request.into_request();
148            req.extensions_mut()
149                .insert(GrpcMethod::new("danube.raft.RaftTransport", "AppendEntries"));
150            self.inner.unary(req, path, codec).await
151        }
152        pub async fn vote(
153            &mut self,
154            request: impl tonic::IntoRequest<super::RaftRequest>,
155        ) -> std::result::Result<tonic::Response<super::RaftReply>, tonic::Status> {
156            self.inner
157                .ready()
158                .await
159                .map_err(|e| {
160                    tonic::Status::unknown(
161                        format!("Service was not ready: {}", e.into()),
162                    )
163                })?;
164            let codec = tonic_prost::ProstCodec::default();
165            let path = http::uri::PathAndQuery::from_static(
166                "/danube.raft.RaftTransport/Vote",
167            );
168            let mut req = request.into_request();
169            req.extensions_mut()
170                .insert(GrpcMethod::new("danube.raft.RaftTransport", "Vote"));
171            self.inner.unary(req, path, codec).await
172        }
173        pub async fn install_snapshot(
174            &mut self,
175            request: impl tonic::IntoRequest<super::RaftRequest>,
176        ) -> std::result::Result<tonic::Response<super::RaftReply>, tonic::Status> {
177            self.inner
178                .ready()
179                .await
180                .map_err(|e| {
181                    tonic::Status::unknown(
182                        format!("Service was not ready: {}", e.into()),
183                    )
184                })?;
185            let codec = tonic_prost::ProstCodec::default();
186            let path = http::uri::PathAndQuery::from_static(
187                "/danube.raft.RaftTransport/InstallSnapshot",
188            );
189            let mut req = request.into_request();
190            req.extensions_mut()
191                .insert(GrpcMethod::new("danube.raft.RaftTransport", "InstallSnapshot"));
192            self.inner.unary(req, path, codec).await
193        }
194        /// Lightweight discovery RPC — returns this node's stable identity.
195        /// Used during cluster bootstrap so seed peers can exchange node_ids.
196        pub async fn get_node_info(
197            &mut self,
198            request: impl tonic::IntoRequest<super::Empty>,
199        ) -> std::result::Result<tonic::Response<super::NodeInfoReply>, tonic::Status> {
200            self.inner
201                .ready()
202                .await
203                .map_err(|e| {
204                    tonic::Status::unknown(
205                        format!("Service was not ready: {}", e.into()),
206                    )
207                })?;
208            let codec = tonic_prost::ProstCodec::default();
209            let path = http::uri::PathAndQuery::from_static(
210                "/danube.raft.RaftTransport/GetNodeInfo",
211            );
212            let mut req = request.into_request();
213            req.extensions_mut()
214                .insert(GrpcMethod::new("danube.raft.RaftTransport", "GetNodeInfo"));
215            self.inner.unary(req, path, codec).await
216        }
217        /// Forward a client write to the current leader.
218        /// Followers use this to proxy proposals they cannot handle locally.
219        pub async fn client_write(
220            &mut self,
221            request: impl tonic::IntoRequest<super::ClientWriteRequest>,
222        ) -> std::result::Result<
223            tonic::Response<super::ClientWriteReply>,
224            tonic::Status,
225        > {
226            self.inner
227                .ready()
228                .await
229                .map_err(|e| {
230                    tonic::Status::unknown(
231                        format!("Service was not ready: {}", e.into()),
232                    )
233                })?;
234            let codec = tonic_prost::ProstCodec::default();
235            let path = http::uri::PathAndQuery::from_static(
236                "/danube.raft.RaftTransport/ClientWrite",
237            );
238            let mut req = request.into_request();
239            req.extensions_mut()
240                .insert(GrpcMethod::new("danube.raft.RaftTransport", "ClientWrite"));
241            self.inner.unary(req, path, codec).await
242        }
243    }
244}
245/// Generated server implementations.
246pub mod raft_transport_server {
247    #![allow(
248        unused_variables,
249        dead_code,
250        missing_docs,
251        clippy::wildcard_imports,
252        clippy::let_unit_value,
253    )]
254    use tonic::codegen::*;
255    /// Generated trait containing gRPC methods that should be implemented for use with RaftTransportServer.
256    #[async_trait]
257    pub trait RaftTransport: std::marker::Send + std::marker::Sync + 'static {
258        async fn append_entries(
259            &self,
260            request: tonic::Request<super::RaftRequest>,
261        ) -> std::result::Result<tonic::Response<super::RaftReply>, tonic::Status>;
262        async fn vote(
263            &self,
264            request: tonic::Request<super::RaftRequest>,
265        ) -> std::result::Result<tonic::Response<super::RaftReply>, tonic::Status>;
266        async fn install_snapshot(
267            &self,
268            request: tonic::Request<super::RaftRequest>,
269        ) -> std::result::Result<tonic::Response<super::RaftReply>, tonic::Status>;
270        /// Lightweight discovery RPC — returns this node's stable identity.
271        /// Used during cluster bootstrap so seed peers can exchange node_ids.
272        async fn get_node_info(
273            &self,
274            request: tonic::Request<super::Empty>,
275        ) -> std::result::Result<tonic::Response<super::NodeInfoReply>, tonic::Status>;
276        /// Forward a client write to the current leader.
277        /// Followers use this to proxy proposals they cannot handle locally.
278        async fn client_write(
279            &self,
280            request: tonic::Request<super::ClientWriteRequest>,
281        ) -> std::result::Result<
282            tonic::Response<super::ClientWriteReply>,
283            tonic::Status,
284        >;
285    }
286    #[derive(Debug)]
287    pub struct RaftTransportServer<T> {
288        inner: Arc<T>,
289        accept_compression_encodings: EnabledCompressionEncodings,
290        send_compression_encodings: EnabledCompressionEncodings,
291        max_decoding_message_size: Option<usize>,
292        max_encoding_message_size: Option<usize>,
293    }
294    impl<T> RaftTransportServer<T> {
295        pub fn new(inner: T) -> Self {
296            Self::from_arc(Arc::new(inner))
297        }
298        pub fn from_arc(inner: Arc<T>) -> Self {
299            Self {
300                inner,
301                accept_compression_encodings: Default::default(),
302                send_compression_encodings: Default::default(),
303                max_decoding_message_size: None,
304                max_encoding_message_size: None,
305            }
306        }
307        pub fn with_interceptor<F>(
308            inner: T,
309            interceptor: F,
310        ) -> InterceptedService<Self, F>
311        where
312            F: tonic::service::Interceptor,
313        {
314            InterceptedService::new(Self::new(inner), interceptor)
315        }
316        /// Enable decompressing requests with the given encoding.
317        #[must_use]
318        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
319            self.accept_compression_encodings.enable(encoding);
320            self
321        }
322        /// Compress responses with the given encoding, if the client supports it.
323        #[must_use]
324        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
325            self.send_compression_encodings.enable(encoding);
326            self
327        }
328        /// Limits the maximum size of a decoded message.
329        ///
330        /// Default: `4MB`
331        #[must_use]
332        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
333            self.max_decoding_message_size = Some(limit);
334            self
335        }
336        /// Limits the maximum size of an encoded message.
337        ///
338        /// Default: `usize::MAX`
339        #[must_use]
340        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
341            self.max_encoding_message_size = Some(limit);
342            self
343        }
344    }
345    impl<T, B> tonic::codegen::Service<http::Request<B>> for RaftTransportServer<T>
346    where
347        T: RaftTransport,
348        B: Body + std::marker::Send + 'static,
349        B::Error: Into<StdError> + std::marker::Send + 'static,
350    {
351        type Response = http::Response<tonic::body::Body>;
352        type Error = std::convert::Infallible;
353        type Future = BoxFuture<Self::Response, Self::Error>;
354        fn poll_ready(
355            &mut self,
356            _cx: &mut Context<'_>,
357        ) -> Poll<std::result::Result<(), Self::Error>> {
358            Poll::Ready(Ok(()))
359        }
360        fn call(&mut self, req: http::Request<B>) -> Self::Future {
361            match req.uri().path() {
362                "/danube.raft.RaftTransport/AppendEntries" => {
363                    #[allow(non_camel_case_types)]
364                    struct AppendEntriesSvc<T: RaftTransport>(pub Arc<T>);
365                    impl<
366                        T: RaftTransport,
367                    > tonic::server::UnaryService<super::RaftRequest>
368                    for AppendEntriesSvc<T> {
369                        type Response = super::RaftReply;
370                        type Future = BoxFuture<
371                            tonic::Response<Self::Response>,
372                            tonic::Status,
373                        >;
374                        fn call(
375                            &mut self,
376                            request: tonic::Request<super::RaftRequest>,
377                        ) -> Self::Future {
378                            let inner = Arc::clone(&self.0);
379                            let fut = async move {
380                                <T as RaftTransport>::append_entries(&inner, request).await
381                            };
382                            Box::pin(fut)
383                        }
384                    }
385                    let accept_compression_encodings = self.accept_compression_encodings;
386                    let send_compression_encodings = self.send_compression_encodings;
387                    let max_decoding_message_size = self.max_decoding_message_size;
388                    let max_encoding_message_size = self.max_encoding_message_size;
389                    let inner = self.inner.clone();
390                    let fut = async move {
391                        let method = AppendEntriesSvc(inner);
392                        let codec = tonic_prost::ProstCodec::default();
393                        let mut grpc = tonic::server::Grpc::new(codec)
394                            .apply_compression_config(
395                                accept_compression_encodings,
396                                send_compression_encodings,
397                            )
398                            .apply_max_message_size_config(
399                                max_decoding_message_size,
400                                max_encoding_message_size,
401                            );
402                        let res = grpc.unary(method, req).await;
403                        Ok(res)
404                    };
405                    Box::pin(fut)
406                }
407                "/danube.raft.RaftTransport/Vote" => {
408                    #[allow(non_camel_case_types)]
409                    struct VoteSvc<T: RaftTransport>(pub Arc<T>);
410                    impl<
411                        T: RaftTransport,
412                    > tonic::server::UnaryService<super::RaftRequest> for VoteSvc<T> {
413                        type Response = super::RaftReply;
414                        type Future = BoxFuture<
415                            tonic::Response<Self::Response>,
416                            tonic::Status,
417                        >;
418                        fn call(
419                            &mut self,
420                            request: tonic::Request<super::RaftRequest>,
421                        ) -> Self::Future {
422                            let inner = Arc::clone(&self.0);
423                            let fut = async move {
424                                <T as RaftTransport>::vote(&inner, request).await
425                            };
426                            Box::pin(fut)
427                        }
428                    }
429                    let accept_compression_encodings = self.accept_compression_encodings;
430                    let send_compression_encodings = self.send_compression_encodings;
431                    let max_decoding_message_size = self.max_decoding_message_size;
432                    let max_encoding_message_size = self.max_encoding_message_size;
433                    let inner = self.inner.clone();
434                    let fut = async move {
435                        let method = VoteSvc(inner);
436                        let codec = tonic_prost::ProstCodec::default();
437                        let mut grpc = tonic::server::Grpc::new(codec)
438                            .apply_compression_config(
439                                accept_compression_encodings,
440                                send_compression_encodings,
441                            )
442                            .apply_max_message_size_config(
443                                max_decoding_message_size,
444                                max_encoding_message_size,
445                            );
446                        let res = grpc.unary(method, req).await;
447                        Ok(res)
448                    };
449                    Box::pin(fut)
450                }
451                "/danube.raft.RaftTransport/InstallSnapshot" => {
452                    #[allow(non_camel_case_types)]
453                    struct InstallSnapshotSvc<T: RaftTransport>(pub Arc<T>);
454                    impl<
455                        T: RaftTransport,
456                    > tonic::server::UnaryService<super::RaftRequest>
457                    for InstallSnapshotSvc<T> {
458                        type Response = super::RaftReply;
459                        type Future = BoxFuture<
460                            tonic::Response<Self::Response>,
461                            tonic::Status,
462                        >;
463                        fn call(
464                            &mut self,
465                            request: tonic::Request<super::RaftRequest>,
466                        ) -> Self::Future {
467                            let inner = Arc::clone(&self.0);
468                            let fut = async move {
469                                <T as RaftTransport>::install_snapshot(&inner, request)
470                                    .await
471                            };
472                            Box::pin(fut)
473                        }
474                    }
475                    let accept_compression_encodings = self.accept_compression_encodings;
476                    let send_compression_encodings = self.send_compression_encodings;
477                    let max_decoding_message_size = self.max_decoding_message_size;
478                    let max_encoding_message_size = self.max_encoding_message_size;
479                    let inner = self.inner.clone();
480                    let fut = async move {
481                        let method = InstallSnapshotSvc(inner);
482                        let codec = tonic_prost::ProstCodec::default();
483                        let mut grpc = tonic::server::Grpc::new(codec)
484                            .apply_compression_config(
485                                accept_compression_encodings,
486                                send_compression_encodings,
487                            )
488                            .apply_max_message_size_config(
489                                max_decoding_message_size,
490                                max_encoding_message_size,
491                            );
492                        let res = grpc.unary(method, req).await;
493                        Ok(res)
494                    };
495                    Box::pin(fut)
496                }
497                "/danube.raft.RaftTransport/GetNodeInfo" => {
498                    #[allow(non_camel_case_types)]
499                    struct GetNodeInfoSvc<T: RaftTransport>(pub Arc<T>);
500                    impl<T: RaftTransport> tonic::server::UnaryService<super::Empty>
501                    for GetNodeInfoSvc<T> {
502                        type Response = super::NodeInfoReply;
503                        type Future = BoxFuture<
504                            tonic::Response<Self::Response>,
505                            tonic::Status,
506                        >;
507                        fn call(
508                            &mut self,
509                            request: tonic::Request<super::Empty>,
510                        ) -> Self::Future {
511                            let inner = Arc::clone(&self.0);
512                            let fut = async move {
513                                <T as RaftTransport>::get_node_info(&inner, request).await
514                            };
515                            Box::pin(fut)
516                        }
517                    }
518                    let accept_compression_encodings = self.accept_compression_encodings;
519                    let send_compression_encodings = self.send_compression_encodings;
520                    let max_decoding_message_size = self.max_decoding_message_size;
521                    let max_encoding_message_size = self.max_encoding_message_size;
522                    let inner = self.inner.clone();
523                    let fut = async move {
524                        let method = GetNodeInfoSvc(inner);
525                        let codec = tonic_prost::ProstCodec::default();
526                        let mut grpc = tonic::server::Grpc::new(codec)
527                            .apply_compression_config(
528                                accept_compression_encodings,
529                                send_compression_encodings,
530                            )
531                            .apply_max_message_size_config(
532                                max_decoding_message_size,
533                                max_encoding_message_size,
534                            );
535                        let res = grpc.unary(method, req).await;
536                        Ok(res)
537                    };
538                    Box::pin(fut)
539                }
540                "/danube.raft.RaftTransport/ClientWrite" => {
541                    #[allow(non_camel_case_types)]
542                    struct ClientWriteSvc<T: RaftTransport>(pub Arc<T>);
543                    impl<
544                        T: RaftTransport,
545                    > tonic::server::UnaryService<super::ClientWriteRequest>
546                    for ClientWriteSvc<T> {
547                        type Response = super::ClientWriteReply;
548                        type Future = BoxFuture<
549                            tonic::Response<Self::Response>,
550                            tonic::Status,
551                        >;
552                        fn call(
553                            &mut self,
554                            request: tonic::Request<super::ClientWriteRequest>,
555                        ) -> Self::Future {
556                            let inner = Arc::clone(&self.0);
557                            let fut = async move {
558                                <T as RaftTransport>::client_write(&inner, request).await
559                            };
560                            Box::pin(fut)
561                        }
562                    }
563                    let accept_compression_encodings = self.accept_compression_encodings;
564                    let send_compression_encodings = self.send_compression_encodings;
565                    let max_decoding_message_size = self.max_decoding_message_size;
566                    let max_encoding_message_size = self.max_encoding_message_size;
567                    let inner = self.inner.clone();
568                    let fut = async move {
569                        let method = ClientWriteSvc(inner);
570                        let codec = tonic_prost::ProstCodec::default();
571                        let mut grpc = tonic::server::Grpc::new(codec)
572                            .apply_compression_config(
573                                accept_compression_encodings,
574                                send_compression_encodings,
575                            )
576                            .apply_max_message_size_config(
577                                max_decoding_message_size,
578                                max_encoding_message_size,
579                            );
580                        let res = grpc.unary(method, req).await;
581                        Ok(res)
582                    };
583                    Box::pin(fut)
584                }
585                _ => {
586                    Box::pin(async move {
587                        let mut response = http::Response::new(
588                            tonic::body::Body::default(),
589                        );
590                        let headers = response.headers_mut();
591                        headers
592                            .insert(
593                                tonic::Status::GRPC_STATUS,
594                                (tonic::Code::Unimplemented as i32).into(),
595                            );
596                        headers
597                            .insert(
598                                http::header::CONTENT_TYPE,
599                                tonic::metadata::GRPC_CONTENT_TYPE,
600                            );
601                        Ok(response)
602                    })
603                }
604            }
605        }
606    }
607    impl<T> Clone for RaftTransportServer<T> {
608        fn clone(&self) -> Self {
609            let inner = self.inner.clone();
610            Self {
611                inner,
612                accept_compression_encodings: self.accept_compression_encodings,
613                send_compression_encodings: self.send_compression_encodings,
614                max_decoding_message_size: self.max_decoding_message_size,
615                max_encoding_message_size: self.max_encoding_message_size,
616            }
617        }
618    }
619    /// Generated gRPC service name
620    pub const SERVICE_NAME: &str = "danube.raft.RaftTransport";
621    impl<T> tonic::server::NamedService for RaftTransportServer<T> {
622        const NAME: &'static str = SERVICE_NAME;
623    }
624}