@@ -11,7 +11,7 @@ use axum::extract::State;
11
11
use axum:: response:: { IntoResponse , Response } ;
12
12
use bittorrent_http_protocol:: v1:: requests:: scrape:: Scrape ;
13
13
use bittorrent_http_protocol:: v1:: responses;
14
- use bittorrent_http_protocol:: v1:: services:: peer_ip_resolver:: { self , ClientIpSources } ;
14
+ use bittorrent_http_protocol:: v1:: services:: peer_ip_resolver:: ClientIpSources ;
15
15
use bittorrent_tracker_core:: authentication:: service:: AuthenticationService ;
16
16
use bittorrent_tracker_core:: authentication:: Key ;
17
17
use bittorrent_tracker_core:: scrape_handler:: ScrapeHandler ;
@@ -20,7 +20,6 @@ use torrust_tracker_configuration::Core;
20
20
use torrust_tracker_primitives:: core:: ScrapeData ;
21
21
22
22
use crate :: packages:: http_tracker_core;
23
- use crate :: packages:: http_tracker_core:: services;
24
23
use crate :: servers:: http:: v1:: extractors:: authentication_key:: Extract as ExtractKey ;
25
24
use crate :: servers:: http:: v1:: extractors:: client_ip_sources:: Extract as ExtractClientIpSources ;
26
25
use crate :: servers:: http:: v1:: extractors:: scrape_request:: ExtractRequest ;
@@ -111,12 +110,6 @@ async fn handle(
111
110
build_response ( scrape_data)
112
111
}
113
112
114
- /* code-review: authentication, authorization and peer IP resolution could be moved
115
- from the handler (Axum) layer into the app layer `services::announce::invoke`.
116
- That would make the handler even simpler and the code more reusable and decoupled from Axum.
117
- See https://github.com/torrust/torrust-tracker/discussions/240.
118
- */
119
-
120
113
#[ allow( clippy:: too_many_arguments) ]
121
114
async fn handle_scrape (
122
115
core_config : & Arc < Core > ,
@@ -127,6 +120,8 @@ async fn handle_scrape(
127
120
client_ip_sources : & ClientIpSources ,
128
121
maybe_key : Option < Key > ,
129
122
) -> Result < ScrapeData , responses:: error:: Error > {
123
+ // todo: move authentication inside `http_tracker_core::services::scrape::handle_scrape`
124
+
130
125
// Authentication
131
126
let return_real_scrape_data = if core_config. private {
132
127
match maybe_key {
@@ -140,25 +135,16 @@ async fn handle_scrape(
140
135
true
141
136
} ;
142
137
143
- // Authorization for scrape requests is handled at the `Tracker` level
144
- // for each torrent.
145
-
146
- let peer_ip = match peer_ip_resolver:: invoke ( core_config. net . on_reverse_proxy , client_ip_sources) {
147
- Ok ( peer_ip) => peer_ip,
148
- Err ( error) => return Err ( responses:: error:: Error :: from ( error) ) ,
149
- } ;
150
-
151
- if return_real_scrape_data {
152
- Ok ( services:: scrape:: invoke (
153
- scrape_handler,
154
- opt_http_stats_event_sender,
155
- & scrape_request. info_hashes ,
156
- & peer_ip,
157
- )
158
- . await )
159
- } else {
160
- Ok ( services:: scrape:: fake ( opt_http_stats_event_sender, & scrape_request. info_hashes , & peer_ip) . await )
161
- }
138
+ http_tracker_core:: services:: scrape:: handle_scrape (
139
+ core_config,
140
+ scrape_handler,
141
+ authentication_service,
142
+ opt_http_stats_event_sender,
143
+ scrape_request,
144
+ client_ip_sources,
145
+ return_real_scrape_data,
146
+ )
147
+ . await
162
148
}
163
149
164
150
fn build_response ( scrape_data : ScrapeData ) -> Response {
0 commit comments