2022-08-29 02:50:14 +02:00
|
|
|
//! # codemp Server
|
|
|
|
//!
|
|
|
|
//! The codemp server itself, in charge of handling the global state, merging operations from
|
|
|
|
//! all clients and synching everyone's cursor.
|
|
|
|
//!
|
|
|
|
|
2022-07-31 13:47:18 +02:00
|
|
|
pub mod actor;
|
2022-08-29 02:50:14 +02:00
|
|
|
pub mod events;
|
2022-07-31 13:47:18 +02:00
|
|
|
pub mod service;
|
2022-07-13 01:58:34 +02:00
|
|
|
|
2022-07-31 13:47:18 +02:00
|
|
|
use std::sync::Arc;
|
2022-07-30 03:02:38 +02:00
|
|
|
|
2022-08-03 15:09:15 +02:00
|
|
|
use tracing::info;
|
2022-07-10 19:01:56 +02:00
|
|
|
|
2022-07-31 13:47:18 +02:00
|
|
|
use tonic::transport::Server;
|
2022-07-30 03:02:38 +02:00
|
|
|
|
2022-07-31 13:47:18 +02:00
|
|
|
use crate::{
|
|
|
|
actor::state::StateManager,
|
2022-08-03 15:09:15 +02:00
|
|
|
service::{buffer::BufferService, workspace::WorkspaceService},
|
2022-07-31 13:47:18 +02:00
|
|
|
};
|
2022-07-10 19:01:56 +02:00
|
|
|
|
2022-07-10 20:44:43 +02:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2022-07-30 03:02:38 +02:00
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
2022-07-10 20:44:43 +02:00
|
|
|
let addr = "[::1]:50051".parse()?;
|
2022-07-13 01:58:34 +02:00
|
|
|
|
2022-07-30 03:02:38 +02:00
|
|
|
let state = Arc::new(StateManager::new());
|
|
|
|
|
|
|
|
info!("Starting server");
|
2022-07-10 19:01:56 +02:00
|
|
|
|
2022-07-10 20:44:43 +02:00
|
|
|
Server::builder()
|
2022-07-31 13:47:18 +02:00
|
|
|
.add_service(WorkspaceService::server(state.clone()))
|
|
|
|
.add_service(BufferService::server(state.clone()))
|
2022-07-10 20:44:43 +02:00
|
|
|
.serve(addr)
|
|
|
|
.await?;
|
2022-07-10 19:01:56 +02:00
|
|
|
|
2022-07-10 20:44:43 +02:00
|
|
|
Ok(())
|
2022-07-10 19:01:56 +02:00
|
|
|
}
|