38 lines
1.4 KiB
Rust
38 lines
1.4 KiB
Rust
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(())
|
|
}
|