diff --git a/extensions/warp-ipfs/shuttle/src/main.rs b/extensions/warp-ipfs/shuttle/src/main.rs index 235cea58e..089a34d2e 100644 --- a/extensions/warp-ipfs/shuttle/src/main.rs +++ b/extensions/warp-ipfs/shuttle/src/main.rs @@ -1,7 +1,5 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter}; -use std::path::PathBuf; - use base64::{ alphabet::STANDARD, engine::{general_purpose::PAD, GeneralPurpose}, @@ -9,6 +7,8 @@ use base64::{ }; use clap::Parser; use rust_ipfs::{Keypair, Multiaddr}; +use std::path::PathBuf; +use std::time::Duration; use zeroize::Zeroizing; @@ -70,6 +70,20 @@ struct Opt { /// TLS Private Key when websocket is used #[clap(long)] ws_tls_private_key: Option, + + /// Enable GC to cleanup any unpinned or orphaned blocks + #[clap(long)] + enable_gc: bool, + + /// Run GC at start + /// Note: its recommended not to use this if GC is enabled. + #[clap(long)] + run_gc_once: bool, + + /// GC Duration in seconds on how often GC should run + /// Note: NOOP if `enable_gc` is false + #[clap(long)] + gc_duration: Option, } #[cfg(not(target_arch = "wasm32"))] @@ -162,6 +176,10 @@ async fn main() -> Result<(), Box> { false, &opts.listen_addr, &opts.external_addr, + opts.enable_gc, + opts.run_gc_once, + opts.gc_duration.map(u64::from).map(Duration::from_secs), + None, true, ) .await?; diff --git a/extensions/warp-ipfs/src/shuttle/server.rs b/extensions/warp-ipfs/src/shuttle/server.rs index 4afbdc114..282f12edf 100644 --- a/extensions/warp-ipfs/src/shuttle/server.rs +++ b/extensions/warp-ipfs/src/shuttle/server.rs @@ -88,6 +88,10 @@ impl ShuttleServer { memory_transport: bool, listen_addrs: &[Multiaddr], external_addrs: &[Multiaddr], + enable_gc: bool, + run_gc_once: bool, + gc_duration: Option, + gc_trigger: Option, ext: bool, ) -> anyhow::Result { let executor = LocalExecutor; @@ -123,11 +127,6 @@ impl ShuttleServer { websocket_pem: wss_certs_and_key, ..Default::default() }) - // TODO: Either enable GC or do manual GC during little to no activity unless we reach a specific threshold - .with_gc(GCConfig { - duration: Duration::from_secs(60), - trigger: GCTrigger::None, - }) .set_temp_pin_duration(Duration::from_secs(60 * 30)) .with_request_response(vec![ RequestResponseConfig { @@ -144,6 +143,13 @@ impl ShuttleServer { }, ]); + if enable_gc { + let duration = gc_duration.unwrap_or(Duration::from_secs(60 * 24)); + let trigger = gc_trigger.unwrap_or_default(); + // TODO: maybe do manual GC during little to no activity unless we reach a specific threshold? + uninitialized = uninitialized.with_gc(GCConfig { duration, trigger }) + } + if enable_relay_server { // Relay is unbound or with higher limits so we can avoid having the connection resetting uninitialized = uninitialized.with_relay_server(RelayConfig::unbounded()); @@ -170,6 +176,17 @@ impl ShuttleServer { let ipfs = uninitialized.start().await?; + if run_gc_once { + match ipfs.gc().await { + Ok(blocks) => { + tracing::info!(blocks_removed = blocks.len(), "cleaned up unpinned blocks") + } + Err(e) => { + tracing::warn!(error = %e, "unable to run GC") + } + } + } + for addr in addrs { ipfs.add_listening_address(addr).await?; }