Skip to content

Commit

Permalink
dev: work on udp tracker service
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Jan 8, 2024
1 parent 35d6c58 commit 6a66691
Show file tree
Hide file tree
Showing 31 changed files with 359 additions and 134 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
name: Run Build Checks
run: cargo check --tests --benches --examples --workspace --all-targets --all-features

# Run Test Locally:
# RUSTFLAGS="-Z profile -C codegen-units=1 -C inline-threshold=0 -C link-dead-code -C overflow-checks=off -C panic=abort -Z panic_abort_tests" RUSTDOCFLAGS="-Z profile -C codegen-units=1 -C inline-threshold=0 -C link-dead-code -C overflow-checks=off -C panic=abort -Z panic_abort_tests" CARGO_INCREMENTAL="0" RUST_BACKTRACE=1 cargo test --tests --benches --examples --workspace --all-targets --all-features

- id: test
name: Run Unit Tests
run: cargo test --tests --benches --examples --workspace --all-targets --all-features
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"[rust]": {
"editor.formatOnSave": true
},
// "rust-analyzer.cargo.extraEnv": {
// "RUSTFLAGS": "-Z profile -C codegen-units=1 -C inline-threshold=0 -C link-dead-code -C overflow-checks=off -C panic=abort -Z panic_abort_tests",
// "RUSTDOCFLAGS": "-Z profile -C codegen-units=1 -C inline-threshold=0 -C link-dead-code -C overflow-checks=off -C panic=abort -Z panic_abort_tests",
// "CARGO_INCREMENTAL": "0",
// "RUST_BACKTRACE": "1"
// },
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.allTargets": true,
Expand Down
94 changes: 92 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ fern = "0"
futures = "0"
hyper = "1"
lazy_static = "1"
log = { version = "0", features = ["release_max_level_info"] }
tracing = "0.1"
tracing-subscriber = "0.3"
multimap = "0"
openssl = { version = "0", features = ["vendored"] }
percent-encoding = "2"
Expand All @@ -55,6 +56,7 @@ reqwest = "0"
serde = { version = "1", features = ["derive"] }
serde_bencode = "0"
serde_json = "1"
ringbuf = "0.4.0-rc.2"
serde_with = "3"
tdyne-peer-id = "1"
tdyne-peer-id-registry = "0"
Expand Down
2 changes: 2 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@
"reannounce",
"Registar",
"repr",
"reqs",
"reqwest",
"rerequests",
"ringbuf",
"rngs",
"routable",
"rusqlite",
Expand Down
2 changes: 1 addition & 1 deletion packages/located-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version.workspace = true
version.workspace = true

[dependencies]
log = { version = "0", features = ["release_max_level_info"] }
tracing = "0.1"

[dev-dependencies]
thiserror = "1"
2 changes: 1 addition & 1 deletion packages/located-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::error::Error;
use std::panic::Location;
use std::sync::Arc;

use log::debug;
use tracing::debug;

pub type DynError = Arc<dyn std::error::Error + Send + Sync>;

Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use std::net::SocketAddr;
use std::sync::Arc;

use derive_more::Constructor;
use log::warn;
use tokio::sync::Mutex;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::Configuration;
use tracing::warn;

use crate::bootstrap::jobs::{health_check_api, http_tracker, torrent_cleanup, tracker_apis, udp_tracker};
use crate::{core, servers};
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/jobs/health_check_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
//! Refer to the [configuration documentation](https://docs.rs/torrust-tracker-configuration)
//! for the API configuration options.

use log::info;
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HealthCheckApi;
use tracing::debug;

use super::Started;
use crate::app::Registry;
Expand Down Expand Up @@ -46,18 +46,18 @@ pub async fn start_job(config: &HealthCheckApi, register: Registry) -> JoinHandl

