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 7fe648c
Show file tree
Hide file tree
Showing 57 changed files with 85 additions and 598 deletions.
2 changes: 1 addition & 1 deletion contrib/bencode/src/access/bencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait BRefAccessExt<'a>: BRefAccess {
fn bytes_ext(&self) -> Option<&'a [u8]>;
}

impl<'a, T> BRefAccess for &'a T
impl<T> BRefAccess for &T
where
T: BRefAccess,
{
Expand Down
6 changes: 3 additions & 3 deletions packages/located-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
location: Box<Location<'a>>,
}

impl<'a, E> std::fmt::Display for LocatedError<'a, E>
impl<E> std::fmt::Display for LocatedError<'_, E>
where
E: Error + ?Sized + Send + Sync,
{
Expand All @@ -59,7 +59,7 @@ where
}
}

impl<'a, E> Error for LocatedError<'a, E>
impl<E> Error for LocatedError<'_, E>
where
E: Error + ?Sized + Send + Sync + 'static,
{
Expand All @@ -68,7 +68,7 @@ where
}
}

impl<'a, E> Clone for LocatedError<'a, E>
impl<E> Clone for LocatedError<'_, E>
where
E: Error + ?Sized + Send + Sync,
{
Expand Down
220 changes: 0 additions & 220 deletions packages/primitives/src/info_hash.rs

This file was deleted.

11 changes: 5 additions & 6 deletions packages/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
//! 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 std::collections::BTreeMap;
use std::time::Duration;

use bittorrent_primitives::info_hash::InfoHash;

/// 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
Loading

0 comments on commit 7fe648c

Please sign in to comment.