Reduce compile times even more

This commit is contained in:
Igor Katson 2024-02-27 08:00:56 +00:00
parent 34f3ec6c29
commit 1b79b66cc3
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 135 additions and 116 deletions

View file

@ -1,6 +1,7 @@
use std::{
cmp::Reverse,
net::SocketAddr,
pin::Pin,
str::FromStr,
sync::{
atomic::{AtomicU16, Ordering},
@ -23,7 +24,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, FutureExt, Stream, StreamExt, TryFutureExt};
use leaky_bucket::RateLimiter;
use librqbit_core::{
@ -232,6 +233,7 @@ impl Drop for RequestPeersStream {
impl Stream for RequestPeersStream {
type Item = SocketAddr;
#[inline(never)]
fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
@ -1144,7 +1146,11 @@ impl DhtState {
&self.cancellation_token
}
pub async fn with_config(mut config: DhtConfig) -> anyhow::Result<Arc<Self>> {
#[inline(never)]
pub fn with_config(
mut config: DhtConfig,
) -> Pin<Box<dyn Future<Output = anyhow::Result<Arc<Self>>> + Send>> {
async move {
let socket = match config.listen_addr {
Some(addr) => UdpSocket::bind(addr)
.await
@ -1186,7 +1192,10 @@ impl DhtState {
});
Ok(state)
}
.boxed()
}
#[inline(never)]
pub fn get_peers(
self: &Arc<Self>,
info_hash: Id20,

View file

@ -1,5 +1,6 @@
// TODO: this now stores only the routing table, but we also need AT LEAST the same socket address...
use futures::{Future, FutureExt};
use librqbit_core::directories::get_configuration_directory;
use librqbit_core::spawn_utils::spawn_with_cancel;
use serde::{Deserialize, Serialize};
@ -7,6 +8,7 @@ use std::fs::OpenOptions;
use std::io::{BufReader, BufWriter};
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::time::Duration;
use tokio_util::sync::CancellationToken;
@ -75,10 +77,12 @@ impl PersistentDht {
Ok(path)
}
pub async fn create(
#[inline(never)]
pub fn create(
config: Option<PersistentDhtConfig>,
cancellation_token: Option<CancellationToken>,
) -> anyhow::Result<Dht> {
) -> Pin<Box<dyn Future<Output = anyhow::Result<Dht>> + Send>> {
async move {
let mut config = config.unwrap_or_default();
let config_filename = match config.config_filename.take() {
Some(config_filename) => config_filename,
@ -98,7 +102,9 @@ impl PersistentDht {
let de = match OpenOptions::new().read(true).open(&config_filename) {
Ok(dht_json) => {
let reader = BufReader::new(dht_json);
match serde_json::from_reader::<_, DhtSerialize<RoutingTable, PeerStore>>(reader) {
match serde_json::from_reader::<_, DhtSerialize<RoutingTable, PeerStore>>(
reader,
) {
Ok(r) => {
info!(filename=?config_filename, "loaded DHT routing table from");
Some(r)
@ -115,7 +121,9 @@ impl PersistentDht {
}
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => None,
_ => return Err(e).with_context(|| format!("error reading {config_filename:?}")),
_ => {
return Err(e).with_context(|| format!("error reading {config_filename:?}"))
}
},
};
let (listen_addr, routing_table, peer_store) = de
@ -165,4 +173,6 @@ impl PersistentDht {
Ok(dht)
}
.boxed()
}
}