Skip to content

Commit

Permalink
Showing 15 changed files with 72 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/dht/Cargo.toml
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@ backoff = "0.4.0"
futures = "0.3"
rand = "0.8"
indexmap = "2"
directories = "5"
dashmap = {version = "5.5.3", features = ["serde"]}

clone_to_owned = {path="../clone_to_owned", package="librqbit-clone-to-owned", version = "2.2.1"}
4 changes: 2 additions & 2 deletions crates/dht/src/persistence.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// TODO: this now stores only the routing table, but we also need AT LEAST the same socket address...

use librqbit_core::directories::get_configuration_directory;
use librqbit_core::spawn_utils::spawn;
use serde::{Deserialize, Serialize};
use std::fs::OpenOptions;
@@ -72,8 +73,7 @@ impl PersistentDht {
let config_filename = match config.config_filename.take() {
Some(config_filename) => config_filename,
None => {
let dirs = directories::ProjectDirs::from("com", "rqbit", "dht")
.context("cannot determine project directory for com.rqbit.dht")?;
let dirs = get_configuration_directory("dht")?;
let path = dirs.cache_dir().join("dht.json");
info!("will store DHT routing table to {:?} periodically", &path);
path
4 changes: 4 additions & 0 deletions crates/librqbit/src/api.rs
Original file line number Diff line number Diff line change
@@ -143,8 +143,10 @@ impl Api {
info,
only_files,
seen_peers,
output_folder,
}) => ApiAddTorrentResponse {
id: None,
output_folder: output_folder.to_string_lossy().into_owned(),
seen_peers: Some(seen_peers),
details: make_torrent_details(&info_hash, &info, only_files.as_deref())
.context("error making torrent details")?,
@@ -159,6 +161,7 @@ impl Api {
ApiAddTorrentResponse {
id: Some(id),
details,
output_folder: handle.info().out_dir.to_string_lossy().into_owned(),
seen_peers: None,
}
}
@@ -227,6 +230,7 @@ pub struct TorrentDetailsResponse {
pub struct ApiAddTorrentResponse {
pub id: Option<usize>,
pub details: TorrentDetailsResponse,
pub output_folder: String,
pub seen_peers: Option<Vec<SocketAddr>>,
}

38 changes: 24 additions & 14 deletions crates/librqbit/src/session.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ use bencode::{bencode_serialize_to_writer, BencodeDeserializer};
use buffers::ByteString;
use dht::{Dht, DhtBuilder, Id20, PersistentDht, PersistentDhtConfig, RequestPeersStream};
use librqbit_core::{
directories::get_configuration_directory,
magnet::Magnet,
peer_id::generate_peer_id,
torrent_metainfo::{torrent_from_bytes, TorrentMetaV1Info, TorrentMetaV1Owned},
@@ -66,7 +67,7 @@ impl SessionDatabase {

fn serialize(&self) -> SerializedSessionDatabase {
SerializedSessionDatabase {
torrents_v2: self
torrents: self
.torrents
.iter()
.map(|(id, torrent)| {
@@ -135,7 +136,7 @@ where

#[derive(Serialize, Deserialize)]
struct SerializedSessionDatabase {
torrents_v2: HashMap<usize, SerializedTorrent>,
torrents: HashMap<usize, SerializedTorrent>,
}

pub struct Session {
@@ -208,9 +209,11 @@ pub struct ListOnlyResponse {
pub info_hash: Id20,
pub info: TorrentMetaV1Info<ByteString>,
pub only_files: Option<Vec<usize>>,
pub output_folder: PathBuf,
pub seen_peers: Vec<SocketAddr>,
}

#[allow(clippy::large_enum_variant)]
pub enum AddTorrentResponse {
AlreadyManaged(TorrentId, ManagedTorrentHandle),
ListOnly(ListOnlyResponse),
@@ -276,7 +279,6 @@ pub struct SessionOptions {
pub disable_dht: bool,
pub disable_dht_persistence: bool,
pub persistence: bool,
// Will default to output_folder/.rqbit-session.json
pub persistence_filename: Option<PathBuf>,
pub dht_config: Option<PersistentDhtConfig>,
pub peer_id: Option<Id20>,
@@ -308,9 +310,12 @@ impl Session {
Some(dht)
};
let peer_opts = opts.peer_opts.unwrap_or_default();
let persistence_filename = opts
.persistence_filename
.unwrap_or_else(|| output_folder.join(".rqbit-session.json"));
let persistence_filename = match opts.persistence_filename {
Some(filename) => filename,
None => get_configuration_directory("session")?
.data_dir()
.join("session.json"),
};
let session = Arc::new(Self {
persistence_filename,
peer_id,
@@ -322,6 +327,10 @@ impl Session {
});

if opts.persistence {
info!(
"will use {:?} for session persistence",
session.persistence_filename
);
if let Some(parent) = session.persistence_filename.parent() {
std::fs::create_dir_all(parent).with_context(|| {
format!("couldn't create directory {:?} for session storage", parent)
@@ -391,7 +400,7 @@ impl Session {
let db: SerializedSessionDatabase =
serde_json::from_reader(&mut rdr).context("error deserializing session database")?;
let mut futures = Vec::new();
for (id, storrent) in db.torrents_v2.into_iter() {
for (id, storrent) in db.torrents.into_iter() {
let trackers: Vec<ByteString> = storrent
.trackers
.into_iter()
@@ -646,22 +655,23 @@ impl Session {

let only_files = get_only_files(opts.only_files, opts.only_files_regex, opts.list_only)?;

let sub_folder = opts.sub_folder.map(PathBuf::from).unwrap_or_default();
let output_folder = opts
.output_folder
.map(PathBuf::from)
.unwrap_or_else(|| self.output_folder.clone())
.join(sub_folder);

if opts.list_only {
return Ok(AddTorrentResponse::ListOnly(ListOnlyResponse {
info_hash,
info,
only_files,
output_folder,
seen_peers: initial_peers,
}));
}

let sub_folder = opts.sub_folder.map(PathBuf::from).unwrap_or_default();
let output_folder = opts
.output_folder
.map(PathBuf::from)
.unwrap_or_else(|| self.output_folder.clone())
.join(sub_folder);

let mut builder = ManagedTorrentBuilder::new(info, info_hash, output_folder.clone());
builder
.overwrite(opts.overwrite)
Binary file added crates/librqbit/webui/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 28c2db2

Please sign in to comment.