Skip to content

Commit

Permalink
This commit is the first step in removing the postgreSql database fro…
Browse files Browse the repository at this point in the history
…m exits

The goal of this change is to make it possible for many thousands of exits
to easily run off a single database with no shared credentials and also to
make it possible for many different organizations to cooperate on this database.

In order to achieve this we will be replacing the postgresql database currently
used by the exits with a smart contract which will be used to register users

Client register flow has changed from client -> Exit -> Ops. Exit forwards a request to an external server with sms api key in order to
verify a client. That server will have write access to the smart contract to add the client, and then return their registration status to
exit, which then forwards that request back to the client
  • Loading branch information
Pranay Tulugu authored and ptulugu committed Sep 20, 2023
1 parent d165efc commit 7534f23
Show file tree
Hide file tree
Showing 32 changed files with 1,024 additions and 2,532 deletions.
373 changes: 175 additions & 198 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions althea_kernel_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ edition = "2018"

[dependencies]
oping = "0.3"
itertools = "0.10"
lazy_static = "1.4"
log = "0.4"
serde_derive = "1.0"
serde = "1.0"
althea_types = { path = "../althea_types" }
ipnetwork = "0.20"
mac_address = "1.1.4"
serde_json = "1.0"

[dependencies.regex]
version = "1.6"
Expand All @@ -25,4 +23,4 @@ features = ["std"]


[features]
integration_test = []
integration_test = []
18 changes: 8 additions & 10 deletions althea_kernel_interface/src/exit_server_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::collections::HashSet;
use std::net::IpAddr;
use KernelInterfaceError as Error;

