wip
This commit is contained in:
@@ -34,6 +34,30 @@ use uuid::Uuid;
|
||||
|
||||
use crate::peer::{send_game_file_chunk, send_game_file_data};
|
||||
|
||||
/// Initialize and start the peer system
|
||||
/// This function replaces the main.rs entry point and allows the peer to be started from other crates
|
||||
pub fn start_peer(
|
||||
game_dir: String,
|
||||
tx_notify_ui: UnboundedSender<PeerEvent>,
|
||||
) -> eyre::Result<UnboundedSender<PeerCommand>> {
|
||||
log::info!("Starting peer system with game directory: {game_dir}");
|
||||
|
||||
let (tx_control, rx_control) = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
// Start the peer in a background task
|
||||
let tx_control_clone = tx_control.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = run_peer(rx_control, tx_notify_ui).await {
|
||||
log::error!("Peer system failed: {e}");
|
||||
}
|
||||
});
|
||||
|
||||
// Set the game directory
|
||||
tx_control.send(PeerCommand::SetGameDir(game_dir))?;
|
||||
|
||||
Ok(tx_control_clone)
|
||||
}
|
||||
|
||||
static CERT_PEM: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../cert.pem"));
|
||||
static KEY_PEM: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../key.pem"));
|
||||
|
||||
@@ -769,7 +793,6 @@ struct Ctx {
|
||||
struct PeerCtx {
|
||||
game_dir: Arc<RwLock<Option<String>>>,
|
||||
local_game_db: Arc<RwLock<Option<GameDB>>>,
|
||||
peer_game_db: Arc<RwLock<PeerGameDB>>,
|
||||
}
|
||||
|
||||
pub async fn run_peer(
|
||||
@@ -786,7 +809,6 @@ pub async fn run_peer(
|
||||
let peer_ctx = PeerCtx {
|
||||
game_dir: ctx.game_dir.clone(),
|
||||
local_game_db: ctx.local_game_db.clone(),
|
||||
peer_game_db: ctx.peer_game_db.clone(),
|
||||
};
|
||||
|
||||
// Start server component
|
||||
|
||||
Reference in New Issue
Block a user