Refactor/clean up
This commit is contained in:
parent
9f945a05af
commit
1f155ac969
|
@ -1,29 +1,13 @@
|
|||
use async_trait::async_trait;
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use lox_library::bridge_table::from_scalar;
|
||||
use lox_library::bridge_table::BridgeLine;
|
||||
use lox_library::bridge_table::BridgeTable;
|
||||
use lox_library::bridge_table::EncryptedBucket;
|
||||
use lox_library::bridge_table::MAX_BRIDGES_PER_BUCKET;
|
||||
use lox_library::proto::*;
|
||||
use lox_library::scalar_u32;
|
||||
use lox_library::IssuerPubKey;
|
||||
use lox_library::OPENINV_LENGTH;
|
||||
use lox_utils::EncBridgeTable;
|
||||
use lox_utils::Invite;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::serde_as;
|
||||
use lox_library::{
|
||||
bridge_table::{from_scalar, BridgeLine, BridgeTable, EncryptedBucket, MAX_BRIDGES_PER_BUCKET},
|
||||
proto::*,
|
||||
scalar_u32, IssuerPubKey, OPENINV_LENGTH,
|
||||
};
|
||||
use lox_utils::{EncBridgeTable, Invite};
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
// used for testing function
|
||||
use std::io::Write;
|
||||
|
||||
// provides a generic way to make network requests
|
||||
#[async_trait]
|
||||
pub trait Networking {
|
||||
async fn request(&self, endpoint: String, body: Vec<u8>) -> Vec<u8>;
|
||||
}
|
||||
pub mod networking;
|
||||
use crate::networking::Networking;
|
||||
|
||||
// Helper functions to get public keys from vector
|
||||
pub fn get_lox_pub(lox_auth_pubkeys: &Vec<IssuerPubKey>) -> &IssuerPubKey {
|
||||
|
@ -280,14 +264,4 @@ pub async fn blockage_migration(
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
// Advance days on server
|
||||
pub async fn advance_days(net: &dyn Networking, days: u16) -> u32 {
|
||||
let resp = net
|
||||
.request(
|
||||
"/advancedays".to_string(),
|
||||
serde_json::to_vec(&days).unwrap(),
|
||||
)
|
||||
.await;
|
||||
let today: u32 = serde_json::from_slice(&resp).unwrap();
|
||||
today
|
||||
}
|
||||
mod tests;
|
25
src/main.rs
25
src/main.rs
|
@ -1,21 +1,12 @@
|
|||
mod client_lib;
|
||||
use client_lib::*;
|
||||
use lox_cli::{self, networking::HyperNet, *};
|
||||
|
||||
mod client_net;
|
||||
use client_net::HyperNet;
|
||||
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use getopts::Options;
|
||||
use lox_library::bridge_table::BridgeLine;
|
||||
use lox_library::bridge_table::MAX_BRIDGES_PER_BUCKET;
|
||||
use lox_library::scalar_u32;
|
||||
use lox_library::IssuerPubKey;
|
||||
use lox_library::{
|
||||
bridge_table::{BridgeLine, MAX_BRIDGES_PER_BUCKET},
|
||||
scalar_u32, IssuerPubKey,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use std::env::args;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use std::{env::args, fs::File, io::Write, path::Path};
|
||||
|
||||
// Prints the argument details for this program
|
||||
fn print_usage(program: &str, opts: Options) {
|
||||
|
@ -208,7 +199,3 @@ async fn main() {
|
|||
lox_cred
|
||||
};
|
||||
}
|
||||
|
||||
// Unit tests
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
// This file provides networking using hyper (which
|
||||
// https://gitlab.torproject.org/onyinyang/lox-server uses).
|
||||
// This file provides a Networking trait and a working hyper implementation
|
||||
|
||||
use crate::client_lib::Networking;
|
||||
use async_trait::async_trait;
|
||||
use hyper::{Body, Client, Method, Request};
|
||||
|
||||
// provides a generic way to make network requests
|
||||
#[async_trait]
|
||||
pub trait Networking {
|
||||
async fn request(&self, endpoint: String, body: Vec<u8>) -> Vec<u8>;
|
||||
}
|
||||
|
||||
pub struct HyperNet {
|
||||
pub hostname: String,
|
||||
}
|
33
src/tests.rs
33
src/tests.rs
|
@ -11,16 +11,35 @@ trust migration and level up functions. */
|
|||
// Note: We can't run multiple time-changing tests simultaneously because
|
||||
// they will invalidate invites that haven't been redeemed yet.
|
||||
|
||||
use super::client_lib::*;
|
||||
use super::client_net::HyperNet;
|
||||
use lox_library::bridge_table::BridgeLine;
|
||||
use lox_library::proto::level_up::{LEVEL_INTERVAL, LEVEL_INVITATIONS};
|
||||
use lox_library::proto::trust_promotion::UNTRUSTED_INTERVAL;
|
||||
use lox_library::scalar_u32;
|
||||
use crate::{networking::*, *};
|
||||
use lox_library::{
|
||||
bridge_table::{self, from_scalar, BridgeLine, BridgeTable},
|
||||
proto::{
|
||||
level_up::{LEVEL_INTERVAL, LEVEL_INVITATIONS},
|
||||
trust_promotion::UNTRUSTED_INTERVAL,
|
||||
},
|
||||
scalar_u32,
|
||||
};
|
||||
|
||||
use std::cmp::min;
|
||||
use hyper::StatusCode;
|
||||
use std::{
|
||||
cmp::min,
|
||||
collections::{HashMap, HashSet},
|
||||
};
|
||||
use tokio::spawn;
|
||||
|
||||
// Advance days on server
|
||||
pub async fn advance_days(net: &dyn Networking, days: u16) -> u32 {
|
||||
let resp = net
|
||||
.request(
|
||||
"/advancedays".to_string(),
|
||||
serde_json::to_vec(&days).unwrap(),
|
||||
)
|
||||
.await;
|
||||
let today: u32 = serde_json::from_slice(&resp).unwrap();
|
||||
today
|
||||
}
|
||||
|
||||
// These are all combined into the same test because otherwise we run into
|
||||
// issues with server state due to asynchronicity.
|
||||
#[tokio::test]
|
||||
|
|
Loading…
Reference in New Issue