settings dialog works now and reloads the session properly
This commit is contained in:
parent
e4543e1ba2
commit
9cbe16b387
13 changed files with 123 additions and 49 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use std::time::Duration;
|
|||
|
||||
pub use crate::dht::DhtStats;
|
||||
pub use crate::dht::{DhtConfig, DhtState, RequestPeersStream};
|
||||
use futures::Future;
|
||||
pub use librqbit_core::id20::Id20;
|
||||
pub use persistence::{PersistentDht, PersistentDhtConfig};
|
||||
|
||||
|
|
@ -26,11 +27,19 @@ pub struct DhtBuilder {}
|
|||
|
||||
impl DhtBuilder {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
pub async fn new() -> anyhow::Result<Dht> {
|
||||
pub async fn new() -> anyhow::Result<(
|
||||
Dht,
|
||||
impl Future<Output = anyhow::Result<()>> + Send + Sync + 'static,
|
||||
)> {
|
||||
DhtState::new().await
|
||||
}
|
||||
|
||||
pub async fn with_config(config: DhtConfig) -> anyhow::Result<Dht> {
|
||||
pub async fn with_config(
|
||||
config: DhtConfig,
|
||||
) -> anyhow::Result<(
|
||||
Dht,
|
||||
impl Future<Output = anyhow::Result<()>> + Send + Sync + 'static,
|
||||
)> {
|
||||
DhtState::with_config(config).await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// TODO: this now stores only the routing table, but we also need AT LEAST the same socket address...
|
||||
|
||||
use futures::Future;
|
||||
use librqbit_core::directories::get_configuration_directory;
|
||||
use librqbit_core::spawn_utils::spawn;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{BufReader, BufWriter};
|
||||
|
|
@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::time::Duration;
|
||||
|
||||
use anyhow::Context;
|
||||
use tracing::{debug, error, error_span, info, trace, warn};
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
use crate::peer_store::PeerStore;
|
||||
use crate::routing_table::RoutingTable;
|
||||
|
|
@ -74,7 +74,13 @@ impl PersistentDht {
|
|||
Ok(path)
|
||||
}
|
||||
|
||||
pub async fn create(config: Option<PersistentDhtConfig>) -> anyhow::Result<Dht> {
|
||||
pub async fn create(
|
||||
config: Option<PersistentDhtConfig>,
|
||||
) -> anyhow::Result<(
|
||||
Dht,
|
||||
impl Future<Output = anyhow::Result<()>> + Send + Sync + 'static,
|
||||
impl Future<Output = anyhow::Result<()>> + Send + Sync + 'static,
|
||||
)> {
|
||||
let mut config = config.unwrap_or_default();
|
||||
let config_filename = match config.config_filename.take() {
|
||||
Some(config_filename) => config_filename,
|
||||
|
|
@ -125,9 +131,9 @@ impl PersistentDht {
|
|||
peer_store,
|
||||
..Default::default()
|
||||
};
|
||||
let dht = DhtState::with_config(dht_config).await?;
|
||||
let (dht, run_worker) = DhtState::with_config(dht_config).await?;
|
||||
|
||||
spawn(error_span!("dht_persistence"), {
|
||||
let run_persistence = {
|
||||
let dht = dht.clone();
|
||||
let dump_interval = config
|
||||
.dump_interval
|
||||
|
|
@ -150,7 +156,8 @@ impl PersistentDht {
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(dht)
|
||||
};
|
||||
|
||||
Ok((dht, run_worker, run_persistence))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue