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"