pull/146/head
Chip Senkbeil 2 years ago
parent 8fb2c5ddb8
commit 9a2f2284b1
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -4,13 +4,10 @@ use crate::{
};
use anyhow::Context;
use clap::Subcommand;
use distant_core::{
net::{
SecretKey32, ServerConfig as NetServerConfig, ServerRef, TcpServerExt,
XChaCha20Poly1305Codec,
},
DistantApiServerHandler, DistantSingleKeyCredentials, Host,
};
use distant_core::net::common::authentication::Verifier;
use distant_core::net::common::{Host, SecretKey32};
use distant_core::net::server::{Server, ServerConfig as NetServerConfig, ServerRef};
use distant_core::{DistantApiServerHandler, DistantSingleKeyCredentials};
use log::*;
use std::io::{self, Read, Write};
@ -163,8 +160,6 @@ impl ServerSubcommand {
SecretKey32::default()
};
let codec = XChaCha20Poly1305Codec::new(key.unprotected_as_bytes());
debug!(
"Starting local API server, binding to {} {}",
addr,
@ -173,21 +168,25 @@ impl ServerSubcommand {
None => "using an ephemeral port".to_string(),
}
);
let server = DistantApiServerHandler::local(NetServerConfig {
let handler = DistantApiServerHandler::local(NetServerConfig {
shutdown: get!(shutdown).unwrap_or_default(),
..Default::default()
})
.context("Failed to create local distant api")?
.start(addr, get!(port).unwrap_or_else(|| 0.into()), codec)
.await
.with_context(|| {
format!(
"Failed to start server @ {} with {}",
addr,
get!(port)
.map(|p| format!("port in range {p}"))
.unwrap_or_else(|| String::from("ephemeral port"))
)
})?;
.context("Failed to create local distant api")?;
let server = Server::tcp()
.handler(handler)
.verifier(Verifier::static_key(key.clone()))
.start(addr, get!(port).unwrap_or_else(|| 0.into()))
.await
.with_context(|| {
format!(
"Failed to start server @ {} with {}",
addr,
get!(port)
.map(|p| format!("port in range {p}"))
.unwrap_or_else(|| String::from("ephemeral port"))
)
})?;
let credentials = DistantSingleKeyCredentials {
host: Host::from(addr),

@ -3,22 +3,24 @@ use crate::{
paths::{global as global_paths, user as user_paths},
};
use anyhow::Context;
use distant_core::{net::PlainCodec, DistantManager, DistantManagerConfig, DistantManagerRef};
use distant_core::net::manager::{Config as ManagerConfig, ManagerServer};
use distant_core::net::server::ServerRef;
use log::*;
pub struct Manager {
pub access: AccessControl,
pub config: DistantManagerConfig,
pub config: ManagerConfig,
pub network: NetworkConfig,
}
impl Manager {
/// Begin listening on the network interface specified within [`NetworkConfig`]
pub async fn listen(self) -> anyhow::Result<DistantManagerRef> {
pub async fn listen(self) -> anyhow::Result<Box<dyn ServerRef>> {
let user = self.config.user;
#[cfg(unix)]
{
use distant_core::net::common::UnixSocketListener;
let socket_path = self.network.unix_socket.as_deref().unwrap_or({
if user {
user_paths::UNIX_SOCKET_PATH.as_path()
@ -34,20 +36,15 @@ impl Manager {
.with_context(|| format!("Failed to create socket directory {parent:?}"))?;
}
let boxed_ref = DistantManager::start_unix_socket_with_permissions(
self.config,
socket_path,
PlainCodec,
self.access.into_mode(),
)
.await
.with_context(|| format!("Failed to start manager at socket {socket_path:?}"))?
.into_inner()
.into_boxed_server_ref()
.map_err(|_| anyhow::anyhow!("Got wrong server ref"))?;
let boxed_ref = ManagerServer::new(self.config)
.start(
UnixSocketListener::bind_with_permissions(socket_path, self.access.into_mode())
.await?,
)
.with_context(|| format!("Failed to start manager at socket {socket_path:?}"))?;
info!("Manager listening using unix socket @ {:?}", socket_path);
Ok(*boxed_ref)
Ok(boxed_ref)
}
#[cfg(windows)]

@ -1,5 +1,5 @@
use clap::Args;
use distant_core::Map;
use distant_core::net::common::Map;
use serde::{Deserialize, Serialize};
#[derive(Args, Debug, Default, Serialize, Deserialize)]

Loading…
Cancel
Save