-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from ikatson/refactor-peer-system
Major refactoring
- Loading branch information
Showing
32 changed files
with
1,429 additions
and
664 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ members = [ | |
panic = "abort" | ||
|
||
[profile.release] | ||
panic = "abort" | ||
panic = "abort" | ||
debug = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
- [x] Selective file downloading (mostly done) | ||
- [x] Proper counting of how much is left, and how much is downloaded | ||
|
||
- [x] Send bitfield at the start if I have something | ||
- [x] use the "update_hash" function in piece checking | ||
- [ ] signaling when file is done | ||
|
||
- [ ] when we have the whole torrent, there's no point talking to peers that also have the whole torrent | ||
|
||
- [ ] when we have the whole torrent, there's no point talking to peers that also have the whole torrent and keep reconnecting to them. | ||
- [ ] per-file stats | ||
- [ ] per-peer stats | ||
|
||
- [x] slow peers cause slowness in the end, need the "end of game" algorithm | ||
- [x (partial)] per-peer stats | ||
- [x] use some concurrent hashmap e.g. flurry or dashmap | ||
- [x] tracing instead of logging. Debugging peers: RUST_LOG=[{peer=.*}]=debug | ||
test-log for tests | ||
- [ ] reopen read only is bugged: | ||
expected to be able to write to disk: error writing to file 0 (""The.Creator.2023.D.AMZN.WEB-DLRip.1.46Gb.MegaPeer.avi"") | ||
|
||
someday: | ||
- [ ] cancellation from the client-side for the lib (i.e. stop the torrent manager) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "librqbit" | ||
version = "2.2.2" | ||
version = "3.0.0-beta.0" | ||
authors = ["Igor Katson <[email protected]>"] | ||
edition = "2018" | ||
description = "The main library used by rqbit torrent client. The binary is just a small wrapper on top of it." | ||
|
@@ -13,6 +13,7 @@ readme = "README.md" | |
|
||
[features] | ||
default = ["sha1-system", "default-tls"] | ||
timed_existence = [] | ||
sha1-system = ["sha1w/sha1-system"] | ||
sha1-openssl = ["sha1w/sha1-openssl"] | ||
sha1-rust = ["sha1w/sha1-rust"] | ||
|
@@ -22,11 +23,11 @@ rust-tls = ["reqwest/rustls-tls"] | |
[dependencies] | ||
bencode = {path = "../bencode", default-features=false, package="librqbit-bencode", version="2.2.1"} | ||
buffers = {path = "../buffers", package="librqbit-buffers", version = "2.2.1"} | ||
librqbit-core = {path = "../librqbit_core", version = "2.2.2"} | ||
librqbit-core = {path = "../librqbit_core", version = "3.0.0"} | ||
clone_to_owned = {path = "../clone_to_owned", package="librqbit-clone-to-owned", version = "2.2.1"} | ||
peer_binary_protocol = {path = "../peer_binary_protocol", package="librqbit-peer-protocol", version = "2.2.2"} | ||
peer_binary_protocol = {path = "../peer_binary_protocol", package="librqbit-peer-protocol", version = "3.0.0"} | ||
sha1w = {path = "../sha1w", default-features=false, package="librqbit-sha1-wrapper", version="2.2.1"} | ||
dht = {path = "../dht", package="librqbit-dht", version="2.2.2"} | ||
dht = {path = "../dht", package="librqbit-dht", version="3.0.0"} | ||
|
||
tokio = {version = "1", features = ["macros", "rt-multi-thread"]} | ||
axum = {version = "0.6"} | ||
|
@@ -43,7 +44,7 @@ byteorder = "1" | |
bincode = "1" | ||
bitvec = "1" | ||
parking_lot = "0.12" | ||
log = "0.4" | ||
tracing = "0.1.40" | ||
size_format = "1" | ||
rand = "0.8" | ||
|
||
|
@@ -55,7 +56,9 @@ uuid = {version = "1.2", features = ["v4"]} | |
futures = "0.3" | ||
url = "2" | ||
hex = "0.4" | ||
backoff = "0.4.0" | ||
dashmap = "5.5.3" | ||
|
||
[dev-dependencies] | ||
futures = {version = "0.3"} | ||
pretty_env_logger = "0.5" | ||
tracing-subscriber = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// For production-grade code look at rqbit::main(), which does the same but has more options. | ||
// | ||
// Usage: | ||
// cargo run --release --example ubuntu /tmp/ubuntu/ | ||
|
||
use std::time::Duration; | ||
|
||
use anyhow::Context; | ||
use librqbit::session::{AddTorrentOptions, AddTorrentResponse, Session}; | ||
use tracing::info; | ||
|
||
// This is ubuntu-21.04-live-server-amd64.iso.torrent | ||
// You can also pass filenames and URLs to add_torrent(). | ||
const MAGNET_LINK: &str = "magnet:?xt=urn:btih:cab507494d02ebb1178b38f2e9d7be299c86b862"; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Output logs to console. | ||
tracing_subscriber::fmt::init(); | ||
|
||
let output_dir = std::env::args() | ||
.nth(1) | ||
.expect("the first argument should be the output directory"); | ||
|
||
// Create the session | ||
let session = Session::new(output_dir.into(), Default::default()) | ||
.await | ||
.context("error creating session")?; | ||
|
||
// Add the torrent to the session | ||
let handle = match session | ||
.add_torrent( | ||
MAGNET_LINK, | ||
Some(AddTorrentOptions { | ||
// Set this to true to allow writing on top of existing files. | ||
// If the file is partially downloaded, librqbit will only download the | ||
// missing pieces. | ||
// | ||
// Otherwise it will throw an error that the file exists. | ||
overwrite: false, | ||
..Default::default() | ||
}), | ||
) | ||
.await | ||
.context("error adding torrent")? | ||
{ | ||
AddTorrentResponse::Added(handle) => handle, | ||
// For a brand new session other variants won't happen. | ||
_ => unreachable!(), | ||
}; | ||
|
||
// Print stats periodically. | ||
tokio::spawn({ | ||
let handle = handle.clone(); | ||
async move { | ||
loop { | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
let stats = handle.torrent_state().stats_snapshot(); | ||
info!("stats: {stats:?}"); | ||
} | ||
} | ||
}); | ||
|
||
// Wait until the download is completed | ||
handle.wait_until_completed().await?; | ||
info!("torrent downloaded"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.