use crate::error::{FossilError, Result};
use crate::repo::Repository;
pub struct QuicServerBuilder {
bind_addr: Option<String>,
}
impl QuicServerBuilder {
pub(crate) fn new() -> Self {
Self { bind_addr: None }
}
pub fn bind(mut self, addr: &str) -> Self {
self.bind_addr = Some(addr.to_string());
self
}
#[cfg(feature = "sync-quic")]
pub fn start_blocking(self, repo: &Repository) -> Result<()> {
use crate::sync::QuicServer;
use std::path::PathBuf;
let bind_addr = self
.bind_addr
.ok_or_else(|| FossilError::InvalidArtifact("bind address is required".to_string()))?;
let rt =
tokio::runtime::Runtime::new().map_err(|e| FossilError::SyncError(e.to_string()))?;
rt.block_on(async {
let server = QuicServer::bind(&bind_addr)?;
println!("QUIC server listening on {}", server.local_addr()?);
server.handle_sync(repo, &PathBuf::new()).await?;
Ok(())
})
}
#[cfg(not(feature = "sync-quic"))]
pub fn start_blocking(self, _repo: &Repository) -> Result<()> {
Err(FossilError::InvalidArtifact(
"QUIC server requires 'sync-quic' feature".to_string(),
))
}
}