Skip to content

Commit

Permalink
Add operator address support for Exits
Browse files Browse the repository at this point in the history
While exits don't need to pay an operator fee they do need an operator
address so we can categorize them per network / operator in operator
tools or elsewhere.

On the exit side this new setting actually has no real functionality,
it's only a tag for remote management software. The operator fee has
been removed becuase the fee is for operational upkeep of nodes and
exits are expected to have bespoke operators.
  • Loading branch information
jkilpatr committed Aug 16, 2024
1 parent 1da8057 commit f122de5
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 88 deletions.
8 changes: 2 additions & 6 deletions integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ use rita_common::{
payment_validator::{ALTHEA_CHAIN_PREFIX, ALTHEA_CONTACT_TIMEOUT},
};
use settings::{
client::RitaClientSettings,
exit::{ExitNetworkSettings, RitaExitSettingsStruct},
localization::LocalizationSettings,
logging::LoggingSettings,
network::NetworkSettings,
payment::PaymentSettings,
client::RitaClientSettings, exit::{ExitNetworkSettings, RitaExitSettingsStruct}, localization::LocalizationSettings, logging::LoggingSettings, network::NetworkSettings, operator::ExitOperatorSettings, payment::PaymentSettings
};
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -397,6 +392,7 @@ pub fn get_default_settings(
exit_network: ExitNetworkSettings::test_default(),
allowed_countries: HashSet::new(),
log: LoggingSettings::default(),
operator: ExitOperatorSettings::default(),
};
let client = RitaClientSettings::default();

Expand Down
5 changes: 3 additions & 2 deletions rita_client/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod extender_checkin;
pub mod installation_details;
pub mod neighbors;
pub mod notifications;
pub mod operator;
pub mod operator_fees;
pub mod prices;
pub mod router;
pub mod usage;
Expand All @@ -22,13 +22,14 @@ use crate::dashboard::extender_checkin::*;
use crate::dashboard::installation_details::*;
use crate::dashboard::neighbors::*;
use crate::dashboard::notifications::*;
use crate::dashboard::operator::*;
use crate::dashboard::operator_fees::*;
use crate::dashboard::prices::*;
use crate::dashboard::router::*;
use crate::dashboard::usage::*;
use actix_async::System;
use actix_web_async::{web, App, HttpServer};
use rita_common::dashboard::auth::*;
use rita_common::dashboard::operator::*;
use rita_common::dashboard::babel::*;
use rita_common::dashboard::backup_created::*;
use rita_common::dashboard::contact_info::*;
Expand Down
80 changes: 0 additions & 80 deletions rita_client/src/dashboard/operator.rs

This file was deleted.

36 changes: 36 additions & 0 deletions rita_client/src/dashboard/operator_fees.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Operator fees are the fees that the operator charges for the service of running the network
//! and providing internet access. This module contains the operator fee related endpoints.

use crate::operator_fee_manager::get_operator_fee_debt;
use actix_web_async::web::Path;
use actix_web_async::{HttpRequest, HttpResponse};
use clarity::Uint256;

pub async fn get_operator_fee(_req: HttpRequest) -> HttpResponse {
debug!("get_operator_fee GET hit");
HttpResponse::Ok().json(settings::get_rita_client().operator.operator_fee)
}

pub async fn set_operator_fee(fee: Path<Uint256>) -> HttpResponse {
let op_fee = fee.into_inner();
debug!("set_operator_fee POST hit {:?}", op_fee);

let mut rita_client = settings::get_rita_client();
rita_client.operator.operator_fee = op_fee;

rita_client.operator.use_operator_price = op_fee == 0_u8.into();

settings::set_rita_client(rita_client);

// save immediately
if let Err(_e) = settings::write_config() {
return HttpResponse::InternalServerError().finish();
}

HttpResponse::Ok().json(settings::get_rita_client().operator.operator_fee)
}

pub async fn get_operator_debt(_req: HttpRequest) -> HttpResponse {
debug!("get operator debt hit");
HttpResponse::Ok().json(get_operator_fee_debt())
}
1 change: 1 addition & 0 deletions rita_common/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ pub mod usage;
pub mod wallet;
pub mod wg_key;
pub mod wifi;
pub mod operator;
80 changes: 80 additions & 0 deletions rita_common/src/dashboard/operator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//! This module contains the operator address related endpoints the operator address is used to organize
//! what network a given device is a part of and for client devices the address to which operator fees are
//! paid, exits only use operator addresses for organization and not for fee collection.
use actix_web_async::web::Path;
use actix_web_async::{HttpRequest, HttpResponse};
use clarity::Address;

enum Mode {
Client,
Exit,
}

fn get_mode() -> Option<Mode> {
if settings::check_if_client() {
Some(Mode::Client)
} else if settings::check_if_exit() {
Some(Mode::Exit)
} else {
None
}
}

fn get_operator_address(mode: Mode) -> Option<Address> {
match mode {
Mode::Client => settings::get_rita_client().operator.operator_address,
Mode::Exit => settings::get_rita_exit().operator.operator_address,
}
}

