settings dialog works now and reloads the session properly

This commit is contained in:
Igor Katson 2023-12-06 23:18:06 +00:00
parent e4543e1ba2
commit 9cbe16b387
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
13 changed files with 123 additions and 49 deletions

View file

@ -23,7 +23,7 @@ use anyhow::{bail, Context};
use backoff::{backoff::Backoff, ExponentialBackoffBuilder};
use bencode::ByteString;
use dashmap::DashMap;
use futures::{stream::FuturesUnordered, Stream, StreamExt, TryFutureExt};
use futures::{stream::FuturesUnordered, Future, Stream, StreamExt, TryFutureExt};
use leaky_bucket::RateLimiter;
use librqbit_core::{id20::Id20, peer_id::generate_peer_id, spawn_utils::spawn};
@ -1127,10 +1127,18 @@ pub struct DhtConfig {
}
impl DhtState {
pub async fn new() -> anyhow::Result<Arc<Self>> {
pub async fn new() -> anyhow::Result<(
Arc<Self>,
impl Future<Output = anyhow::Result<()>> + Send + Sync + 'static,
)> {
Self::with_config(DhtConfig::default()).await
}
pub async fn with_config(config: DhtConfig) -> anyhow::Result<Arc<Self>> {
pub async fn with_config(
config: DhtConfig,
) -> anyhow::Result<(
Arc<Self>,
impl Future<Output = anyhow::Result<()>> + Send + Sync + 'static,
)> {
let socket = match config.listen_addr {
Some(addr) => UdpSocket::bind(addr)
.await
@ -1160,15 +1168,15 @@ impl DhtState {
config.peer_store.unwrap_or_else(|| PeerStore::new(peer_id)),
));
spawn(error_span!("dht"), {
let run_worker = {
let state = state.clone();
async move {
let worker = DhtWorker { socket, dht: state };
worker.start(in_rx, &bootstrap_addrs).await?;
Ok(())
}
});
Ok(state)
};
Ok((state, run_worker))
}
pub fn get_peers(