// Run the API server
let join_handle = tokio::spawn(async move {
info!("Starting Health Check API server: http://{}", bind_addr);
debug!("Starting Health Check API server: http://{}", bind_addr);

let handle = server::start(bind_addr, tx_start, rx_halt, register);

if let Ok(()) = handle.await {
info!("Health Check API server on http://{} stopped", bind_addr);
debug!("Health Check API server on http://{} stopped", bind_addr);
}
});

// Wait until the API server job is running
match rx_start.await {
Ok(msg) => info!("Torrust Health Check API server started on socket: {}", msg.address),
Ok(msg) => debug!("Torrust Health Check API server started on socket: {}", msg.address),
Err(e) => panic!("the Health Check API server was dropped: {e}"),
}

Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use std::net::SocketAddr;
use std::sync::Arc;

use axum_server::tls_rustls::RustlsConfig;
use log::info;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HttpTracker;
use tracing::debug;

use super::make_rust_tls;
use crate::app::RegistrationForm;
Expand Down Expand Up @@ -53,7 +53,7 @@ pub async fn start_job(
Version::V1 => Some(start_v1(socket, tls, tracker.clone(), form).await),
}
} else {
info!("Note: Not loading Http Tracker Service, Not Enabled in Configuration.");
debug!("Note: Not loading Http Tracker Service, Not Enabled in Configuration.");
None
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/jobs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ pub struct Started {

pub async fn make_rust_tls(enabled: bool, cert: &Option<String>, key: &Option<String>) -> Option<Result<RustlsConfig, Error>> {
if !enabled {
info!("tls not enabled");
debug!("tls not enabled");
return None;
}

if let (Some(cert), Some(key)) = (cert, key) {
info!("Using https: cert path: {cert}.");
info!("Using https: key path: {cert}.");
debug!("Using https: cert path: {cert}.");
debug!("Using https: key path: {cert}.");

Some(
RustlsConfig::from_pem_file(cert, key)
Expand Down Expand Up @@ -77,9 +77,9 @@ use std::panic::Location;
use std::sync::Arc;

use axum_server::tls_rustls::RustlsConfig;
use log::info;
use thiserror::Error;
use torrust_tracker_located_error::{DynError, LocatedError};
use tracing::debug;

/// Error returned by the Bootstrap Process.
#[derive(Error, Debug)]
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/jobs/torrent_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use std::sync::Arc;

use chrono::Utc;
use log::info;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::Configuration;
use tracing::debug;

use crate::core;

Expand All @@ -37,15 +37,15 @@ pub fn start_job(config: &Arc<Configuration>, tracker: &Arc<core::Tracker>) -> J
loop {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
info!("Stopping torrent cleanup job..");
debug!("Stopping torrent cleanup job..");
break;
}
_ = interval.tick() => {
if let Some(tracker) = weak_tracker.upgrade() {
let start_time = Utc::now().time();
info!("Cleaning up torrents..");
debug!("Cleaning up torrents..");
tracker.cleanup_torrents().await;
info!("Cleaned up torrents in: {}ms", (Utc::now().time() - start_time).num_milliseconds());
debug!("Cleaned up torrents in: {}ms", (Utc::now().time() - start_time).num_milliseconds());
} else {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/tracker_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use std::net::SocketAddr;
use std::sync::Arc;

use axum_server::tls_rustls::RustlsConfig;
use log::info;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::{AccessTokens, HttpApi};
use tracing::debug;

use super::make_rust_tls;
use crate::app::RegistrationForm;
Expand Down Expand Up @@ -76,7 +76,7 @@ pub async fn start_job(
Version::V1 => Some(start_v1(bind_to, tls, tracker.clone(), form, access_tokens).await),
}
} else {
info!("Note: Not loading Http Tracker Service, Not Enabled in Configuration.");
debug!("Note: Not loading Http Tracker Service, Not Enabled in Configuration.");
None
}
}
Expand Down
Loading

0 comments on commit 6a66691

Please sign in to comment.