From d834fe3b2c7a47a92ff6c71cd2c1dec24ff110d4 Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Mon, 25 Apr 2022 16:42:37 +0800 Subject: [PATCH] feature gated p2p + update deps + pushed bindings --- .gitignore | 2 + Cargo.lock | Bin 222943 -> 218639 bytes apps/debug/Cargo.toml | 2 - apps/desktop/src-tauri/tauri.linux.conf.json | 2 +- apps/server/Cargo.toml | 6 +-- apps/server/src/main.rs | 42 ++++++++++++------- core/Cargo.toml | 13 ++++-- core/prisma/Cargo.toml | 2 - core/src/db/migrate.rs | 7 ++++ core/src/file/cas/identifier.rs | 2 +- core/src/job/jobs.rs | 4 +- core/src/lib.rs | 26 ++++++------ core/src/library/loader.rs | 2 +- core/src/library/statistics.rs | 40 +++++++++--------- core/src/sync/engine.rs | 2 +- core/src/sync/examples/file.rs | 10 ++--- core/src/sync/examples/tag.rs | 6 +-- core/src/sys/locations.rs | 16 +++---- 18 files changed, 100 insertions(+), 84 deletions(-) diff --git a/.gitignore b/.gitignore index ca2f6b272..ead1724ac 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,5 @@ yalc.lock todos.md examples/*/*.lock /target + +/sdserver_data \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index bffe1c80122bbfc172bd65e74b5cf6cc027b98f9..8308891cbfcca3e00a8f6264fc6a0a0c7bb43711 100644 GIT binary patch delta 3951 zcmYjUX^frMS=RZ!vBw_Ac!@pZH5oevClPkezKGZ}whCQhH{w#Kuhql{VWzyr-O7pYBjQfrekH_0YbGAlN5?_#RwRyV6=hHiLj;mqkx zFD&Tx(XmcEy{0>V^Zc2o={qBJ!);{uR_2*WQVD6f=USDdij~F{?nRMQDXp`PUUOrG z@jfLS$QK)!4>p&2@sG%=PTcNhj@^*owrsW&)$P&yTfhn>wfODA~5 zUd9BA#bjY3TcN0QE=HE6GToWOqce5)hjd3DUoi8ZkFDa}g$Jj*y?^n=dj2soHIa=< zGA7P~Q^E=vG=cp?oFd1BmqNJ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jc{T69Sk?V}cU^BauHnZ}d0;*Mxbrt<>XP34 z_NMcC=g*m4N{AqV96=GFMbnwnXdoR5Um8g>f*>&gz_=#~h&cBQor{@UMvDR&q#Lny z_gqk(Ti;t%wv*nr^3sOhO>K2yZ&$DXh{=Gt1dJkq2q<8OVV4NIfn*2kE-=~ye`eba z13Xj;1_4ak&5;=CWE0YW@|{}_U)&ohyD#Z|uRXb`x3}(Yjb_ae6AK#@|ObpPZ5H+b$m@ZHc;|EzbqFb(+t;Dsum%G}}Dc9NFK>7LV z-gNuA>7CJE{qzK;9RR0OLLtatc$k9Da7lm>, + _event_receiver: web::Data>, core: web::Data, } @@ -65,7 +67,7 @@ impl StreamHandler> for Socket { payload: SocketResponsePayload::Query(response), }), Err(err) => { - // println!("query error: {:?}", err); + println!("query error: {:?}", err); // Err(err.to_string()) }, }; @@ -77,12 +79,11 @@ impl StreamHandler> for Socket { payload: SocketResponsePayload::Query(response), }), Err(err) => { - // println!("command error: {:?}", err); + println!("command error: {:?}", err); // Err(err.to_string()) }, }; }, - _ => {}, } }; @@ -113,7 +114,6 @@ impl Handler for Socket { fn handle(&mut self, msg: SocketResponse, ctx: &mut Self::Context) { let string = serde_json::to_string(&msg).unwrap(); - println!("sending response: {string}"); ctx.text(string); } } @@ -137,16 +137,21 @@ async fn ws_handler( ) -> Result { let resp = ws::start( Socket { - event_receiver, + _event_receiver: event_receiver, core: controller, }, &req, stream, ); - println!("{:?}", resp); resp } +#[get("/file/{file:.*}")] +async fn file() -> impl Responder { + // TODO + format!("OK") +} + async fn not_found() -> impl Responder { HttpResponse::build(StatusCode::OK).body("We're past the event horizon...") } @@ -163,6 +168,7 @@ async fn main() -> std::io::Result<()> { .service(index) .service(healthcheck) .service(ws_handler) + .service(file) .default_service(web::route().to(not_found)) }) .bind(("0.0.0.0", 8080))? @@ -174,15 +180,23 @@ async fn setup() -> ( web::Data>, web::Data, ) { - let data_dir_var = "DATA_DIR"; - let data_dir = match env::var(data_dir_var) { - Ok(path) => path, - Err(e) => panic!("${} is not set ({})", data_dir_var, e), + let data_dir_path = match env::var(DATA_DIR_ENV_VAR) { + Ok(path) => Path::new(&path).to_path_buf(), + Err(_e) => { + #[cfg(not(debug_assertions))] + { + panic!("${} is not set ({})", DATA_DIR_ENV_VAR, _e) + } + + std::env::current_dir() + .expect( + "Unable to get your currrent directory. Maybe try setting $DATA_DIR?", + ) + .join("sdserver_data") + }, }; - let data_dir_path = Path::new(&data_dir); - - let (mut core, event_receiver) = Core::new(data_dir_path.to_path_buf()).await; + let (mut core, event_receiver) = Core::new(data_dir_path).await; core.initializer().await; diff --git a/core/Cargo.toml b/core/Cargo.toml index ac8c49aaf..48ebc2e50 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -7,13 +7,15 @@ license = "GNU GENERAL PUBLIC LICENSE" repository = "https://github.com/jamiepine/spacedrive" edition = "2021" +[features] +p2p = ["dep:libp2p"] # This feature controlls whether the Spacedrive Core contains the Peer to Peer syncing engine (It isn't required for the hosted core so we can disable it). + [dependencies] -swift-rs = "0.2.3" hotwatch = "0.4.6" hostname = "0.3.1" + # Universal Dependencies anyhow = "1.0.44" -log = "0.4.14" base64 = "0.13.0" serde = { version = "1.0", features = ["derive"] } chrono = { version = "0.4.0", features = ["serde"] } @@ -21,13 +23,13 @@ serde_json = "1.0" futures = "0.3" data-encoding = "2.3.2" ring = "0.17.0-alpha.10" -once_cell = "1.8.0" int-enum = "0.4.0" + # Project dependencies ts-rs = "6.1" prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust.git", tag = "0.4.0" } walkdir = "^2.3.2" -libp2p = "0.43.0" +libp2p = { version = "0.43.0", optional = true } lazy_static = "1.4.0" uuid = "0.8" sysinfo = "0.23.9" @@ -41,3 +43,6 @@ image = "0.24.1" webp = "0.2.2" uhlc = "0.4.1" ffmpeg-next = "5.0.3" + +[target.'cfg(target_os = "macos")'.dependencies] +swift-rs = "0.2.3" \ No newline at end of file diff --git a/core/prisma/Cargo.toml b/core/prisma/Cargo.toml index c8fd197f5..de83528d7 100644 --- a/core/prisma/Cargo.toml +++ b/core/prisma/Cargo.toml @@ -3,7 +3,5 @@ name = "prisma-cli" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.4.0" } \ No newline at end of file diff --git a/core/src/db/migrate.rs b/core/src/db/migrate.rs index bcfb524b1..eee387954 100644 --- a/core/src/db/migrate.rs +++ b/core/src/db/migrate.rs @@ -33,6 +33,7 @@ pub async fn run_migrations(db_url: &str) -> Result<()> { { Ok(data) => { if data.len() == 0 { + #[cfg(debug_assertions)] println!("Migration table does not exist"); // execute migration match client._execute_raw(INIT_MIGRATION).await { @@ -47,8 +48,10 @@ pub async fn run_migrations(db_url: &str) -> Result<()> { .await .unwrap(); + #[cfg(debug_assertions)] println!("Migration table created: {:?}", value); } else { + #[cfg(debug_assertions)] println!("Migration table exists: {:?}", data); } @@ -93,6 +96,7 @@ pub async fn run_migrations(db_url: &str) -> Result<()> { .await?; if existing_migration.is_none() { + #[cfg(debug_assertions)] println!("Running migration: {}", name); let steps = migration_sql.split(";").collect::>(); @@ -111,6 +115,7 @@ pub async fn run_migrations(db_url: &str) -> Result<()> { for (i, step) in steps.iter().enumerate() { match client._execute_raw(&format!("{};", step)).await { Ok(_) => { + #[cfg(debug_assertions)] println!("Step {} ran successfully", i); client .migration() @@ -127,8 +132,10 @@ pub async fn run_migrations(db_url: &str) -> Result<()> { } } + #[cfg(debug_assertions)] println!("Migration {} recorded successfully", name); } else { + #[cfg(debug_assertions)] println!("Migration {} already exists", name); } } diff --git a/core/src/file/cas/identifier.rs b/core/src/file/cas/identifier.rs index 908165052..b71a9eeb9 100644 --- a/core/src/file/cas/identifier.rs +++ b/core/src/file/cas/identifier.rs @@ -2,7 +2,7 @@ use crate::job::jobs::JobReportUpdate; use crate::{ file::FileError, job::{jobs::Job, worker::WorkerContext}, - prisma::{self, file_path}, + prisma::{file_path}, CoreContext, }; use anyhow::Result; diff --git a/core/src/job/jobs.rs b/core/src/job/jobs.rs index 8e2657fa0..641646000 100644 --- a/core/src/job/jobs.rs +++ b/core/src/job/jobs.rs @@ -173,8 +173,8 @@ pub struct JobReportCreate {} impl Replicate for JobReport { type Create = JobReportCreate; - async fn create(_data: Self::Create, ctx: SyncContext) {} - async fn delete(ctx: SyncContext) {} + async fn create(_data: Self::Create, _ctx: SyncContext) {} + async fn delete(_ctx: SyncContext) {} } #[repr(i32)] diff --git a/core/src/lib.rs b/core/src/lib.rs index df215803e..b90a72e0a 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,6 +1,5 @@ use crate::file::cas::identifier::FileIdentifierJob; use job::jobs::{Job, JobReport, Jobs}; -use log::{error, info}; use prisma::PrismaClient; use serde::{Deserialize, Serialize}; use state::client::ClientState; @@ -22,6 +21,7 @@ pub mod encode; pub mod file; pub mod job; pub mod library; +#[cfg(target_os = "p2p")] pub mod p2p; pub mod prisma; pub mod state; @@ -91,12 +91,12 @@ impl CoreContext { .internal_sender .send(InternalEvent::JobIngest(job)) .unwrap_or_else(|e| { - error!("Failed to spawn job. {:?}", e); + println!("Failed to spawn job. {:?}", e); }); } pub async fn emit(&self, event: CoreEvent) { self.event_sender.send(event).await.unwrap_or_else(|e| { - error!("Failed to emit event. {:?}", e); + println!("Failed to emit event. {:?}", e); }); } } @@ -138,9 +138,9 @@ impl Core { // prepare basic client state let mut state = ClientState::new(data_dir, "diamond-mastering-space-dragon").unwrap(); // load from disk - state - .read_disk() - .unwrap_or(error!("No client state found, creating new one...")); + state.read_disk().unwrap_or(println!( + "Error: No client state found, creating new one..." + )); state.save(); @@ -160,6 +160,7 @@ impl Core { internal_channel, }; + #[cfg(feature = "p2p")] tokio::spawn(async move { p2p::listener::listen(None).await.unwrap_or(()); }); @@ -213,22 +214,22 @@ impl Core { println!("Initializing..."); if self.state.libraries.len() == 0 { match library::loader::create(&self, None).await { - Ok(library) => info!("Created new library: {:?}", library), - Err(e) => info!("Error creating library: {:?}", e), + Ok(library) => println!("Created new library: {:?}", library), + Err(e) => println!("Error creating library: {:?}", e), } } else { for library in self.state.libraries.iter() { // init database for library match library::loader::load(&library.library_path, &library.library_uuid).await { - Ok(library) => info!("Loaded library: {:?}", library), - Err(e) => info!("Error loading library: {:?}", e), + Ok(library) => println!("Loaded library: {:?}", library), + Err(e) => println!("Error loading library: {:?}", e), } } } // init client match client::create(&self).await { - Ok(_) => info!("Spacedrive online"), - Err(e) => info!("Error initializing client: {:?}", e), + Ok(_) => println!("Spacedrive online"), + Err(e) => println!("Error initializing client: {:?}", e), }; } @@ -279,6 +280,7 @@ impl Core { // query sources of data async fn exec_query(&self, query: ClientQuery) -> Result { + #[cfg(fdebug_assertions)] println!("Core query: {:?}", query); let ctx = self.get_context(); Ok(match query { diff --git a/core/src/library/loader.rs b/core/src/library/loader.rs index ad5b0a111..44fb5dd64 100644 --- a/core/src/library/loader.rs +++ b/core/src/library/loader.rs @@ -3,7 +3,7 @@ use uuid::Uuid; use crate::state::client::LibraryState; use crate::{db::migrate, prisma::library, state}; -use crate::{prisma, Core}; +use crate::Core; use super::LibraryError; diff --git a/core/src/library/statistics.rs b/core/src/library/statistics.rs index bfc0e1063..719a985af 100644 --- a/core/src/library/statistics.rs +++ b/core/src/library/statistics.rs @@ -1,9 +1,7 @@ -use crate::{prisma::library_statistics, state::client, CoreContext}; +use crate::prisma::library_statistics; use serde::{Deserialize, Serialize}; use ts_rs::TS; -use super::LibraryError; - #[derive(Debug, Serialize, Deserialize, TS, Clone)] #[ts(export)] pub struct Statistics { @@ -44,24 +42,24 @@ impl Default for Statistics { } } -impl Statistics { - pub async fn recalculate(ctx: &CoreContext) -> Result<(), LibraryError> { - let config = client::get(); - let db = &ctx.database; +// impl Statistics { +// pub async fn recalculate(ctx: &CoreContext) -> Result<(), LibraryError> { +// let config = client::get(); +// let db = &ctx.database; - let library_data = config.get_current_library(); +// let library_data = config.get_current_library(); - let library_statistics_db = match db - .library_statistics() - .find_unique(library_statistics::id::equals(library_data.library_id)) - .exec() - .await? - { - Some(library_statistics_db) => library_statistics_db.into(), - // create the default values if database has no entry - None => Statistics::default(), - }; +// let library_statistics_db = match db +// .library_statistics() +// .find_unique(library_statistics::id::equals(library_data.library_id)) +// .exec() +// .await? +// { +// Some(library_statistics_db) => library_statistics_db.into(), +// // create the default values if database has no entry +// None => Statistics::default(), +// }; - Ok(()) - } -} +// Ok(()) +// } +// } diff --git a/core/src/sync/engine.rs b/core/src/sync/engine.rs index 47653233f..57070ea15 100644 --- a/core/src/sync/engine.rs +++ b/core/src/sync/engine.rs @@ -48,7 +48,7 @@ pub enum SyncTransport { } impl SyncEngine { - pub fn new(core_ctx: &FakeCoreContext) -> Self { + pub fn new(_core_ctx: &FakeCoreContext) -> Self { let (client_pool_sender, _client_pool_receiver) = mpsc::channel(10); SyncEngine { diff --git a/core/src/sync/examples/file.rs b/core/src/sync/examples/file.rs index 7520457fc..af2be0cc3 100644 --- a/core/src/sync/examples/file.rs +++ b/core/src/sync/examples/file.rs @@ -28,15 +28,15 @@ impl PropertyOperation for File { type Create = FileCreate; type Update = FileUpdate; - async fn create(_data: Self::Create, ctx: SyncContext) {} - async fn update(_data: Self::Update, ctx: SyncContext) {} - async fn delete(ctx: SyncContext) {} + async fn create(_data: Self::Create, _ctx: SyncContext) {} + async fn update(_data: Self::Update, _ctx: SyncContext) {} + async fn delete(_ctx: SyncContext) {} } #[async_trait::async_trait] impl Replicate for File { type Create = FileCreate; - async fn create(_data: Self::Create, ctx: SyncContext) {} - async fn delete(ctx: SyncContext) {} + async fn create(_data: Self::Create, _ctx: SyncContext) {} + async fn delete(_ctx: SyncContext) {} } diff --git a/core/src/sync/examples/tag.rs b/core/src/sync/examples/tag.rs index 155413541..6b53a2e28 100644 --- a/core/src/sync/examples/tag.rs +++ b/core/src/sync/examples/tag.rs @@ -29,7 +29,7 @@ impl PropertyOperation for Tag { type Create = TagCreate; type Update = TagUpdate; - async fn create(_data: Self::Create, ctx: SyncContext) {} - async fn update(_data: Self::Update, ctx: SyncContext) {} - async fn delete(ctx: SyncContext) {} + async fn create(_data: Self::Create, _ctx: SyncContext) {} + async fn update(_data: Self::Update, _ctx: SyncContext) {} + async fn delete(_ctx: SyncContext) {} } diff --git a/core/src/sys/locations.rs b/core/src/sys/locations.rs index b617a8c38..4b3ed4ebc 100644 --- a/core/src/sys/locations.rs +++ b/core/src/sys/locations.rs @@ -1,12 +1,7 @@ use crate::{ - file::indexer::IndexerJob, - prisma::{file_path, location}, - state::client, - sys::{volumes, volumes::Volume}, - ClientQuery, CoreContext, CoreEvent, + file::indexer::IndexerJob, prisma::location, state::client, ClientQuery, CoreContext, CoreEvent, }; use anyhow::Result; -use log::info; use serde::{Deserialize, Serialize}; use std::{fs, io, io::Write, path::Path}; use thiserror::Error; @@ -80,7 +75,7 @@ pub async fn get_location( None => Err(LocationError::NotFound(location_id.to_string()))?, }; - info!("Retrieved location: {:?}", location); + println!("Retrieved location: {:?}", location); Ok(location.into()) } @@ -100,7 +95,6 @@ pub async fn new_location_and_scan( pub async fn get_locations(ctx: &CoreContext) -> Result, SysError> { let db = &ctx.database; - let config = client::get(); let locations = db.location().find_many(vec![]).exec().await?; @@ -119,7 +113,7 @@ pub async fn create_location(ctx: &CoreContext, path: &str) -> Result info!("Path is valid, creating location for '{}'", &path), + Ok(_) => println!("Path is valid, creating location for '{}'", &path), Err(e) => Err(LocationError::FileReadError(e))?, } // check if location already exists @@ -131,7 +125,7 @@ pub async fn create_location(ctx: &CoreContext, path: &str) -> Result location, None => { - info!( + println!( "Location does not exist, creating new location for '{}'", &path ); @@ -152,7 +146,7 @@ pub async fn create_location(ctx: &CoreContext, path: &str) -> Result