Update API usage for iroh 0.98

This commit is contained in:
link2xt
2026-04-27 21:41:51 +02:00
parent e3bb0febb7
commit 5b6d48ac43
2 changed files with 16 additions and 13 deletions

View File

@@ -95,7 +95,7 @@ impl BackupProvider {
/// [`Accounts::stop_io`]: crate::accounts::Accounts::stop_io /// [`Accounts::stop_io`]: crate::accounts::Accounts::stop_io
pub async fn prepare(context: &Context) -> Result<Self> { pub async fn prepare(context: &Context) -> Result<Self> {
let relay_mode = RelayMode::Disabled; let relay_mode = RelayMode::Disabled;
let endpoint = Endpoint::builder() let endpoint = Endpoint::builder(iroh::endpoint::presets::Minimal)
.alpns(vec![BACKUP_ALPN.to_vec()]) .alpns(vec![BACKUP_ALPN.to_vec()])
.relay_mode(relay_mode) .relay_mode(relay_mode)
.bind() .bind()
@@ -167,7 +167,7 @@ impl BackupProvider {
async fn handle_connection( async fn handle_connection(
context: Context, context: Context,
conn: iroh::endpoint::Connecting, conn: iroh::endpoint::Accepting,
auth_token: String, auth_token: String,
dbfile: Arc<TempPathGuard>, dbfile: Arc<TempPathGuard>,
) -> Result<()> { ) -> Result<()> {
@@ -303,7 +303,10 @@ pub async fn get_backup2(
) -> Result<()> { ) -> Result<()> {
let relay_mode = RelayMode::Disabled; let relay_mode = RelayMode::Disabled;
let endpoint = Endpoint::builder().relay_mode(relay_mode).bind().await?; let endpoint = Endpoint::builder(iroh::endpoint::presets::Minimal)
.relay_mode(relay_mode)
.bind()
.await?;
let conn = endpoint.connect(node_addr, BACKUP_ALPN).await?; let conn = endpoint.connect(node_addr, BACKUP_ALPN).await?;
let (mut send_stream, mut recv_stream) = conn.open_bi().await?; let (mut send_stream, mut recv_stream) = conn.open_bi().await?;

View File

@@ -26,7 +26,7 @@
use anyhow::{Context as _, Result, anyhow, bail}; use anyhow::{Context as _, Result, anyhow, bail};
use data_encoding::BASE32_NOPAD; use data_encoding::BASE32_NOPAD;
use futures_lite::StreamExt; use futures_lite::StreamExt;
use iroh::discovery::static_provider::StaticProvider; use iroh::address_lookup::MemoryLookup;
use iroh::{ use iroh::{
Endpoint, EndpointAddr, EndpointId, PublicKey, RelayMode, RelayUrl, SecretKey, TransportAddr, Endpoint, EndpointAddr, EndpointId, PublicKey, RelayMode, RelayUrl, SecretKey, TransportAddr,
}; };
@@ -58,8 +58,8 @@ pub struct Iroh {
/// Iroh router needed for Iroh peer channels. /// Iroh router needed for Iroh peer channels.
pub(crate) router: iroh::protocol::Router, pub(crate) router: iroh::protocol::Router,
/// Discovery service. /// Address lookup, called "Discovery service" before Iroh 0.96.0.
pub(crate) discovery: StaticProvider, pub(crate) address_lookup: MemoryLookup,
/// [Gossip] needed for Iroh peer channels. /// [Gossip] needed for Iroh peer channels.
pub(crate) gossip: Gossip, pub(crate) gossip: Gossip,
@@ -122,7 +122,7 @@ impl Iroh {
// Inform iroh of potentially new node addresses // Inform iroh of potentially new node addresses
for node_addr in &peers { for node_addr in &peers {
if !node_addr.is_empty() { if !node_addr.is_empty() {
self.discovery.add_endpoint_info(node_addr.clone()); self.address_lookup.add_endpoint_info(node_addr.clone());
} }
} }
@@ -149,7 +149,7 @@ impl Iroh {
/// Add gossip peer to realtime channel if it is already active. /// Add gossip peer to realtime channel if it is already active.
pub async fn maybe_add_gossip_peer(&self, topic: TopicId, peer: EndpointAddr) -> Result<()> { pub async fn maybe_add_gossip_peer(&self, topic: TopicId, peer: EndpointAddr) -> Result<()> {
if self.iroh_channels.read().await.get(&topic).is_some() { if self.iroh_channels.read().await.get(&topic).is_some() {
self.discovery.add_endpoint_info(peer.clone()); self.address_lookup.add_endpoint_info(peer.clone());
self.gossip.subscribe(topic, vec![peer.id]).await?; self.gossip.subscribe(topic, vec![peer.id]).await?;
} }
Ok(()) Ok(())
@@ -247,7 +247,7 @@ impl Context {
/// Create iroh endpoint and gossip. /// Create iroh endpoint and gossip.
async fn init_peer_channels(&self) -> Result<Iroh> { async fn init_peer_channels(&self) -> Result<Iroh> {
info!(self, "Initializing peer channels."); info!(self, "Initializing peer channels.");
let secret_key = SecretKey::generate(&mut rand::rng()); let secret_key = SecretKey::generate();
let public_key = secret_key.public(); let public_key = secret_key.public();
let relay_mode = if let Some(relay_url) = self let relay_mode = if let Some(relay_url) = self
@@ -264,9 +264,9 @@ impl Context {
RelayMode::Default RelayMode::Default
}; };
let discovery = StaticProvider::new(); let address_lookup = MemoryLookup::new();
let endpoint = Endpoint::builder() let endpoint = Endpoint::builder(iroh::endpoint::presets::Minimal)
.discovery(discovery.clone()) .address_lookup(address_lookup.clone())
.secret_key(secret_key) .secret_key(secret_key)
.alpns(vec![GOSSIP_ALPN.to_vec()]) .alpns(vec![GOSSIP_ALPN.to_vec()])
.relay_mode(relay_mode) .relay_mode(relay_mode)
@@ -288,7 +288,7 @@ impl Context {
Ok(Iroh { Ok(Iroh {
router, router,
discovery, address_lookup,
gossip, gossip,
sequence_numbers: Mutex::new(HashMap::new()), sequence_numbers: Mutex::new(HashMap::new()),
iroh_channels: RwLock::new(HashMap::new()), iroh_channels: RwLock::new(HashMap::new()),