hashiverse_server/
main.rs1use clap::Parser;
2use hashiverse_lib::tools::time_provider::time_provider::RealTimeProvider;
3use hashiverse_lib::tools::tools::configure_logging_with_time_provider;
4use hashiverse_lib::transport::bootstrap_provider::bootstrap_provider::BootstrapProvider;
5use hashiverse_lib::transport::ddos::ddos::DdosProtection;
6use hashiverse_server_lib::environment::disk_environment_store::DiskEnvironmentFactory;
7use hashiverse_server_lib::environment::environment::EnvironmentFactory;
8use hashiverse_server_lib::transport::full_https_transport::FullHttpsTransportFactory;
9use hashiverse_server_lib::server::args::Args;
10use hashiverse_server_lib::server::hashiverse_server::HashiverseServer;
11use std::sync::Arc;
12use tokio_util::sync::CancellationToken;
13use hashiverse_lib::tools::config;
14use hashiverse_lib::tools::parallel_pow_generator::NativeParallelPowGenerator;
15use hashiverse_lib::tools::runtime_services::RuntimeServices;
16use hashiverse_lib::transport::bootstrap_provider::dnssec_bootstrap_provider::DnssecBootstrapProvider;
17use hashiverse_server_lib::transport::ddos::ipset_ddos::IpsetDdosProtection;
18
19#[tokio::main(flavor = "multi_thread")]
20async fn main() -> anyhow::Result<()> {
21 let args = Args::parse();
22 let time_provider = Arc::new(RealTimeProvider);
23 configure_logging_with_time_provider(&args.log_level, time_provider.clone());
24
25 rustls::crypto::ring::default_provider()
27 .install_default()
28 .expect("Failed to install Ring as the crypto provider");
29
30 let environment_factory: Arc<dyn EnvironmentFactory> = Arc::new(DiskEnvironmentFactory::new(args.base_path.as_str()));
31 let ddos_protection: Arc<dyn DdosProtection> = Arc::new(IpsetDdosProtection::new(config::SERVER_DDOS_IPSET_SET_NAME, config::SERVER_DDOS_SCORE_THRESHOLD, config::SERVER_DDOS_DECAY_PER_SECOND, config::SERVER_DDOS_BAD_REQUEST_PENALTY, config::SERVER_DDOS_MAX_CONNECTIONS_PER_IP));
32 let bootstrap_provider: Arc<dyn BootstrapProvider> = Arc::new(DnssecBootstrapProvider::new());
33 let transport_factory = Arc::new(FullHttpsTransportFactory::new(ddos_protection, bootstrap_provider));
34 let runtime_services = Arc::new(RuntimeServices { time_provider, transport_factory, pow_generator: Arc::new(NativeParallelPowGenerator::new()) });
35
36 let cancellation_token = CancellationToken::new();
37
38 hashiverse_server_lib::tools::tools::spawn_ctrl_c_handler(cancellation_token.clone());
39
40 let hashiverse_server = HashiverseServer::new(runtime_services, environment_factory, args).await?;
41 hashiverse_server.run(cancellation_token).await;
42
43 Ok(())
44}