Add endpoint to return server constants
This commit is contained in:
parent
2ad2f2e211
commit
050e628ae7
|
@ -489,6 +489,20 @@ impl LoxServerContext {
|
|||
}
|
||||
}
|
||||
|
||||
// Return the serialized pubkeys for the Bridge Authority as an HTTP response
|
||||
pub fn send_constants(self) -> Response<Body> {
|
||||
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<Body> {
|
||||
let req = match serde_json::from_slice(&request) {
|
||||
|
|
|
@ -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<Body>;
|
||||
fn reachability(&self) -> Request<Body>;
|
||||
fn pubkeys(&self) -> Request<Body>;
|
||||
fn constants(&self) -> Request<Body>;
|
||||
fn openinvite(&self, request: proto::open_invite::Request) -> Request<Body>;
|
||||
fn trustpromo(&self, request: proto::trust_promotion::Request) -> Request<Body>;
|
||||
fn trustmigration(&self, request: proto::migration::Request) -> Request<Body>;
|
||||
|
@ -123,6 +125,14 @@ mod tests {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
fn constants(&self) -> Request<Body> {
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("http://localhost/constants")
|
||||
.body(Body::empty())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn openinvite(&self, request: proto::open_invite::Request) -> Request<Body> {
|
||||
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();
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -789,13 +789,6 @@ pub fn get_bridgelines_from_bucket(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_constants() -> Result<String, JsValue> {
|
||||
match serde_json::to_string(&lox_utils::LOX_SYSTEM_INFO) {
|
||||
Ok(system_info_str) => Ok(system_info_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn invitation_is_trusted(unspecified_invitation_str: String) -> Result<bool, JsValue> {
|
||||
match serde_json::from_str::<Invitation>(&unspecified_invitation_str) {
|
||||
|
|
Loading…
Reference in New Issue