This commit is contained in:
Igor Katson 2023-11-24 12:47:33 +00:00
parent 0aa1af7933
commit 5e728fc67b
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
5 changed files with 23 additions and 36 deletions

View file

@ -1,4 +1,4 @@
use anyhow::{bail, Context}; use anyhow::{Context};
use axum::body::Bytes; use axum::body::Bytes;
use axum::extract::{Path, Query, State}; use axum::extract::{Path, Query, State};
use axum::response::IntoResponse; use axum::response::IntoResponse;
@ -472,7 +472,7 @@ impl ApiInternal {
}) })
} }
fn api_dump_haves(&self, idx: usize) -> Result<String> { fn api_dump_haves(&self, _idx: usize) -> Result<String> {
Err(anyhow::anyhow!("not implemented").into()) Err(anyhow::anyhow!("not implemented").into())
// let mgr = self.mgr_handle(idx)?; // let mgr = self.mgr_handle(idx)?;
// Ok(format!( // Ok(format!(

View file

@ -17,7 +17,7 @@ use crate::{
dht_utils::{read_metainfo_from_peer_receiver, ReadMetainfoResult}, dht_utils::{read_metainfo_from_peer_receiver, ReadMetainfoResult},
peer_connection::PeerConnectionOptions, peer_connection::PeerConnectionOptions,
spawn_utils::{spawn, BlockingSpawner}, spawn_utils::{spawn, BlockingSpawner},
torrent_state::{ManagedTorrent, ManagedTorrentBuilder, ManagedTorrentHandle}, torrent_state::{ManagedTorrentBuilder, ManagedTorrentHandle},
}; };
pub const SUPPORTED_SCHEMES: [&str; 3] = ["http:", "https:", "magnet:"]; pub const SUPPORTED_SCHEMES: [&str; 3] = ["http:", "https:", "magnet:"];

View file

@ -1,32 +1,19 @@
use std::{ use std::{
collections::HashSet,
fs::{File, OpenOptions}, fs::{File, OpenOptions},
net::SocketAddr,
path::{Path, PathBuf},
sync::Arc, sync::Arc,
time::{Duration, Instant}, time::Instant,
}; };
use anyhow::Context; use anyhow::Context;
use bencode::from_bytes;
use buffers::ByteString; use librqbit_core::{lengths::Lengths, torrent_metainfo::TorrentMetaV1Info};
use librqbit_core::{
id20::Id20, lengths::Lengths, peer_id::generate_peer_id, speed_estimator::SpeedEstimator,
torrent_metainfo::TorrentMetaV1Info,
};
use parking_lot::Mutex; use parking_lot::Mutex;
use reqwest::Url;
use sha1w::Sha1; use sha1w::Sha1;
use size_format::SizeFormatterBinary as SF; use size_format::SizeFormatterBinary as SF;
use tracing::{debug, info, span, warn, Level}; use tracing::{debug, info, warn};
use crate::{ use crate::{chunk_tracker::ChunkTracker, file_ops::FileOps};
chunk_tracker::ChunkTracker,
file_ops::FileOps,
spawn_utils::{spawn, BlockingSpawner},
torrent_state::{ManagedTorrent, ManagedTorrentHandle, TorrentStateLive, TorrentStateOptions},
tracker_comms::{TrackerError, TrackerRequest, TrackerRequestEvent, TrackerResponse},
};
use super::{paused::TorrentStatePaused, ManagedTorrentInfo}; use super::{paused::TorrentStatePaused, ManagedTorrentInfo};
@ -64,7 +51,7 @@ impl TorrentStateInitializing {
full_path.push(relative_path); full_path.push(relative_path);
std::fs::create_dir_all(full_path.parent().unwrap())?; std::fs::create_dir_all(full_path.parent().unwrap())?;
let file = if (&self.meta).options.overwrite { let file = if self.meta.options.overwrite {
OpenOptions::new() OpenOptions::new()
.create(true) .create(true)
.read(true) .read(true)
@ -86,12 +73,12 @@ impl TorrentStateInitializing {
}; };
let lengths = let lengths =
make_lengths(&(&self.meta).info).context("unable to compute Lengths from torrent")?; make_lengths(&self.meta.info).context("unable to compute Lengths from torrent")?;
debug!("computed lengths: {:?}", &lengths); debug!("computed lengths: {:?}", &lengths);
info!("Doing initial checksum validation, this might take a while..."); info!("Doing initial checksum validation, this might take a while...");
let initial_check_results = (&self.meta).spawner.spawn_block_in_place(|| { let initial_check_results = self.meta.spawner.spawn_block_in_place(|| {
FileOps::<Sha1>::new(&(&self.meta).info, &files, &lengths) FileOps::<Sha1>::new(&self.meta.info, &files, &lengths)
.initial_check(self.only_files.as_deref()) .initial_check(self.only_files.as_deref())
})?; })?;

View file

@ -63,8 +63,8 @@ use clone_to_owned::CloneToOwned;
use futures::{stream::FuturesUnordered, StreamExt}; use futures::{stream::FuturesUnordered, StreamExt};
use librqbit_core::{ use librqbit_core::{
id20::Id20, id20::Id20,
lengths::{self, ChunkInfo, Lengths, ValidPieceIndex}, lengths::{ChunkInfo, Lengths, ValidPieceIndex},
speed_estimator::{self, SpeedEstimator}, speed_estimator::{SpeedEstimator},
torrent_metainfo::TorrentMetaV1Info, torrent_metainfo::TorrentMetaV1Info,
}; };
use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
@ -88,7 +88,7 @@ use crate::{
peer_connection::{ peer_connection::{
PeerConnection, PeerConnectionHandler, PeerConnectionOptions, WriterRequest, PeerConnection, PeerConnectionHandler, PeerConnectionOptions, WriterRequest,
}, },
spawn_utils::{spawn, BlockingSpawner}, spawn_utils::{spawn},
tracker_comms::{TrackerError, TrackerRequest, TrackerRequestEvent, TrackerResponse}, tracker_comms::{TrackerError, TrackerRequest, TrackerRequestEvent, TrackerResponse},
type_aliases::{PeerHandle, BF}, type_aliases::{PeerHandle, BF},
}; };
@ -165,7 +165,7 @@ impl TorrentStateLive {
let have_bytes = paused.chunk_tracker.get_have_bytes(); let have_bytes = paused.chunk_tracker.get_have_bytes();
let needed_bytes = paused.chunk_tracker.get_needed_bytes(); let needed_bytes = paused.chunk_tracker.get_needed_bytes();
let lengths = paused.chunk_tracker.get_lengths().clone(); let lengths = *paused.chunk_tracker.get_lengths();
let state = Arc::new(TorrentStateLive { let state = Arc::new(TorrentStateLive {
meta: paused.info.clone(), meta: paused.info.clone(),

View file

@ -7,21 +7,21 @@ use std::net::SocketAddr;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use std::{collections::HashSet, path::Path}; use std::{path::Path};
use anyhow::Context; use anyhow::Context;
use buffers::ByteString; use buffers::ByteString;
use librqbit_core::id20::Id20; use librqbit_core::id20::Id20;
use librqbit_core::peer_id::generate_peer_id; use librqbit_core::peer_id::generate_peer_id;
use librqbit_core::speed_estimator::SpeedEstimator;
use librqbit_core::torrent_metainfo::TorrentMetaV1Info; use librqbit_core::torrent_metainfo::TorrentMetaV1Info;
pub use live::*; pub use live::*;
use parking_lot::RwLock; use parking_lot::RwLock;
use tokio::sync::mpsc::Sender;
use tracing::trace_span;
use url::Url; use url::Url;
use crate::spawn_utils::{spawn, BlockingSpawner}; use crate::spawn_utils::{BlockingSpawner};
use initializing::TorrentStateInitializing; use initializing::TorrentStateInitializing;
@ -70,7 +70,7 @@ impl ManagedTorrent {
self.info.info_hash self.info.info_hash
} }
pub(crate) fn add_peer(&self, peer: SocketAddr) -> bool { pub(crate) fn add_peer(&self, _peer: SocketAddr) -> bool {
todo!() todo!()
} }