From dfe25bddacd903154d73ac5ac7054dd1c3f9d754 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 19 Dec 2021 23:08:02 +0100 Subject: Add Profile::gossip_own_state() Signed-off-by: Matthias Beyer --- lib/src/profile/mod.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/src/profile/mod.rs') diff --git a/lib/src/profile/mod.rs b/lib/src/profile/mod.rs index d1ab90f..3b1e063 100644 --- a/lib/src/profile/mod.rs +++ b/lib/src/profile/mod.rs @@ -169,6 +169,30 @@ impl Profile { pub fn add_device(&mut self, d: Device) -> Result<()> { self.state.add_device(d) } + + pub async fn gossip_own_state(&self, topic: String) -> Result<()> { + let cid = self.state + .profile_head() + .as_ref() + .ok_or_else(|| anyhow::anyhow!("Profile has no HEAD yet"))? + .to_bytes(); + + let peer_id = self.client + .own_id() + .await? + .to_bytes(); + + self.client + .ipfs + .pubsub_publish(topic, { + crate::gossip::GossipMessage::CurrentProfileState { + peer_id, + cid, + }.into_bytes()? + }) + .await + .map_err(anyhow::Error::from) + } } -- cgit v1.2.3