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