Skip to content

Commit 1b01bf0

Browse files
committed
refactor: [torrust#1338] rearrange code
1 parent ec0e437 commit 1b01bf0

File tree

1 file changed

+52
-49
lines changed
  • packages/http-tracker-core/src/services

1 file changed

+52
-49
lines changed

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

+52-49
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,6 @@ use torrust_tracker_primitives::core::ScrapeData;
2222

2323
use crate::statistics;
2424

25-
/// Errors related to announce requests.
26-
#[derive(thiserror::Error, Debug, Clone)]
27-
pub enum HttpScrapeError {
28-
#[error("Error resolving peer IP: {source}")]
29-
PeerIpResolutionError { source: PeerIpResolutionError },
30-
31-
#[error("Tracker core error: {source}")]
32-
TrackerCoreError { source: TrackerCoreError },
33-
}
34-
35-
impl From<PeerIpResolutionError> for HttpScrapeError {
36-
fn from(peer_ip_resolution_error: PeerIpResolutionError) -> Self {
37-
Self::PeerIpResolutionError {
38-
source: peer_ip_resolution_error,
39-
}
40-
}
41-
}
42-
43-
impl From<TrackerCoreError> for HttpScrapeError {
44-
fn from(tracker_core_error: TrackerCoreError) -> Self {
45-
Self::TrackerCoreError {
46-
source: tracker_core_error,
47-
}
48-
}
49-
}
50-
51-
impl From<ScrapeError> for HttpScrapeError {
52-
fn from(announce_error: ScrapeError) -> Self {
53-
Self::TrackerCoreError {
54-
source: announce_error.into(),
55-
}
56-
}
57-
}
58-
59-
impl From<WhitelistError> for HttpScrapeError {
60-
fn from(whitelist_error: WhitelistError) -> Self {
61-
Self::TrackerCoreError {
62-
source: whitelist_error.into(),
63-
}
64-
}
65-
}
66-
67-
impl From<authentication::key::Error> for HttpScrapeError {
68-
fn from(whitelist_error: authentication::key::Error) -> Self {
69-
Self::TrackerCoreError {
70-
source: whitelist_error.into(),
71-
}
72-
}
73-
}
7425
/// The HTTP tracker `scrape` service.
7526
///
7627
/// The service sends an statistics event that increments:
@@ -110,6 +61,8 @@ impl ScrapeService {
11061
}
11162
}
11263

64+
/// Handles a scrape request.
65+
///
11366
/// # Errors
11467
///
11568
/// This function will return an error if:
@@ -186,6 +139,56 @@ async fn send_scrape_event(
186139
}
187140
}
188141

142+
/// Errors related to announce requests.
143+
#[derive(thiserror::Error, Debug, Clone)]
144+
pub enum HttpScrapeError {
145+
#[error("Error resolving peer IP: {source}")]
146+
PeerIpResolutionError { source: PeerIpResolutionError },
147+
148+
#[error("Tracker core error: {source}")]
149+
TrackerCoreError { source: TrackerCoreError },
150+
}
151+
152+
impl From<PeerIpResolutionError> for HttpScrapeError {
153+
fn from(peer_ip_resolution_error: PeerIpResolutionError) -> Self {
154+
Self::PeerIpResolutionError {
155+
source: peer_ip_resolution_error,
156+
}
157+
}
158+
}
159+
160+
impl From<TrackerCoreError> for HttpScrapeError {
161+
fn from(tracker_core_error: TrackerCoreError) -> Self {
162+
Self::TrackerCoreError {
163+
source: tracker_core_error,
164+
}
165+
}
166+
}
167+
168+
impl From<ScrapeError> for HttpScrapeError {
169+
fn from(announce_error: ScrapeError) -> Self {
170+
Self::TrackerCoreError {
171+
source: announce_error.into(),
172+
}
173+
}
174+
}
175+
176+
impl From<WhitelistError> for HttpScrapeError {
177+
fn from(whitelist_error: WhitelistError) -> Self {
178+
Self::TrackerCoreError {
179+
source: whitelist_error.into(),
180+
}
181+
}
182+
}
183+
184+
impl From<authentication::key::Error> for HttpScrapeError {
185+
fn from(whitelist_error: authentication::key::Error) -> Self {
186+
Self::TrackerCoreError {
187+
source: whitelist_error.into(),
188+
}
189+
}
190+
}
191+
189192
#[cfg(test)]
190193
mod tests {
191194

0 commit comments

Comments
 (0)