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.
|
|
|
|
//!
|
|
|
|
|
2023-04-12 04:59:33 +02:00
|
|
|
use clap::Parser;
|
2022-08-03 15:09:15 +02:00
|
|
|
use tracing::info;
|
2022-07-31 13:47:18 +02:00
|
|
|
use tonic::transport::Server;
|
2022-07-30 03:02:38 +02:00
|
|
|
|
2023-04-12 04:59:33 +02:00
|
|
|
mod buffer;
|
|
|
|
|
2023-04-07 03:05:21 +02:00
|
|
|
use crate::buffer::service::BufferService;
|
2022-07-10 19:01:56 +02:00
|
|
|
|
2023-04-12 04:59:33 +02:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
struct CliArgs {
|
|
|
|
|
|
|
|
/// address to listen on
|
|
|
|
#[arg(long, default_value = "[::1]:50051")]
|
|
|
|
host: String,
|
|
|
|
|
|
|
|
/// enable debug log level
|
|
|
|
#[arg(long, default_value_t = false)]
|
|
|
|
debug: bool,
|
|
|
|
}
|
|
|
|
|
2022-07-10 20:44:43 +02:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2023-04-12 04:59:33 +02:00
|
|
|
let args = CliArgs::parse();
|
2022-07-30 03:02:38 +02:00
|
|
|
|
2023-04-12 04:59:33 +02:00
|
|
|
tracing_subscriber::fmt()
|
|
|
|
.with_writer(std::io::stdout)
|
|
|
|
.with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO })
|
|
|
|
.init();
|
2022-07-13 01:58:34 +02:00
|
|
|
|
2023-07-01 19:04:10 +02:00
|
|
|
info!(">> codemp server");
|
|
|
|
info!("binding on {}", args.host);
|
2022-07-10 19:01:56 +02:00
|
|
|
|
2022-07-10 20:44:43 +02:00
|
|
|
Server::builder()
|
2023-04-07 03:05:21 +02:00
|
|
|
.add_service(BufferService::new().server())
|
2023-04-12 04:59:33 +02:00
|
|
|
.serve(args.host.parse()?)
|
2022-07-10 20:44:43 +02:00
|
|
|
.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
|
|
|
}
|