8000 Split Fog View API into Client-facing and Store (Fog Router) APIs by samdealy · Pull Request #2265 · mobilecoinfoundation/mobilecoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Split Fog View API into Client-facing and Store (Fog Router) APIs #2265

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

Merged
merged 3 commits into from
Jul 19, 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
< 10000 div id="files" class="diff-view js-diff-container" data-hpc>
7 changes: 7 additions & 0 deletions fog/api/proto/view.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ message MultiViewStoreQueryResponse {
FogViewStoreDecryptionError decryption_error = 2;
}

/// Fulfills requests sent directly by a Fog client, e.g. a mobile phone using the SDK.
service FogViewAPI {
/// This is called to perform IX key exchange with the enclave before calling GetOutputs.
rpc Auth(attest.AuthMessage) returns (attest.AuthMessage) {}
/// Input should be an encrypted QueryRequest, result is an encrypted QueryResponse
rpc Query(attest.Message) returns (attest.Message) {}
}

/// Fulfills requests sent by the Fog View Router. This is not meant to fulfill requests sent directly by the client.
service FogViewStoreAPI {
/// This is called to perform IX key exchange with the enclave before calling GetOutputs.
rpc Auth(attest.AuthMessage) returns (attest.AuthMessage) {}
/// Input should be an encrypted MultiViewStoreQueryRequest, result is an encrypted QueryResponse.
rpc MultiViewStoreQuery(MultiViewStoreQueryRequest) returns (MultiViewStoreQueryResponse) {}
}
Expand Down
26 changes: 26 additions & 0 deletions fog/uri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ impl UriScheme for FogViewScheme {
const DEFAULT_INSECURE_PORT: u16 = 3225;
}

/// Fog View Store Scheme
#[derive(Debug, Hash, Ord, PartialOrd, Eq, PartialEq, Clone)]
pub struct FogViewStoreScheme {}

impl UriScheme for FogViewStoreScheme {
/// The part before the '://' of a URL.
const SCHEME_SECURE: &'static str = "fog-view-store";
const SCHEME_INSECURE: &'static str = "insecure-fog-view-store";

/// Default port numbers
const DEFAULT_SECURE_PORT: u16 = 443;
const DEFAULT_INSECURE_PORT: u16 = 3225;
}

/// Fog Ledger Uri Scheme
#[derive(Debug, Hash, Ord, PartialOrd, Eq, PartialEq, Clone)]
pub struct FogLedgerScheme {}
Expand Down Expand Up @@ -81,6 +95,8 @@ pub type FogIngestUri = Uri<FogIngestScheme>;
pub type FogLedgerUri = Uri<FogLedgerScheme>;
/// Uri used when talking to fog view router service.
pub type FogViewRouterUri = Uri<FogViewRouterScheme>;
/// Uri used when talking to fog view store service.
pub type FogViewStoreUri = Uri<FogViewStoreScheme>;
/// Uri used when talking to fog-view service, with the right default ports and
/// scheme.
pub type FogViewUri = Uri<FogViewScheme>;
Expand Down Expand Up @@ -155,6 +171,16 @@ mod tests {
ResponderId::from_str("node1.test.mobilecoin.com:3225").unwrap()
);
assert!(!uri.use_tls());

let uri =
FogViewStoreUri::from_str("insecure-fog-view-store://node1.test.mobilecoin.com:3225/")
.unwrap();
assert_eq!(uri.addr(), "node1.test.mobilecoin.com:3225");
assert_eq!(
uri.responder_id().unwrap(),
ResponderId::from_str("node1.test.mobilecoin.com:3225").unwrap()
);
assert!(!uri.use_tls());
}

