Skip to content

Commit fa9afd2

Browse files
committed
fix: use initial topic on resend
1 parent 073afeb commit fa9afd2

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/mimefactory.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::path::Path;
77
use anyhow::{bail, Context as _, Result};
88
use base64::Engine as _;
99
use chrono::TimeZone;
10+
use data_encoding::BASE32_NOPAD;
1011
use deltachat_contact_tools::sanitize_bidi_characters;
12+
use iroh_gossip::proto::TopicId;
1113
use mail_builder::headers::address::{Address, EmailAddress};
1214
use mail_builder::headers::HeaderType;
1315
use mail_builder::mime::MimePart;
@@ -29,7 +31,7 @@ use crate::location;
2931
use crate::message::{self, Message, MsgId, Viewtype};
3032
use crate::mimeparser::{is_hidden, SystemMessage};
3133
use crate::param::Param;
32-
use crate::peer_channels::create_iroh_header;
34+
use crate::peer_channels::{create_iroh_header, get_iroh_topic_for_msg};
3335
use crate::peerstate::Peerstate;
3436
use crate::simplify::escape_message_footer_marks;
3537
use crate::stock_str;
@@ -126,6 +128,9 @@ pub struct MimeFactory {
126128

127129
/// True if the avatar should be attached.
128130
pub attach_selfavatar: bool,
131+
132+
/// Sustain webxdc topic on resend.
133+
webxdc_topic: Option<TopicId>,
129134
}
130135

131136
/// Result of rendering a message, ready to be submitted to a send job.
@@ -319,6 +324,7 @@ impl MimeFactory {
319324
member_timestamps.is_empty()
320325
|| to.len() + past_members.len() == member_timestamps.len()
321326
);
327+
let webxdc_topic = get_iroh_topic_for_msg(context, msg.id).await?;
322328
let factory = MimeFactory {
323329
from_addr,
324330
from_displayname,
@@ -336,6 +342,7 @@ impl MimeFactory {
336342
last_added_location_id: None,
337343
sync_ids_to_delete: None,
338344
attach_selfavatar,
345+
webxdc_topic,
339346
};
340347
Ok(factory)
341348
}
@@ -370,6 +377,7 @@ impl MimeFactory {
370377
last_added_location_id: None,
371378
sync_ids_to_delete: None,
372379
attach_selfavatar: false,
380+
webxdc_topic: None,
373381
};
374382

375383
Ok(res)
@@ -1569,10 +1577,13 @@ impl MimeFactory {
15691577
let json = msg.param.get(Param::Arg).unwrap_or_default();
15701578
parts.push(context.build_status_update_part(json));
15711579
} else if msg.viewtype == Viewtype::Webxdc {
1580+
let topic = self
1581+
.webxdc_topic
1582+
.map(|top| BASE32_NOPAD.encode(top.as_bytes()).to_ascii_lowercase())
1583+
.unwrap_or(create_iroh_header(context, msg.id).await?);
15721584
headers.push((
15731585
HeaderDef::IrohGossipTopic.into(),
1574-
mail_builder::headers::raw::Raw::new(create_iroh_header(context, msg.id).await?)
1575-
.into(),
1586+
mail_builder::headers::raw::Raw::new(topic).into(),
15761587
));
15771588
if let (Some(json), _) = context
15781589
.render_webxdc_status_update_object(

src/peer_channels.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Iroh {
108108

109109
info!(
110110
ctx,
111-
"IROH_REALTIME: Joining gossip with peers: {:?}", node_ids,
111+
"IROH_REALTIME: Joining gossip {topic} with peers: {:?}", node_ids,
112112
);
113113

114114
// Inform iroh of potentially new node addresses
@@ -141,11 +141,11 @@ impl Iroh {
141141
pub async fn maybe_add_gossip_peer(&self, topic: TopicId, peer: NodeAddr) -> Result<()> {
142142
if self.iroh_channels.read().await.get(&topic).is_some() {
143143
self.router.endpoint().add_node_addr(peer.clone())?;
144-
145-
self.gossip
146-
.subscribe_with_opts(topic, JoinOptions::with_bootstrap(vec![peer.node_id]));
144+
self.gossip.subscribe(topic, vec![peer.node_id])?;
145+
Ok(())
146+
} else {
147+
anyhow::bail!("can not read iroh channels");
147148
}
148-
Ok(())
149149
}
150150

151151
/// Send realtime data to the gossip swarm.
@@ -316,7 +316,7 @@ impl Context {
316316
if let Some(iroh) = &*self.iroh.read().await {
317317
info!(
318318
self,
319-
"Adding (maybe existing) peer with id {} to gossip", peer.node_id
319+
"Adding (maybe existing) peer with id {} to {topic}", peer.node_id
320320
);
321321
iroh.maybe_add_gossip_peer(topic, peer).await?;
322322
}
@@ -559,6 +559,10 @@ async fn subscribe_loop(
559559

560560
#[cfg(test)]
561561
mod tests {
562+
use std::time::Duration;
563+
564+
use tokio::time::timeout;
565+
562566
use super::*;
563567
use crate::{
564568
chat::{self, add_contact_to_chat, resend_msgs, send_msg, ChatId, ProtectionStatus},
@@ -986,7 +990,10 @@ mod tests {
986990
let fiona_advert = fiona.pop_sent_msg().await;
987991
alice.recv_msg_trash(&fiona_advert).await;
988992

989-
fiona_connect_future.await.unwrap();
993+
timeout(Duration::from_secs(2), fiona_connect_future)
994+
.await
995+
.unwrap()
996+
.unwrap();
990997
send_webxdc_realtime_data(alice, instance.id, b"alice -> bob & fiona".into())
991998
.await
992999
.unwrap();
@@ -1030,17 +1037,19 @@ mod tests {
10301037
.unwrap();
10311038
let alice_advertisement = alice.pop_sent_msg().await;
10321039

1033-
send_webxdc_realtime_advertisement(bob, bob_webxdc.id)
1040+
let bob_advertisement_future = send_webxdc_realtime_advertisement(bob, bob_webxdc.id)
10341041
.await
1042+
.unwrap()
10351043
.unwrap();
10361044
let bob_advertisement = bob.pop_sent_msg().await;
10371045

10381046
eprintln!("Receiving advertisements");
10391047
bob.recv_msg_trash(&alice_advertisement).await;
10401048
alice.recv_msg_trash(&bob_advertisement).await;
10411049

1042-
eprintln!("Alice waits for connection");
1050+
eprintln!("Alice and Bob wait for connection");
10431051
alice_advertisement_future.await.unwrap();
1052+
bob_advertisement_future.await.unwrap();
10441053

10451054
// Alice sends ephemeral message
10461055
eprintln!("Sending ephemeral message");

src/receive_imf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ RETURNING id
16591659
created_db_entries.push(row_id);
16601660
}
16611661

1662-
// check all parts whether they contain a new logging webxdc
1662+
// Maybe set logging xdc and add gossip topics for webxdcs.
16631663
for (part, msg_id) in mime_parser.parts.iter().zip(&created_db_entries) {
16641664
// check if any part contains a webxdc topic id
16651665
if part.typ == Viewtype::Webxdc {

0 commit comments

Comments
 (0)