feat: switch to UDS instead of using TCP
This commit is contained in:
parent
a8ea3044de
commit
0a3d8a2a39
@ -15,7 +15,7 @@ use sha3::Digest;
|
|||||||
use sqlx::{ConnectOptions, Executor, Pool, Sqlite};
|
use sqlx::{ConnectOptions, Executor, Pool, Sqlite};
|
||||||
use sqlx::migrate::Migrator;
|
use sqlx::migrate::Migrator;
|
||||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
||||||
use tokio::net::{TcpListener, TcpStream};
|
use tokio::net::{UnixListener, UnixStream};
|
||||||
use tokio::sync::mpsc::{Sender, UnboundedSender};
|
use tokio::sync::mpsc::{Sender, UnboundedSender};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tokio_tungstenite::{
|
use tokio_tungstenite::{
|
||||||
@ -24,19 +24,17 @@ use tokio_tungstenite::{
|
|||||||
};
|
};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::types::{
|
||||||
types::{
|
protocol::{
|
||||||
protocol::{
|
MessageRequest,
|
||||||
MessageRequest,
|
MessageResponse,
|
||||||
MessageResponse,
|
RegisterRequest,
|
||||||
RegisterRequest,
|
RegisterResponse,
|
||||||
RegisterResponse,
|
RequestContainer,
|
||||||
RequestContainer,
|
RequestKind,
|
||||||
RequestKind,
|
ResponseContainer,
|
||||||
ResponseContainer,
|
|
||||||
},
|
|
||||||
user::User,
|
|
||||||
},
|
},
|
||||||
|
user::User,
|
||||||
};
|
};
|
||||||
use crate::handlers::SecretsRequestInfo;
|
use crate::handlers::SecretsRequestInfo;
|
||||||
use crate::types::config::Config;
|
use crate::types::config::Config;
|
||||||
@ -53,7 +51,7 @@ pub mod influx;
|
|||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||||
|
|
||||||
pub type WsStream = WebSocketStream<TcpStream>;
|
pub type WsStream = WebSocketStream<UnixStream>;
|
||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
pub db: Pool<Sqlite>,
|
pub db: Pool<Sqlite>,
|
||||||
@ -134,7 +132,7 @@ async fn main() -> Result<()> {
|
|||||||
let (updater_tx, updater_rx) = tokio::sync::mpsc::unbounded_channel();
|
let (updater_tx, updater_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
|
|
||||||
// set up server
|
// set up server
|
||||||
let server = TcpListener::bind(&config.server.address).await?;
|
let server = UnixListener::bind(&config.server.path)?;
|
||||||
let state = Arc::new(RwLock::new(State {
|
let state = Arc::new(RwLock::new(State {
|
||||||
db: pool,
|
db: pool,
|
||||||
clients: Default::default(),
|
clients: Default::default(),
|
||||||
@ -144,7 +142,12 @@ async fn main() -> Result<()> {
|
|||||||
updater_tx,
|
updater_tx,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
info!("Listening on ws://{}/", server.local_addr()?);
|
let listening_on = server.local_addr()
|
||||||
|
.ok()
|
||||||
|
.and_then(|addr| addr.as_pathname().map(ToOwned::to_owned))
|
||||||
|
.and_then(|addr| addr.to_str().map(ToOwned::to_owned))
|
||||||
|
.unwrap_or_else(|| config.server.path.to_string_lossy().to_string());
|
||||||
|
info!("Listening on ws://unix:{listening_on}/");
|
||||||
|
|
||||||
let (quit_tx, mut quit_rx) = tokio::sync::mpsc::channel(1);
|
let (quit_tx, mut quit_rx) = tokio::sync::mpsc::channel(1);
|
||||||
let (announce_tx, mut announce_rx) = tokio::sync::mpsc::channel(1);
|
let (announce_tx, mut announce_rx) = tokio::sync::mpsc::channel(1);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
@ -11,7 +13,7 @@ pub struct Config {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
pub address: String,
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
Loading…
Reference in New Issue
Block a user