- chore: ran cargo fix on the codebase

This commit is contained in:
2025-03-07 21:03:15 -05:00
parent 3b789d0fd4
commit b6f2d3f456
59 changed files with 1324 additions and 523 deletions

View File

@@ -1,7 +1,10 @@
use crate::auth_client::AuthClient;
use crate::bufferpool::BufferPool;
use crate::character_client::CharacterClient;
use crate::connection_service::ConnectionService;
use crate::metrics::{ACTIVE_CONNECTIONS, PACKETS_RECEIVED};
use crate::packet::Packet;
use crate::router::PacketRouter;
use dotenv::dotenv;
use std::collections::HashMap;
use std::env;
@@ -18,24 +21,21 @@ use tracing::{debug, error, info, warn};
use utils::consul_registration;
use utils::service_discovery::get_service_address;
use warp::Filter;
use crate::character_client::CharacterClient;
use crate::connection_service::ConnectionService;
use crate::router::PacketRouter;
mod packet_type;
mod packet;
mod router;
mod packets;
mod enums;
mod dataconsts;
mod types;
mod handlers;
mod bufferpool;
mod metrics;
mod auth_client;
mod bufferpool;
mod character_client;
mod connection_state;
mod connection_service;
mod connection_state;
mod dataconsts;
mod enums;
mod handlers;
mod metrics;
mod packet;
mod packet_type;
mod packets;
mod router;
mod types;
pub mod common {
tonic::include_proto!("common");
@@ -57,7 +57,10 @@ const MAX_CONCURRENT_CONNECTIONS: usize = 100;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
tracing_subscriber::fmt()
.with_max_level(Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string())).unwrap_or_else(|_| Level::INFO))
.with_max_level(
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
.unwrap_or_else(|_| Level::INFO),
)
.init();
// Set the gRPC server address
@@ -67,7 +70,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let consul_url = env::var("CONSUL_URL").unwrap_or_else(|_| "http://127.0.0.1:8500".to_string());
let service_name = env::var("SERVICE_NAME").unwrap_or_else(|_| "packet-service".to_string());
let service_address = env::var("PACKET_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
let service_address =
env::var("PACKET_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
let service_port = port.clone();
let health_check_url = format!("http://{}:{}/health", service_address, health_port);
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
@@ -89,17 +93,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
meta,
&health_check_url,
)
.await?;
.await?;
// Start health-check endpoint
consul_registration::start_health_check(addr.as_str()).await?;
let auth_address = auth_node.get(0).unwrap();
let auth_url = format!("http://{}:{}", auth_address.ServiceAddress, auth_address.ServicePort);
let auth_url = format!(
"http://{}:{}",
auth_address.ServiceAddress, auth_address.ServicePort
);
let auth_client = Arc::new(Mutex::new(AuthClient::connect(&auth_url).await?));
let character_address = character_node.get(0).unwrap();
let character_url = format!("http://{}:{}", character_address.ServiceAddress, character_address.ServicePort);
let character_url = format!(
"http://{}:{}",
character_address.ServiceAddress, character_address.ServicePort
);
let character_client = Arc::new(Mutex::new(CharacterClient::connect(&character_url).await?));
let full_addr = format!("{}:{}", &addr, port);
@@ -130,17 +140,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::spawn(async move {
let _permit = permit;
let connection_id = packet_router.connection_service.add_connection();
if let Err(e) = packet_router.handle_connection(&mut socket, pool, connection_id.clone()).await {
if let Err(e) = packet_router
.handle_connection(&mut socket, pool, connection_id.clone())
.await
{
error!("Error handling connection: {}", e);
}
packet_router.connection_service.remove_connection(&connection_id);
packet_router
.connection_service
.remove_connection(&connection_id);
});
}
});
utils::signal_handler::wait_for_signal().await;
consul_registration::deregister_service(&consul_url, service_id.as_str()).await.expect("");
consul_registration::deregister_service(&consul_url, service_id.as_str())
.await
.expect("");
info!("service {} deregistered", service_name);
Ok(())
}