-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): [#191] add scrape app service
- Loading branch information
1 parent
c4bee79
commit ae1a076
Showing
8 changed files
with
45 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::extract::State; | ||
use axum::http::StatusCode; | ||
use axum::response::{IntoResponse, Response}; | ||
use log::debug; | ||
|
||
use crate::http::axum_implementation::extractors::peer_ip; | ||
use crate::http::axum_implementation::extractors::remote_client_ip::RemoteClientIp; | ||
use crate::http::axum_implementation::extractors::scrape_request::ExtractRequest; | ||
use crate::http::axum_implementation::services; | ||
use crate::tracker::Tracker; | ||
|
||
#[allow(clippy::unused_async)] | ||
pub async fn handle( | ||
State(tracker): State<Arc<Tracker>>, | ||
ExtractRequest(scrape_request): ExtractRequest, | ||
_remote_client_ip: RemoteClientIp, | ||
) -> String { | ||
remote_client_ip: RemoteClientIp, | ||
) -> Response { | ||
debug!("http scrape request: {:#?}", &scrape_request); | ||
|
||
/* | ||
todo: | ||
- Add the service that sends the event for statistics. | ||
- Build the HTTP bencoded response. | ||
- [x] Add the service that sends the event for statistics. | ||
- [ ] Build the HTTP bencoded response. | ||
*/ | ||
|
||
let scrape_data = tracker.scrape(&scrape_request.info_hashes).await; | ||
let peer_ip = match peer_ip::resolve(tracker.config.on_reverse_proxy, &remote_client_ip) { | ||
Ok(peer_ip) => peer_ip, | ||
Err(err) => return err, | ||
}; | ||
|
||
let scrape_data = services::scrape::invoke(tracker.clone(), &scrape_request.info_hashes, &peer_ip).await; | ||
|
||
debug!("scrape data: {:#?}", &scrape_data); | ||
|
||
"todo".to_string() | ||
(StatusCode::OK, "todo").into_response() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod announce; | ||
pub mod scrape; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::net::IpAddr; | ||
use std::sync::Arc; | ||
|
||
use crate::protocol::info_hash::InfoHash; | ||
use crate::tracker::{statistics, ScrapeData, Tracker}; | ||
|
||
pub async fn invoke(tracker: Arc<Tracker>, info_hashes: &Vec<InfoHash>, original_peer_ip: &IpAddr) -> ScrapeData { | ||
let scrape_data = tracker.scrape(info_hashes).await; | ||
|
||
match original_peer_ip { | ||
IpAddr::V4(_) => { | ||
tracker.send_stats_event(statistics::Event::Tcp4Scrape).await; | ||
} | ||
IpAddr::V6(_) => { | ||
tracker.send_stats_event(statistics::Event::Tcp6Scrape).await; | ||
} | ||
} | ||
|
||
scrape_data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters