Skip to content

Commit

Permalink
More reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
Millie C committed Sep 1, 2022
1 parent 6f717b2 commit af5eb34
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use mc_common::logger::log;
use mc_fog_api::ledger_grpc::KeyImageStoreApiClient;
use mc_fog_ledger_enclave::{ENCLAVE_FILE, LedgerSgxEnclave};
use mc_fog_ledger_server::LedgerRouterConfig;
use mc_fog_ledger_server::KeyImageRouterServer;
use clap::Parser;
use mc_fog_uri::{LedgerStoreUri, KeyImageStoreScheme};
use mc_fog_uri::{KeyImageStoreUri, KeyImageStoreScheme};
use mc_util_grpc::ConnectionUriGrpcioChannel;
use mc_util_uri::UriScheme;

Expand All @@ -25,7 +26,7 @@ fn main() {
enclave_path.to_str().unwrap(),
&config.client_responder_id
);
let _enclave = LedgerSgxEnclave::new(
let enclave = LedgerSgxEnclave::new(
enclave_path,
&config.client_responder_id,
config.omap_capacity,
Expand All @@ -44,21 +45,19 @@ fn main() {
KeyImageStoreScheme::SCHEME_INSECURE,
i
);
let shard_uri = LedgerStoreUri::from_str(&shard_uri_string).unwrap();
let shard_uri = KeyImageStoreUri::from_str(&shard_uri_string).unwrap();
let ledger_store_grpc_client = KeyImageStoreApiClient::new(
ChannelBuilder::default_channel_builder(grpc_env.clone())
.connect_to_uri(&shard_uri, &logger),
);
ledger_store_grpc_clients.push(ledger_store_grpc_client);
}

todo!();

/*
let mut router_server =
LedgerRouterServer::new(config, enclave, ledger_store_grpc_clients, logger);
KeyImageRouterServer::new(config, enclave, ledger_store_grpc_clients, logger);
router_server.start();

loop {
std::thread::sleep(std::time::Duration::from_millis(1000));
}*/
}
}
22 changes: 11 additions & 11 deletions fog/ledger/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use clap::Parser;
use mc_attest_core::ProviderId;
use mc_common::ResponderId;
use mc_fog_uri::{FogLedgerUri, LedgerRouterUri, LedgerStoreUri};
use mc_fog_uri::{FogLedgerUri, KeyImageRouterUri, KeyImageStoreUri};
use mc_util_parse::parse_duration_in_seconds;
use mc_util_uri::AdminUri;
use serde::Serialize;
Expand Down Expand Up @@ -79,24 +79,24 @@ pub struct LedgerServerConfig {
/// TODO - This is almost identical to Fog View's implementation of this
/// combine it later?
#[derive(Clone, Serialize)]
pub enum ClientListenUri {
pub enum KeyImageClientListenUri {
/// URI used by the FogViewServer when fulfilling direct client requests.
ClientFacing(LedgerRouterUri),
ClientFacing(KeyImageRouterUri),
/// URI used by the FogViewServer when fulfilling Fog View Router requests.
Store(LedgerStoreUri),
Store(KeyImageStoreUri),
}

impl FromStr for ClientListenUri {
impl FromStr for KeyImageClientListenUri {
type Err = String;
fn from_str(input: &str) -> Result<Self, String> {
if let Ok(fog_ledger_router_uri) = LedgerRouterUri::from_str(input) {
return Ok(ClientListenUri::ClientFacing(fog_ledger_router_uri));
if let Ok(ledger_router_uri) = KeyImageRouterUri::from_str(input) {
return Ok(KeyImageClientListenUri::ClientFacing(ledger_router_uri));
}
if let Ok(fog_ledger_store_uri) = LedgerStoreUri::from_str(input) {
return Ok(ClientListenUri::Store(fog_ledger_store_uri));
if let Ok(ledger_store_uri) = KeyImageStoreUri::from_str(input) {
return Ok(KeyImageClientListenUri::Store(ledger_store_uri));
}

Err(format!("Incorrect ClientListenUri string: {}.", input))
Err(format!("Incorrect KeyImageClientListenUri string: {}.", input))
}
}

Expand All @@ -113,7 +113,7 @@ pub struct LedgerRouterConfig {

/// gRPC listening URI for client requests.
#[clap(long, env = "MC_CLIENT_LISTEN_URI")]
pub client_listen_uri: ClientListenUri,
pub client_listen_uri: KeyImageClientListenUri,

// TODO: Add store instance uris which are of type Vec<FogLedgerStoreUri>.
/// The capacity to build the OMAP (ORAM hash table) with.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,69 @@ use mc_fog_ledger_enclave::LedgerEnclaveProxy;
use mc_fog_uri::ConnectionUri;
use mc_util_grpc::{ReadinessIndicator, ConnectionUriGrpcioServer};

use crate::{ledger_router_service::LedgerRouterService, config::LedgerRouterConfig};
use crate::{key_image_router_service::KeyImageRouterService, config::LedgerRouterConfig};

#[allow(dead_code)] // FIXME
pub struct LedgerRouterServer {
pub struct KeyImageRouterServer {
server: grpcio::Server,
logger: Logger,
}

impl LedgerRouterServer {
impl KeyImageRouterServer {
/// Creates a new ledger router server instance
#[allow(dead_code)] // FIXME
pub fn new<E> (
config: LedgerRouterConfig,
enclave: E,
shards: Vec<ledger_grpc::LedgerStoreApiClient>,
shards: Vec<ledger_grpc::KeyImageStoreApiClient>,
logger: Logger,
) -> LedgerRouterServer
) -> KeyImageRouterServer
where
E: LedgerEnclaveProxy,
{
let readiness_indicator = ReadinessIndicator::default();

let env = Arc::new(
grpcio::EnvBuilder::new()
.name_prefix("Fog-ledger-router-server".to_string())
.name_prefix("key-image-router-and-store-server".to_string())
.build(),
);

// Init ledger router service.
let ledger_router_service = ledger_grpc::create_ledger_api(
LedgerRouterService::new(enclave, shards, logger.clone()),
);
log::debug!(logger, "Constructed Fog Ledger Router GRPC Service");

// Health check service
// Health check service - will be used in both cases
let health_service =
mc_util_grpc::HealthService::new(
Some(readiness_indicator.into()), logger.clone()
).into_service();

match config.client_listen_uri {
crate::config::ClientListenUri::ClientFacing(_ledger_router_uri) => todo!(),
crate::config::ClientListenUri::Store(ledger_store_uri) => {
// Router server
crate::config::KeyImageClientListenUri::ClientFacing(ledger_router_uri) => {

// Init ledger router service.
let ledger_router_service = ledger_grpc::create_ledger_api(
KeyImageRouterService::new(enclave, shards, logger.clone()),
);
log::debug!(logger, "Constructed Key Image Store GRPC Service");

// Package service into grpc server
log::info!(
logger,
"Starting Fog View Router server on {}",
ledger_store_uri.addr(),
"Starting Key Image Store server on {}",
ledger_router_uri.addr(),
);
let server_builder = grpcio::ServerBuilder::new(env)
.register_service(ledger_router_service)
.register_service(health_service)
.bind_using_uri(&ledger_store_uri, logger.clone());
.bind_using_uri(&ledger_router_uri, logger.clone());

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

Self { server, logger }
},
// Store server.
crate::config::KeyImageClientListenUri::Store(_ledger_store_uri) => {
todo!()
},
}
}

Expand All @@ -85,7 +90,7 @@ impl LedgerRouterServer {
}
}

impl Drop for LedgerRouterServer {
impl Drop for KeyImageRouterServer {
fn drop(&mut self) {
self.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ use crate::router_handlers;

#[allow(dead_code)] // FIXME
#[derive(Clone)]
pub struct LedgerRouterService<E>
pub struct KeyImageRouterService<E>
where
E: LedgerEnclaveProxy,
{
enclave: E,
shards: Vec<Arc<ledger_grpc::LedgerStoreApiClient>>,
shards: Vec<Arc<ledger_grpc::KeyImageStoreApiClient>>,
logger: Logger,
}

impl<E: LedgerEnclaveProxy> LedgerRouterService<E> {
impl<E: LedgerEnclaveProxy> KeyImageRouterService<E> {
/// Creates a new LedgerRouterService that can be used by a gRPC server to
/// fulfill gRPC requests.
#[allow(dead_code)] // FIXME
pub fn new(enclave: E, shards: Vec<ledger_grpc::LedgerStoreApiClient>, logger: Logger) -> Self {
pub fn new(enclave: E, shards: Vec<ledger_grpc::KeyImageStoreApiClient>, logger: Logger) -> Self {
let shards = shards.into_iter().map(Arc::new).collect();
Self {
enclave,
Expand All @@ -38,7 +38,7 @@ impl<E: LedgerEnclaveProxy> LedgerRouterService<E> {
}
}

impl<E> LedgerApi for LedgerRouterService<E>
impl<E> LedgerApi for KeyImageRouterService<E>
where
E: LedgerEnclaveProxy,
{
Expand Down
7 changes: 6 additions & 1 deletion fog/ledger/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ mod router_handlers;
mod server;
mod untrusted_tx_out_service;

//Router & store system. KeyImageService can function as a Store but the router is implemented as a different GRPC server struct.
mod key_image_router_service;
mod key_image_router_server;

pub use block_service::BlockService;
pub use config::LedgerServerConfig;
pub use key_image_service::KeyImageService;
pub use merkle_proof_service::MerkleProofService;
pub use server::LedgerServer;
pub use untrusted_tx_out_service::UntrustedTxOutService;

pub use config::LedgerRouterConfig;
pub use config::LedgerRouterConfig;
pub use key_image_router_server::KeyImageRouterServer;
8 changes: 4 additions & 4 deletions fog/ledger/server/src/router_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mc_fog_api::{
ledger::{LedgerRequest, LedgerResponse, MultiKeyImageStoreRequest, MultiKeyImageStoreResponse}, ledger_grpc::KeyImageStoreApiClient,
};
use mc_fog_ledger_enclave::LedgerEnclaveProxy;
use mc_fog_uri::LedgerStoreUri;
use mc_fog_uri::KeyImageStoreUri;
//use mc_fog_ledger_enclave_api::LedgerEnclaveProxy;
use mc_util_grpc::{rpc_invalid_arg_error};
use std::{str::FromStr, sync::Arc};
Expand Down Expand Up @@ -84,7 +84,7 @@ pub struct ProcessedShardResponseData {
/// Uris for individual Fog Ledger Stores that need to be authenticated with
/// by the Fog Router. It should only have entries if
/// `shard_clients_for_retry` has entries.
pub store_uris_for_authentication: Vec<LedgerStoreUri>,
pub store_uris_for_authentication: Vec<KeyImageStoreUri>,

/// New, successfully processed query responses.
pub new_query_responses: Vec<attest::Message>,
Expand All @@ -93,7 +93,7 @@ pub struct ProcessedShardResponseData {
impl ProcessedShardResponseData {
pub fn new(
shard_clients_for_retry: Vec<Arc<KeyImageStoreApiClient>>,
store_uris_for_authentication: Vec<LedgerStoreUri>,
store_uris_for_authentication: Vec<KeyImageStoreUri>,
new_query_responses: Vec<attest::Message>,
) -> Self {
ProcessedShardResponseData {
Expand All @@ -119,7 +119,7 @@ pub fn process_shard_responses(
if response.has_decryption_error() {
shard_clients_for_retry.push(shard_client);
let store_uri =
LedgerStoreUri::from_str(&response.get_decryption_error().store_uri)?;
KeyImageStoreUri::from_str(&response.get_decryption_error().store_uri)?;
store_uris_for_authentication.push(store_uri);
} else {
new_query_responses.push(response.take_query_response());
Expand Down
4 changes: 2 additions & 2 deletions fog/uri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ pub type FogIngestUri = Uri<FogIngestScheme>;
/// and scheme.
pub type FogLedgerUri = Uri<FogLedgerScheme>;
/// Uri used when talking to fog ledger router service.
pub type LedgerRouterUri = Uri<KeyImageRouterScheme>;
pub type KeyImageRouterUri = Uri<KeyImageRouterScheme>;
/// Uri used when talking to fog ledger store service.
pub type LedgerStoreUri = Uri<KeyImageStoreScheme>;
pub type KeyImageStoreUri = Uri<KeyImageStoreScheme>;
/// Uri used when talking to fog view router service.
pub type FogViewRouterUri = Uri<FogViewRouterScheme>;
/// Uri used when talking to fog view store service.
Expand Down

0 comments on commit af5eb34

Please sign in to comment.