From 9027ebfe84b361931bca46fe23f47e6a8363d686 Mon Sep 17 00:00:00 2001 From: notplants Date: Fri, 14 Jan 2022 12:37:34 -0500 Subject: [PATCH] Create new sbot connection for each query --- examples/ssb-client.rs | 34 +++++++++++++++++++++------------- src/sbot.rs | 23 ++++++++--------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/examples/ssb-client.rs b/examples/ssb-client.rs index 10fea55..f9f0ac9 100644 --- a/examples/ssb-client.rs +++ b/examples/ssb-client.rs @@ -10,19 +10,19 @@ async fn run() -> Result<(), GolgiError> { let id = sbot_client.whoami().await?; println!("whoami: {}", id); - let name = SsbMessageContent::About { - about: id.clone(), - name: Some("golgi".to_string()), - title: None, - branch: None, - image: None, - description: None, - location: None, - start_datetime: None, - }; - - let name_msg_ref = sbot_client.publish(name).await?; - println!("name_msg_ref: {}", name_msg_ref); + // let name = SsbMessageContent::About { + // about: id.clone(), + // name: Some("golgi".to_string()), + // title: None, + // branch: None, + // image: None, + // description: None, + // location: None, + // start_datetime: None, + // }; + // + // let name_msg_ref = sbot_client.publish(name).await?; + // println!("name_msg_ref: {}", name_msg_ref); let post = SsbMessageContent::Post { text: "golgi go womp womp".to_string(), @@ -42,6 +42,14 @@ async fn run() -> Result<(), GolgiError> { let description = sbot_client.get_description(&author).await?; println!("found description: {:?}", description); + let post = SsbMessageContent::Post { + text: "golgi go womp womp2".to_string(), + mentions: None, + }; + + let post_msg_ref = sbot_client.publish(post).await?; + println!("post_msg_ref2: {}", post_msg_ref); + Ok(()) } diff --git a/src/sbot.rs b/src/sbot.rs index decc427..5d05c25 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -33,17 +33,13 @@ pub struct SbotConnection { } /// The Scuttlebutt identity, keys and configuration parameters for connecting to a local sbot -/// instance, as well as handles for calling RPC methods and receiving responses. pub struct Sbot { pub id: String, public_key: ed25519::PublicKey, private_key: ed25519::SecretKey, address: String, // aka caps key (scuttleverse identifier) - network_id: auth::Key, - // the primary connection with sbot which can be re-used for non-stream calls - // note that stream calls will each need their own SbotConnection - sbot_connection: SbotConnection, + network_id: auth::Key } impl Sbot { @@ -67,17 +63,12 @@ impl Sbot { .await .expect("couldn't read local secret"); - let sbot_connection = - Sbot::_get_sbot_connection_helper(address.clone(), network_id.clone(), pk, sk.clone()) - .await?; - Ok(Self { id, public_key: pk, private_key: sk, address, - network_id, - sbot_connection, + network_id }) } @@ -152,10 +143,11 @@ impl Sbot { /// Call the `whoami` RPC method and return an `id`. pub async fn whoami(&mut self) -> Result { - let req_id = self.sbot_connection.client.whoami_req_send().await?; + let mut sbot_connection = self.get_sbot_connection().await?; + let req_id = sbot_connection.client.whoami_req_send().await?; let result = utils::get_async( - &mut self.sbot_connection.rpc_reader, + &mut sbot_connection.rpc_reader, req_id, utils::json_res_parse, ) @@ -177,10 +169,11 @@ impl Sbot { /// `Channel` and `Vote`. See the `kuska_ssb` documentation for further details such as field /// names and accepted values for each variant. pub async fn publish(&mut self, msg: SsbMessageContent) -> Result { - let req_id = self.sbot_connection.client.publish_req_send(msg).await?; + let mut sbot_connection = self.get_sbot_connection().await?; + let req_id = sbot_connection.client.publish_req_send(msg).await?; utils::get_async( - &mut self.sbot_connection.rpc_reader, + &mut sbot_connection.rpc_reader, req_id, utils::string_res_parse, )