Skip to content

Commit 082ac3a

Browse files
committed
fix: use initial topic on resend
1 parent 9e5a4d4 commit 082ac3a

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/mimefactory.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use std::io::Cursor;
55

66
use anyhow::{Context as _, Result, bail, ensure};
77
use base64::Engine as _;
8+
use chrono::TimeZone;
9+
use data_encoding::BASE32_NOPAD;
810
use deltachat_contact_tools::sanitize_bidi_characters;
11+
use iroh_gossip::proto::TopicId;
12+
use mail_builder::headers::address::{Address, EmailAddress};
913
use mail_builder::headers::HeaderType;
1014
use mail_builder::headers::address::{Address, EmailAddress};
1115
use mail_builder::mime::MimePart;
@@ -27,7 +31,8 @@ use crate::log::{info, warn};
2731
use crate::message::{Message, MsgId, Viewtype};
2832
use crate::mimeparser::{SystemMessage, is_hidden};
2933
use crate::param::Param;
30-
use crate::peer_channels::create_iroh_header;
34+
use crate::peer_channels::{create_iroh_header, get_iroh_topic_for_msg};
35+
use crate::peerstate::Peerstate;
3136
use crate::simplify::escape_message_footer_marks;
3237
use crate::stock_str;
3338
use crate::tools::{
@@ -138,6 +143,9 @@ pub struct MimeFactory {
138143

139144
/// True if the avatar should be attached.
140145
pub attach_selfavatar: bool,
146+
147+
/// Sustain webxdc topic on resend.
148+
webxdc_topic: Option<TopicId>,
141149
}
142150

143151
/// Result of rendering a message, ready to be submitted to a send job.
@@ -448,7 +456,7 @@ impl MimeFactory {
448456
member_timestamps.is_empty()
449457
|| to.len() + past_members.len() == member_timestamps.len()
450458
);
451-
459+
let webxdc_topic = get_iroh_topic_for_msg(context, msg.id).await?;
452460
let factory = MimeFactory {
453461
from_addr,
454462
from_displayname,
@@ -468,6 +476,7 @@ impl MimeFactory {
468476
last_added_location_id: None,
469477
sync_ids_to_delete: None,
470478
attach_selfavatar,
479+
webxdc_topic,
471480
};
472481
Ok(factory)
473482
}
@@ -515,6 +524,7 @@ impl MimeFactory {
515524
last_added_location_id: None,
516525
sync_ids_to_delete: None,
517526
attach_selfavatar: false,
527+
webxdc_topic: None,
518528
};
519529

520530
Ok(res)
@@ -1672,10 +1682,13 @@ impl MimeFactory {
16721682
let json = msg.param.get(Param::Arg).unwrap_or_default();
16731683
parts.push(context.build_status_update_part(json));
16741684
} else if msg.viewtype == Viewtype::Webxdc {
1685+
let topic = self
1686+
.webxdc_topic
1687+
.map(|top| BASE32_NOPAD.encode(top.as_bytes()).to_ascii_lowercase())
1688+
.unwrap_or(create_iroh_header(context, msg.id).await?);
16751689
headers.push((
16761690
HeaderDef::IrohGossipTopic.into(),
1677-
mail_builder::headers::raw::Raw::new(create_iroh_header(context, msg.id).await?)
1678-
.into(),
1691+
mail_builder::headers::raw::Raw::new(topic).into(),
16791692
));
16801693
if let (Some(json), _) = context
16811694
.render_webxdc_status_update_object(

src/peer_channels.rs

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

110110
info!(
111111
ctx,
112-
"IROH_REALTIME: Joining gossip with peers: {:?}", node_ids,
112+
"IROH_REALTIME: Joining gossip {topic} with peers: {:?}", node_ids,
113113
);
114114

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

152152
/// Send realtime data to the gossip swarm.
@@ -317,7 +317,7 @@ impl Context {
317317
if let Some(iroh) = &*self.iroh.read().await {
318318
info!(
319319
self,
320-
"Adding (maybe existing) peer with id {} to gossip", peer.node_id
320+
"Adding (maybe existing) peer with id {} to {topic}", peer.node_id
321321
);
322322
iroh.maybe_add_gossip_peer(topic, peer).await?;
323323
}
@@ -560,6 +560,10 @@ async fn subscribe_loop(
560560

561561
#[cfg(test)]
562562
mod tests {
563+
use std::time::Duration;
564+
565+
use tokio::time::timeout;
566+
563567
use super::*;
564568
use crate::{
565569
EventType,
@@ -991,7 +995,10 @@ mod tests {
991995
let fiona_advert = fiona.pop_sent_msg().await;
992996
alice.recv_msg_trash(&fiona_advert).await;
993997

994-
fiona_connect_future.await.unwrap();
998+
timeout(Duration::from_secs(2), fiona_connect_future)
999+
.await
1000+
.unwrap()
1001+
.unwrap();
9951002
send_webxdc_realtime_data(alice, instance.id, b"alice -> bob & fiona".into())
9961003
.await
9971004
.unwrap();
@@ -1035,17 +1042,19 @@ mod tests {
10351042
.unwrap();
10361043
let alice_advertisement = alice.pop_sent_msg().await;
10371044

1038-
send_webxdc_realtime_advertisement(bob, bob_webxdc.id)
1045+
let bob_advertisement_future = send_webxdc_realtime_advertisement(bob, bob_webxdc.id)
10391046
.await
1047+
.unwrap()
10401048
.unwrap();
10411049
let bob_advertisement = bob.pop_sent_msg().await;
10421050

10431051
eprintln!("Receiving advertisements");
10441052
bob.recv_msg_trash(&alice_advertisement).await;
10451053
alice.recv_msg_trash(&bob_advertisement).await;
10461054

1047-
eprintln!("Alice waits for connection");
1055+
eprintln!("Alice and Bob wait for connection");
10481056
alice_advertisement_future.await.unwrap();
1057+
bob_advertisement_future.await.unwrap();
10491058

10501059
// Alice sends ephemeral message
10511060
eprintln!("Sending ephemeral message");

src/receive_imf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ RETURNING id
21412141
created_db_entries.push(row_id);
21422142
}
21432143

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

0 commit comments

Comments
 (0)