Publish address
This commit is contained in:
parent
1258a3697d
commit
8dcd594dd7
|
@ -1079,7 +1079,25 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "golgi"
|
name = "golgi"
|
||||||
version = "0.1.4"
|
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 = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-stream 0.3.3",
|
"async-stream 0.3.3",
|
||||||
|
@ -2205,7 +2223,7 @@ dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger 0.6.2",
|
"env_logger 0.6.2",
|
||||||
"golgi",
|
"golgi 0.1.5",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log 0.4.17",
|
"log 0.4.17",
|
||||||
"peach-lib",
|
"peach-lib",
|
||||||
|
@ -2247,7 +2265,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs 4.0.0",
|
"dirs 4.0.0",
|
||||||
"fslock",
|
"fslock",
|
||||||
"golgi",
|
"golgi 0.1.5",
|
||||||
"jsonrpc-client-core",
|
"jsonrpc-client-core",
|
||||||
"jsonrpc-client-http",
|
"jsonrpc-client-http",
|
||||||
"jsonrpc-core 8.0.1",
|
"jsonrpc-core 8.0.1",
|
||||||
|
@ -2341,7 +2359,7 @@ dependencies = [
|
||||||
"dirs 4.0.0",
|
"dirs 4.0.0",
|
||||||
"env_logger 0.8.4",
|
"env_logger 0.8.4",
|
||||||
"futures 0.3.21",
|
"futures 0.3.21",
|
||||||
"golgi",
|
"golgi 0.1.4",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log 0.4.17",
|
"log 0.4.17",
|
||||||
"maud",
|
"maud",
|
||||||
|
|
|
@ -37,5 +37,6 @@ log = "0.4"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
peach-lib = { path = "../peach-lib" }
|
peach-lib = { path = "../peach-lib" }
|
||||||
rpassword = "5.0"
|
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"
|
async-std = "1.10.0"
|
||||||
|
|
|
@ -40,6 +40,8 @@ pub enum PeachConfigError {
|
||||||
PeachLibError { source: PeachError },
|
PeachLibError { source: PeachError },
|
||||||
#[snafu(display("Error in golgi: {}", source))]
|
#[snafu(display("Error in golgi: {}", source))]
|
||||||
Golgi { source: GolgiError },
|
Golgi { source: GolgiError },
|
||||||
|
#[snafu(display("{}", message))]
|
||||||
|
CmdInputError { message: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for PeachConfigError {
|
impl From<std::io::Error> for PeachConfigError {
|
||||||
|
|
|
@ -2,6 +2,7 @@ mod change_password;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod error;
|
mod error;
|
||||||
mod generate_manifest;
|
mod generate_manifest;
|
||||||
|
mod publish_address;
|
||||||
mod set_permissions;
|
mod set_permissions;
|
||||||
mod setup_networking;
|
mod setup_networking;
|
||||||
mod setup_peach;
|
mod setup_peach;
|
||||||
|
@ -55,6 +56,10 @@ enum PeachConfig {
|
||||||
/// Returns sbot id if sbot is running
|
/// Returns sbot id if sbot is running
|
||||||
#[structopt(name = "whoami")]
|
#[structopt(name = "whoami")]
|
||||||
WhoAmI,
|
WhoAmI,
|
||||||
|
|
||||||
|
/// Publish domain and port
|
||||||
|
#[structopt(name = "publish-address")]
|
||||||
|
PublishAddress(PublishAddressOpts),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
|
@ -95,6 +100,13 @@ pub struct ChangePasswordOpts {
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt, Debug)]
|
||||||
|
pub struct PublishAddressOpts {
|
||||||
|
/// Specify address in the form domain:port
|
||||||
|
#[structopt(short, long)]
|
||||||
|
address: String,
|
||||||
|
}
|
||||||
|
|
||||||
arg_enum! {
|
arg_enum! {
|
||||||
/// enum options for real-time clock choices
|
/// enum options for real-time clock choices
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -169,6 +181,17 @@ async fn run() {
|
||||||
error!("sbot whoami encountered an error: {}", err)
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
|
@ -9,7 +9,8 @@ async-std = "1.10"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
dirs = "4.0"
|
dirs = "4.0"
|
||||||
fslock="0.1"
|
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-core = "0.5"
|
||||||
jsonrpc-client-http = "0.5"
|
jsonrpc-client-http = "0.5"
|
||||||
jsonrpc-core = "8.0"
|
jsonrpc-core = "8.0"
|
||||||
|
|
Loading…
Reference in New Issue