Server implemented. Linux client implemented.
This commit is contained in:
68
furumi-server/src/main.rs
Normal file
68
furumi-server/src/main.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
pub mod vfs;
|
||||
pub mod security;
|
||||
pub mod server;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use clap::Parser;
|
||||
use tonic::transport::Server;
|
||||
use vfs::local::LocalVfs;
|
||||
use furumi_common::proto::remote_file_system_server::RemoteFileSystemServer;
|
||||
use server::RemoteFileSystemImpl;
|
||||
use security::AuthInterceptor;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// IP address and port to bind the server to
|
||||
#[arg(short, long, env = "FURUMI_BIND", default_value = "[::1]:50051")]
|
||||
bind: String,
|
||||
|
||||
/// Document root directory to expose via VFS
|
||||
#[arg(short, long, env = "FURUMI_ROOT", default_value = ".")]
|
||||
root: PathBuf,
|
||||
|
||||
/// Authentication Bearer token (leave empty to disable auth)
|
||||
#[arg(short, long, env = "FURUMI_TOKEN", default_value = "")]
|
||||
token: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let args = Args::parse();
|
||||
let addr = args.bind.parse()?;
|
||||
|
||||
// Resolve the document root to an absolute path for safety and clarity
|
||||
let root_path = std::fs::canonicalize(&args.root)
|
||||
.unwrap_or_else(|_| args.root.clone());
|
||||
|
||||
if !root_path.exists() || !root_path.is_dir() {
|
||||
eprintln!("Error: Root path {:?} does not exist or is not a directory", root_path);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let vfs = Arc::new(LocalVfs::new(&root_path));
|
||||
let remote_fs = RemoteFileSystemImpl::new(vfs);
|
||||
let auth = AuthInterceptor::new(args.token.clone());
|
||||
let svc = RemoteFileSystemServer::with_interceptor(remote_fs, auth.clone());
|
||||
|
||||
println!("Furumi-ng Server listening on {}", addr);
|
||||
if args.token.is_empty() {
|
||||
println!("WARNING: Authentication is DISABLED");
|
||||
} else {
|
||||
println!("Authentication is enabled (Bearer token required)");
|
||||
}
|
||||
println!("Document Root: {:?}", root_path);
|
||||
|
||||
Server::builder()
|
||||
// Enable TCP Keep-Alive and HTTP2 Ping to keep connections alive for long media streams
|
||||
.tcp_keepalive(Some(std::time::Duration::from_secs(60)))
|
||||
.http2_keepalive_interval(Some(std::time::Duration::from_secs(60)))
|
||||
.add_service(svc)
|
||||
.serve(addr)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user