Skip to content

Commit

Permalink
feat: [#675] tracker checker (HTTP tracker) supports more service add…
Browse files Browse the repository at this point in the history
…ress formats

Now it supports a path prefix. It will be remove by the client to build
the "scrape" URLs.

This type of URL is very common in tracker lists like in
https://newtrackon.com/.

```console
TORRUST_CHECKER_CONFIG='{
    "udp_trackers": [],
    "http_trackers": [
	"http://127.0.0.1:7070",
	"http://127.0.0.1:7070/",
	"http://127.0.0.1:7070/announce"
    ],
    "health_checks": []
}' cargo run --bin tracker_checker
```
  • Loading branch information
josecelano committed Sep 12, 2024
1 parent 520026d commit faee02f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/console/clients/checker/checks/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@ pub async fn run(http_trackers: Vec<Url>, timeout: Duration) -> Vec<Result<Check
tracing::debug!("HTTP trackers ...");

for ref url in http_trackers {
let mut base_url = url.clone();
base_url.set_path("");

let mut checks = Checks {
url: url.clone(),
results: Vec::default(),
};

// Announce
{
let check = check_http_announce(url, timeout).await.map(|_| ());
let check = check_http_announce(&base_url, timeout).await.map(|_| ());

checks.results.push((Check::Announce, check));
}

// Scrape
{
let check = check_http_scrape(url, timeout).await.map(|_| ());
let check = check_http_scrape(&base_url, timeout).await.map(|_| ());

checks.results.push((Check::Scrape, check));
}
Expand Down
37 changes: 36 additions & 1 deletion src/console/clients/checker/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod tests {
}

mod http_trackers {
use crate::console::clients::checker::config::{Configuration, PlainConfiguration};
use crate::console::clients::checker::config::{Configuration, PlainConfiguration, ServiceUrl};

#[test]
fn it_should_fail_when_a_tracker_http_url_is_invalid() {
Expand All @@ -227,6 +227,41 @@ mod tests {

assert!(Configuration::try_from(plain_config).is_err());
}

#[test]
fn it_should_allow_the_url_to_contain_a_path() {
// This is the common format for HTTP tracker URLs:
// http://domain.com:7070/announce

let plain_config = PlainConfiguration {
udp_trackers: vec![],
http_trackers: vec!["http://127.0.0.1:7070/announce".to_string()],
health_checks: vec![],
};

let config = Configuration::try_from(plain_config).expect("Invalid plain configuration");

assert_eq!(
config.http_trackers[0],
"http://127.0.0.1:7070/announce".parse::<ServiceUrl>().unwrap()
);
}

#[test]
fn it_should_allow_the_url_to_contain_an_empty_path() {
let plain_config = PlainConfiguration {
udp_trackers: vec![],
http_trackers: vec!["http://127.0.0.1:7070/".to_string()],
health_checks: vec![],
};

let config = Configuration::try_from(plain_config).expect("Invalid plain configuration");

assert_eq!(
config.http_trackers[0],
"http://127.0.0.1:7070/".parse::<ServiceUrl>().unwrap()
);
}
}

mod health_checks {
Expand Down

0 comments on commit faee02f

Please sign in to comment.