Skip to content

Commit

Permalink
refactor: rename tunnel service
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtread committed Sep 9, 2024
1 parent 35dec23 commit 241dfab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/services/game/manager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{rules::RuleSet, AttrMap, Game, GameJoinableState, GamePlayer, GameRef, GameSnapshot};
use crate::{
config::RuntimeConfig,
services::{tunnel::TunnelService, udp_tunnel::TunnelServiceV2},
services::{tunnel::TunnelService, udp_tunnel::UdpTunnelService},
session::{
models::game_manager::{
AsyncMatchmakingStatus, GameSettings, GameSetupContext, MatchmakingResult,
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct GameManager {
/// Tunneling service
tunnel_service: Arc<TunnelService>,
/// Tunneling service v2
tunnel_service_v2: Arc<TunnelServiceV2>,
udp_tunnel_service: Arc<UdpTunnelService>,
/// Runtime configuration
config: Arc<RuntimeConfig>,
}
Expand All @@ -67,15 +67,15 @@ impl GameManager {
/// Starts a new game manager service returning its link
pub fn new(
tunnel_service: Arc<TunnelService>,
tunnel_service_v2: Arc<TunnelServiceV2>,
udp_tunnel_service: Arc<UdpTunnelService>,
config: Arc<RuntimeConfig>,
) -> Self {
Self {
games: Default::default(),
next_id: AtomicU32::new(1),
queue: Default::default(),
tunnel_service,
tunnel_service_v2,
udp_tunnel_service,
config,
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl GameManager {
if let Some(association) = session.association {
self.tunnel_service
.associate_pool(association, game_id, index as u8);
self.tunnel_service_v2
self.udp_tunnel_service
.associate_pool(association, game_id, index as u8);
}

Expand Down Expand Up @@ -227,7 +227,7 @@ impl GameManager {
created_at,
self.clone(),
self.tunnel_service.clone(),
self.tunnel_service_v2.clone(),
self.udp_tunnel_service.clone(),
);
let link = Arc::new(RwLock::new(game));
{
Expand Down
11 changes: 6 additions & 5 deletions src/services/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::sync::{Arc, Weak};
use tdf::{ObjectId, TdfMap, TdfSerializer};
use tokio::sync::RwLock;

use super::{tunnel::TunnelService, udp_tunnel::TunnelServiceV2};
use super::{tunnel::TunnelService, udp_tunnel::UdpTunnelService};

pub mod manager;
pub mod rules;
Expand All @@ -56,7 +56,7 @@ pub struct Game {
/// Access to the tunneling service
pub tunnel_service: Arc<TunnelService>,
/// Access to version 2 of the tunneling service
pub tunnel_service_v2: Arc<TunnelServiceV2>,
pub udp_tunnel_service: Arc<UdpTunnelService>,
}

/// Snapshot of the current game state and players
Expand Down Expand Up @@ -225,7 +225,7 @@ impl Game {
created_at: DateTime<Utc>,
game_manager: Arc<GameManager>,
tunnel_service: Arc<TunnelService>,
tunnel_service_v2: Arc<TunnelServiceV2>,
udp_tunnel_service: Arc<UdpTunnelService>,
) -> Game {
Game {
id,
Expand All @@ -236,7 +236,7 @@ impl Game {
created_at,
game_manager,
tunnel_service,
tunnel_service_v2,
udp_tunnel_service,
}
}

Expand Down Expand Up @@ -362,7 +362,8 @@ impl Game {

// Remove the tunnel
self.tunnel_service.dissociate_pool(self.id, index as u8);
self.tunnel_service_v2.dissociate_pool(self.id, index as u8);
self.udp_tunnel_service
.dissociate_pool(self.id, index as u8);

// Remove the player
let player = self.players.remove(index);
Expand Down
14 changes: 6 additions & 8 deletions src/services/udp_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type PoolId = GameID;
pub async fn create_tunnel_service(
sessions: Arc<Sessions>,
tunnel_addr: SocketAddr,
) -> Arc<TunnelServiceV2> {
) -> Arc<UdpTunnelService> {
let socket = UdpSocket::bind(tunnel_addr).await.unwrap();
let service = Arc::new(TunnelService::new(socket, sessions));
let service = Arc::new(UdpTunnelService::new(socket, sessions));

debug!("started tunneling server {tunnel_addr}");

Expand All @@ -47,7 +47,7 @@ pub async fn create_tunnel_service(
}

/// Reads inbound messages from the tunnel service
pub async fn accept_messages(service: Arc<TunnelService>) {
pub async fn accept_messages(service: Arc<UdpTunnelService>) {
// Buffer to recv messages
let mut buffer = [0; u16::MAX as usize];

Expand Down Expand Up @@ -104,7 +104,7 @@ const KEEP_ALIVE_TIMEOUT: Duration = Duration::from_secs(KEEP_ALIVE_DELAY.as_sec

/// Background task that sends out keep alive messages to all the sockets connected
/// to the tunnel system. Removes inactive and dead connections
pub async fn keep_alive(service: Arc<TunnelService>) {
pub async fn keep_alive(service: Arc<UdpTunnelService>) {
// Task set for keep alive tasks
let mut send_task_set = JoinSet::new();

Expand Down Expand Up @@ -170,9 +170,7 @@ pub async fn keep_alive(service: Arc<TunnelService>) {
}
}

pub type TunnelServiceV2 = TunnelService;

pub struct TunnelService {
pub struct UdpTunnelService {
socket: UdpSocket,
next_tunnel_id: AtomicU32,
mappings: RwLock<TunnelMappings>,
Expand Down Expand Up @@ -323,7 +321,7 @@ impl TunnelMappings {
}
}

impl TunnelService {
impl UdpTunnelService {
pub fn new(socket: UdpSocket, sessions: Arc<Sessions>) -> Self {
Self {
socket,
Expand Down

0 comments on commit 241dfab

Please sign in to comment.