mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
fix: never initialize Iroh if realtime is disabled
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
//! (scoped per WebXDC app instance/message-id). The other peers can then join the gossip with `joinRealtimeChannel().setListener()`
|
//! (scoped per WebXDC app instance/message-id). The other peers can then join the gossip with `joinRealtimeChannel().setListener()`
|
||||||
//! and `joinRealtimeChannel().send()` just like the other peers.
|
//! and `joinRealtimeChannel().send()` just like the other peers.
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, bail, Context as _, Result};
|
||||||
use email::Header;
|
use email::Header;
|
||||||
use futures_lite::StreamExt;
|
use futures_lite::StreamExt;
|
||||||
use iroh_gossip::net::{Event, Gossip, GossipEvent, JoinOptions, GOSSIP_ALPN};
|
use iroh_gossip::net::{Event, Gossip, GossipEvent, JoinOptions, GOSSIP_ALPN};
|
||||||
@@ -277,6 +277,10 @@ impl Context {
|
|||||||
|
|
||||||
/// Get or initialize the iroh peer channel.
|
/// Get or initialize the iroh peer channel.
|
||||||
pub async fn get_or_try_init_peer_channel(&self) -> Result<&Iroh> {
|
pub async fn get_or_try_init_peer_channel(&self) -> Result<&Iroh> {
|
||||||
|
if !self.get_config_bool(Config::WebxdcRealtimeEnabled).await? {
|
||||||
|
bail!("Attempt to get Iroh when realtime is disabled");
|
||||||
|
}
|
||||||
|
|
||||||
let ctx = self.clone();
|
let ctx = self.clone();
|
||||||
self.iroh
|
self.iroh
|
||||||
.get_or_try_init(|| async { ctx.init_peer_channels().await })
|
.get_or_try_init(|| async { ctx.init_peer_channels().await })
|
||||||
@@ -949,6 +953,10 @@ mod tests {
|
|||||||
// creates iroh endpoint as side effect
|
// creates iroh endpoint as side effect
|
||||||
leave_webxdc_realtime(alice, MsgId::new(1)).await.unwrap();
|
leave_webxdc_realtime(alice, MsgId::new(1)).await.unwrap();
|
||||||
|
|
||||||
assert!(alice.ctx.iroh.get().is_none())
|
assert!(alice.ctx.iroh.get().is_none());
|
||||||
|
|
||||||
|
// This internal function should return error
|
||||||
|
// if accidentally called with the setting disabled.
|
||||||
|
assert!(alice.ctx.get_or_try_init_peer_channel().await.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1454,8 +1454,13 @@ async fn add_parts(
|
|||||||
let relay_server = node_addr.relay_url().map(|relay| relay.as_str());
|
let relay_server = node_addr.relay_url().map(|relay| relay.as_str());
|
||||||
iroh_add_peer_for_topic(context, instance_id, topic, node_id, relay_server)
|
iroh_add_peer_for_topic(context, instance_id, topic, node_id, relay_server)
|
||||||
.await?;
|
.await?;
|
||||||
let iroh = context.get_or_try_init_peer_channel().await?;
|
if context
|
||||||
iroh.maybe_add_gossip_peers(topic, vec![node_addr]).await?;
|
.get_config_bool(Config::WebxdcRealtimeEnabled)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
let iroh = context.get_or_try_init_peer_channel().await?;
|
||||||
|
iroh.maybe_add_gossip_peers(topic, vec![node_addr]).await?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
|
|||||||
Reference in New Issue
Block a user