From 8dcd594dd78f0dd62db0254ec4adb76a3aa7c573 Mon Sep 17 00:00:00 2001 From: notplants Date: Tue, 5 Jul 2022 15:56:52 +0200 Subject: [PATCH 01/10] Publish address --- Cargo.lock | 26 ++++++++++++++++---- peach-config/Cargo.toml | 3 ++- peach-config/src/error.rs | 2 ++ peach-config/src/main.rs | 23 ++++++++++++++++++ peach-config/src/publish_address.rs | 37 +++++++++++++++++++++++++++++ peach-lib/Cargo.toml | 3 ++- 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 peach-config/src/publish_address.rs diff --git a/Cargo.lock b/Cargo.lock index bfaf051..c3b84ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,7 +1079,25 @@ dependencies = [ [[package]] name = "golgi" version = "0.1.4" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#ca4c1114ddf328b818144c5a1af0187b1357e9be" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#ca4c1114ddf328b818144c5a1af0187b1357e9be" +dependencies = [ + "async-std", + "async-stream 0.3.3", + "base64 0.13.0", + "futures 0.3.21", + "hex", + "kuska-handshake", + "kuska-sodiumoxide", + "kuska-ssb", + "log 0.4.17", + "serde 1.0.137", + "serde_json", + "sha2", +] + +[[package]] +name = "golgi" +version = "0.1.5" dependencies = [ "async-std", "async-stream 0.3.3", @@ -2205,7 +2223,7 @@ dependencies = [ "async-std", "clap", "env_logger 0.6.2", - "golgi", + "golgi 0.1.5", "lazy_static", "log 0.4.17", "peach-lib", @@ -2247,7 +2265,7 @@ dependencies = [ "chrono", "dirs 4.0.0", "fslock", - "golgi", + "golgi 0.1.5", "jsonrpc-client-core", "jsonrpc-client-http", "jsonrpc-core 8.0.1", @@ -2341,7 +2359,7 @@ dependencies = [ "dirs 4.0.0", "env_logger 0.8.4", "futures 0.3.21", - "golgi", + "golgi 0.1.4", "lazy_static", "log 0.4.17", "maud", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index ee34f61..acfbc4c 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -37,5 +37,6 @@ log = "0.4" lazy_static = "1.4.0" peach-lib = { path = "../peach-lib" } rpassword = "5.0" -golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" } +#golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" } +golgi = { path = "../../golgi" } async-std = "1.10.0" diff --git a/peach-config/src/error.rs b/peach-config/src/error.rs index 4b3ef41..862a866 100644 --- a/peach-config/src/error.rs +++ b/peach-config/src/error.rs @@ -40,6 +40,8 @@ pub enum PeachConfigError { PeachLibError { source: PeachError }, #[snafu(display("Error in golgi: {}", source))] Golgi { source: GolgiError }, + #[snafu(display("{}", message))] + CmdInputError { message: String }, } impl From for PeachConfigError { diff --git a/peach-config/src/main.rs b/peach-config/src/main.rs index be860f5..bc7c86f 100644 --- a/peach-config/src/main.rs +++ b/peach-config/src/main.rs @@ -2,6 +2,7 @@ mod change_password; mod constants; mod error; mod generate_manifest; +mod publish_address; mod set_permissions; mod setup_networking; mod setup_peach; @@ -55,6 +56,10 @@ enum PeachConfig { /// Returns sbot id if sbot is running #[structopt(name = "whoami")] WhoAmI, + + /// Publish domain and port + #[structopt(name = "publish-address")] + PublishAddress(PublishAddressOpts), } #[derive(StructOpt, Debug)] @@ -95,6 +100,13 @@ pub struct ChangePasswordOpts { password: Option, } +#[derive(StructOpt, Debug)] +pub struct PublishAddressOpts { + /// Specify address in the form domain:port + #[structopt(short, long)] + address: String, +} + arg_enum! { /// enum options for real-time clock choices #[derive(Debug)] @@ -169,6 +181,17 @@ async fn run() { error!("sbot whoami encountered an error: {}", err) } }, + PeachConfig::PublishAddress(opts) => { + match publish_address::publish_address(opts.address).await { + Ok(_) => {} + Err(err) => { + error!( + "peach-config encountered an error during publish address: {}", + err + ) + } + } + } } } } diff --git a/peach-config/src/publish_address.rs b/peach-config/src/publish_address.rs new file mode 100644 index 0000000..60ce1f6 --- /dev/null +++ b/peach-config/src/publish_address.rs @@ -0,0 +1,37 @@ +use crate::error::PeachConfigError; +use golgi::kuska_ssb::api::dto::content::PubAddress; +use golgi::messages::SsbMessageContent; +use peach_lib::sbot::init_sbot; + +/// Utility function to publish the address (domain:port) of the pub +/// publishing the address causes the domain and port to be used for invite generation, +/// and also gossips this pub address to their peers +pub async fn publish_address(address: String) -> Result<(), PeachConfigError> { + // split address into domain:port + let split: Vec<&str> = address.split(':').collect(); + let (domain, port): (&str, &str) = (split[0], split[1]); + // convert port to u16 + let port_as_u16: u16 = port + .parse() + .map_err(|_err| PeachConfigError::CmdInputError { + message: "Failure to parse domain and port. Address must be of the format host:port." + .to_string(), + })?; + // publish address + let mut sbot = init_sbot().await?; + let pub_id = sbot.whoami().await?; + // Compose a `pub` address type message. + let pub_address_msg = SsbMessageContent::Pub { + address: Some(PubAddress { + // Host name (can be an IP address if onboarding over WiFi). + host: Some(domain.to_string()), + // Port. + port: port_as_u16, + // Public key. + key: pub_id, + }), + }; + // Publish the `pub` address message. + let _pub_msg_ref = sbot.publish(pub_address_msg).await?; + Ok(()) +} diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index ee14e50..5ffc87b 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -9,7 +9,8 @@ async-std = "1.10" chrono = "0.4" dirs = "4.0" fslock="0.1" -golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi" } +#golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi" } +golgi = { path = "../../golgi" } jsonrpc-client-core = "0.5" jsonrpc-client-http = "0.5" jsonrpc-core = "8.0" -- 2.49.0 From f1ab2caa089bb27124c46c302853f7abdb3248a6 Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 6 Jul 2022 12:39:55 +0200 Subject: [PATCH 02/10] Fix golgi imports --- Cargo.lock | 26 ++++---------------------- peach-config/Cargo.toml | 3 +-- peach-config/src/main.rs | 3 ++- peach-lib/Cargo.toml | 3 +-- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3b84ee..bfaf051 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,25 +1079,7 @@ dependencies = [ [[package]] name = "golgi" version = "0.1.4" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#ca4c1114ddf328b818144c5a1af0187b1357e9be" -dependencies = [ - "async-std", - "async-stream 0.3.3", - "base64 0.13.0", - "futures 0.3.21", - "hex", - "kuska-handshake", - "kuska-sodiumoxide", - "kuska-ssb", - "log 0.4.17", - "serde 1.0.137", - "serde_json", - "sha2", -] - -[[package]] -name = "golgi" -version = "0.1.5" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#ca4c1114ddf328b818144c5a1af0187b1357e9be" dependencies = [ "async-std", "async-stream 0.3.3", @@ -2223,7 +2205,7 @@ dependencies = [ "async-std", "clap", "env_logger 0.6.2", - "golgi 0.1.5", + "golgi", "lazy_static", "log 0.4.17", "peach-lib", @@ -2265,7 +2247,7 @@ dependencies = [ "chrono", "dirs 4.0.0", "fslock", - "golgi 0.1.5", + "golgi", "jsonrpc-client-core", "jsonrpc-client-http", "jsonrpc-core 8.0.1", @@ -2359,7 +2341,7 @@ dependencies = [ "dirs 4.0.0", "env_logger 0.8.4", "futures 0.3.21", - "golgi 0.1.4", + "golgi", "lazy_static", "log 0.4.17", "maud", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index acfbc4c..ee34f61 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -37,6 +37,5 @@ log = "0.4" lazy_static = "1.4.0" peach-lib = { path = "../peach-lib" } rpassword = "5.0" -#golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" } -golgi = { path = "../../golgi" } +golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" } async-std = "1.10.0" diff --git a/peach-config/src/main.rs b/peach-config/src/main.rs index bc7c86f..289b7ff 100644 --- a/peach-config/src/main.rs +++ b/peach-config/src/main.rs @@ -57,7 +57,8 @@ enum PeachConfig { #[structopt(name = "whoami")] WhoAmI, - /// Publish domain and port + /// Publish domain and port. + /// It takes an address argument of the form host:port #[structopt(name = "publish-address")] PublishAddress(PublishAddressOpts), } diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index 5ffc87b..ee14e50 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -9,8 +9,7 @@ async-std = "1.10" chrono = "0.4" dirs = "4.0" fslock="0.1" -#golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi" } -golgi = { path = "../../golgi" } +golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi" } jsonrpc-client-core = "0.5" jsonrpc-client-http = "0.5" jsonrpc-core = "8.0" -- 2.49.0 From bdac23092ae70bd5fcf13703825d8ab9286e0caa Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 7 Jul 2022 10:41:36 +0200 Subject: [PATCH 03/10] Change changepassword to change-password --- Cargo.lock | 27 +++++++++++++++++++++++---- peach-config/Cargo.toml | 2 +- peach-config/src/main.rs | 2 +- peach-lib/Cargo.toml | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfaf051..76080e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,7 +1079,26 @@ dependencies = [ [[package]] name = "golgi" version = "0.1.4" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#ca4c1114ddf328b818144c5a1af0187b1357e9be" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#ca4c1114ddf328b818144c5a1af0187b1357e9be" +dependencies = [ + "async-std", + "async-stream 0.3.3", + "base64 0.13.0", + "futures 0.3.21", + "hex", + "kuska-handshake", + "kuska-sodiumoxide", + "kuska-ssb", + "log 0.4.17", + "serde 1.0.137", + "serde_json", + "sha2", +] + +[[package]] +name = "golgi" +version = "0.1.5" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git?branch=dev#414e8869f91974ae88431d74a8c8138e0a0ccdc6" dependencies = [ "async-std", "async-stream 0.3.3", @@ -2205,7 +2224,7 @@ dependencies = [ "async-std", "clap", "env_logger 0.6.2", - "golgi", + "golgi 0.1.5", "lazy_static", "log 0.4.17", "peach-lib", @@ -2247,7 +2266,7 @@ dependencies = [ "chrono", "dirs 4.0.0", "fslock", - "golgi", + "golgi 0.1.5", "jsonrpc-client-core", "jsonrpc-client-http", "jsonrpc-core 8.0.1", @@ -2341,7 +2360,7 @@ dependencies = [ "dirs 4.0.0", "env_logger 0.8.4", "futures 0.3.21", - "golgi", + "golgi 0.1.4", "lazy_static", "log 0.4.17", "maud", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index ee34f61..fca5f35 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -37,5 +37,5 @@ log = "0.4" lazy_static = "1.4.0" peach-lib = { path = "../peach-lib" } rpassword = "5.0" -golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" } +golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git", branch = "dev" } async-std = "1.10.0" diff --git a/peach-config/src/main.rs b/peach-config/src/main.rs index 289b7ff..2fd7624 100644 --- a/peach-config/src/main.rs +++ b/peach-config/src/main.rs @@ -46,7 +46,7 @@ enum PeachConfig { Update(UpdateOpts), /// Changes the password for the peach-web interface - #[structopt(name = "changepassword")] + #[structopt(name = "change-password")] ChangePassword(ChangePasswordOpts), /// Updates file permissions on PeachCloud device diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index ee14e50..5228801 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -9,7 +9,7 @@ async-std = "1.10" chrono = "0.4" dirs = "4.0" fslock="0.1" -golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi" } +golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git", branch = "dev" } jsonrpc-client-core = "0.5" jsonrpc-client-http = "0.5" jsonrpc-core = "8.0" -- 2.49.0 From 58bf306d3b22b50570f4a648be537e689953220a Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 7 Jul 2022 10:49:49 +0200 Subject: [PATCH 04/10] Fix golgi import --- Cargo.lock | 2 +- peach-config/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76080e4..6a22bff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2224,7 +2224,7 @@ dependencies = [ "async-std", "clap", "env_logger 0.6.2", - "golgi 0.1.5", + "golgi 0.1.4", "lazy_static", "log 0.4.17", "peach-lib", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index fca5f35..ee34f61 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -37,5 +37,5 @@ log = "0.4" lazy_static = "1.4.0" peach-lib = { path = "../peach-lib" } rpassword = "5.0" -golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git", branch = "dev" } +golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" } async-std = "1.10.0" -- 2.49.0 From 7daab74b374b7b2819be09676cc4a6c596c79ad2 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 7 Jul 2022 10:51:44 +0200 Subject: [PATCH 05/10] Fix golgi import --- Cargo.lock | 25 +++---------------------- peach-lib/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a22bff..382dac8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1095,25 +1095,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "golgi" -version = "0.1.5" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git?branch=dev#414e8869f91974ae88431d74a8c8138e0a0ccdc6" -dependencies = [ - "async-std", - "async-stream 0.3.3", - "base64 0.13.0", - "futures 0.3.21", - "hex", - "kuska-handshake", - "kuska-sodiumoxide", - "kuska-ssb", - "log 0.4.17", - "serde 1.0.137", - "serde_json", - "sha2", -] - [[package]] name = "h2" version = "0.1.26" @@ -2224,7 +2205,7 @@ dependencies = [ "async-std", "clap", "env_logger 0.6.2", - "golgi 0.1.4", + "golgi", "lazy_static", "log 0.4.17", "peach-lib", @@ -2266,7 +2247,7 @@ dependencies = [ "chrono", "dirs 4.0.0", "fslock", - "golgi 0.1.5", + "golgi", "jsonrpc-client-core", "jsonrpc-client-http", "jsonrpc-core 8.0.1", @@ -2360,7 +2341,7 @@ dependencies = [ "dirs 4.0.0", "env_logger 0.8.4", "futures 0.3.21", - "golgi 0.1.4", + "golgi", "lazy_static", "log 0.4.17", "maud", diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index 5228801..7c8ea4a 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -9,7 +9,7 @@ async-std = "1.10" chrono = "0.4" dirs = "4.0" fslock="0.1" -golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git", branch = "dev" } +golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" } jsonrpc-client-core = "0.5" jsonrpc-client-http = "0.5" jsonrpc-core = "8.0" -- 2.49.0 From 7489916d5f53e4129bb4c025f55994d21cfaa027 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 7 Jul 2022 10:57:03 +0200 Subject: [PATCH 06/10] Remove cargo.lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 382dac8..478b6a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1078,8 +1078,8 @@ dependencies = [ [[package]] name = "golgi" -version = "0.1.4" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#ca4c1114ddf328b818144c5a1af0187b1357e9be" +version = "0.2.2" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#22d12f31ac37a05ec5db6e62bc667bb006fc31fd" dependencies = [ "async-std", "async-stream 0.3.3", -- 2.49.0 From 90badbfe3051e387321f537c6347ce580ce353b8 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 7 Jul 2022 10:57:27 +0200 Subject: [PATCH 07/10] Add cargo.lock to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 41e4e65..e075842 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target *peachdeploy.sh *vpsdeploy.sh *bindeploy.sh +Cargo.lock -- 2.49.0 From 466db8ceea38e6bdb29b812753b56c8eb2702708 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 7 Jul 2022 13:42:32 +0200 Subject: [PATCH 08/10] Update sbot.rs to new history_stream api --- peach-web/src/utils/sbot.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/peach-web/src/utils/sbot.rs b/peach-web/src/utils/sbot.rs index 28ce5d1..6a61c66 100644 --- a/peach-web/src/utils/sbot.rs +++ b/peach-web/src/utils/sbot.rs @@ -8,6 +8,7 @@ use std::{ process::{Command, Output}, }; +use async_std::stream::StreamExt; use async_std::task; use dirs; use futures::stream::TryStreamExt; @@ -134,7 +135,11 @@ pub fn latest_sequence_number() -> Result> { let id = sbot_client.whoami().await?; let history_stream = sbot_client.create_history_stream(id).await?; - let mut msgs: Vec = history_stream.try_collect().await?; + let msg_stream = history_stream.map(|res| match res { + Ok(kvt) => Ok(kvt.value), + Err(err) => Err(err), + }); + let mut msgs: Vec = msg_stream.try_collect().await?; // there will be zero messages when the sbot is run for the first time if msgs.is_empty() { -- 2.49.0 From 9704269c8aa1dcd18aa83b1f8ae14f694c7dc03e Mon Sep 17 00:00:00 2001 From: mycognosist Date: Thu, 7 Jul 2022 15:44:31 +0100 Subject: [PATCH 09/10] Remove Cargo.lock from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index e075842..41e4e65 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ target *peachdeploy.sh *vpsdeploy.sh *bindeploy.sh -Cargo.lock -- 2.49.0 From eddb167c4c69653977b6b37fcc99b72a60582b5d Mon Sep 17 00:00:00 2001 From: mycognosist Date: Thu, 7 Jul 2022 15:54:19 +0100 Subject: [PATCH 10/10] Remove KVT to Value map and retrieve sequence number directly from KVT --- peach-web/src/utils/sbot.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/peach-web/src/utils/sbot.rs b/peach-web/src/utils/sbot.rs index 6a61c66..24c1b15 100644 --- a/peach-web/src/utils/sbot.rs +++ b/peach-web/src/utils/sbot.rs @@ -8,12 +8,11 @@ use std::{ process::{Command, Output}, }; -use async_std::stream::StreamExt; use async_std::task; use dirs; use futures::stream::TryStreamExt; use golgi::{ - api::friends::RelationshipQuery, blobs, messages::SsbMessageValue, sbot::Keystore, Sbot, + api::friends::RelationshipQuery, blobs, messages::SsbMessageKVT, sbot::Keystore, Sbot, }; use log::debug; use peach_lib::config_manager; @@ -135,11 +134,7 @@ pub fn latest_sequence_number() -> Result> { let id = sbot_client.whoami().await?; let history_stream = sbot_client.create_history_stream(id).await?; - let msg_stream = history_stream.map(|res| match res { - Ok(kvt) => Ok(kvt.value), - Err(err) => Err(err), - }); - let mut msgs: Vec = msg_stream.try_collect().await?; + let mut msgs: Vec = history_stream.try_collect().await?; // there will be zero messages when the sbot is run for the first time if msgs.is_empty() { @@ -149,7 +144,7 @@ pub fn latest_sequence_number() -> Result> { msgs.reverse(); // return the sequence number of the latest msg - Ok(msgs[0].sequence) + Ok(msgs[0].value.sequence) } }) } -- 2.49.0