From 984bbe9370c930277b769a77d582c59da93c1abb Mon Sep 17 00:00:00 2001 From: onyinyang Date: Mon, 13 Feb 2023 23:58:38 -0500 Subject: [PATCH] Add trust migration server handling --- crates/lox-distributor/src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index 9d356e7..b03b6ef 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -100,6 +100,10 @@ async fn handle( let bytes = body::to_bytes(req.into_body()).await.unwrap(); verify_and_send_trust_promo(bytes, context.ba) }), + (&Method::POST, "/trustmig") => Ok::<_, Infallible>({ + let bytes = body::to_bytes(req.into_body()).await.unwrap(); + verify_and_send_trust_migration(bytes, context.ba) + }), _ => { // Return 404 not found response. Ok(Response::builder() @@ -124,6 +128,7 @@ fn generate_invite(db: Arc>) -> Response { resp } + fn send_reachability_cred(ba: Arc>) -> Response { let ba_obj = ba.lock().unwrap(); let mut resp = Response::new(Body::from(serde_json::to_string(&ba_obj.reachability_pub).unwrap())); @@ -172,6 +177,18 @@ fn verify_and_send_trust_promo(request: Bytes, ba: Arc>) -> Re .insert("Access-Control-Allow-Origin", HeaderValue::from_static("*")); resp } + +fn verify_and_send_trust_migration(request: Bytes, ba: Arc>) -> Response { + let req: proto::migration::Request = serde_json::from_slice(&request).unwrap(); + let mut ba_obj = ba.lock().unwrap(); + let response = ba_obj.handle_migration(req).unwrap(); + let trust_migration_resp_str = serde_json::to_string(&response).unwrap(); + let mut resp = Response::new(Body::from(trust_migration_resp_str)); + resp.headers_mut() + .insert("Access-Control-Allow-Origin", HeaderValue::from_static("*")); + resp +} + async fn shutdown_signal() { tokio::signal::ctrl_c() .await