Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ rcgen = { version = "0.13.1", features = ["pem"] }
x509-parser = "0.16.0"

# RPC/Protocol
prpc = "0.3.0"
prpc-build = "0.3.6"
prpc = "0.4.0"
prpc-build = "0.4.1"

# Development/Testing
bindgen = "0.70.1"
Expand Down
4 changes: 2 additions & 2 deletions kms/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use anyhow::{anyhow, Context, Result};
use clap::Parser;
use config::KmsConfig;
use main_service::{KmsState, RpcHandler};
use ra_rpc::rocket_helper::QuoteVerifier;
use rocket::fairing::AdHoc;
use tracing::info;

mod config;
mod ct_log;
mod main_service;
mod web_routes;

fn app_version() -> String {
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -53,7 +53,7 @@ async fn main() -> Result<()> {
res.set_raw_header("X-App-Version", app_version());
})
}))
.mount("/", web_routes::routes())
.mount("/prpc", ra_rpc::prpc_routes!(KmsState, RpcHandler))
.manage(state);

if !pccs_url.is_empty() {
Expand Down
9 changes: 1 addition & 8 deletions kms/src/main_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,7 @@ impl KmsRpc for RpcHandler {
impl RpcCall<KmsState> for RpcHandler {
type PrpcService = KmsServer<Self>;

fn into_prpc_service(self) -> Self::PrpcService {
KmsServer::new(self)
}

fn construct(context: CallContext<'_, KmsState>) -> Result<Self>
where
Self: Sized,
{
fn construct(context: CallContext<'_, KmsState>) -> Result<Self> {
Ok(RpcHandler {
state: context.state.clone(),
attestation: context.attestation,
Expand Down
68 changes: 0 additions & 68 deletions kms/src/web_routes.rs

This file was deleted.

33 changes: 21 additions & 12 deletions ra-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,40 @@ pub struct CallContext<'a, State> {
pub remote_endpoint: Option<RemoteEndpoint>,
}

pub trait RpcCall<State> {
type PrpcService: PrpcService + Send + 'static;
pub trait RpcCall<State>: Sized {
type PrpcService: PrpcService + From<Self> + Send + 'static;

fn construct(context: CallContext<'_, State>) -> Result<Self>
where
Self: Sized;
fn into_prpc_service(self) -> Self::PrpcService;
async fn call(self, method: String, payload: Vec<u8>, is_json: bool) -> (u16, Vec<u8>)
where
Self: Sized,
{
dispatch_prpc(method, payload, is_json, self.into_prpc_service()).await
fn construct(context: CallContext<'_, State>) -> Result<Self>;

async fn call(
self,
method: String,
payload: Vec<u8>,
is_json: bool,
is_query: bool,
) -> (u16, Vec<u8>) {
dispatch_prpc(
method,
payload,
is_json,
is_query,
<Self::PrpcService as From<Self>>::from(self),
)
.await
}
}

async fn dispatch_prpc(
path: String,
data: Vec<u8>,
json: bool,
query: bool,
server: impl PrpcService + Send + 'static,
) -> (u16, Vec<u8>) {
use prpc::server::Error;

info!("dispatching request: {}", path);
let result = server.dispatch_request(&path, data, json).await;
let result = server.dispatch_request(&path, data, json, query).await;
let (code, data) = match result {
Ok(data) => (200, data),
Err(err) => {
Expand Down
Loading