Files
telemt/src/main.rs
T

84 lines
2.1 KiB
Rust
Raw Normal View History

//! telemt — Telegram MTProto Proxy
2025-12-30 05:08:05 +03:00
2026-03-04 01:08:42 +03:00
mod api;
2026-03-09 11:05:46 +03:00
mod cli;
2026-01-07 17:22:10 +03:00
mod config;
2026-04-05 17:23:40 +03:00
mod conntrack_control;
2025-12-30 05:08:05 +03:00
mod crypto;
#[cfg(unix)]
mod daemon;
2026-01-07 17:22:10 +03:00
mod error;
2026-04-17 16:36:15 +03:00
mod healthcheck;
2026-02-14 23:01:43 +02:00
mod ip_tracker;
#[cfg(test)]
#[path = "tests/ip_tracker_encapsulation_adversarial_tests.rs"]
mod ip_tracker_encapsulation_adversarial_tests;
#[cfg(test)]
2026-03-23 20:32:55 +03:00
#[path = "tests/ip_tracker_hotpath_adversarial_tests.rs"]
mod ip_tracker_hotpath_adversarial_tests;
#[cfg(test)]
2026-03-21 15:45:29 +03:00
#[path = "tests/ip_tracker_regression_tests.rs"]
mod ip_tracker_regression_tests;
mod logging;
2026-03-09 11:05:46 +03:00
mod maestro;
2026-02-17 01:11:01 +03:00
mod metrics;
2026-03-09 11:05:46 +03:00
mod network;
2025-12-30 05:08:05 +03:00
mod protocol;
mod proxy;
2026-05-08 14:38:24 +03:00
mod quota_state;
mod service;
2026-03-09 11:05:46 +03:00
mod startup;
2025-12-30 05:08:05 +03:00
mod stats;
2026-01-07 17:22:10 +03:00
mod stream;
mod synlimit_control;
2026-02-20 12:55:26 +03:00
mod tls_front;
2026-03-09 11:05:46 +03:00
mod transport;
2025-12-30 05:08:05 +03:00
mod util;
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
2026-03-27 11:35:52 +03:00
// Install rustls crypto provider early
2026-03-24 10:33:06 +03:00
let _ = rustls::crypto::ring::default_provider().install_default();
2026-03-27 11:35:52 +03:00
let args: Vec<String> = std::env::args().skip(1).collect();
let cmd = cli::parse_command(&args);
// Handle subcommands that don't need the server (stop, reload, status, init)
if let Some(exit_code) = cli::execute_subcommand(&cmd) {
std::process::exit(exit_code);
}
#[cfg(unix)]
{
let daemon_opts = cmd.daemon_opts;
2026-03-27 11:35:52 +03:00
// Daemonize BEFORE runtime
if daemon_opts.should_daemonize() {
match daemon::daemonize(daemon_opts.working_dir.as_deref()) {
Ok(daemon::DaemonizeResult::Parent) => {
std::process::exit(0);
}
Ok(daemon::DaemonizeResult::Child) => {
2026-03-27 11:35:52 +03:00
// continue
}
Err(e) => {
eprintln!("[telemt] Daemonization failed: {}", e);
std::process::exit(1);
}
}
}
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?
.block_on(maestro::run_with_daemon(daemon_opts))
}
#[cfg(not(unix))]
{
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?
.block_on(maestro::run())
}
2026-02-14 01:36:14 +03:00
}