Skip to content

Commit 3fbab31

Browse files
committed
refactor: [#1002] rename is_good fn to meets_retaining_policy
A "good" torrent means it should be retained in the repository according to the tracker policy. It should not be removed (even if it does not have any peers).
1 parent 1766587 commit 3fbab31

17 files changed

Lines changed: 36 additions & 36 deletions

packages/torrent-repository/src/entry/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait Entry {
2222
fn get_swarm_metadata(&self) -> SwarmMetadata;
2323

2424
/// Returns True if Still a Valid Entry according to the Tracker Policy
25-
fn is_good(&self, policy: &TrackerPolicy) -> bool;
25+
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool;
2626

2727
/// Returns True if the Peers is Empty
2828
fn peers_is_empty(&self) -> bool;
@@ -53,7 +53,7 @@ pub trait Entry {
5353
#[allow(clippy::module_name_repetitions)]
5454
pub trait EntrySync {
5555
fn get_swarm_metadata(&self) -> SwarmMetadata;
56-
fn is_good(&self, policy: &TrackerPolicy) -> bool;
56+
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool;
5757
fn peers_is_empty(&self) -> bool;
5858
fn get_peers_len(&self) -> usize;
5959
fn get_peers(&self, limit: Option<usize>) -> Vec<Arc<peer::Peer>>;
@@ -65,7 +65,7 @@ pub trait EntrySync {
6565
#[allow(clippy::module_name_repetitions)]
6666
pub trait EntryAsync {
6767
fn get_swarm_metadata(&self) -> impl std::future::Future<Output = SwarmMetadata> + Send;
68-
fn check_good(self, policy: &TrackerPolicy) -> impl std::future::Future<Output = bool> + Send;
68+
fn meets_retaining_policy(self, policy: &TrackerPolicy) -> impl std::future::Future<Output = bool> + Send;
6969
fn peers_is_empty(&self) -> impl std::future::Future<Output = bool> + Send;
7070
fn get_peers_len(&self) -> impl std::future::Future<Output = usize> + Send;
7171
fn get_peers(&self, limit: Option<usize>) -> impl std::future::Future<Output = Vec<Arc<peer::Peer>>> + Send;

packages/torrent-repository/src/entry/mutex_parking_lot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl EntrySync for EntryMutexParkingLot {
1313
self.lock().get_swarm_metadata()
1414
}
1515

16-
fn is_good(&self, policy: &TrackerPolicy) -> bool {
17-
self.lock().is_good(policy)
16+
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool {
17+
self.lock().meets_retaining_policy(policy)
1818
}
1919

2020
fn peers_is_empty(&self) -> bool {

packages/torrent-repository/src/entry/mutex_std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl EntrySync for EntryMutexStd {
1313
self.lock().expect("it should get a lock").get_swarm_metadata()
1414
}
1515

16-
fn is_good(&self, policy: &TrackerPolicy) -> bool {
17-
self.lock().expect("it should get a lock").is_good(policy)
16+
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool {
17+
self.lock().expect("it should get a lock").meets_retaining_policy(policy)
1818
}
1919

2020
fn peers_is_empty(&self) -> bool {

packages/torrent-repository/src/entry/mutex_tokio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl EntryAsync for EntryMutexTokio {
1313
self.lock().await.get_swarm_metadata()
1414
}
1515

16-
async fn check_good(self, policy: &TrackerPolicy) -> bool {
17-
self.lock().await.is_good(policy)
16+
async fn meets_retaining_policy(self, policy: &TrackerPolicy) -> bool {
17+
self.lock().await.meets_retaining_policy(policy)
1818
}
1919

2020
async fn peers_is_empty(&self) -> bool {

packages/torrent-repository/src/entry/rw_lock_parking_lot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl EntrySync for EntryRwLockParkingLot {
1313
self.read().get_swarm_metadata()
1414
}
1515

16-
fn is_good(&self, policy: &TrackerPolicy) -> bool {
17-
self.read().is_good(policy)
16+
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool {
17+
self.read().meets_retaining_policy(policy)
1818
}
1919

2020
fn peers_is_empty(&self) -> bool {

packages/torrent-repository/src/entry/single.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Entry for EntrySingle {
2222
}
2323
}
2424

25-
fn is_good(&self, policy: &TrackerPolicy) -> bool {
25+
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool {
2626
if policy.persistent_torrent_completed_stat && self.downloaded > 0 {
2727
return true;
2828
}

packages/torrent-repository/src/repository/dash_map_mutex_std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ where
103103
}
104104

105105
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) {
106-
self.torrents.retain(|_, entry| entry.is_good(policy));
106+
self.torrents.retain(|_, entry| entry.meets_retaining_policy(policy));
107107
}
108108
}

packages/torrent-repository/src/repository/rw_lock_std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ where
126126
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) {
127127
let mut db = self.get_torrents_mut();
128128

129-
db.retain(|_, e| e.is_good(policy));
129+
db.retain(|_, e| e.meets_retaining_policy(policy));
130130
}
131131
}

packages/torrent-repository/src/repository/rw_lock_std_mutex_std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ where
124124
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) {
125125
let mut db = self.get_torrents_mut();
126126

127-
db.retain(|_, e| e.lock().expect("it should lock entry").is_good(policy));
127+
db.retain(|_, e| e.lock().expect("it should lock entry").meets_retaining_policy(policy));
128128
}
129129
}

packages/torrent-repository/src/repository/rw_lock_std_mutex_tokio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ where
143143
handles = zip(db.keys().copied(), db.values().cloned())
144144
.map(|(infohash, torrent)| {
145145
torrent
146-
.check_good(policy)
147-
.map(move |good| if good { None } else { Some(infohash) })
146+
.meets_retaining_policy(policy)
147+
.map(move |should_be_retained| if should_be_retained { None } else { Some(infohash) })
148148
.boxed()
149149
})
150150
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)