Skip to content

Commit

Permalink
feat(node_manager): add unit tests and modify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and jacderida committed May 28, 2024
1 parent 74bd95d commit 19f8a07
Show file tree
Hide file tree
Showing 5 changed files with 446 additions and 41 deletions.
1 change: 1 addition & 0 deletions sn_node_manager/src/add_services/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl InstallNodeServiceCtxBuilder {
}

pub struct AddNodeServiceOptions {
pub auto_set_nat_flags: bool,
pub bootstrap_peers: Vec<Multiaddr>,
pub count: Option<u16>,
pub delete_safenode_src: bool,
Expand Down
32 changes: 29 additions & 3 deletions sn_node_manager/src/add_services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ use crate::{
config::{create_owned_dir, get_user_safenode_data_dir},
VerbosityLevel, DAEMON_SERVICE_NAME,
};
use color_eyre::{eyre::eyre, Help, Result};
use color_eyre::{
eyre::{eyre, OptionExt},
Help, Result,
};
use colored::Colorize;
use service_manager::ServiceInstallCtx;
use sn_service_management::{
auditor::AuditorServiceData, control::ServiceControl, DaemonServiceData, FaucetServiceData,
NodeRegistry, NodeServiceData, ServiceStatus,
NatDetectionStatus, NodeRegistry, NodeServiceData, ServiceStatus,
};
use std::{
ffi::OsString,
Expand All @@ -39,7 +42,7 @@ use std::{
///
/// Returns the service names of the added services.
pub async fn add_node(
options: AddNodeServiceOptions,
mut options: AddNodeServiceOptions,
node_registry: &mut NodeRegistry,
service_control: &dyn ServiceControl,
verbosity: VerbosityLevel,
Expand Down Expand Up @@ -179,6 +182,29 @@ pub async fn add_node(
options.safenode_src_path.clone(),
service_safenode_path.clone(),
)?;

if options.auto_set_nat_flags {
let nat_status = node_registry
.nat_status
.clone()
.ok_or_eyre("NAT status has not been set. Run 'nat-detection' first")?;

match nat_status {
NatDetectionStatus::Public => {
options.upnp = false;
options.home_network = false;
}
NatDetectionStatus::UPnP => {
options.upnp = true;
options.home_network = false;
}
NatDetectionStatus::Private => {
options.upnp = false;
options.home_network = true;
}
}
}

let install_ctx = InstallNodeServiceCtxBuilder {
bootstrap_peers: options.bootstrap_peers.clone(),
data_dir_path: service_data_dir_path.clone(),
Expand Down
Loading

0 comments on commit 19f8a07

Please sign in to comment.