diff --git a/Cargo.lock b/Cargo.lock index 08ff622..f967a0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1278,6 +1278,7 @@ dependencies = [ "librqbit-dht", "librqbit-peer-protocol", "librqbit-sha1-wrapper", + "librqbit-tracker-comms", "librqbit-upnp", "openssl", "parking_lot", @@ -1397,6 +1398,26 @@ dependencies = [ "sha1", ] +[[package]] +name = "librqbit-tracker-comms" +version = "1.0.0" +dependencies = [ + "anyhow", + "async-stream", + "byteorder", + "futures", + "librqbit-bencode", + "librqbit-buffers", + "librqbit-core", + "rand", + "reqwest", + "serde", + "tokio", + "tracing", + "url", + "urlencoding", +] + [[package]] name = "librqbit-upnp" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index a3a89a4..22f0267 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "crates/peer_binary_protocol", "crates/dht", "crates/upnp" -] +, "crates/tracker_comms"] [profile.dev] panic = "abort" @@ -22,4 +22,4 @@ debug = true [profile.release-github] inherits = "release" -debug = false \ No newline at end of file +debug = false diff --git a/crates/librqbit/Cargo.toml b/crates/librqbit/Cargo.toml index b840cf8..e05ceb5 100644 --- a/crates/librqbit/Cargo.toml +++ b/crates/librqbit/Cargo.toml @@ -23,6 +23,7 @@ rust-tls = ["reqwest/rustls-tls"] [dependencies] bencode = {path = "../bencode", default-features=false, package="librqbit-bencode", version="2.2.1"} +tracker_comms = {path = "../tracker_comms", default-features=false, package="librqbit-tracker-comms", version="1.0.0"} buffers = {path = "../buffers", package="librqbit-buffers", version = "2.2.1"} librqbit-core = {path = "../librqbit_core", version = "3.5.0"} clone_to_owned = {path = "../clone_to_owned", package="librqbit-clone-to-owned", version = "2.2.1"} diff --git a/crates/librqbit/src/lib.rs b/crates/librqbit/src/lib.rs index 817c086..d16c427 100644 --- a/crates/librqbit/src/lib.rs +++ b/crates/librqbit/src/lib.rs @@ -36,9 +36,6 @@ mod session; mod spawn_utils; mod torrent_state; pub mod tracing_subscriber_config_utils; -pub mod tracker_comms; -pub mod tracker_comms_http; -pub mod tracker_comms_udp; mod type_aliases; pub use api::Api; diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 529be59..2252332 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -9,6 +9,16 @@ use std::{ time::Duration, }; +use crate::{ + dht_utils::{read_metainfo_from_peer_receiver, ReadMetainfoResult}, + peer_connection::PeerConnectionOptions, + read_buf::ReadBuf, + spawn_utils::BlockingSpawner, + torrent_state::{ + ManagedTorrentBuilder, ManagedTorrentHandle, ManagedTorrentState, TorrentStateLive, + }, + type_aliases::PeerStream, +}; use anyhow::{bail, Context}; use bencode::{bencode_serialize_to_writer, BencodeDeserializer}; use buffers::{ByteBuf, ByteBufT, ByteString}; @@ -32,18 +42,7 @@ use tokio::net::{TcpListener, TcpStream}; use tokio_stream::StreamExt; use tokio_util::sync::{CancellationToken, DropGuard}; use tracing::{debug, error, error_span, info, trace, warn, Instrument}; - -use crate::{ - dht_utils::{read_metainfo_from_peer_receiver, ReadMetainfoResult}, - peer_connection::PeerConnectionOptions, - read_buf::ReadBuf, - spawn_utils::BlockingSpawner, - torrent_state::{ - ManagedTorrentBuilder, ManagedTorrentHandle, ManagedTorrentState, TorrentStateLive, - }, - tracker_comms::TrackerComms, - type_aliases::PeerStream, -}; +use tracker_comms::TrackerComms; pub const SUPPORTED_SCHEMES: [&str; 3] = ["http:", "https:", "magnet:"]; diff --git a/crates/tracker_comms/Cargo.toml b/crates/tracker_comms/Cargo.toml new file mode 100644 index 0000000..98329ec --- /dev/null +++ b/crates/tracker_comms/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "librqbit-tracker-comms" +version = "1.0.0" +edition = "2018" +description = "Common interface around various sha1 implementations used in rqbit torrent client." +license = "Apache-2.0" +documentation = "https://docs.rs/librqbit-tracker-comms" +repository = "https://github.com/ikatson/rqbit" +readme = "README.md" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = "1" +anyhow = "1" +futures = "0.3" +async-stream = "0.3.5" +buffers = {path = "../buffers", package="librqbit-buffers", version = "2.2.1"} +librqbit-core = {path = "../librqbit_core", version = "3.5.0"} +byteorder = "1.5" +serde = {version = "1", features=["derive"]} +urlencoding = "2" +rand = "0.8" +tracing = "0.1.40" +reqwest = {version="0.11.22", default-features=false, features = ["json"]} +bencode = {path = "../bencode", default-features=false, package="librqbit-bencode", version="2.2.1"} +url = "2" \ No newline at end of file diff --git a/crates/tracker_comms/resources/test/udp-tracker-announce-response.bin b/crates/tracker_comms/resources/test/udp-tracker-announce-response.bin new file mode 100644 index 0000000..4b1bc3a Binary files /dev/null and b/crates/tracker_comms/resources/test/udp-tracker-announce-response.bin differ diff --git a/crates/tracker_comms/src/lib.rs b/crates/tracker_comms/src/lib.rs new file mode 100644 index 0000000..74cc980 --- /dev/null +++ b/crates/tracker_comms/src/lib.rs @@ -0,0 +1,5 @@ +mod tracker_comms; +mod tracker_comms_http; +mod tracker_comms_udp; + +pub use tracker_comms::*; diff --git a/crates/librqbit/src/tracker_comms.rs b/crates/tracker_comms/src/tracker_comms.rs similarity index 100% rename from crates/librqbit/src/tracker_comms.rs rename to crates/tracker_comms/src/tracker_comms.rs diff --git a/crates/librqbit/src/tracker_comms_http.rs b/crates/tracker_comms/src/tracker_comms_http.rs similarity index 100% rename from crates/librqbit/src/tracker_comms_http.rs rename to crates/tracker_comms/src/tracker_comms_http.rs diff --git a/crates/librqbit/src/tracker_comms_udp.rs b/crates/tracker_comms/src/tracker_comms_udp.rs similarity index 97% rename from crates/librqbit/src/tracker_comms_udp.rs rename to crates/tracker_comms/src/tracker_comms_udp.rs index 1e72ae8..35af733 100644 --- a/crates/librqbit/src/tracker_comms_udp.rs +++ b/crates/tracker_comms/src/tracker_comms_udp.rs @@ -12,9 +12,9 @@ const ACTION_ANNOUNCE: u32 = 1; // const ACTION_ERROR: u32 = 3; pub const EVENT_NONE: u32 = 0; -pub const EVENT_COMPLETED: u32 = 1; -pub const EVENT_STARTED: u32 = 2; -pub const EVENT_STOPPED: u32 = 3; +// pub const EVENT_COMPLETED: u32 = 1; +// pub const EVENT_STARTED: u32 = 2; +// pub const EVENT_STOPPED: u32 = 3; pub type ConnectionId = u64; const CONNECTION_ID_MAGIC: ConnectionId = 0x41727101980; @@ -293,7 +293,7 @@ mod tests { Response::Connect(connection_id) => { dbg!(connection_id) } - other => panic!("unexpected response {other:?}"), + other => panic!("unexpected response {:?}", other), }; let hash = Id20::from_str("775459190aa65566591634203f8d9f17d341f969").unwrap(); @@ -335,7 +335,7 @@ mod tests { Response::Announce(r) => { dbg!(r); } - other => panic!("unexpected response {other:?}"), + other => panic!("unexpected response {:?}", other), } } }