mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
send smpt-message for advertisement
This commit is contained in:
@@ -440,6 +440,12 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
{
|
{
|
||||||
// join advertised gossip topics
|
// join advertised gossip topics
|
||||||
Ok((topics, instance_id)) => {
|
Ok((topics, instance_id)) => {
|
||||||
|
warn!(context, "Joining topics: {:#?}", topics);
|
||||||
|
warn!(
|
||||||
|
context,
|
||||||
|
"{:?}",
|
||||||
|
mime_parser.get_header(HeaderDef::IrohPublicGossip)
|
||||||
|
);
|
||||||
if let Some(node_addr) = mime_parser.get_header(HeaderDef::IrohPublicGossip) {
|
if let Some(node_addr) = mime_parser.get_header(HeaderDef::IrohPublicGossip) {
|
||||||
match serde_json::from_str::<NodeAddr>(node_addr)
|
match serde_json::from_str::<NodeAddr>(node_addr)
|
||||||
.context("Failed to parse node address")
|
.context("Failed to parse node address")
|
||||||
|
|||||||
@@ -497,30 +497,39 @@ impl Context {
|
|||||||
MessageState::Undefined | MessageState::OutPreparing | MessageState::OutDraft
|
MessageState::Undefined | MessageState::OutPreparing | MessageState::OutDraft
|
||||||
);
|
);
|
||||||
|
|
||||||
let ephemeral = status_update.gossip_topic.is_some();
|
let mut ephemeral = status_update.gossip_topic.is_some();
|
||||||
if send_now {
|
if send_now {
|
||||||
if let Some(ref topic) = status_update.gossip_topic {
|
if let Some(ref topic) = status_update.gossip_topic {
|
||||||
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
// find out if any row with `topic = topic` exists in the gossip_peers table
|
||||||
topic
|
let topic_exists = self
|
||||||
.get(0..32)
|
.sql
|
||||||
.context("Can't get 32 bytes from rfc724_mid")?,
|
.query_row_optional(
|
||||||
))?;
|
"SELECT 1 FROM iroh_gossip_peers WHERE topic=?",
|
||||||
|
(topic,),
|
||||||
|
|_| Ok(()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.context("Failed to check if gossip topic exists")?
|
||||||
|
.is_some();
|
||||||
|
|
||||||
|
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
||||||
|
topic.get(0..32).context("Can't get 32 bytes from topic")?,
|
||||||
|
))?;
|
||||||
self.join_and_subscribe_topic(topic, instance_msg_id)
|
self.join_and_subscribe_topic(topic, instance_msg_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
if !topic_exists {
|
||||||
info!(self, "here3");
|
info!(
|
||||||
|
self,
|
||||||
let gossip = self.gossip.lock().await;
|
"Gossip topic {topic} does not exist, sending over smpt",
|
||||||
if let Some(ref gossip) = *gossip {
|
);
|
||||||
|
ephemeral = false;
|
||||||
|
} else {
|
||||||
|
if let Some(ref gossip) = *self.gossip.lock().await {
|
||||||
gossip
|
gossip
|
||||||
.broadcast(topic, serde_json::to_string(&status_update)?.into())
|
.broadcast(topic, serde_json::to_string(&status_update)?.into())
|
||||||
.await?;
|
.await?;
|
||||||
} else {
|
|
||||||
warn!(self, "send_webxdc_status_update: no gossip available.");
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
warn!(self, "send_webxdc_status_update: no gossip topic given.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,9 +677,7 @@ impl Context {
|
|||||||
for update_item in updates.updates {
|
for update_item in updates.updates {
|
||||||
if let Some(ref topic) = update_item.gossip_topic {
|
if let Some(ref topic) = update_item.gossip_topic {
|
||||||
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
||||||
topic
|
topic.get(0..32).context("Can't get 32 bytes from topic")?,
|
||||||
.get(0..32)
|
|
||||||
.context("Can't get 32 bytes from rfc724_mid")?,
|
|
||||||
))?;
|
))?;
|
||||||
topics.push(topic);
|
topics.push(topic);
|
||||||
}
|
}
|
||||||
@@ -919,9 +926,7 @@ impl Message {
|
|||||||
/// Join a gossip topic and subscribe to it.
|
/// Join a gossip topic and subscribe to it.
|
||||||
pub async fn join_gossip_topic(ctx: &Context, msg_id: MsgId, topic: &str) -> Result<()> {
|
pub async fn join_gossip_topic(ctx: &Context, msg_id: MsgId, topic: &str) -> Result<()> {
|
||||||
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
let topic = TopicId::from_str(&iroh_base::base32::fmt(
|
||||||
topic
|
topic.get(0..32).context("Can't get 32 bytes from topic")?,
|
||||||
.get(0..32)
|
|
||||||
.context("Can't get 32 bytes from rfc724_mid")?,
|
|
||||||
))?;
|
))?;
|
||||||
info!(ctx, "Received join request from frontend");
|
info!(ctx, "Received join request from frontend");
|
||||||
ctx.join_and_subscribe_topic(topic, msg_id).await
|
ctx.join_and_subscribe_topic(topic, msg_id).await
|
||||||
|
|||||||
Reference in New Issue
Block a user