mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
feat(iroh): pass direct addresses from Endpoint to Gossip
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use email::Header;
|
use email::Header;
|
||||||
|
use futures_lite::StreamExt;
|
||||||
use iroh_gossip::net::{Gossip, JoinTopicFut, GOSSIP_ALPN};
|
use iroh_gossip::net::{Gossip, JoinTopicFut, GOSSIP_ALPN};
|
||||||
use iroh_gossip::proto::{Event as IrohEvent, TopicId};
|
use iroh_gossip::proto::{Event as IrohEvent, TopicId};
|
||||||
use iroh_net::key::{PublicKey, SecretKey};
|
use iroh_net::key::{PublicKey, SecretKey};
|
||||||
@@ -255,6 +256,7 @@ impl Context {
|
|||||||
|
|
||||||
// Shuts down on deltachat shutdown
|
// Shuts down on deltachat shutdown
|
||||||
tokio::spawn(endpoint_loop(context, endpoint.clone(), gossip.clone()));
|
tokio::spawn(endpoint_loop(context, endpoint.clone(), gossip.clone()));
|
||||||
|
tokio::spawn(gossip_direct_address_loop(endpoint.clone(), gossip.clone()));
|
||||||
|
|
||||||
Ok(Iroh {
|
Ok(Iroh {
|
||||||
endpoint,
|
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.
|
/// Cache a peers [NodeId] for one topic.
|
||||||
pub(crate) async fn iroh_add_peer_for_topic(
|
pub(crate) async fn iroh_add_peer_for_topic(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
|
|||||||
Reference in New Issue
Block a user