Skip to content

Commit

Permalink
refactor: add servers modules
Browse files Browse the repository at this point in the history
Move apps into a "servers" module.
  • Loading branch information
josecelano committed Mar 17, 2023
1 parent 0bb295c commit 46f4900
Show file tree
Hide file tree
Showing 81 changed files with 171 additions and 166 deletions.
4 changes: 2 additions & 2 deletions src/jobs/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HttpTracker;

use crate::http::v1::launcher;
use crate::http::Version;
use crate::servers::http::v1::launcher;
use crate::servers::http::Version;
use crate::tracker;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/tracker_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HttpApi;

use crate::apis::server;
use crate::servers::apis::server;
use crate::tracker;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/udp_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use log::{error, info, warn};
use tokio::task::JoinHandle;
use torrust_tracker_configuration::UdpTracker;

use crate::servers::udp::server::Udp;
use crate::tracker;
use crate::udp::server::Udp;

#[must_use]
pub fn start_job(config: &UdpTracker, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
pub mod apis;
pub mod databases;
pub mod http;
pub mod jobs;
pub mod logging;
pub mod protocol;
pub mod servers;
pub mod setup;
pub mod signals;
pub mod stats;
pub mod tracker;
pub mod udp;

#[macro_use]
extern crate lazy_static;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/apis/server.rs → src/servers/apis/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod tests {
use torrust_tracker_configuration::Configuration;
use torrust_tracker_test_helpers::configuration;

use crate::apis::server::ApiServer;
use crate::servers::apis::server::ApiServer;
use crate::tracker;
use crate::tracker::statistics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use serde::Deserialize;
use super::responses::{
auth_key_response, failed_to_delete_key_response, failed_to_generate_key_response, failed_to_reload_keys_response,
};
use crate::apis::v1::context::auth_key::resources::AuthKey;
use crate::apis::v1::responses::{invalid_auth_key_param_response, ok_response};
use crate::servers::apis::v1::context::auth_key::resources::AuthKey;
use crate::servers::apis::v1::responses::{invalid_auth_key_param_response, ok_response};
use crate::tracker::auth::Key;
use crate::tracker::Tracker;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::error::Error;
use axum::http::{header, StatusCode};
use axum::response::{IntoResponse, Response};

use crate::apis::v1::context::auth_key::resources::AuthKey;
use crate::apis::v1::responses::unhandled_rejection_response;
use crate::servers::apis::v1::context::auth_key::resources::AuthKey;
use crate::servers::apis::v1::responses::unhandled_rejection_response;

/// # Panics
///
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use serde::{de, Deserialize, Deserializer};

use super::resources::torrent::ListItem;
use super::responses::{torrent_info_response, torrent_list_response, torrent_not_known_response};
use crate::apis::v1::responses::invalid_info_hash_param_response;
use crate::apis::InfoHashParam;
use crate::protocol::info_hash::InfoHash;
use crate::servers::apis::v1::responses::invalid_info_hash_param_response;
use crate::servers::apis::InfoHashParam;
use crate::tracker::services::torrent::{get_torrent_info, get_torrents, Pagination};
use crate::tracker::Tracker;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ mod tests {
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes};

use super::Torrent;
use crate::apis::v1::context::torrent::resources::peer::Peer;
use crate::apis::v1::context::torrent::resources::torrent::ListItem;
use crate::protocol::clock::DurationSinceUnixEpoch;
use crate::protocol::info_hash::InfoHash;
use crate::servers::apis::v1::context::torrent::resources::peer::Peer;
use crate::servers::apis::v1::context::torrent::resources::torrent::ListItem;
use crate::tracker::peer;
use crate::tracker::services::torrent::{BasicInfo, Info};

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use axum::response::Response;
use super::responses::{
failed_to_reload_whitelist_response, failed_to_remove_torrent_from_whitelist_response, failed_to_whitelist_torrent_response,
};
use crate::apis::v1::responses::{invalid_info_hash_param_response, ok_response};
use crate::apis::InfoHashParam;
use crate::protocol::info_hash::InfoHash;
use crate::servers::apis::v1::responses::{invalid_info_hash_param_response, ok_response};
use crate::servers::apis::InfoHashParam;
use crate::tracker::Tracker;

pub async fn add_torrent_to_whitelist_handler(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error::Error;

use axum::response::Response;

use crate::apis::v1::responses::unhandled_rejection_response;
use crate::servers::apis::v1::responses::unhandled_rejection_response;

#[must_use]
pub fn failed_to_remove_torrent_from_whitelist_response<E: Error>(e: E) -> Response {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::response::{IntoResponse, Response};
use serde::Deserialize;
use torrust_tracker_configuration::{Configuration, HttpApi};

use crate::apis::v1::responses::unhandled_rejection_response;
use crate::servers::apis::v1::responses::unhandled_rejection_response;

#[derive(Deserialize, Debug)]
pub struct QueryParams {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub fn percent_decode_peer_id(raw_peer_id: &str) -> Result<peer::Id, IdConversio
mod tests {
use std::str::FromStr;

use crate::http::percent_encoding::{percent_decode_info_hash, percent_decode_peer_id};
use crate::protocol::info_hash::InfoHash;
use crate::servers::http::percent_encoding::{percent_decode_info_hash, percent_decode_peer_id};
use crate::tracker::peer;

#[test]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use axum::extract::FromRequestParts;
use axum::http::request::Parts;
use axum::response::{IntoResponse, Response};

use crate::http::v1::query::Query;
use crate::http::v1::requests::announce::{Announce, ParseAnnounceQueryError};
use crate::http::v1::responses;
use crate::servers::http::v1::query::Query;
use crate::servers::http::v1::requests::announce::{Announce, ParseAnnounceQueryError};
use crate::servers::http::v1::responses;

pub struct ExtractRequest(pub Announce);

Expand Down Expand Up @@ -53,9 +53,9 @@ mod tests {
use std::str::FromStr;

use super::extract_announce_from;
use crate::http::v1::requests::announce::{Announce, Compact, Event};
use crate::http::v1::responses::error::Error;
use crate::protocol::info_hash::InfoHash;
use crate::servers::http::v1::requests::announce::{Announce, Compact, Event};
use crate::servers::http::v1::responses::error::Error;
use crate::tracker::peer;

fn assert_error_response(error: &Error, error_message: &str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use axum::http::request::Parts;
use axum::response::{IntoResponse, Response};
use serde::Deserialize;

use crate::http::v1::handlers::common::auth;
use crate::http::v1::responses;
use crate::servers::http::v1::handlers::common::auth;
use crate::servers::http::v1::responses;
use crate::tracker::auth::Key;

pub struct Extract(pub Key);
Expand Down Expand Up @@ -85,7 +85,7 @@ fn custom_error(rejection: &PathRejection) -> responses::error::Error {
mod tests {

use super::parse_key;
use crate::http::v1::responses::error::Error;
use crate::servers::http::v1::responses::error::Error;

fn assert_error_response(error: &Error, error_message: &str) {
assert!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use axum::http::request::Parts;
use axum::response::Response;
use axum_client_ip::RightmostXForwardedFor;

use crate::http::v1::services::peer_ip_resolver::ClientIpSources;
use crate::servers::http::v1::services::peer_ip_resolver::ClientIpSources;

pub struct Extract(pub ClientIpSources);

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use axum::extract::FromRequestParts;
use axum::http::request::Parts;
use axum::response::{IntoResponse, Response};

use crate::http::v1::query::Query;
use crate::http::v1::requests::scrape::{ParseScrapeQueryError, Scrape};
use crate::http::v1::responses;
use crate::servers::http::v1::query::Query;
use crate::servers::http::v1::requests::scrape::{ParseScrapeQueryError, Scrape};
use crate::servers::http::v1::responses;

pub struct ExtractRequest(pub Scrape);

Expand Down Expand Up @@ -53,9 +53,9 @@ mod tests {
use std::str::FromStr;

use super::extract_scrape_from;
use crate::http::v1::requests::scrape::Scrape;
use crate::http::v1::responses::error::Error;
use crate::protocol::info_hash::InfoHash;
use crate::servers::http::v1::requests::scrape::Scrape;
use crate::servers::http::v1::responses::error::Error;

struct TestInfoHash {
pub bencoded: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use axum::extract::State;
use axum::response::{IntoResponse, Response};
use log::debug;

use crate::http::v1::extractors::announce_request::ExtractRequest;
use crate::http::v1::extractors::authentication_key::Extract as ExtractKey;
use crate::http::v1::extractors::client_ip_sources::Extract as ExtractClientIpSources;
use crate::http::v1::handlers::common::auth;
use crate::http::v1::requests::announce::{Announce, Compact, Event};
use crate::http::v1::responses::{self, announce};
use crate::http::v1::services::peer_ip_resolver::ClientIpSources;
use crate::http::v1::services::{self, peer_ip_resolver};
use crate::protocol::clock::{Current, Time};
use crate::servers::http::v1::extractors::announce_request::ExtractRequest;
use crate::servers::http::v1::extractors::authentication_key::Extract as ExtractKey;
use crate::servers::http::v1::extractors::client_ip_sources::Extract as ExtractClientIpSources;
use crate::servers::http::v1::handlers::common::auth;
use crate::servers::http::v1::requests::announce::{Announce, Compact, Event};
use crate::servers::http::v1::responses::{self, announce};
use crate::servers::http::v1::services::peer_ip_resolver::ClientIpSources;
use crate::servers::http::v1::services::{self, peer_ip_resolver};
use crate::tracker::auth::Key;
use crate::tracker::peer::Peer;
use crate::tracker::{AnnounceData, Tracker};
Expand Down Expand Up @@ -141,10 +141,10 @@ mod tests {

use torrust_tracker_test_helpers::configuration;

use crate::http::v1::requests::announce::Announce;
use crate::http::v1::responses;
use crate::http::v1::services::peer_ip_resolver::ClientIpSources;
use crate::protocol::info_hash::InfoHash;
use crate::servers::http::v1::requests::announce::Announce;
use crate::servers::http::v1::responses;
use crate::servers::http::v1::services::peer_ip_resolver::ClientIpSources;
use crate::tracker::services::common::tracker_factory;
use crate::tracker::{peer, Tracker};

Expand Down Expand Up @@ -197,8 +197,8 @@ mod tests {
use std::sync::Arc;

use super::{private_tracker, sample_announce_request, sample_client_ip_sources};
use crate::http::v1::handlers::announce::handle_announce;
use crate::http::v1::handlers::announce::tests::assert_error_response;
use crate::servers::http::v1::handlers::announce::handle_announce;
use crate::servers::http::v1::handlers::announce::tests::assert_error_response;
use crate::tracker::auth;

#[tokio::test]
Expand Down Expand Up @@ -238,8 +238,8 @@ mod tests {
use std::sync::Arc;

use super::{sample_announce_request, sample_client_ip_sources, whitelisted_tracker};
use crate::http::v1::handlers::announce::handle_announce;
use crate::http::v1::handlers::announce::tests::assert_error_response;
use crate::servers::http::v1::handlers::announce::handle_announce;
use crate::servers::http::v1::handlers::announce::tests::assert_error_response;

#[tokio::test]
async fn it_should_fail_when_the_announced_torrent_is_not_whitelisted() {
Expand All @@ -266,9 +266,9 @@ mod tests {
use std::sync::Arc;

use super::{sample_announce_request, tracker_on_reverse_proxy};
use crate::http::v1::handlers::announce::handle_announce;
use crate::http::v1::handlers::announce::tests::assert_error_response;
use crate::http::v1::services::peer_ip_resolver::ClientIpSources;
use crate::servers::http::v1::handlers::announce::handle_announce;
use crate::servers::http::v1::handlers::announce::tests::assert_error_response;
use crate::servers::http::v1::services::peer_ip_resolver::ClientIpSources;

#[tokio::test]
async fn it_should_fail_when_the_right_most_x_forwarded_for_header_ip_is_not_available() {
Expand All @@ -295,9 +295,9 @@ mod tests {
use std::sync::Arc;

use super::{sample_announce_request, tracker_not_on_reverse_proxy};
use crate::http::v1::handlers::announce::handle_announce;
use crate::http::v1::handlers::announce::tests::assert_error_response;
use crate::http::v1::services::peer_ip_resolver::ClientIpSources;
use crate::servers::http::v1::handlers::announce::handle_announce;
use crate::servers::http::v1::handlers::announce::tests::assert_error_response;
use crate::servers::http::v1::services::peer_ip_resolver::ClientIpSources;

#[tokio::test]
async fn it_should_fail_when_the_client_ip_from_the_connection_info_is_not_available() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::panic::Location;

use thiserror::Error;

use crate::http::v1::responses;
use crate::servers::http::v1::responses;
use crate::tracker::auth;

#[derive(Debug, Error)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::http::v1::responses;
use crate::http::v1::services::peer_ip_resolver::PeerIpResolutionError;
use crate::servers::http::v1::responses;
use crate::servers::http::v1::services::peer_ip_resolver::PeerIpResolutionError;

impl From<PeerIpResolutionError> for responses::error::Error {
fn from(err: PeerIpResolutionError) -> Self {
Expand All @@ -13,8 +13,8 @@ impl From<PeerIpResolutionError> for responses::error::Error {
mod tests {
use std::panic::Location;

use crate::http::v1::responses;
use crate::http::v1::services::peer_ip_resolver::PeerIpResolutionError;
use crate::servers::http::v1::responses;
use crate::servers::http::v1::services::peer_ip_resolver::PeerIpResolutionError;

fn assert_error_response(error: &responses::error::Error, error_message: &str) {
assert!(
Expand Down
File renamed without changes.
Loading

0 comments on commit 46f4900

Please sign in to comment.