Skip to content

Commit

Permalink
Merge pull request #52 from darksoil-studio/develop
Browse files Browse the repository at this point in the history
Make gossip_arc_clamp a field in HolochainPluginConfig
  • Loading branch information
guillemcordoba authored Nov 4, 2024
2 parents f3f05df + c50027b commit c2aa1d8
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Changed

- Gossip arc clamp is not a setting part of `HolochainPluginConfig`.
1 change: 1 addition & 0 deletions crates/hc-pilot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn main() {
wan_network_config,
holochain_dir: conductor_dir,
admin_port: args.admin_port,
gossip_arc_clamp: None,
},
))
.setup(|app| {
Expand Down
6 changes: 0 additions & 6 deletions crates/tauri-plugin-holochain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,3 @@ ctrlc = "3.4"
[build-dependencies]
tauri-plugin = { version = "2.0.0", features = ["build"] }

[features]
default = ["gossip_arc_normal"]

gossip_arc_empty = []
gossip_arc_full = []
gossip_arc_normal = []
15 changes: 0 additions & 15 deletions crates/tauri-plugin-holochain/src/features.rs

This file was deleted.

27 changes: 7 additions & 20 deletions crates/tauri-plugin-holochain/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,13 @@ use holochain_client::AdminWebsocket;
use crate::{
filesystem::FileSystem,
launch::signal::{can_connect_to_signal_server, run_local_signal_service},
HolochainPluginConfig, HolochainRuntime,
GossipArcClamp, HolochainPluginConfig, HolochainRuntime,
};

mod mdns;
mod signal;
use mdns::spawn_mdns_bootstrap;

#[cfg(feature = "gossip_arc_empty")]
fn override_gossip_arc_clamping() -> Option<String> {
Some(String::from("empty"))
}

#[cfg(feature = "gossip_arc_full")]
fn override_gossip_arc_clamping() -> Option<String> {
Some(String::from("full"))
}

#[cfg(feature = "gossip_arc_normal")]
fn override_gossip_arc_clamping() -> Option<String> {
None
}

// pub static RUNNING_HOLOCHAIN: RwLock<Option<RunningHolochainInfo>> = RwLock::const_new(None);

/// Launch the holochain conductor in the background
Expand All @@ -48,8 +33,8 @@ pub async fn launch_holochain_runtime(

let filesystem = FileSystem::new(config.holochain_dir).await?;
let admin_port = if let Some(admin_port) = config.admin_port {
admin_port
} else {
admin_port
} else {
portpicker::pick_unused_port().expect("No ports free")
};

Expand Down Expand Up @@ -83,7 +68,10 @@ pub async fn launch_holochain_runtime(
filesystem.keystore_dir().into(),
config.wan_network_config.map(|n| n.bootstrap_url),
signal_urls,
override_gossip_arc_clamping(),
config.gossip_arc_clamp.map(|n| match n {
GossipArcClamp::Full => "full".to_string(),
GossipArcClamp::Empty => "empty".to_string(),
}),
);

let conductor_handle = Conductor::builder()
Expand Down Expand Up @@ -231,4 +219,3 @@ pub async fn wait_until_admin_ws_is_available(admin_port: u16) -> crate::Result<

// Ok(Arc::new(config))
// }

51 changes: 41 additions & 10 deletions crates/tauri-plugin-holochain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use http_server::{pong_iframe, read_asset};
use lair_signer::LairAgentSignerWithProvenance;
use launch::launch_holochain_runtime;
use tauri::{
http::response, ipc::CapabilityBuilder, plugin::{Builder, TauriPlugin}, AppHandle, Emitter, Manager, RunEvent, Runtime, WebviewUrl, WebviewWindowBuilder
http::response,
ipc::CapabilityBuilder,
plugin::{Builder, TauriPlugin},
AppHandle, Emitter, Manager, RunEvent, Runtime, WebviewUrl, WebviewWindowBuilder,
};

use holochain::{
Expand All @@ -25,12 +28,11 @@ use url2::Url2;
mod commands;
mod config;
mod error;
mod features;
mod filesystem;
mod hc_live_file;
mod http_server;
mod lair_signer;
mod launch;
mod hc_live_file;

use commands::install_web_app::{install_app, install_web_app, update_app, UpdateAppError};
pub use error::{Error, Result};
Expand Down Expand Up @@ -507,6 +509,11 @@ pub struct WANNetworkConfig {
pub signal_url: Url2,
}

pub enum GossipArcClamp {
Full,
Empty,
}

pub struct HolochainPluginConfig {
/// The directory where the holochain files and databases will be stored in
pub holochain_dir: PathBuf,
Expand All @@ -515,21 +522,47 @@ pub struct HolochainPluginConfig {
pub wan_network_config: Option<WANNetworkConfig>,
/// Force the conductor to run at this admin port
pub admin_port: Option<u16>,
/// 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<GossipArcClamp>,
}

fn default_gossip_arc_clamp() -> Option<GossipArcClamp> {
if cfg!(mobile) {
Some(GossipArcClamp::Empty)
} else {
None
}
}

impl HolochainPluginConfig {
pub fn new(holochain_dir: PathBuf, wan_network_config: Option<WANNetworkConfig>) -> Self {
pub fn new(
holochain_dir: PathBuf,
wan_network_config: Option<WANNetworkConfig>,
) -> Self {
HolochainPluginConfig {
holochain_dir,
wan_network_config,
admin_port: None,
gossip_arc_clamp: default_gossip_arc_clamp(),
}
}

pub fn admin_port(mut self, admin_port: u16) -> Self {
self.admin_port = Some(admin_port);
self
}

pub fn gossip_arc_clamp(mut self, gossip_arc_clamp: GossipArcClamp) -> Self {
self.gossip_arc_clamp = Some(gossip_arc_clamp);
self
}
}

fn plugin_builder<R: Runtime>() -> Builder<R> {
Expand Down Expand Up @@ -631,8 +664,7 @@ fn plugin_builder<R: Runtime>() -> Builder<R> {
r
})
})
.on_event(|app, event| {
match event {
.on_event(|app, event| match event {
RunEvent::Exit => {
if tauri::is_dev() {
if let Ok(h) = app.holochain() {
Expand All @@ -642,9 +674,8 @@ fn plugin_builder<R: Runtime>() -> Builder<R> {
}
}
}
_ =>{ }
}
})
_ => {}
})
}

/// Initializes the plugin, waiting for holochain to launch before finishing the app's setup.
Expand Down Expand Up @@ -707,7 +738,7 @@ async fn launch_and_setup_holochain<R: Runtime>(
}
std::process::exit(0);
})?;
}
}

let p = HolochainPlugin::<R> {
app_handle: app_handle.clone(),
Expand Down

0 comments on commit c2aa1d8

Please sign in to comment.