fn set_operator_address_and_save(mode: Mode, address: Option<Address>) {
match mode {
Mode::Client => {
let mut rita_client = settings::get_rita_client();
rita_client.operator.operator_address = address;
settings::set_rita_client(rita_client);
}
Mode::Exit => {
let mut rita_exit = settings::get_rita_exit();
rita_exit.operator.operator_address = address;
settings::set_rita_exit(rita_exit);
}
}

// Save configuration immediately and log any error, but don't return it
if let Err(e) = settings::write_config() {
error!("Failed to write config: {:?}", e);
}
}

pub async fn get_operator(_req: HttpRequest) -> HttpResponse {
trace!("get operator address: Hit");

match get_mode() {
Some(mode) => HttpResponse::Ok().json(get_operator_address(mode)),
None => HttpResponse::InternalServerError().finish(),
}
}

pub async fn change_operator(path: Path<Address>) -> HttpResponse {
trace!("add operator address: Hit");
let provided_address = Some(path.into_inner());

match get_mode() {
Some(mode) => {
set_operator_address_and_save(mode, provided_address);
HttpResponse::Ok().finish()
}
None => HttpResponse::InternalServerError().finish(),
}
}

pub async fn remove_operator(_path: Path<Address>) -> HttpResponse {
match get_mode() {
Some(mode) => {
set_operator_address_and_save(mode, None);
HttpResponse::Ok().finish()
}
None => HttpResponse::InternalServerError().finish(),
}
}
4 changes: 4 additions & 0 deletions rita_exit/src/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rita_common::dashboard::localization::*;
use rita_common::dashboard::logging::*;
use rita_common::dashboard::mesh_ip::*;
use rita_common::dashboard::nickname::*;
use rita_common::dashboard::operator::*;
use rita_common::dashboard::own_info::*;
use rita_common::dashboard::remote_access::*;
use rita_common::dashboard::settings::*;
Expand Down Expand Up @@ -45,6 +46,9 @@ pub fn start_rita_exit_dashboard(startup_status: Arc<RwLock<Option<String>>>) {
.wrap(middleware::AuthMiddlewareFactory)
.wrap(middleware::HeadersMiddlewareFactory)
.route("/info", web::get().to(get_own_info))
.route("/operator", web::get().to(get_operator))
.route("/operator/{address}", web::post().to(change_operator))
.route("/operator/remove", web::post().to(remove_operator))
.route("/local_fee", web::get().to(get_local_fee))
.route("/local_fee/{fee}", web::post().to(set_local_fee))
.route("/metric_factor", web::get().to(get_metric_factor))
Expand Down
4 changes: 4 additions & 0 deletions settings/src/exit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::localization::LocalizationSettings;
use crate::logging::LoggingSettings;
use crate::network::NetworkSettings;
use crate::operator::ExitOperatorSettings;
use crate::payment::PaymentSettings;
use crate::{json_merge, set_rita_exit, SettingsError};
use althea_types::{regions::Regions, ExitIdentity, Identity, WgKey};
Expand Down Expand Up @@ -108,6 +109,8 @@ pub struct RitaExitSettingsStruct {
pub localization: LocalizationSettings,
pub network: NetworkSettings,
pub exit_network: ExitNetworkSettings,
#[serde(default)]
pub operator: ExitOperatorSettings,
/// Countries which the clients to the exit are allowed from, blank for no geoip validation.
/// (ISO country code)
#[serde(skip_serializing_if = "HashSet::is_empty", default)]
Expand All @@ -131,6 +134,7 @@ impl RitaExitSettingsStruct {
payment: PaymentSettings::default(),
localization: LocalizationSettings::default(),
network: NetworkSettings::default(),
operator: ExitOperatorSettings::default(),
exit_network: ExitNetworkSettings::test_default(),
allowed_countries: HashSet::new(),
log: LoggingSettings::default(),
Expand Down
12 changes: 12 additions & 0 deletions settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ pub fn get_rita_exit() -> RitaExitSettingsStruct {
}
}

/// This code checks to see if the current device/setting is client or not
pub fn check_if_client() -> bool {
let netns = KI.check_integration_test_netns();
match SETTINGS.read().unwrap().get(&netns) {
Some(Settings::Adaptor(_)) => false,
Some(Settings::Client(_)) => true,
Some(Settings::Exit(_)) => false,
None => false,
}
}


/// This code checks to see if the current device/setting is an exit or not
pub fn check_if_exit() -> bool {
let netns = KI.check_integration_test_netns();
Expand Down
15 changes: 15 additions & 0 deletions settings/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,18 @@ impl Default for OperatorSettings {
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct ExitOperatorSettings {
/// The operator managing this router
#[serde(default = "default_operator_address")]
pub operator_address: Option<Address>,
}

impl Default for ExitOperatorSettings {
fn default() -> ExitOperatorSettings {
ExitOperatorSettings {
operator_address: default_operator_address(),
}
}
}

0 comments on commit f122de5

Please sign in to comment.