From 8536f9163c97d5796f2f66723488a6737fcfb098 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Fri, 1 Nov 2024 13:28:44 -0400 Subject: [PATCH 1/2] refactor: make gossip_arc_clamp and explicit setting, rather than specifying via features flags (cherry picked from commit a02fe9f276a62120ad2de80b8f569bf476107674) --- crates/hc-pilot/src/main.rs | 1 + .../src-tauri/src/lib.rs.hbs | 2 +- .../end-user-happ/src-tauri/src/lib.rs.hbs | 2 +- crates/tauri-plugin-holochain/Cargo.toml | 6 ----- crates/tauri-plugin-holochain/src/features.rs | 15 ----------- crates/tauri-plugin-holochain/src/launch.rs | 25 ++++--------------- crates/tauri-plugin-holochain/src/lib.rs | 18 +++++++++++-- examples/end-user-happ/src-tauri/src/lib.rs | 2 +- .../holochain-runtime/src-tauri/src/lib.rs | 2 +- 9 files changed, 26 insertions(+), 47 deletions(-) delete mode 100644 crates/tauri-plugin-holochain/src/features.rs diff --git a/crates/hc-pilot/src/main.rs b/crates/hc-pilot/src/main.rs index 66cdb7c3..181b405b 100644 --- a/crates/hc-pilot/src/main.rs +++ b/crates/hc-pilot/src/main.rs @@ -114,6 +114,7 @@ fn main() { wan_network_config, holochain_dir: conductor_dir, admin_port: args.admin_port, + gossip_arc_clamp: None, }, )) .setup(|app| { diff --git a/crates/scaffold-holochain-runtime/templates/holochain-runtime/src-tauri/src/lib.rs.hbs b/crates/scaffold-holochain-runtime/templates/holochain-runtime/src-tauri/src/lib.rs.hbs index 5a1fae08..ec5bcc99 100644 --- a/crates/scaffold-holochain-runtime/templates/holochain-runtime/src-tauri/src/lib.rs.hbs +++ b/crates/scaffold-holochain-runtime/templates/holochain-runtime/src-tauri/src/lib.rs.hbs @@ -15,7 +15,7 @@ pub fn run() { ) .plugin(tauri_plugin_holochain::init( vec_to_locked(vec![]).expect("Can't build passphrase"), - HolochainPluginConfig::new(holochain_dir(), wan_network_config()) + HolochainPluginConfig::new(holochain_dir(), wan_network_config(), None) )) .setup(|app| { let handle = app.handle().clone(); diff --git a/crates/scaffold-tauri-happ/templates/end-user-happ/src-tauri/src/lib.rs.hbs b/crates/scaffold-tauri-happ/templates/end-user-happ/src-tauri/src/lib.rs.hbs index 57fd1263..9b911254 100644 --- a/crates/scaffold-tauri-happ/templates/end-user-happ/src-tauri/src/lib.rs.hbs +++ b/crates/scaffold-tauri-happ/templates/end-user-happ/src-tauri/src/lib.rs.hbs @@ -23,7 +23,7 @@ pub fn run() { ) .plugin(tauri_plugin_holochain::init( vec_to_locked(vec![]).expect("Can't build passphrase"), - HolochainPluginConfig::new(holochain_dir(), wan_network_config()) + HolochainPluginConfig::new(holochain_dir(), wan_network_config(), None) )) .setup(|app| { let handle = app.handle().clone(); diff --git a/crates/tauri-plugin-holochain/Cargo.toml b/crates/tauri-plugin-holochain/Cargo.toml index 564562d7..2edbfb5f 100644 --- a/crates/tauri-plugin-holochain/Cargo.toml +++ b/crates/tauri-plugin-holochain/Cargo.toml @@ -61,9 +61,3 @@ async-trait = "0.1" [build-dependencies] tauri-plugin = { version = "2.0.0", features = ["build"] } -[features] -default = ["gossip_arc_normal"] - -gossip_arc_empty = [] -gossip_arc_full = [] -gossip_arc_normal = [] diff --git a/crates/tauri-plugin-holochain/src/features.rs b/crates/tauri-plugin-holochain/src/features.rs deleted file mode 100644 index 37e319f8..00000000 --- a/crates/tauri-plugin-holochain/src/features.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[cfg(all(feature = "gossip_arc_empty", feature = "gossip_arc_full"))] -compile_error!( - "The `gossip_arc_empty` and `gossip_arc_full` features are both enabled, which is an error. Please enable only one." -); -#[cfg(all(feature = "gossip_arc_empty", feature = "gossip_arc_normal"))] -compile_error!( - "The `gossip_arc_empty` and `gossip_arc_normal` features are both enabled, which is an error. Please enable only one." -); -#[cfg(all(feature = "gossip_arc_full", feature = "gossip_arc_normal"))] -compile_error!( - "The `gossip_arc_full` and `gossip_arc_normal` features are both enabled, which is an error. Please enable only one." -); - -#[cfg(all(not(feature = "gossip_arc_empty"), not(feature = "gossip_arc_full"), not(feature = "gossip_arc_normal")))] -compile_error!("All of the `gossip_arc_empty`, `gossip_arc_full`, and `gossip_arc_normal` features are disabled. Please enable one of them."); diff --git a/crates/tauri-plugin-holochain/src/launch.rs b/crates/tauri-plugin-holochain/src/launch.rs index 56b749fc..47393d21 100644 --- a/crates/tauri-plugin-holochain/src/launch.rs +++ b/crates/tauri-plugin-holochain/src/launch.rs @@ -11,7 +11,7 @@ use holochain_client::AdminWebsocket; use crate::{ filesystem::FileSystem, launch::signal::{can_connect_to_signal_server, run_local_signal_service}, - HolochainPluginConfig, HolochainRuntime, + HolochainPluginConfig, HolochainRuntime, GossipArcClamp }; mod mdns; @@ -20,24 +20,6 @@ use mdns::spawn_mdns_bootstrap; pub const DEVICE_SEED_LAIR_KEYSTORE_TAG: &'static str = "DEVICE_SEED"; -#[cfg(feature = "gossip_arc_empty")] -fn override_gossip_arc_clamping() -> Option { - Some(String::from("empty")) -} - -#[cfg(feature = "gossip_arc_full")] -fn override_gossip_arc_clamping() -> Option { - Some(String::from("full")) -} - -#[cfg(feature = "gossip_arc_normal")] -fn override_gossip_arc_clamping() -> Option { - if cfg!(mobile) { - Some(String::from("empty")) - } else { - None - } -} // pub static RUNNING_HOLOCHAIN: RwLock> = RwLock::const_new(None); @@ -83,7 +65,10 @@ pub async fn launch_holochain_runtime( filesystem.keystore_dir().into(), wan_network_config, local_signal_url, - override_gossip_arc_clamping(), + config.gossip_arc_clamp.map(|n| match n { + GossipArcClamp::Full => "full".to_string(), + GossipArcClamp::Empty => "empty".to_string() + }) ); let keystore = diff --git a/crates/tauri-plugin-holochain/src/lib.rs b/crates/tauri-plugin-holochain/src/lib.rs index ad38f31c..4e1eb2c5 100644 --- a/crates/tauri-plugin-holochain/src/lib.rs +++ b/crates/tauri-plugin-holochain/src/lib.rs @@ -29,7 +29,6 @@ use url2::Url2; mod commands; mod config; mod error; -mod features; mod filesystem; mod http_server; mod lair_signer; @@ -520,6 +519,11 @@ pub struct WANNetworkConfig { pub ice_servers_urls: Vec, } +pub enum GossipArcClamp { + Full, + Empty +} + pub struct HolochainPluginConfig { /// The directory where the holochain files and databases will be stored in pub holochain_dir: PathBuf, @@ -528,14 +532,24 @@ pub struct HolochainPluginConfig { pub wan_network_config: Option, /// Force the conductor to run at this admin port pub admin_port: Option, + /// Force the conductor to always have a "full", or "empty" Gossip Arc for all DNAs. + /// The Gossip Arc is the subsection of the DHT that you aim to store and serve to others. + /// + /// A Full Gossip Arc means that your peer will always try to hold the full DHT state, + /// and serve it to others. + /// + /// An Empty Gossip Arc means that your peer will always go to the network to fetch DHT data, + /// unless they authored it. + pub gossip_arc_clamp: Option } impl HolochainPluginConfig { - pub fn new(holochain_dir: PathBuf, wan_network_config: Option) -> Self { + pub fn new(holochain_dir: PathBuf, wan_network_config: Option, gossip_arc_clamp: Option) -> Self { HolochainPluginConfig { holochain_dir, wan_network_config, admin_port: None, + gossip_arc_clamp, } } diff --git a/examples/end-user-happ/src-tauri/src/lib.rs b/examples/end-user-happ/src-tauri/src/lib.rs index 69d649aa..d28bd57c 100644 --- a/examples/end-user-happ/src-tauri/src/lib.rs +++ b/examples/end-user-happ/src-tauri/src/lib.rs @@ -91,7 +91,7 @@ pub fn run() { ) .plugin(tauri_plugin_holochain::async_init( vec_to_locked(vec![]).expect("Can't build passphrase"), - HolochainPluginConfig::new(holochain_dir(), wan_network_config()) + HolochainPluginConfig::new(holochain_dir(), wan_network_config(), None) )) .setup(|app| { let handle = app.handle().clone(); diff --git a/examples/holochain-runtime/src-tauri/src/lib.rs b/examples/holochain-runtime/src-tauri/src/lib.rs index c46aaddd..4f595378 100644 --- a/examples/holochain-runtime/src-tauri/src/lib.rs +++ b/examples/holochain-runtime/src-tauri/src/lib.rs @@ -13,7 +13,7 @@ pub fn run() { ) .plugin(tauri_plugin_holochain::init( vec_to_locked(vec![]).expect("Can't build passphrase"), - HolochainPluginConfig::new(holochain_dir(), wan_network_config()) + HolochainPluginConfig::new(holochain_dir(), wan_network_config(), None) )) .setup(|app| { let handle = app.handle().clone(); From 45cb939982533ec8fdc5286e6ea35bc055a121f9 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Fri, 1 Nov 2024 15:10:21 -0400 Subject: [PATCH 2/2] chore: fmt --- crates/tauri-plugin-holochain/src/launch.rs | 7 +++---- crates/tauri-plugin-holochain/src/lib.rs | 12 ++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/tauri-plugin-holochain/src/launch.rs b/crates/tauri-plugin-holochain/src/launch.rs index 47393d21..44fa4c6d 100644 --- a/crates/tauri-plugin-holochain/src/launch.rs +++ b/crates/tauri-plugin-holochain/src/launch.rs @@ -11,7 +11,7 @@ use holochain_client::AdminWebsocket; use crate::{ filesystem::FileSystem, launch::signal::{can_connect_to_signal_server, run_local_signal_service}, - HolochainPluginConfig, HolochainRuntime, GossipArcClamp + GossipArcClamp, HolochainPluginConfig, HolochainRuntime, }; mod mdns; @@ -20,7 +20,6 @@ use mdns::spawn_mdns_bootstrap; pub const DEVICE_SEED_LAIR_KEYSTORE_TAG: &'static str = "DEVICE_SEED"; - // pub static RUNNING_HOLOCHAIN: RwLock> = RwLock::const_new(None); /// Launch the holochain conductor in the background @@ -67,8 +66,8 @@ pub async fn launch_holochain_runtime( local_signal_url, config.gossip_arc_clamp.map(|n| match n { GossipArcClamp::Full => "full".to_string(), - GossipArcClamp::Empty => "empty".to_string() - }) + GossipArcClamp::Empty => "empty".to_string(), + }), ); let keystore = diff --git a/crates/tauri-plugin-holochain/src/lib.rs b/crates/tauri-plugin-holochain/src/lib.rs index 4e1eb2c5..2b218987 100644 --- a/crates/tauri-plugin-holochain/src/lib.rs +++ b/crates/tauri-plugin-holochain/src/lib.rs @@ -521,7 +521,7 @@ pub struct WANNetworkConfig { pub enum GossipArcClamp { Full, - Empty + Empty, } pub struct HolochainPluginConfig { @@ -534,17 +534,21 @@ pub struct HolochainPluginConfig { pub admin_port: Option, /// Force the conductor to always have a "full", or "empty" Gossip Arc for all DNAs. /// The Gossip Arc is the subsection of the DHT that you aim to store and serve to others. - /// + /// /// A Full Gossip Arc means that your peer will always try to hold the full DHT state, /// and serve it to others. /// /// An Empty Gossip Arc means that your peer will always go to the network to fetch DHT data, /// unless they authored it. - pub gossip_arc_clamp: Option + pub gossip_arc_clamp: Option, } impl HolochainPluginConfig { - pub fn new(holochain_dir: PathBuf, wan_network_config: Option, gossip_arc_clamp: Option) -> Self { + pub fn new( + holochain_dir: PathBuf, + wan_network_config: Option, + gossip_arc_clamp: Option, + ) -> Self { HolochainPluginConfig { holochain_dir, wan_network_config,