@@ -7,6 +7,7 @@ use std::sync::Arc;
7
7
use aquatic_udp_protocol:: AnnounceEvent ;
8
8
use axum:: extract:: State ;
9
9
use axum:: response:: { IntoResponse , Response } ;
10
+ use bittorrent_http_tracker_core:: services:: announce:: HttpAnnounceError ;
10
11
use bittorrent_http_tracker_protocol:: v1:: requests:: announce:: { Announce , Compact , Event } ;
11
12
use bittorrent_http_tracker_protocol:: v1:: responses:: { self } ;
12
13
use bittorrent_http_tracker_protocol:: v1:: services:: peer_ip_resolver:: ClientIpSources ;
@@ -111,7 +112,12 @@ async fn handle(
111
112
. await
112
113
{
113
114
Ok ( announce_data) => announce_data,
114
- Err ( error) => return ( StatusCode :: OK , error. write ( ) ) . into_response ( ) ,
115
+ Err ( error) => {
116
+ let error_response = responses:: error:: Error {
117
+ failure_reason : error. to_string ( ) ,
118
+ } ;
119
+ return ( StatusCode :: OK , error_response. write ( ) ) . into_response ( ) ;
120
+ }
115
121
} ;
116
122
build_response ( announce_request, announce_data)
117
123
}
@@ -126,7 +132,7 @@ async fn handle_announce(
126
132
announce_request : & Announce ,
127
133
client_ip_sources : & ClientIpSources ,
128
134
maybe_key : Option < Key > ,
129
- ) -> Result < AnnounceData , responses :: error :: Error > {
135
+ ) -> Result < AnnounceData , HttpAnnounceError > {
130
136
bittorrent_http_tracker_core:: services:: announce:: handle_announce (
131
137
& core_config. clone ( ) ,
132
138
& announce_handler. clone ( ) ,
@@ -290,6 +296,7 @@ mod tests {
290
296
291
297
use std:: str:: FromStr ;
292
298
299
+ use bittorrent_http_tracker_protocol:: v1:: responses;
293
300
use bittorrent_tracker_core:: authentication;
294
301
295
302
use super :: { initialize_private_tracker, sample_announce_request, sample_client_ip_sources} ;
@@ -315,7 +322,14 @@ mod tests {
315
322
. await
316
323
. unwrap_err ( ) ;
317
324
318
- assert_error_response ( & response, "Tracker authentication error: Missing authentication key" ) ;
325
+ let error_response = responses:: error:: Error {
326
+ failure_reason : response. to_string ( ) ,
327
+ } ;
328
+
329
+ assert_error_response (
330
+ & error_response,
331
+ "Tracker core error: Tracker core authentication error: Missing authentication key" ,
332
+ ) ;
319
333
}
320
334
321
335
#[ tokio:: test]
@@ -339,15 +353,21 @@ mod tests {
339
353
. await
340
354
. unwrap_err ( ) ;
341
355
356
+ let error_response = responses:: error:: Error {
357
+ failure_reason : response. to_string ( ) ,
358
+ } ;
359
+
342
360
assert_error_response (
343
- & response ,
344
- "Tracker authentication error: Failed to read key: YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ" ,
361
+ & error_response ,
362
+ "Tracker core error: Tracker core authentication error: Failed to read key: YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ" ,
345
363
) ;
346
364
}
347
365
}
348
366
349
367
mod with_tracker_in_listed_mode {
350
368
369
+ use bittorrent_http_tracker_protocol:: v1:: responses;
370
+
351
371
use super :: { initialize_listed_tracker, sample_announce_request, sample_client_ip_sources} ;
352
372
use crate :: v1:: handlers:: announce:: handle_announce;
353
373
use crate :: v1:: handlers:: announce:: tests:: assert_error_response;
@@ -371,10 +391,14 @@ mod tests {
371
391
. await
372
392
. unwrap_err ( ) ;
373
393
394
+ let error_response = responses:: error:: Error {
395
+ failure_reason : response. to_string ( ) ,
396
+ } ;
397
+
374
398
assert_error_response (
375
- & response ,
399
+ & error_response ,
376
400
& format ! (
377
- "Tracker whitelist error: The torrent: {}, is not whitelisted" ,
401
+ "Tracker core error: Tracker core whitelist error: The torrent: {}, is not whitelisted" ,
378
402
announce_request. info_hash
379
403
) ,
380
404
) ;
@@ -383,6 +407,7 @@ mod tests {
383
407
384
408
mod with_tracker_on_reverse_proxy {
385
409
410
+ use bittorrent_http_tracker_protocol:: v1:: responses;
386
411
use bittorrent_http_tracker_protocol:: v1:: services:: peer_ip_resolver:: ClientIpSources ;
387
412
388
413
use super :: { initialize_tracker_on_reverse_proxy, sample_announce_request} ;
@@ -411,15 +436,20 @@ mod tests {
411
436
. await
412
437
. unwrap_err ( ) ;
413
438
439
+ let error_response = responses:: error:: Error {
440
+ failure_reason : response. to_string ( ) ,
441
+ } ;
442
+
414
443
assert_error_response (
415
- & response ,
444
+ & error_response ,
416
445
"Error resolving peer IP: missing or invalid the right most X-Forwarded-For IP" ,
417
446
) ;
418
447
}
419
448
}
420
449
421
450
mod with_tracker_not_on_reverse_proxy {
422
451
452
+ use bittorrent_http_tracker_protocol:: v1:: responses;
423
453
use bittorrent_http_tracker_protocol:: v1:: services:: peer_ip_resolver:: ClientIpSources ;
424
454
425
455
use super :: { initialize_tracker_not_on_reverse_proxy, sample_announce_request} ;
@@ -448,8 +478,12 @@ mod tests {
448
478
. await
449
479
. unwrap_err ( ) ;
450
480
481
+ let error_response = responses:: error:: Error {
482
+ failure_reason : response. to_string ( ) ,
483
+ } ;
484
+
451
485
assert_error_response (
452
- & response ,
486
+ & error_response ,
453
487
"Error resolving peer IP: cannot get the client IP from the connection info" ,
454
488
) ;
455
489
}
0 commit comments