diff --git a/src/peer_channels.rs b/src/peer_channels.rs index 550eba4f12..8c24507a23 100644 --- a/src/peer_channels.rs +++ b/src/peer_channels.rs @@ -25,6 +25,7 @@ use anyhow::{anyhow, Context as _, Result}; use email::Header; +use futures_lite::StreamExt; use iroh_gossip::net::{Gossip, JoinTopicFut, GOSSIP_ALPN}; use iroh_gossip::proto::{Event as IrohEvent, TopicId}; use iroh_net::key::{PublicKey, SecretKey}; @@ -255,6 +256,7 @@ impl Context { // Shuts down on deltachat shutdown tokio::spawn(endpoint_loop(context, endpoint.clone(), gossip.clone())); + tokio::spawn(gossip_direct_address_loop(endpoint.clone(), gossip.clone())); Ok(Iroh { endpoint, @@ -273,6 +275,15 @@ impl Context { } } +/// Loop to update direct addresses of the gossip. +async fn gossip_direct_address_loop(endpoint: Endpoint, gossip: Gossip) -> Result<()> { + let mut stream = endpoint.direct_addresses(); + while let Some(addrs) = stream.next().await { + gossip.update_direct_addresses(&addrs)?; + } + Ok(()) +} + /// Cache a peers [NodeId] for one topic. pub(crate) async fn iroh_add_peer_for_topic( ctx: &Context,