This one makes it better for sure
This commit is contained in:
parent
15d17355b5
commit
f42007f436
2 changed files with 204 additions and 194 deletions
|
|
@ -4,6 +4,7 @@ use std::{
|
|||
io::{BufReader, BufWriter, Read},
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
pin::Pin,
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
|
|
@ -24,7 +25,7 @@ use bencode::{bencode_serialize_to_writer, BencodeDeserializer};
|
|||
use buffers::{ByteBuf, ByteBufT, ByteString};
|
||||
use clone_to_owned::CloneToOwned;
|
||||
use dht::{Dht, DhtBuilder, DhtConfig, Id20, PersistentDht, PersistentDhtConfig};
|
||||
use futures::{stream::FuturesUnordered, TryFutureExt};
|
||||
use futures::{stream::FuturesUnordered, Future, FutureExt, TryFutureExt};
|
||||
use librqbit_core::{
|
||||
directories::get_configuration_directory,
|
||||
magnet::Magnet,
|
||||
|
|
@ -377,8 +378,9 @@ pub(crate) struct CheckedIncomingConnection {
|
|||
|
||||
impl Session {
|
||||
/// Create a new session. The passed in folder will be used as a default unless overriden per torrent.
|
||||
pub async fn new(output_folder: PathBuf) -> anyhow::Result<Arc<Self>> {
|
||||
Self::new_with_opts(output_folder, SessionOptions::default()).await
|
||||
#[inline(never)]
|
||||
pub fn new(output_folder: PathBuf) -> Pin<Box<dyn Future<Output = anyhow::Result<Arc<Self>>>>> {
|
||||
Self::new_with_opts(output_folder, SessionOptions::default())
|
||||
}
|
||||
|
||||
pub fn default_persistence_filename() -> anyhow::Result<PathBuf> {
|
||||
|
|
@ -391,10 +393,12 @@ impl Session {
|
|||
}
|
||||
|
||||
/// Create a new session with options.
|
||||
pub async fn new_with_opts(
|
||||
#[inline(never)]
|
||||
pub fn new_with_opts(
|
||||
output_folder: PathBuf,
|
||||
mut opts: SessionOptions,
|
||||
) -> anyhow::Result<Arc<Self>> {
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<Arc<Self>>>>> {
|
||||
async move {
|
||||
let peer_id = opts.peer_id.unwrap_or_else(generate_peer_id);
|
||||
let token = CancellationToken::new();
|
||||
|
||||
|
|
@ -479,6 +483,8 @@ impl Session {
|
|||
|
||||
Ok(session)
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
|
||||
async fn task_persistence(self: Arc<Self>) -> anyhow::Result<()> {
|
||||
// Populate initial from the state filename
|
||||
|
|
@ -738,11 +744,12 @@ impl Session {
|
|||
}
|
||||
|
||||
/// Add a torrent to the session.
|
||||
pub async fn add_torrent(
|
||||
&self,
|
||||
add: AddTorrent<'_>,
|
||||
pub fn add_torrent<'a>(
|
||||
&'a self,
|
||||
add: AddTorrent<'a>,
|
||||
opts: Option<AddTorrentOptions>,
|
||||
) -> anyhow::Result<AddTorrentResponse> {
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<AddTorrentResponse>> + Send + 'a>> {
|
||||
async move {
|
||||
// Magnet links are different in that we first need to discover the metadata.
|
||||
let span = error_span!("add_torrent");
|
||||
let _ = span.enter();
|
||||
|
|
@ -763,8 +770,8 @@ impl Session {
|
|||
|
||||
let (info_hash, info, trackers, peer_rx, initial_peers) = match add {
|
||||
AddTorrent::Url(magnet) if magnet.starts_with("magnet:") => {
|
||||
let magnet =
|
||||
Magnet::parse(&magnet).context("provided path is not a valid magnet URL")?;
|
||||
let magnet = Magnet::parse(&magnet)
|
||||
.context("provided path is not a valid magnet URL")?;
|
||||
let info_hash = magnet
|
||||
.as_id20()
|
||||
.context("magnet link didn't contain a BTv1 infohash")?;
|
||||
|
|
@ -869,6 +876,8 @@ impl Session {
|
|||
)
|
||||
.await
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn main_torrent_info(
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ pub struct InitLoggingResult {
|
|||
pub line_broadcast: LineBroadcast,
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn init_logging(opts: InitLoggingOptions) -> anyhow::Result<InitLoggingResult> {
|
||||
let stderr_filter = EnvFilter::builder()
|
||||
.with_default_directive(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue