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::{ use std::{
cmp::Reverse, cmp::Reverse,
net::SocketAddr, net::SocketAddr,
pin::Pin,
str::FromStr, str::FromStr,
sync::{ sync::{
atomic::{AtomicU16, Ordering}, atomic::{AtomicU16, Ordering},
@ -23,7 +24,7 @@ use anyhow::{bail, Context};
use backoff::{backoff::Backoff, ExponentialBackoffBuilder}; use backoff::{backoff::Backoff, ExponentialBackoffBuilder};
use bencode::ByteString; use bencode::ByteString;
use dashmap::DashMap; use dashmap::DashMap;
use futures::{stream::FuturesUnordered, Stream, StreamExt, TryFutureExt}; use futures::{stream::FuturesUnordered, Future, FutureExt, Stream, StreamExt, TryFutureExt};
use leaky_bucket::RateLimiter; use leaky_bucket::RateLimiter;
use librqbit_core::{ use librqbit_core::{
@ -232,6 +233,7 @@ impl Drop for RequestPeersStream {
impl Stream for RequestPeersStream { impl Stream for RequestPeersStream {
type Item = SocketAddr; type Item = SocketAddr;
#[inline(never)]
fn poll_next( fn poll_next(
mut self: std::pin::Pin<&mut Self>, mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>, cx: &mut std::task::Context<'_>,
@ -1144,7 +1146,11 @@ impl DhtState {
&self.cancellation_token &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 { let socket = match config.listen_addr {
Some(addr) => UdpSocket::bind(addr) Some(addr) => UdpSocket::bind(addr)
.await .await
@ -1186,7 +1192,10 @@ impl DhtState {
}); });
Ok(state) Ok(state)
} }
.boxed()
}
#[inline(never)]
pub fn get_peers( pub fn get_peers(
self: &Arc<Self>, self: &Arc<Self>,
info_hash: Id20, 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... // 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::directories::get_configuration_directory;
use librqbit_core::spawn_utils::spawn_with_cancel; use librqbit_core::spawn_utils::spawn_with_cancel;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -7,6 +8,7 @@ use std::fs::OpenOptions;
use std::io::{BufReader, BufWriter}; use std::io::{BufReader, BufWriter};
use std::net::SocketAddr; use std::net::SocketAddr;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::time::Duration; use std::time::Duration;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
@ -75,10 +77,12 @@ impl PersistentDht {
Ok(path) Ok(path)
} }
pub async fn create( #[inline(never)]
pub fn create(
config: Option<PersistentDhtConfig>, config: Option<PersistentDhtConfig>,
cancellation_token: Option<CancellationToken>, 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 mut config = config.unwrap_or_default();
let config_filename = match config.config_filename.take() { let config_filename = match config.config_filename.take() {
Some(config_filename) => config_filename, Some(config_filename) => config_filename,
@ -98,7 +102,9 @@ impl PersistentDht {
let de = match OpenOptions::new().read(true).open(&config_filename) { let de = match OpenOptions::new().read(true).open(&config_filename) {
Ok(dht_json) => { Ok(dht_json) => {
let reader = BufReader::new(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) => { Ok(r) => {
info!(filename=?config_filename, "loaded DHT routing table from"); info!(filename=?config_filename, "loaded DHT routing table from");
Some(r) Some(r)
@ -115,7 +121,9 @@ impl PersistentDht {
} }
Err(e) => match e.kind() { Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => None, 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 let (listen_addr, routing_table, peer_store) = de
@ -165,4 +173,6 @@ impl PersistentDht {
Ok(dht) Ok(dht)
} }
.boxed()
}
} }