Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add report fetching logic to FVR #2454

Merged
merged 1 commit into from
Aug 30, 2022
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
11 changes: 9 additions & 2 deletions fog/view/server/src/bin/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//! MobileCoin Fog View Router target
use grpcio::ChannelBuilder;
use mc_attest_net::{Client, RaClient};
use mc_common::logger::log;
use mc_fog_api::view_grpc::FogViewStoreApiClient;
use mc_fog_uri::FogViewStoreUri;
Expand Down Expand Up @@ -56,8 +57,14 @@ fn main() {
fog_view_store_grpc_clients.push(fog_view_store_grpc_client);
}

let mut router_server =
FogViewRouterServer::new(config, sgx_enclave, fog_view_store_grpc_clients, logger);
let ias_client = Client::new(&config.ias_api_key).expect("Could not create IAS client");
let mut router_server = FogViewRouterServer::new(
config,
sgx_enclave,
ias_client,
fog_view_store_grpc_clients,
logger,
);
router_server.start();

loop {
Expand Down
8 changes: 8 additions & 0 deletions fog/view/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ pub struct FogViewRouterConfig {
#[clap(long, env = "MC_CLIENT_LISTEN_URI")]
pub client_listen_uri: FogViewRouterUri,

/// PEM-formatted keypair to send with an Attestation Request.
#[clap(long, env = "MC_IAS_API_KEY")]
pub ias_api_key: String,

/// The IAS SPID to use when getting a quote
#[clap(long, env = "MC_IAS_SPID")]
pub ias_spid: ProviderId,

// TODO: Add shard uris which are of type Vec<FogViewStoreUri>.
/// The capacity to build the OMAP (ORAM hash table) with.
/// About 75% of this capacity can be used.
Expand Down
55 changes: 47 additions & 8 deletions fog/view/server/src/fog_view_router_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,43 @@
//! Constructible from config (for testability) and with a mechanism for
//! stopping it

use crate::{config::FogViewRouterConfig, fog_view_router_service::FogViewRouterService};
use crate::{config::FogViewRouterConfig, counters, fog_view_router_service::FogViewRouterService};
use futures::executor::block_on;
use mc_attest_net::RaClient;
use mc_common::logger::{log, Logger};
use mc_fog_api::view_grpc;
use mc_fog_uri::ConnectionUri;
use mc_fog_view_enclave::ViewEnclaveProxy;
use mc_sgx_report_cache_untrusted::ReportCacheThread;
use mc_util_grpc::{ConnectionUriGrpcioServer, ReadinessIndicator};
use std::sync::Arc;

pub struct FogViewRouterServer {
pub struct FogViewRouterServer<E, RC>
where
E: ViewEnclaveProxy,
RC: RaClient + Send + Sync + 'static,
{
server: grpcio::Server,
enclave: E,
config: FogViewRouterConfig,
logger: Logger,
ra_client: RC,
report_cache_thread: Option<ReportCacheThread>,
}

impl FogViewRouterServer {
impl<E, RC> FogViewRouterServer<E, RC>
where
E: ViewEnclaveProxy,
RC: RaClient + Send + Sync + 'static,
{
/// Creates a new view router server instance
pub fn new<E>(
pub fn new(
config: FogViewRouterConfig,
enclave: E,
ra_client: RC,
shards: Vec<view_grpc::FogViewStoreApiClient>,
logger: Logger,
) -> FogViewRouterServer
) -> FogViewRouterServer<E, RC>
where
E: ViewEnclaveProxy,
{
Expand All @@ -38,7 +53,7 @@ impl FogViewRouterServer {
);

let fog_view_router_service = view_grpc::create_fog_view_router_api(
FogViewRouterService::new(enclave, shards, logger.clone()),
FogViewRouterService::new(enclave.clone(), shards, logger.clone()),
);
log::debug!(logger, "Constructed Fog View Router GRPC Service");

Expand All @@ -60,11 +75,28 @@ impl FogViewRouterServer {

let server = server_builder.build().unwrap();

Self { server, logger }
Self {
server,
enclave,
config,
logger,
ra_client,
report_cache_thread: None,
}
}

/// Starts the server
pub fn start(&mut self) {
self.report_cache_thread = Some(
ReportCacheThread::start(
self.enclave.clone(),
self.ra_client.clone(),
self.config.ias_spid,
&counters::ENCLAVE_REPORT_TIMESTAMP,
self.logger.clone(),
)
.expect("failed starting report cache thread"),
);
self.server.start();
for (host, port) in self.server.bind_addrs() {
log::info!(self.logger, "API listening on {}:{}", host, port);
Expand All @@ -73,11 +105,18 @@ impl FogViewRouterServer {

/// Stops the server
pub fn stop(&mut self) {
if let Some(ref mut thread) = self.report_cache_thread.take() {
thread.stop().expect("Could not stop report cache thread");
}
block_on(self.server.shutdown()).expect("Could not stop grpc server");
}
}

impl Drop for FogViewRouterServer {
impl<E, RC> Drop for FogViewRouterServer<E, RC>
where
E: ViewEnclaveProxy,
RC: RaClient + Send + Sync + 'static,
{
fn drop(&mut self) {
self.stop();
}
Expand Down