Skip to content

Commit

Permalink
refactor: replace InfoHash with external extracted crate
Browse files Browse the repository at this point in the history
The `InfoHash` struct has been extracted into a new crate to be reused
in other projects like the Torrust Index:

https://github.com/torrust/bittorrent-primitives
  • Loading branch information
josecelano committed Oct 30, 2024
1 parent 7d7dba5 commit 874b3c7
Show file tree
Hide file tree
Showing 55 changed files with 80 additions and 594 deletions.
220 changes: 0 additions & 220 deletions packages/primitives/src/info_hash.rs

This file was deleted.

10 changes: 4 additions & 6 deletions packages/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
//! which is a `BitTorrent` tracker server. These structures are used not only
//! by the tracker server crate, but also by other crates in the Torrust
//! ecosystem.
use std::collections::BTreeMap;
use std::time::Duration;

use info_hash::InfoHash;

pub mod info_hash;
pub mod pagination;
pub mod peer;
pub mod swarm_metadata;
pub mod torrent_metrics;

use bittorrent_primitives::info_hash::InfoHash;
use std::collections::BTreeMap;
use std::time::Duration;

/// Duration since the Unix Epoch.
pub type DurationSinceUnixEpoch = Duration;

Expand Down
2 changes: 1 addition & 1 deletion packages/torrent-repository/benches/helpers/asyn.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;
use std::time::{Duration, Instant};

use bittorrent_primitives::info_hash::InfoHash;
use futures::stream::FuturesUnordered;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_torrent_repository::repository::RepositoryAsync;

use super::utils::{generate_unique_info_hashes, DEFAULT_PEER};
Expand Down
2 changes: 1 addition & 1 deletion packages/torrent-repository/benches/helpers/sync.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;
use std::time::{Duration, Instant};

use bittorrent_primitives::info_hash::InfoHash;
use futures::stream::FuturesUnordered;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_torrent_repository::repository::Repository;

use super::utils::{generate_unique_info_hashes, DEFAULT_PEER};
Expand Down
2 changes: 1 addition & 1 deletion packages/torrent-repository/benches/helpers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes, PeerId};
use torrust_tracker_primitives::info_hash::InfoHash;
use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::peer::Peer;
use torrust_tracker_primitives::DurationSinceUnixEpoch;
use zerocopy::I64;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use bittorrent_primitives::info_hash::InfoHash;
use dashmap::DashMap;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
2 changes: 1 addition & 1 deletion packages/torrent-repository/src/repository/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
4 changes: 2 additions & 2 deletions packages/torrent-repository/src/repository/rw_lock_std.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand All @@ -21,7 +21,7 @@ impl<T> RwLockStd<T> {
/// Panics if unable to get a lock.
pub fn write(
&self,
) -> std::sync::RwLockWriteGuard<'_, std::collections::BTreeMap<torrust_tracker_primitives::info_hash::InfoHash, T>> {
) -> std::sync::RwLockWriteGuard<'_, std::collections::BTreeMap<bittorrent_primitives::info_hash::InfoHash, T>> {
self.torrents.write().expect("it should get lock")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::iter::zip;
use std::pin::Pin;
use std::sync::Arc;

use bittorrent_primitives::info_hash::InfoHash;
use futures::future::join_all;
use futures::{Future, FutureExt};
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
7 changes: 2 additions & 5 deletions packages/torrent-repository/src/repository/rw_lock_tokio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand All @@ -19,10 +19,7 @@ impl<T> RwLockTokio<T> {
pub fn write(
&self,
) -> impl std::future::Future<
Output = tokio::sync::RwLockWriteGuard<
'_,
std::collections::BTreeMap<torrust_tracker_primitives::info_hash::InfoHash, T>,
>,
Output = tokio::sync::RwLockWriteGuard<'_, std::collections::BTreeMap<bittorrent_primitives::info_hash::InfoHash, T>>,
> {
self.torrents.write()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use bittorrent_primitives::info_hash::InfoHash;
use crossbeam_skiplist::SkipMap;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
2 changes: 1 addition & 1 deletion packages/torrent-repository/tests/common/repo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bittorrent_primitives::info_hash::InfoHash;
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
Expand Down
2 changes: 1 addition & 1 deletion packages/torrent-repository/tests/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::collections::{BTreeMap, HashSet};
use std::hash::{DefaultHasher, Hash, Hasher};

use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes};
use bittorrent_primitives::info_hash::InfoHash;
use rstest::{fixture, rstest};
use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::PersistentTorrents;
Expand Down
Loading

0 comments on commit 874b3c7

Please sign in to comment.