#[test]
Expand Down
19 changes: 11 additions & 8 deletions fog/view/server/src/bin/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//! MobileCoin Fog View Router target
use grpcio::ChannelBuilder;
use mc_common::logger::log;
use mc_fog_api::view_grpc::FogViewApiClient;
use mc_fog_uri::FogViewUri;
use mc_fog_api::view_grpc::FogViewStoreApiClient;
use mc_fog_uri::FogViewStoreUri;
use mc_fog_view_enclave::{SgxViewEnclave, ENCLAVE_FILE};
use mc_fog_view_server::{
config::FogViewRouterConfig, fog_view_router_server::FogViewRouterServer,
Expand Down Expand Up @@ -37,24 +37,27 @@ fn main() {
);

// TODO: Remove and get from a config.
let mut fog_view_grpc_clients = Vec::new();
let mut fog_view_store_grpc_clients = Vec::new();
let grpc_env = Arc::new(
grpcio::EnvBuilder::new()
.name_prefix("Main-RPC".to_string())
.build(),
);
for i in 0..50 {
let shard_uri_string = format!("insecure-fog-view://node{}.test.mobilecoin.com:3225", i);
let shard_uri = FogViewUri::from_str(&shard_uri_string).unwrap();
let fog_view_grpc_client = FogViewApiClient::new(
let shard_uri_string = format!(
"insecure-fog-view-store://node{}.test.mobilecoin.com:3225",
i
);
let shard_uri = FogViewStoreUri::from_str(&shard_uri_string).unwrap();
let fog_view_store_grpc_client = FogViewStoreApiClient::new(
ChannelBuilder::default_channel_builder(grpc_env.clone())
.connect_to_uri(&shard_uri, &logger),
);
fog_view_grpc_clients.push(fog_view_grpc_client);
fog_view_store_grpc_clients.push(fog_view_store_grpc_client);
}

let mut router_server =
FogViewRouterServer::new(config, sgx_enclave, fog_view_grpc_clients, logger);
FogViewRouterServer::new(config, sgx_enclave, fog_view_store_grpc_clients, logger);
router_server.start();

loop {
Expand Down
30 changes: 27 additions & 3 deletions fog/view/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use clap::Parser;
use mc_attest_core::ProviderId;
use mc_common::ResponderId;
use mc_fog_sql_recovery_db::SqlRecoveryDbConnectionConfig;
use mc_fog_uri::{FogViewRouterUri, FogViewUri};
use mc_fog_uri::{FogViewRouterUri, FogViewStoreUri, FogViewUri};
use mc_util_parse::parse_duration_in_seconds;
use mc_util_uri::AdminUri;
use serde::Serialize;
use std::time::Duration;
use std::{str::FromStr, time::Duration};

/// Configuration parameters for the MobileCoin Fog View Node
#[derive(Clone, Parser, Serialize)]
Expand All @@ -34,7 +34,7 @@ pub struct MobileAcctViewConfig {

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

/// Optional admin listening URI.
#[clap(long, env = "MC_ADMIN_LISTEN_URI")]
Expand Down Expand Up @@ -69,6 +69,30 @@ pub struct MobileAcctViewConfig {
pub postgres_config: SqlRecoveryDbConnectionConfig,
}

/// A FogViewServer can either fulfill client requests directly or fulfill Fog
/// View Router requests, and these types of servers use different URLs.
#[derive(Clone, Serialize)]
pub enum ClientListenUri {
/// URI used by the FogViewServer when fulfilling direct client requests.
ClientFacing(FogViewUri),
/// URI used by the FogViewServer when fulfilling Fog View Router requests.
Store(FogViewStoreUri),
}

impl FromStr for ClientListenUri {
type Err = String;
fn from_str(input: &str) -> Result<Self, String> {
if let Ok(fog_view_uri) = FogViewUri::from_str(input) {
return Ok(ClientListenUri::ClientFacing(fog_view_uri));
}
if let Ok(fog_view_store_uri) = FogViewStoreUri::from_str(input) {
return Ok(ClientListenUri::Store(fog_view_store_uri));
}

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

/// Configuration parameters for the Fog View Router.
#[derive(Clone, Parser, Serialize)]
#[clap(version)]
Expand Down
2 changes: 1 addition & 1 deletion fog/view/server/src/fog_view_router_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl FogViewRouterServer {
pub fn new<E>(
config: FogViewRouterConfig,
enclave: E,
shards: Vec<view_grpc::FogViewApiClient>,
shards: Vec<view_grpc::FogViewStoreApiClient>,
logger: Logger,
) -> FogViewRouterServer
where
Expand Down
6 changes: 3 additions & 3 deletions fog/view/server/src/fog_view_router_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use grpcio::{DuplexSink, RequestStream, RpcContext};
use mc_common::logger::{log, Logger};
use mc_fog_api::{
view::{FogViewRouterRequest, FogViewRouterResponse},
view_grpc::{FogViewApiClient, FogViewRouterApi},
view_grpc::{FogViewRouterApi, FogViewStoreApiClient},
};
use mc_fog_view_enclave_api::ViewEnclaveProxy;
use mc_util_grpc::rpc_logger;
Expand All @@ -19,7 +19,7 @@ where
E: ViewEnclaveProxy,
{
enclave: E,
shard_clients: Vec<Arc<FogViewApiClient>>,
shard_clients: Vec<Arc<FogViewStoreApiClient>>,
logger: Logger,
}

Expand All @@ -29,7 +29,7 @@ impl<E: ViewEnclaveProxy> FogViewRouterService<E> {
///
/// TODO: Add a `view_store_clients` parameter of type FogApiClient, and
/// perform view store authentication on each one.
pub fn new(enclave: E, shard_clients: Vec<FogViewApiClient>, logger: Logger) -> Self {
pub fn new(enclave: E, shard_clients: Vec<FogViewStoreApiClient>, logger: Logger) -> Self {
let shard_clients = shard_clients.into_iter().map(Arc::new).collect();
Self {
enclave,
Expand Down
Loading
0