#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct ExitClient {
pub internal_ip: IpAddr,
pub internet_ipv6_list: Vec<IpNetwork>,
pub internet_ipv6: Option<IpNetwork>,
pub public_key: WgKey,
pub mesh_ip: IpAddr,
pub port: u16,
Expand Down Expand Up @@ -39,15 +39,13 @@ impl dyn KernelInterface {

for c in clients.iter() {
// For the allowed IPs, we appends the clients internal ip as well
// as the client ipv6 assigned list and add this to wireguards allowed ips
// internet_ipv6_list is already in the form of "<subnet1>,<subnet2>.."
let i_ipv6 = &c.internet_ipv6_list;
// as the client ipv6 assigned ip and add this to wireguards allowed ips
// internet_ipv6 is already in the form of "<subnet1>,<subnet2>.."
let i_ipv6 = &c.internet_ipv6;
let mut allowed_ips = c.internal_ip.to_string().to_owned();
if !i_ipv6.is_empty() {
for ip_net in i_ipv6 {
allowed_ips.push(',');
allowed_ips.push_str(&ip_net.to_string());
}
if let Some(i_ipv6) = i_ipv6 {
allowed_ips.push(',');
allowed_ips.push_str(&i_ipv6.to_string());
}

args.push("peer".into());
Expand Down
8 changes: 3 additions & 5 deletions althea_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ base64 = "0.13"
serde_derive = "1.0"
serde = "1.0"
serde_json = "1.0"
hex = "0.4"
sodiumoxide = "0.2"
clarity = "1.2"
arrayvec = {version= "0.7", features = ["serde"]}
arrayvec = { version = "0.7", features = ["serde"] }
phonenumber = "0.3"
lettre = {version = "0.10", features = ["serde"]}
lettre = { version = "0.10", features = ["serde"] }
ipnetwork = "0.20"
bincode = "1.3"
deep_space = {workspace = true}
deep_space = { workspace = true }

[dev-dependencies]
rand = "0.8"

2 changes: 0 additions & 2 deletions althea_types/src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,6 @@ pub struct OperatorExitCheckinMessage {
pub pass: String,
/// This is to keep track of the rita exit uptime for debugging purposes
pub exit_uptime: Duration,
/// A list of registered wg keys that ops can use to display routers to be registered
pub registered_keys: Option<Vec<WgKey>>,
/// Number of users online
pub users_online: Option<u32>,
}
Expand Down
5 changes: 2 additions & 3 deletions antenna_forwarding_protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ authors = ["Justin Kilpatrick <[email protected]>"]
edition = "2018"

[dependencies]
althea_types = { path = "../althea_types"}
althea_types = { path = "../althea_types" }
serde_json = "1.0"
serde_derive = "1.0"
serde = "1.0"
sodiumoxide = "0.2"
clarity = "1.2"
log = "0.4"
lazy_static = "1.4"

[dev-dependencies]
rand = "0.8"
rand = "0.8"
4 changes: 0 additions & 4 deletions auto_bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ edition = "2018"
web30 = "1.0"
num256 = "0.5"
clarity = "1.2"
rand = "0.8"
num = "0.4"
log = "0.4"
serde_derive = "1.0"
serde = "1.0"
tokio = "1.2"
futures = {version="0.3", features = ["thread-pool"]}

[dev-dependencies]
actix = "0.13"
Expand Down
2 changes: 0 additions & 2 deletions babel_monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ version = "0.1.0"
edition = "2018"

[dependencies]
ascii = "1.0"
env_logger = "0.10"
ipnetwork = "0.20"
log = "0.4"
serde = "1.0"
Expand Down
5 changes: 1 addition & 4 deletions clu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ althea_kernel_interface = { path = "../althea_kernel_interface" }
althea_types = { path = "../althea_types" }
lazy_static = "1.4"
log = "0.4"
env_logger = "0.10.0"
ipgen = "1.0.1"
rand = "0.8"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
clarity = "1.2"
sodiumoxide = "0.2"
deep_space = {workspace = true}
deep_space = { workspace = true }

[dependencies.regex]
version = "1.5"
Expand Down
11 changes: 4 additions & 7 deletions integration_tests/src/setup_utils/rita.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rita_common::rita_loop::{
start_core_rita_endpoints, start_rita_common_loops,
write_to_disk::{save_to_disk_loop, SettingsOnDisk},
};
use rita_exit::initialize_db_pool;
use rita_exit::{
operator_update::update_loop::start_operator_update_loop,
rita_loop::{start_rita_exit_endpoints, start_rita_exit_loop},
Expand Down Expand Up @@ -164,9 +163,9 @@ pub fn spawn_rita(

start_rita_common_loops();
start_rita_client_loops();
save_to_disk_loop(SettingsOnDisk::RitaClientSettings(
save_to_disk_loop(SettingsOnDisk::RitaClientSettings(Box::new(
settings::get_rita_client(),
));
)));
start_core_rita_endpoints(4);
start_client_dashboard(s.network.rita_dashboard_port);
start_antenna_forwarder(s);
Expand Down Expand Up @@ -254,14 +253,12 @@ pub fn spawn_rita_exit(

let system = actix_async::System::new();

initialize_db_pool();

start_rita_common_loops();
start_rita_exit_loop();
start_operator_update_loop();
save_to_disk_loop(SettingsOnDisk::RitaExitSettingsStruct(
save_to_disk_loop(SettingsOnDisk::RitaExitSettingsStruct(Box::new(
settings::get_rita_exit(),
));
)));

let workers = 4;
start_core_rita_endpoints(workers as usize);
Expand Down
3 changes: 0 additions & 3 deletions integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,7 @@ pub fn get_default_settings(

let mut exit = exit.clone();
let mut client = client.clone();
// exit should allow instant registration by any requester
exit.verif_settings = None;
exit.network.mesh_ip = Some(cluster.root_ip);
exit.exit_network.cluster_exits = cluster_exits.clone();
client.exit_client.contact_info = Some(
ContactType::Both {
number: "+11111111".parse().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions rita_bin/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ fn main() {

start_rita_common_loops();
start_rita_client_loops();
save_to_disk_loop(SettingsOnDisk::RitaClientSettings(
save_to_disk_loop(SettingsOnDisk::RitaClientSettings(Box::new(
settings::get_rita_client(),
));
)));
start_core_rita_endpoints(4);
start_client_dashboard(settings.network.rita_dashboard_port);
start_antenna_forwarder(settings);
Expand Down
36 changes: 2 additions & 34 deletions rita_bin/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#![allow(clippy::pedantic)]
#![forbid(unsafe_code)]

use std::collections::HashSet;

#[cfg(feature = "jemalloc")]
use jemallocator::Jemalloc;
#[cfg(feature = "jemalloc")]
Expand All @@ -25,7 +23,6 @@ static GLOBAL: Jemalloc = Jemalloc;
extern crate log;

use docopt::Docopt;
use ipnetwork::IpNetwork;
use rita_common::debt_keeper::save_debt_on_shutdown;
use rita_common::logging::enable_remote_logging;
use rita_common::rita_loop::start_core_rita_endpoints;
Expand All @@ -34,8 +31,6 @@ use rita_common::rita_loop::write_to_disk::save_to_disk_loop;
use rita_common::rita_loop::write_to_disk::SettingsOnDisk;
use rita_common::usage_tracker::save_usage_on_shutdown;
use rita_common::utils::env_vars_contains;
use rita_exit::database::sms::send_admin_notification_sms;
use rita_exit::initialize_db_pool;
use rita_exit::operator_update::update_loop::start_operator_update_loop;
use rita_exit::rita_loop::start_rita_exit_endpoints;
use rita_exit::rita_loop::start_rita_exit_loop;
Expand All @@ -56,28 +51,6 @@ fn sanity_check_config() {

// check wg_exit_v2 port is valid
assert!(exit_settings.exit_network.wg_v2_tunnel_port < 59999);

// Check that there is atleast one exit in cluster
assert!(!exit_settings.exit_network.cluster_exits.is_empty());

// Check cluster exits have different ips and wg_keys
let mut ip_sub: Option<IpNetwork> = None;
let mut wg_key_hashset = HashSet::new();
for id in exit_settings.exit_network.cluster_exits.iter() {
if let Some(net) = ip_sub {
if net.contains(id.mesh_ip) {
panic!("Ips in cluster exits collide in /116 subnet");
}
} else {
ip_sub = Some(IpNetwork::new(id.mesh_ip, 116).unwrap())
}

if wg_key_hashset.contains(&id.wg_public_key) {
panic!("Conflicting wg keys in cluster exits, please fix");
} else {
wg_key_hashset.insert(id.wg_public_key);
}
}
}

fn main() {
Expand Down Expand Up @@ -148,19 +121,14 @@ fn main() {
);
trace!("Starting with Identity: {:?}", settings.get_identity());

send_admin_notification_sms("Exit restarted");

// Initialize db pool
initialize_db_pool();

let system = actix_async::System::new();

start_rita_common_loops();
start_rita_exit_loop();
start_operator_update_loop();
save_to_disk_loop(SettingsOnDisk::RitaExitSettingsStruct(
save_to_disk_loop(SettingsOnDisk::RitaExitSettingsStruct(Box::new(
settings::get_rita_exit(),
));
)));

let workers = settings.workers;
start_core_rita_endpoints(workers as usize);
Expand Down
13 changes: 6 additions & 7 deletions rita_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"

[dependencies]
compressed_log = "0.5"
num-traits="0.2"
num-traits = "0.2"
num256 = "0.5"
serde = "1.0"
serde_derive = "1.0"
Expand All @@ -25,20 +25,19 @@ lettre = "0.10"
rand = "0.8.0"
phonenumber = "0.3"
babel_monitor = { path = "../babel_monitor" }
arrayvec = {version= "0.7", features = ["serde"]}
arrayvec = { version = "0.7", features = ["serde"] }
sodiumoxide = "0.2"
clu = { path = "../clu" }
web30 = "1.0"
awc = "3.1"
ipnetwork = "0.20"
actix-async = {package="actix", version = "0.13"}
actix-web-async = { package="actix-web", version = "4.3", default_features = false, features= ["openssl"]}
actix-web-httpauth-async = { package="actix-web-httpauth", version = "0.8.0"}
actix-async = { package = "actix", version = "0.13" }
actix-web-async = { package = "actix-web", version = "4.3", default_features = false, features = [
"openssl",
] }
clarity = "1.2"
openssh-keys = "0.6"
mac_address = "1.1.4"
futures = { version = "0.3", features = ["compat"] }
deep_space = {workspace = true}

[lib]
name = "rita_client"
Expand Down
34 changes: 21 additions & 13 deletions rita_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,45 @@ license = "Apache-2.0"
rand = "0.8.0"
ipnetwork = "0.20"
serde_derive = "1.0"
hex-literal = "0.3"
docopt = "1.1"
serde = "1.0"
bytes = "1.0"
compressed_log = "0.5.4"
byteorder = { version = "1.4", features = ["i128"] }
arrayvec = {version= "0.7", features = ["serde"]}
arrayvec = { version = "0.7", features = ["serde"] }
babel_monitor = { path = "../babel_monitor" }
flate2 = { version = "1.0", features = ["rust_backend"], default-features = false }
actix-async = {package="actix", version = "0.13"}
auto-bridge = {path = "../auto_bridge"}
flate2 = { version = "1.0", features = [
"rust_backend",
], default-features = false }
actix-async = { package = "actix", version = "0.13" }
auto-bridge = { path = "../auto_bridge" }
serde_json = "1.0"
log = { version = "0.4", features = ["release_max_level_info"] }
settings = { path = "../settings" }
clarity = "1.2"
futures = { version = "0.3", features = ["compat"] }
num256 = "0.5"
num-traits="0.2"
num-traits = "0.2"
bincode = "1.3"
serde_cbor = "0.11"
lazy_static = "1.4"
althea_kernel_interface = { path = "../althea_kernel_interface" }
actix-web-httpauth-async = { package="actix-web-httpauth", version = "0.8.0"}
actix-web-async = { package="actix-web", version = "4.3", default_features = false, features= ["openssl"]}
awc = {version = "3.1", default-features = false, features=["openssl", "compress-gzip", "compress-zstd"]}
actix-web-httpauth-async = { package = "actix-web-httpauth", version = "0.8.0" }
actix-web-async = { package = "actix-web", version = "4.3", default_features = false, features = [
"openssl",
] }
awc = { version = "3.1", default-features = false, features = [
"openssl",
"compress-gzip",
"compress-zstd",
] }
actix-service = "2.0.2"
web30 = "1.0"
althea_types = { path = "../althea_types" }
deep_space = {workspace = true}
prost-types ="0.12"
cosmos-sdk-proto-althea = {package = "cosmos-sdk-proto-althea", version = "0.16", features = ["ethermint"]}
deep_space = { workspace = true }
prost-types = "0.12"
cosmos-sdk-proto-althea = { package = "cosmos-sdk-proto-althea", version = "0.16", features = [
"ethermint",
] }

[dependencies.regex]
version = "1.6"
Expand Down
Loading

0 comments on commit 7534f23

Please sign in to comment.