mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
runtime: configure the destination stamper before the network starts
This commit is contained in:
1 parent
ee9190db0f
commit
3bb885cd63
4 files changed
+73
-2
No files matched your search
@@ -2067,6 +2067,7 @@ pub rns_runtime::reticulum::StartupRNodeRuntime::interface_id: rns_interface::tr
|
||||
pub rns_runtime::reticulum::StartupRNodeRuntime::observer: rns_runtime::reticulum::RNodeRuntimeObserver
|
||||
pub const rns_runtime::reticulum::BLACKHOLE_LINK_COST: f64
|
||||
pub const rns_runtime::reticulum::DEFAULT_ANNOUNCE_SUBSCRIPTION_CAPACITY: usize
|
||||
pub fn rns_runtime::reticulum::configure_destination_stamper(core::option::Option<&str>, &rns_runtime::reticulum::InitOptions) -> core::result::Result<(), rns_runtime::reticulum::ReticulumError>
|
||||
pub fn rns_runtime::reticulum::get_instance() -> core::option::Option<&'static rns_runtime::reticulum::ReticulumHandle>
|
||||
pub async fn rns_runtime::reticulum::init(core::option::Option<&str>, core::option::Option<std::path::PathBuf>, rns_runtime::lifecycle::ShutdownSignal, alloc::sync::Arc<core::sync::atomic::AtomicBool>) -> core::result::Result<rns_runtime::reticulum::ReticulumHandle, rns_runtime::reticulum::ReticulumError>
|
||||
pub async fn rns_runtime::reticulum::init_with_options(core::option::Option<&str>, core::option::Option<std::path::PathBuf>, rns_runtime::lifecycle::ShutdownSignal, alloc::sync::Arc<core::sync::atomic::AtomicBool>, rns_runtime::reticulum::InitOptions) -> core::result::Result<rns_runtime::reticulum::ReticulumHandle, rns_runtime::reticulum::ReticulumError>
|
||||
|
||||
+2
-2
@@ -87,8 +87,8 @@
|
||||
"tier": "provisional",
|
||||
"compatibility": "reviewed-snapshot",
|
||||
"snapshot": "api/snapshots/rns-runtime.txt",
|
||||
"itemCount": 2461,
|
||||
"sha256": "5080d5423276206703c0b547c334e8996a12fd912da4190e6325040a4260eade"
|
||||
"itemCount": 2462,
|
||||
"sha256": "d704669b199ab5f476134deb1396d298939085e3bdd0f77195b1cf10652ef703"
|
||||
},
|
||||
{
|
||||
"name": "rns-tools",
|
||||
|
||||
@@ -639,6 +639,51 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stamp_made_before_the_network_starts_is_saved_where_init_loads_it() {
|
||||
let _settings = test_settings::blocking_unstamped();
|
||||
let dir = scratch_dir("early");
|
||||
std::fs::write(
|
||||
dir.join("config"),
|
||||
"[stamps]\n destination_value = 8\n destination_cost = 6\n",
|
||||
)
|
||||
.unwrap();
|
||||
let configdir = dir.to_str().unwrap();
|
||||
crate::reticulum::configure_destination_stamper(
|
||||
Some(configdir),
|
||||
&crate::reticulum::InitOptions::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(policy().destination_value, 8.0);
|
||||
let identity = Identity::new();
|
||||
let app = "test.prepare.early";
|
||||
let destination =
|
||||
Destination::new(Some(&identity), Direction::In, DestType::Single, app).unwrap();
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.build()
|
||||
.unwrap();
|
||||
runtime
|
||||
.block_on(prepare(&destination, &identity).unwrap().ready())
|
||||
.unwrap();
|
||||
let material = destination.stamp_material(&identity.get_public_key());
|
||||
assert!(
|
||||
load_destination_stamp(&dir.join("storage"), &destination.hash, &material, 6.0)
|
||||
.is_some()
|
||||
);
|
||||
|
||||
// Without a config the defaults apply, and none is written.
|
||||
let bare = scratch_dir("bare");
|
||||
crate::reticulum::configure_destination_stamper(
|
||||
bare.to_str(),
|
||||
&crate::reticulum::InitOptions::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(policy().destination_value, 25.0);
|
||||
assert!(!bare.join("config").exists());
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
let _ = std::fs::remove_dir_all(bare);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepare_does_nothing_when_destinations_are_not_stamped() {
|
||||
let _settings = test_settings::blocking_unstamped();
|
||||
|
||||
@@ -11278,6 +11278,31 @@ fn parse_blocked_ips(lines: &[String]) -> Vec<std::net::IpAddr> {
|
||||
lines.iter().filter_map(|line| line.parse().ok()).collect()
|
||||
}
|
||||
|
||||
/// Configure the destination stamper as `init` would for this config
|
||||
/// directory, without starting anything, so a stamp made before the network
|
||||
/// starts is saved where `init` loads it. A missing config reads as the default.
|
||||
pub fn configure_destination_stamper(
|
||||
configdir: Option<&str>,
|
||||
options: &InitOptions,
|
||||
) -> Result<(), ReticulumError> {
|
||||
let config_dir = resolve_config_dir(configdir);
|
||||
let config_path = config_dir.join("config");
|
||||
let config = if config_path.exists() {
|
||||
Config::from_file(&config_path)
|
||||
} else {
|
||||
Config::parse(Config::default_config())
|
||||
}
|
||||
.map_err(ReticulumError::Config)?;
|
||||
let mut rc = ReticulumConfig::try_from_config(&config).map_err(ReticulumError::Config)?;
|
||||
rc.apply_init_options(options);
|
||||
rc.stamp_workers.install();
|
||||
crate::destination_stamper::configure(
|
||||
rc.stamps,
|
||||
Some(StoragePaths::from_config_dir(&config_dir).storage_dir),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_or_create_config(path: &Path) -> Result<(Config, bool), ReticulumError> {
|
||||
if path.exists() {
|
||||
Config::from_file(path)
|
||||
|
||||
Reference in new issue
Block a user