|
@@ -1,12 +1,17 @@
|
|
|
+//! This module contains the generated gRPC server code for the Signatory service.
|
|
|
use std::net::SocketAddr;
|
|
|
use std::path::Path;
|
|
|
|
|
|
+use tokio::io::{AsyncRead, AsyncWrite};
|
|
|
+use tokio_stream::Stream;
|
|
|
+use tonic::transport::server::Connected;
|
|
|
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};
|
|
|
use tonic::{Request, Response, Status};
|
|
|
|
|
|
use crate::proto::{self, signatory_server};
|
|
|
use crate::signatory::Signatory;
|
|
|
|
|
|
+/// The server implementation for the Signatory service.
|
|
|
pub struct CdkSignatoryServer<T>
|
|
|
where
|
|
|
T: Signatory + Send + Sync + 'static,
|
|
@@ -130,6 +135,7 @@ where
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// Error type for the gRPC server
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
pub enum Error {
|
|
|
/// Transport error
|
|
@@ -141,7 +147,7 @@ pub enum Error {
|
|
|
}
|
|
|
|
|
|
/// Runs the signatory server
|
|
|
-pub async fn grpc_server<T, I: AsRef<Path>>(
|
|
|
+pub async fn start_grpc_server<T, I: AsRef<Path>>(
|
|
|
signatory: T,
|
|
|
addr: SocketAddr,
|
|
|
tls_dir: Option<I>,
|
|
@@ -220,3 +226,23 @@ where
|
|
|
.await?;
|
|
|
Ok(())
|
|
|
}
|
|
|
+
|
|
|
+/// Starts the gRPC signatory server with an incoming stream of connections.
|
|
|
+pub async fn start_grpc_server_with_incoming<T, I, IO, IE>(
|
|
|
+ signatory: T,
|
|
|
+ incoming: I,
|
|
|
+) -> Result<(), Error>
|
|
|
+where
|
|
|
+ T: Signatory + Send + Sync + 'static,
|
|
|
+ I: Stream<Item = Result<IO, IE>>,
|
|
|
+ IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
|
|
|
+ IE: Into<Box<dyn std::error::Error + Send + Sync>>,
|
|
|
+{
|
|
|
+ Server::builder()
|
|
|
+ .add_service(signatory_server::SignatoryServer::new(CdkSignatoryServer {
|
|
|
+ inner: signatory,
|
|
|
+ }))
|
|
|
+ .serve_with_incoming(incoming)
|
|
|
+ .await?;
|
|
|
+ Ok(())
|
|
|
+}
|