mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
update UDP scrapper config api
This commit is contained in:
parent
3b0dd1942f
commit
1150f93817
2 changed files with 32 additions and 7 deletions
|
|
@ -54,18 +54,20 @@ pub struct Config {
|
||||||
#[arg(long, short, default_value_t = 8000)]
|
#[arg(long, short, default_value_t = 8000)]
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
|
||||||
/// Bind local UDP client for `scrape_udp_server`
|
/// Bind local UDP socket on given address
|
||||||
///
|
///
|
||||||
/// * not in use if the `scrape_udp_server` is not set
|
/// * the default UDP server is not in use without the optional `scrape` argument value
|
||||||
#[arg(long, default_values_t = vec![
|
#[arg(long, default_values_t = vec![
|
||||||
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0)),
|
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0)),
|
||||||
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 0, 0, 0))
|
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 0, 0, 0))
|
||||||
])]
|
])]
|
||||||
pub scrape_udp_client: Vec<SocketAddr>,
|
pub udp: Vec<SocketAddr>,
|
||||||
|
|
||||||
/// Scrape given UDP trackers to display peers/seeders/leechers info
|
/// Scrape given trackers (to display peers/seeders/leechers info)
|
||||||
|
///
|
||||||
|
/// * supports multi-stack IPv4/IPv6 trackers
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub scrape_udp_server: Option<Vec<SocketAddr>>,
|
pub scrape: Option<Vec<Url>>,
|
||||||
|
|
||||||
/// Configure instance in the debug mode
|
/// Configure instance in the debug mode
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
|
|
|
||||||
27
src/main.rs
27
src/main.rs
|
|
@ -121,8 +121,31 @@ fn rocket() -> _ {
|
||||||
);
|
);
|
||||||
let scraper = Scraper::init(
|
let scraper = Scraper::init(
|
||||||
config
|
config
|
||||||
.scrape_udp_server
|
.scrape
|
||||||
.map(|s| (config.scrape_udp_client, s)),
|
.map(|u| {
|
||||||
|
u.into_iter()
|
||||||
|
.map(|url| {
|
||||||
|
use std::str::FromStr;
|
||||||
|
if url.scheme() == "tcp" {
|
||||||
|
todo!("TCP scrape is not implemented")
|
||||||
|
}
|
||||||
|
if url.scheme() != "udp" {
|
||||||
|
todo!("Scheme `{}` is not supported", url.scheme())
|
||||||
|
}
|
||||||
|
std::net::SocketAddr::new(
|
||||||
|
std::net::IpAddr::from_str(
|
||||||
|
url.host_str()
|
||||||
|
.expect("Required valid host value")
|
||||||
|
.trim_start_matches('[')
|
||||||
|
.trim_end_matches(']'),
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
url.port().expect("Required valid port value"),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.map(|a| (config.udp, a)),
|
||||||
);
|
);
|
||||||
let storage = Storage::init(config.preload, config.list_limit, config.capacity).unwrap(); // @TODO handle
|
let storage = Storage::init(config.preload, config.list_limit, config.capacity).unwrap(); // @TODO handle
|
||||||
rocket::build()
|
rocket::build()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue