Skip to content

Commit 9cd7e9b

Browse files
committed
test: add tests for udp::handlers:handle_scrape
1 parent c1ede2a commit 9cd7e9b

File tree

3 files changed

+411
-90
lines changed

3 files changed

+411
-90
lines changed

src/tracker/torrent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::peer::TorrentPeer;
88
use crate::protocol::clock::clock::{DefaultClock, TimeNow};
99
use crate::{PeerId, MAX_SCRAPE_TORRENTS};
1010

11-
#[derive(Serialize, Deserialize, Clone)]
11+
#[derive(Serialize, Deserialize, Clone, Debug)]
1212
pub struct TorrentEntry {
1313
#[serde(skip)]
1414
pub peers: std::collections::BTreeMap<PeerId, TorrentPeer>,

src/tracker/tracker.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,20 @@ impl TorrentTracker {
9090

9191
// Adding torrents is not relevant to public trackers.
9292
pub async fn add_torrent_to_whitelist(&self, info_hash: &InfoHash) -> Result<(), database::Error> {
93-
self.database.add_info_hash_to_whitelist(info_hash.clone()).await?;
94-
self.whitelist.write().await.insert(info_hash.clone());
93+
self.add_torrent_to_database_whitelist(info_hash).await?;
94+
self.add_torrent_to_memory_whitelist(info_hash).await;
9595
Ok(())
9696
}
9797

98+
async fn add_torrent_to_database_whitelist(&self, info_hash: &InfoHash) -> Result<(), database::Error> {
99+
self.database.add_info_hash_to_whitelist(*info_hash).await?;
100+
Ok(())
101+
}
102+
103+
pub async fn add_torrent_to_memory_whitelist(&self, info_hash: &InfoHash) -> bool {
104+
self.whitelist.write().await.insert(*info_hash)
105+
}
106+
98107
// Removing torrents is not relevant to public trackers.
99108
pub async fn remove_torrent_from_whitelist(&self, info_hash: &InfoHash) -> Result<(), database::Error> {
100109
self.database.remove_info_hash_from_whitelist(info_hash.clone()).await?;

0 commit comments

Comments
 (0)