Add server side for trust promo requests
This commit is contained in:
parent
8529083285
commit
3a51161587
|
@ -90,14 +90,16 @@ async fn handle(
|
|||
.unwrap()),
|
||||
_ => match (req.method(), req.uri().path()) {
|
||||
(&Method::GET, "/invite") => Ok::<_, Infallible>(generate_invite(context.db)),
|
||||
(&Method::GET, "/reachability") => Ok::<_, Infallible>(send_reachability_cred(context.ba)),
|
||||
(&Method::GET, "/pubkeys") => Ok::<_, Infallible>(send_keys(context.ba)),
|
||||
//TODO: figure out the format of the request and parse it?
|
||||
(&Method::POST, "/openreq") => Ok::<_, Infallible>({
|
||||
let bytes = body::to_bytes(req.into_body()).await.unwrap();
|
||||
verify_and_send_open_cred(bytes, context.ba)
|
||||
}),
|
||||
//(&Method::POST, "/json_api") => api_post_response(req).await,
|
||||
//(&Method::GET, "/json_api") => api_get_response().await,
|
||||
(&Method::POST, "/trustpromo") => Ok::<_, Infallible>({
|
||||
let bytes = body::to_bytes(req.into_body()).await.unwrap();
|
||||
verify_and_send_trust_promo(bytes, context.ba)
|
||||
}),
|
||||
_ => {
|
||||
// Return 404 not found response.
|
||||
Ok(Response::builder()
|
||||
|
@ -121,6 +123,13 @@ fn generate_invite(db: Arc<Mutex<lox::BridgeDb>>) -> Response<Body> {
|
|||
resp
|
||||
}
|
||||
|
||||
fn send_reachability_cred(ba: Arc<Mutex<BridgeAuth>>) -> Response<Body> {
|
||||
let ba_obj = ba.lock().unwrap();
|
||||
let mut resp = Response::new(Body::from(serde_json::to_string(&ba_obj.reachability_pub).unwrap()));
|
||||
resp.headers_mut().insert("Access-Control-Allow-Origin", HeaderValue::from_static("*"));
|
||||
resp
|
||||
}
|
||||
|
||||
fn send_keys(ba: Arc<Mutex<BridgeAuth>>) -> Response<Body> {
|
||||
let ba_obj = ba.lock().unwrap();
|
||||
// vector of public keys (to serialize)
|
||||
|
@ -149,6 +158,16 @@ fn verify_and_send_open_cred(request: Bytes, ba: Arc<Mutex<BridgeAuth>>) -> Resp
|
|||
resp
|
||||
}
|
||||
|
||||
fn verify_and_send_trust_promo(request: Bytes, ba: Arc<Mutex<BridgeAuth>>) -> Response<Body> {
|
||||
let req: proto::trust_promotion::Request = serde_json::from_slice(&request).unwrap();
|
||||
let mut ba_obj = ba.lock().unwrap();
|
||||
let response = ba_obj.handle_trust_promotion(req).unwrap();
|
||||
let trust_promo_resp_str = serde_json::to_string(&response).unwrap();
|
||||
let mut resp = Response::new(Body::from(trust_promo_resp_str));
|
||||
resp.headers_mut()
|
||||
.insert("Access-Control-Allow-Origin", HeaderValue::from_static("*"));
|
||||
resp
|
||||
}
|
||||
async fn shutdown_signal() {
|
||||
tokio::signal::ctrl_c()
|
||||
.await
|
||||
|
|
Loading…
Reference in New Issue