diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index bc0112d..f066ba7 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -489,6 +489,20 @@ impl LoxServerContext { } } + // Return the serialized pubkeys for the Bridge Authority as an HTTP response + pub fn send_constants(self) -> Response
{ + let constants = lox_utils::LOX_SYSTEM_INFO; + match serde_json::to_string(&constants) { + Ok(resp) => prepare_header(resp), + Err(e) => { + println!("Error parsing Constants to JSON"); + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) + } + } + } + // Verify the open invitation request and return the result as an HTTP response pub fn verify_and_send_open_cred(self, request: Bytes) -> Response { let req = match serde_json::from_slice(&request) { diff --git a/crates/lox-distributor/src/request_handler.rs b/crates/lox-distributor/src/request_handler.rs index 560146b..47a3d9d 100644 --- a/crates/lox-distributor/src/request_handler.rs +++ b/crates/lox-distributor/src/request_handler.rs @@ -21,6 +21,7 @@ pub async fn handle( Ok::<_, Infallible>(cloned_context.send_reachability_cred()) } (&Method::POST, "/pubkeys") => Ok::<_, Infallible>(cloned_context.send_keys()), + (&Method::POST, "/constants") => Ok::<_, Infallible>(cloned_context.send_constants()), (&Method::POST, "/openreq") => Ok::<_, Infallible>({ let bytes = body::to_bytes(req.into_body()).await.unwrap(); cloned_context.verify_and_send_open_cred(bytes) @@ -87,6 +88,7 @@ mod tests { fn invite(&self) -> Request; fn reachability(&self) -> Request; fn pubkeys(&self) -> Request; + fn constants(&self) -> Request; fn openinvite(&self, request: proto::open_invite::Request) -> Request; fn trustpromo(&self, request: proto::trust_promotion::Request) -> Request; fn trustmigration(&self, request: proto::migration::Request) -> Request; @@ -123,6 +125,14 @@ mod tests { .unwrap() } + fn constants(&self) -> Request { + Request::builder() + .method("POST") + .uri("http://localhost/constants") + .body(Body::empty()) + .unwrap() + } + fn openinvite(&self, request: proto::open_invite::Request) -> Request { let req_str = serde_json::to_string(&request).unwrap(); Request::builder() @@ -372,6 +382,16 @@ mod tests { assert_eq!(pubkey_response.status(), StatusCode::OK); } + #[tokio::test] + async fn test_handle_constants() { + let th = TestHarness::new(); + let lc = LoxClientMock {}; + // Test Pubkeys + let constant_request = lc.constants(); + let constant_response = handle(th.context.clone(), constant_request).await.unwrap(); + assert_eq!(constant_response.status(), StatusCode::OK); + } + #[tokio::test] async fn test_handle_lox_protocols() { let mut th = TestHarness::new(); diff --git a/crates/lox-utils/src/lib.rs b/crates/lox-utils/src/lib.rs index 8f1d7a2..7fefa6c 100644 --- a/crates/lox-utils/src/lib.rs +++ b/crates/lox-utils/src/lib.rs @@ -2,7 +2,7 @@ use lox_library::bridge_table::{ from_scalar, BridgeLine, BridgeTable, EncryptedBucket, MAX_BRIDGES_PER_BUCKET, }; use lox_library::cred::{BucketReachability, Invitation, Lox}; -use lox_library::proto; +use lox_library::proto::{self, check_blockage, level_up, trust_promotion}; use lox_library::{IssuerPubKey, OPENINV_LENGTH}; use serde::{Deserialize, Serialize}; use serde_with::serde_as; @@ -75,17 +75,21 @@ pub struct PubKeys { #[derive(Debug, Deserialize, Serialize)] pub struct LoxSystemInfo { - max_blockages: [u32; proto::level_up::MAX_LEVEL + 1], - level_interval: [u32; proto::level_up::MAX_LEVEL + 1], - level_invitations: [u32; proto::level_up::MAX_LEVEL + 1], - min_trust_level: u32, + pub max_level: usize, + pub untrusted_interval: u32, + pub max_blockages: [u32; level_up::MAX_LEVEL + 1], + pub level_interval: [u32; level_up::MAX_LEVEL + 1], + pub level_invitations: [u32; level_up::MAX_LEVEL + 1], + pub min_blockage_migration_trust_level: u32, } pub const LOX_SYSTEM_INFO: LoxSystemInfo = LoxSystemInfo { - max_blockages: proto::level_up::MAX_BLOCKAGES, - level_interval: proto::level_up::LEVEL_INTERVAL, - level_invitations: proto::level_up::LEVEL_INVITATIONS, - min_trust_level: proto::check_blockage::MIN_TRUST_LEVEL, + max_level: level_up::MAX_LEVEL, + untrusted_interval: trust_promotion::UNTRUSTED_INTERVAL, + max_blockages: level_up::MAX_BLOCKAGES, + level_interval: level_up::LEVEL_INTERVAL, + level_invitations: level_up::LEVEL_INVITATIONS, + min_blockage_migration_trust_level: check_blockage::MIN_TRUST_LEVEL, }; #[serde_as] diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js index cbd3d30..062d049 100644 --- a/crates/lox-wasm/index.js +++ b/crates/lox-wasm/index.js @@ -19,6 +19,8 @@ import init, { set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_issued_invite_expiry, get_received_invite_expiry, get_bridgelines_from_bucket} from "./pkg/lox_wasm.js"; let pubkeys = await simple_request("/pubkeys"); console.log("Got pubkeys: " + pubkeys); +let constants = await simple_request("/constants"); +console.log("Got constants: " + constants); // Get Lox Invitation let requested_invite = await init().then(() => { diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index e03316c..99737fd 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -789,13 +789,6 @@ pub fn get_bridgelines_from_bucket( } } -pub fn get_constants() -> Result