Skip to content

Commit ed12f9a

Browse files
committed
fix: use initial topic on resend
1 parent f81f775 commit ed12f9a

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/mimefactory.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::path::Path;
77
use anyhow::{Context as _, Result, bail, ensure};
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;
13+
use mail_builder::headers::address::{Address, EmailAddress};
1114
use mail_builder::headers::HeaderType;
1215
use mail_builder::headers::address::{Address, EmailAddress};
1316
use mail_builder::mime::MimePart;
@@ -29,7 +32,8 @@ use crate::log::{info, warn};
2932
use crate::message::{self, Message, MsgId, Viewtype};
3033
use crate::mimeparser::{SystemMessage, is_hidden};
3134
use crate::param::Param;
32-
use crate::peer_channels::create_iroh_header;
35+
use crate::peer_channels::{create_iroh_header, get_iroh_topic_for_msg};
36+
use crate::peerstate::Peerstate;
3337
use crate::simplify::escape_message_footer_marks;
3438
use crate::stock_str;
3539
use crate::tools::{
@@ -140,6 +144,9 @@ pub struct MimeFactory {
140144

141145
/// True if the avatar should be attached.
142146
pub attach_selfavatar: bool,
147+
148+
/// Sustain webxdc topic on resend.
149+
webxdc_topic: Option<TopicId>,
143150
}
144151

145152
/// Result of rendering a message, ready to be submitted to a send job.
@@ -450,7 +457,7 @@ impl MimeFactory {
450457
member_timestamps.is_empty()
451458
|| to.len() + past_members.len() == member_timestamps.len()
452459
);
453-
460+
let webxdc_topic = get_iroh_topic_for_msg(context, msg.id).await?;
454461
let factory = MimeFactory {
455462
from_addr,
456463
from_displayname,
@@ -470,6 +477,7 @@ impl MimeFactory {
470477
last_added_location_id: None,
471478
sync_ids_to_delete: None,
472479
attach_selfavatar,
480+
webxdc_topic,
473481
};
474482
Ok(factory)
475483
}
@@ -517,6 +525,7 @@ impl MimeFactory {
517525
last_added_location_id: None,
518526
sync_ids_to_delete: None,
519527
attach_selfavatar: false,
528+
webxdc_topic: None,
520529
};
521530

522531
Ok(res)
@@ -1674,10 +1683,13 @@ impl MimeFactory {
16741683
let json = msg.param.get(Param::Arg).unwrap_or_default();
16751684
parts.push(context.build_status_update_part(json));
16761685
} else if msg.viewtype == Viewtype::Webxdc {
1686+
let topic = self
1687+
.webxdc_topic
1688+
.map(|top| BASE32_NOPAD.encode(top.as_bytes()).to_ascii_lowercase())
1689+
.unwrap_or(create_iroh_header(context, msg.id).await?);
16771690
headers.push((
16781691
HeaderDef::IrohGossipTopic.into(),
1679-
mail_builder::headers::raw::Raw::new(create_iroh_header(context, msg.id).await?)
1680-
.into(),
1692+
mail_builder::headers::raw::Raw::new(topic).into(),
16811693
));
16821694
if let (Some(json), _) = context
16831695
.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
@@ -2124,7 +2124,7 @@ RETURNING id
21242124
created_db_entries.push(row_id);
21252125
}
21262126

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

0 commit comments

Comments
 (0)