Skip to content

Commit

Permalink
Minor touches
Browse files Browse the repository at this point in the history
  • Loading branch information
akoshelev committed Mar 25, 2024
1 parent b215d35 commit 4647d11
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 31 deletions.
15 changes: 9 additions & 6 deletions ipa-core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,16 @@ impl RequestHandler for QueryRequestHandler {
}
RouteId::ReceiveQuery => {
let req = req.into::<QueryConfig>()?;
let transport = Clone::clone(self.transport.lock().unwrap().as_ref().unwrap());
HelperResponse::from(qp.new_query(transport, req).await?)
HelperResponse::from(qp.new_query(self.transport(), req).await?)
}
RouteId::PrepareQuery => {
let req = req.into::<PrepareQuery>()?;
let transport = Clone::clone(self.transport.lock().unwrap().as_ref().unwrap());
HelperResponse::from(qp.prepare(&transport, req)?)
HelperResponse::from(qp.prepare(&self.transport(), req)?)
}
RouteId::QueryInput => {
let query_id = ext_query_id(&req)?;
let transport = Clone::clone(self.transport.lock().unwrap().as_ref().unwrap());
HelperResponse::from(qp.receive_inputs(
transport,
self.transport(),
QueryInput {
query_id,
input_stream: data,
Expand All @@ -89,6 +86,12 @@ impl RequestHandler for QueryRequestHandler {
}
}

impl QueryRequestHandler {
fn transport(&self) -> TransportImpl {
Clone::clone(self.transport.lock().unwrap().as_ref().unwrap())
}
}

#[derive(Clone)]
pub struct RequestHandlerSetup {
qp: Arc<QueryProcessor>,
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/bin/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ipa_core::{
},
config::{hpke_registry, HpkeServerConfig, NetworkConfig, ServerConfig, TlsConfig},
error::BoxError,
helpers::{HelperIdentity, RequestHandler},
helpers::HelperIdentity,
net::{ClientIdentity, HttpTransport, MpcHelperClient},
AppSetup,
};
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub enum Role {
}

#[derive(Clone, Debug)]
#[cfg_attr(test, derive(Copy, PartialEq, Eq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cfg_attr(
feature = "enable-serde",
derive(serde::Serialize, serde::Deserialize),
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/helpers/transport/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub enum QueryConfigError {
}

#[derive(Clone, Debug)]
#[cfg_attr(test, derive(Copy, PartialEq, Eq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct PrepareQuery {
pub query_id: QueryId,
Expand Down
30 changes: 17 additions & 13 deletions ipa-core/src/net/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ fn make_http_connector() -> HttpConnector {
connector
}

#[cfg(all(test, feature = "real-world-infra"))] // TODO fix back
// #[cfg(all(test, web_test))] // TODO fix back
#[cfg(all(test, web_test))]
pub(crate) mod tests {
use std::{
fmt::Debug,
Expand All @@ -432,11 +431,11 @@ pub(crate) mod tests {
use crate::{
ff::{FieldType, Fp31},
helpers::{
make_boxed_handler, query::QueryType::TestMultiply, routing::Addr, ApiError,
BodyStream, BytesStream, HelperResponse, PanickingHandler, RequestHandler,
RoleAssignment, Transport, MESSAGE_PAYLOAD_SIZE_BYTES,
make_boxed_handler, query::QueryType::TestMultiply, BytesStream, HelperResponse,
PanickingHandler, RequestHandler, RoleAssignment, Transport,
MESSAGE_PAYLOAD_SIZE_BYTES,
},
net::{test::TestServer, HttpTransport},
net::test::TestServer,
protocol::step::StepNarrow,
query::ProtocolResult,
secret_sharing::replicated::semi_honest::AdditiveShare as Replicated,
Expand Down Expand Up @@ -517,7 +516,7 @@ pub(crate) mod tests {

let output = test_query_command(
|client| async move { client.echo(expected_output).await.unwrap() },
|| Box::new(PanickingHandler::default()),
|| Box::<PanickingHandler>::default(),
)
.await;
assert_eq!(expected_output, &output);
Expand Down Expand Up @@ -550,13 +549,14 @@ pub(crate) mod tests {

#[tokio::test]
async fn prepare() {
let input = PrepareQuery {
query_id: QueryId,
config: QueryConfig::new(TestMultiply, FieldType::Fp31, 1).unwrap(),
roles: RoleAssignment::new(HelperIdentity::make_three()),
};
let config = QueryConfig::new(TestMultiply, FieldType::Fp31, 1).unwrap();
let handler = move || {
make_boxed_handler(move |addr, _| async move {
let input = PrepareQuery {
query_id: QueryId,
config,
roles: RoleAssignment::new(HelperIdentity::make_three()),
};
let prepare_query = addr.into::<PrepareQuery>().unwrap();
assert_eq!(prepare_query, input);

Expand All @@ -566,7 +566,11 @@ pub(crate) mod tests {

test_query_command(
|client| {
let req = input.clone();
let req = PrepareQuery {
query_id: QueryId,
config,
roles: RoleAssignment::new(HelperIdentity::make_three()),
};
async move { client.prepare_query(req).await.unwrap() }
},
handler,
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/net/server/handlers/query/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod tests {
config: QueryConfig::new(TestMultiply, FieldType::Fp31, 1).unwrap(),
roles: RoleAssignment::new(HelperIdentity::make_three()),
});
let expected_prepare_query = req.data;
let expected_prepare_query = req.data.clone();
let TestServer { transport, .. } = TestServer::builder()
.with_request_handler(Box::new(
move |addr: Addr<HelperIdentity>, _data: BodyStream| {
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/net/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ mod tests {
use crate::{
config::{NetworkConfig, ServerConfig},
ff::{FieldType, Fp31, Serializable},
helpers::query::QueryType::TestMultiply,
helpers::query::{QueryInput, QueryType::TestMultiply},
net::{
client::ClientIdentity,
test::{get_test_identity, TestConfig, TestConfigBuilder, TestServer},
Expand Down
8 changes: 4 additions & 4 deletions ipa-core/src/query/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ impl Processor {
let prepare_request = PrepareQuery {
query_id,
config: req,
roles,
roles: roles.clone(),
};

// Inform other parties about new query. If any of them rejects it, this join will fail
try_join(
transport.send(left, prepare_request, stream::empty()),
transport.send(right, prepare_request, stream::empty()),
transport.send(left, prepare_request.clone(), stream::empty()),
transport.send(right, prepare_request.clone(), stream::empty()),
)
.await
.map_err(NewQueryError::Transport)?;
Expand Down Expand Up @@ -511,7 +511,7 @@ mod tests {
let req = prepare_query(identities);
let transport = network.transport(identities[1]);
let processor = Processor::default();
processor.prepare(&transport, req).unwrap();
processor.prepare(&transport, req.clone()).unwrap();
assert!(matches!(
processor.prepare(&transport, req),
Err(PrepareQueryError::AlreadyRunning)
Expand Down
11 changes: 8 additions & 3 deletions ipa-core/src/test_fixture/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,14 @@ impl<B: ShardBinding> ShardWorld<B> {
let participants = make_participants(&mut StdRng::seed_from_u64(config.seed + shard_seed));
let network = InMemoryMpcNetwork::default();

let mut gateways = network
.transports()
.map(|t| Gateway::new(QueryId, config.gateway_config, *config.role_assignment(), t));
let mut gateways = network.transports().map(|t| {
Gateway::new(
QueryId,
config.gateway_config,
config.role_assignment().clone(),
t,
)
});

// The name for `g` is too complicated and depends on features enabled
#[allow(clippy::redundant_closure_for_method_calls)]
Expand Down

0 comments on commit 4647d11

Please sign in to comment.