Skip to content

Commit 8c31549

Browse files
committed
refactor: [#1524] rename methods
1 parent 28603fe commit 8c31549

File tree

16 files changed

+46
-46
lines changed

16 files changed

+46
-46
lines changed

packages/axum-http-tracker-server/src/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<S> Environment<S> {
2929
self.container
3030
.tracker_core_container
3131
.in_memory_torrent_repository
32-
.upsert_peer(info_hash, peer, None)
32+
.handle_announcement(info_hash, peer, None)
3333
.await
3434
}
3535
}

packages/axum-rest-tracker-api-server/src/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ where
3737
self.container
3838
.tracker_core_container
3939
.in_memory_torrent_repository
40-
.upsert_peer(info_hash, peer, None)
40+
.handle_announcement(info_hash, peer, None)
4141
.await
4242
}
4343
}

packages/http-tracker-core/src/services/announce.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl AnnounceService {
8787

8888
let announce_data = self
8989
.announce_handler
90-
.announce(
90+
.handle_announcement(
9191
&announce_request.info_hash,
9292
&mut peer,
9393
&remote_client_addr.ip(),

packages/http-tracker-core/src/services/scrape.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl ScrapeService {
7878
let scrape_data = if self.authentication_is_required() && !self.is_authenticated(maybe_key).await {
7979
ScrapeData::zeroed(&scrape_request.info_hashes)
8080
} else {
81-
self.scrape_handler.scrape(&scrape_request.info_hashes).await?
81+
self.scrape_handler.handle_scrape(&scrape_request.info_hashes).await?
8282
};
8383

8484
let remote_client_addr = resolve_remote_client_addr(&self.core_config.net.on_reverse_proxy.into(), client_ip_sources)?;
@@ -291,7 +291,7 @@ mod tests {
291291
let original_peer_ip = peer.ip();
292292
container
293293
.announce_handler
294-
.announce(&info_hash, &mut peer, &original_peer_ip, &PeersWanted::AsManyAsPossible)
294+
.handle_announcement(&info_hash, &mut peer, &original_peer_ip, &PeersWanted::AsManyAsPossible)
295295
.await
296296
.unwrap();
297297

@@ -482,7 +482,7 @@ mod tests {
482482
let original_peer_ip = peer.ip();
483483
container
484484
.announce_handler
485-
.announce(&info_hash, &mut peer, &original_peer_ip, &PeersWanted::AsManyAsPossible)
485+
.handle_announcement(&info_hash, &mut peer, &original_peer_ip, &PeersWanted::AsManyAsPossible)
486486
.await
487487
.unwrap();
488488

packages/tracker-core/src/announce_handler.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl AnnounceHandler {
154154
///
155155
/// Returns an error if the tracker is running in `listed` mode and the
156156
/// torrent is not whitelisted.
157-
pub async fn announce(
157+
pub async fn handle_announcement(
158158
&self,
159159
info_hash: &InfoHash,
160160
peer: &mut peer::Peer,
@@ -178,7 +178,7 @@ impl AnnounceHandler {
178178

179179
let _number_of_downloads_increased = self
180180
.in_memory_torrent_repository
181-
.upsert_peer(info_hash, peer, opt_persistent_torrent)
181+
.handle_announcement(info_hash, peer, opt_persistent_torrent)
182182
.await;
183183

184184
Ok(self.build_announce_data(info_hash, peer, peers_wanted).await)
@@ -456,7 +456,7 @@ mod tests {
456456
let mut peer = sample_peer();
457457

458458
let announce_data = announce_handler
459-
.announce(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
459+
.handle_announcement(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
460460
.await
461461
.unwrap();
462462

@@ -469,7 +469,7 @@ mod tests {
469469

470470
let mut previously_announced_peer = sample_peer_1();
471471
announce_handler
472-
.announce(
472+
.handle_announcement(
473473
&sample_info_hash(),
474474
&mut previously_announced_peer,
475475
&peer_ip(),
@@ -480,7 +480,7 @@ mod tests {
480480

481481
let mut peer = sample_peer_2();
482482
let announce_data = announce_handler
483-
.announce(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
483+
.handle_announcement(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
484484
.await
485485
.unwrap();
486486

@@ -493,7 +493,7 @@ mod tests {
493493

494494
let mut previously_announced_peer_1 = sample_peer_1();
495495
announce_handler
496-
.announce(
496+
.handle_announcement(
497497
&sample_info_hash(),
498498
&mut previously_announced_peer_1,
499499
&peer_ip(),
@@ -504,7 +504,7 @@ mod tests {
504504

505505
let mut previously_announced_peer_2 = sample_peer_2();
506506
announce_handler
507-
.announce(
507+
.handle_announcement(
508508
&sample_info_hash(),
509509
&mut previously_announced_peer_2,
510510
&peer_ip(),
@@ -515,7 +515,7 @@ mod tests {
515515

516516
let mut peer = sample_peer_3();
517517
let announce_data = announce_handler
518-
.announce(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::only(1))
518+
.handle_announcement(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::only(1))
519519
.await
520520
.unwrap();
521521

@@ -540,7 +540,7 @@ mod tests {
540540
let mut peer = seeder();
541541

542542
let announce_data = announce_handler
543-
.announce(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
543+
.handle_announcement(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
544544
.await
545545
.unwrap();
546546

@@ -554,7 +554,7 @@ mod tests {
554554
let mut peer = leecher();
555555

556556
let announce_data = announce_handler
557-
.announce(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
557+
.handle_announcement(&sample_info_hash(), &mut peer, &peer_ip(), &PeersWanted::AsManyAsPossible)
558558
.await
559559
.unwrap();
560560

@@ -568,7 +568,7 @@ mod tests {
568568
// We have to announce with "started" event because peer does not count if peer was not previously known
569569
let mut started_peer = started_peer();
570570
announce_handler
571-
.announce(
571+
.handle_announcement(
572572
&sample_info_hash(),
573573
&mut started_peer,
574574
&peer_ip(),
@@ -579,7 +579,7 @@ mod tests {
579579

580580
let mut completed_peer = completed_peer();
581581
let announce_data = announce_handler
582-
.announce(
582+
.handle_announcement(
583583
&sample_info_hash(),
584584
&mut completed_peer,
585585
&peer_ip(),

packages/tracker-core/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ mod tests {
203203
// Announce a "complete" peer for the torrent
204204
let mut complete_peer = complete_peer();
205205
announce_handler
206-
.announce(
206+
.handle_announcement(
207207
&info_hash,
208208
&mut complete_peer,
209209
&IpAddr::V4(Ipv4Addr::new(126, 0, 0, 10)),
@@ -215,7 +215,7 @@ mod tests {
215215
// Announce an "incomplete" peer for the torrent
216216
let mut incomplete_peer = incomplete_peer();
217217
announce_handler
218-
.announce(
218+
.handle_announcement(
219219
&info_hash,
220220
&mut incomplete_peer,
221221
&IpAddr::V4(Ipv4Addr::new(126, 0, 0, 11)),
@@ -225,7 +225,7 @@ mod tests {
225225
.unwrap();
226226

227227
// Scrape
228-
let scrape_data = scrape_handler.scrape(&vec![info_hash]).await.unwrap();
228+
let scrape_data = scrape_handler.handle_scrape(&vec![info_hash]).await.unwrap();
229229

230230
// The expected swarm metadata for the torrent
231231
let mut expected_scrape_data = ScrapeData::empty();
@@ -259,7 +259,7 @@ mod tests {
259259

260260
let non_whitelisted_info_hash = "3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0".parse::<InfoHash>().unwrap(); // DevSkim: ignore DS173237
261261

262-
let scrape_data = scrape_handler.scrape(&vec![non_whitelisted_info_hash]).await.unwrap();
262+
let scrape_data = scrape_handler.handle_scrape(&vec![non_whitelisted_info_hash]).await.unwrap();
263263

264264
// The expected zeroed swarm metadata for the file
265265
let mut expected_scrape_data = ScrapeData::empty();

packages/tracker-core/src/scrape_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl ScrapeHandler {
107107
/// # BEP Reference:
108108
///
109109
/// [BEP 48: Scrape Protocol](https://www.bittorrent.org/beps/bep_0048.html)
110-
pub async fn scrape(&self, info_hashes: &Vec<InfoHash>) -> Result<ScrapeData, ScrapeError> {
110+
pub async fn handle_scrape(&self, info_hashes: &Vec<InfoHash>) -> Result<ScrapeData, ScrapeError> {
111111
let mut scrape_data = ScrapeData::empty();
112112

113113
for info_hash in info_hashes {
@@ -158,7 +158,7 @@ mod tests {
158158

159159
let info_hashes = vec!["3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0".parse::<InfoHash>().unwrap()]; // DevSkim: ignore DS173237
160160

161-
let scrape_data = scrape_handler.scrape(&info_hashes).await.unwrap();
161+
let scrape_data = scrape_handler.handle_scrape(&info_hashes).await.unwrap();
162162

163163
let mut expected_scrape_data = ScrapeData::empty();
164164

@@ -176,7 +176,7 @@ mod tests {
176176
"99c82bb73505a3c0b453f9fa0e881d6e5a32a0c1".parse::<InfoHash>().unwrap(), // DevSkim: ignore DS173237
177177
];
178178

179-
let scrape_data = scrape_handler.scrape(&info_hashes).await.unwrap();
179+
let scrape_data = scrape_handler.handle_scrape(&info_hashes).await.unwrap();
180180

181181
let mut expected_scrape_data = ScrapeData::empty();
182182
expected_scrape_data.add_file_with_zeroed_metadata(&info_hashes[0]);

packages/tracker-core/src/torrent/manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ mod tests {
241241
peer.updated = DurationSinceUnixEpoch::new(0, 0);
242242
let _number_of_downloads_increased = services
243243
.in_memory_torrent_repository
244-
.upsert_peer(&infohash, &peer, None)
244+
.handle_announcement(&infohash, &peer, None)
245245
.await;
246246

247247
// Simulate the time has passed 1 second more than the max peer timeout.
@@ -259,7 +259,7 @@ mod tests {
259259
// Add a peer to the torrent
260260
let mut peer = sample_peer();
261261
peer.updated = DurationSinceUnixEpoch::new(0, 0);
262-
let _number_of_downloads_increased = in_memory_torrent_repository.upsert_peer(infohash, &peer, None).await;
262+
let _number_of_downloads_increased = in_memory_torrent_repository.handle_announcement(infohash, &peer, None).await;
263263

264264
// Remove the peer. The torrent is now peerless.
265265
in_memory_torrent_repository

packages/tracker-core/src/torrent/repository/in_memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl InMemoryTorrentRepository {
4949
///
5050
/// This function panics if the underling swarms return an error.
5151
#[must_use]
52-
pub async fn upsert_peer(
52+
pub async fn handle_announcement(
5353
&self,
5454
info_hash: &InfoHash,
5555
peer: &peer::Peer,

packages/tracker-core/src/torrent/services.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ mod tests {
252252
let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned(); // DevSkim: ignore DS173237
253253
let info_hash = InfoHash::from_str(&hash).unwrap();
254254
let _number_of_downloads_increased = in_memory_torrent_repository
255-
.upsert_peer(&info_hash, &sample_peer(), None)
255+
.handle_announcement(&info_hash, &sample_peer(), None)
256256
.await;
257257

258258
let torrent_info = get_torrent_info(&in_memory_torrent_repository, &info_hash).await.unwrap();
@@ -298,7 +298,7 @@ mod tests {
298298
let info_hash = InfoHash::from_str(&hash).unwrap();
299299

300300
let _number_of_downloads_increased = in_memory_torrent_repository
301-
.upsert_peer(&info_hash, &sample_peer(), None)
301+
.handle_announcement(&info_hash, &sample_peer(), None)
302302
.await;
303303

304304
let torrents = get_torrents_page(&in_memory_torrent_repository, Some(&Pagination::default())).await;
@@ -325,10 +325,10 @@ mod tests {
325325
let info_hash2 = InfoHash::from_str(&hash2).unwrap();
326326

327327
let _number_of_downloads_increased = in_memory_torrent_repository
328-
.upsert_peer(&info_hash1, &sample_peer(), None)
328+
.handle_announcement(&info_hash1, &sample_peer(), None)
329329
.await;
330330
let _number_of_downloads_increased = in_memory_torrent_repository
331-
.upsert_peer(&info_hash2, &sample_peer(), None)
331+
.handle_announcement(&info_hash2, &sample_peer(), None)
332332
.await;
333333

334334
let offset = 0;
@@ -350,10 +350,10 @@ mod tests {
350350
let info_hash2 = InfoHash::from_str(&hash2).unwrap();
351351

352352
let _number_of_downloads_increased = in_memory_torrent_repository
353-
.upsert_peer(&info_hash1, &sample_peer(), None)
353+
.handle_announcement(&info_hash1, &sample_peer(), None)
354354
.await;
355355
let _number_of_downloads_increased = in_memory_torrent_repository
356-
.upsert_peer(&info_hash2, &sample_peer(), None)
356+
.handle_announcement(&info_hash2, &sample_peer(), None)
357357
.await;
358358

359359
let offset = 1;
@@ -380,13 +380,13 @@ mod tests {
380380
let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned(); // DevSkim: ignore DS173237
381381
let info_hash1 = InfoHash::from_str(&hash1).unwrap();
382382
let _number_of_downloads_increased = in_memory_torrent_repository
383-
.upsert_peer(&info_hash1, &sample_peer(), None)
383+
.handle_announcement(&info_hash1, &sample_peer(), None)
384384
.await;
385385

386386
let hash2 = "03840548643af2a7b63a9f5cbca348bc7150ca3a".to_owned(); // DevSkim: ignore DS173237
387387
let info_hash2 = InfoHash::from_str(&hash2).unwrap();
388388
let _number_of_downloads_increased = in_memory_torrent_repository
389-
.upsert_peer(&info_hash2, &sample_peer(), None)
389+
.handle_announcement(&info_hash2, &sample_peer(), None)
390390
.await;
391391

392392
let torrents = get_torrents_page(&in_memory_torrent_repository, Some(&Pagination::default())).await;
@@ -436,7 +436,7 @@ mod tests {
436436
let info_hash = sample_info_hash();
437437

438438
let _ = in_memory_torrent_repository
439-
.upsert_peer(&info_hash, &sample_peer(), None)
439+
.handle_announcement(&info_hash, &sample_peer(), None)
440440
.await;
441441

442442
let torrent_info = get_torrents(&in_memory_torrent_repository, &[info_hash]).await;

0 commit comments

Comments
 (0)