mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
remove aquatic_common_tcp crate, move contents into aquatic_http
It doesn't make a lot of sense to make a separate crate for the few things here. I don't really want tight coupling between the crates anyway, since it impedes making changes in them and makes understanding them more difficult.
This commit is contained in:
parent
32402a4dca
commit
f1f708465a
15 changed files with 117 additions and 162 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
|
@ -54,19 +54,6 @@ dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aquatic_common_tcp"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"aquatic_common",
|
|
||||||
"mio",
|
|
||||||
"native-tls",
|
|
||||||
"parking_lot",
|
|
||||||
"serde",
|
|
||||||
"socket2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aquatic_http"
|
name = "aquatic_http"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
@ -74,7 +61,6 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"aquatic_cli_helpers",
|
"aquatic_cli_helpers",
|
||||||
"aquatic_common",
|
"aquatic_common",
|
||||||
"aquatic_common_tcp",
|
|
||||||
"aquatic_http_protocol",
|
"aquatic_http_protocol",
|
||||||
"either",
|
"either",
|
||||||
"flume",
|
"flume",
|
||||||
|
|
@ -94,6 +80,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"simplelog",
|
"simplelog",
|
||||||
"smartstring",
|
"smartstring",
|
||||||
|
"socket2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
members = [
|
members = [
|
||||||
"aquatic_cli_helpers",
|
"aquatic_cli_helpers",
|
||||||
"aquatic_common",
|
"aquatic_common",
|
||||||
"aquatic_common_tcp",
|
|
||||||
"aquatic_http",
|
"aquatic_http",
|
||||||
"aquatic_http_load_test",
|
"aquatic_http_load_test",
|
||||||
"aquatic_http_protocol",
|
"aquatic_http_protocol",
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "aquatic_common_tcp"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Joakim Frostegård <joakim.frostegard@gmail.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
license = "Apache-2.0"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "aquatic_common_tcp"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
anyhow = "1"
|
|
||||||
aquatic_common = { path = "../aquatic_common" }
|
|
||||||
mio = { version = "0.7", features = ["tcp", "os-poll", "os-util"] }
|
|
||||||
native-tls = "0.2"
|
|
||||||
parking_lot = "0.11"
|
|
||||||
serde = { version = "1", features = ["derive"] }
|
|
||||||
socket2 = { version = "0.3", features = ["reuseport"] }
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
|
|
||||||
|
|
||||||
pub type SocketWorkerStatus = Option<Result<(), String>>;
|
|
||||||
pub type SocketWorkerStatuses = Arc<Mutex<Vec<SocketWorkerStatus>>>;
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "lowercase")]
|
|
||||||
pub enum LogLevel {
|
|
||||||
Off,
|
|
||||||
Error,
|
|
||||||
Warn,
|
|
||||||
Info,
|
|
||||||
Debug,
|
|
||||||
Trace
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for LogLevel {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub struct HandlerConfig {
|
|
||||||
/// Maximum number of requests to receive from channel before locking
|
|
||||||
/// mutex and starting work
|
|
||||||
pub max_requests_per_iter: usize,
|
|
||||||
pub channel_recv_timeout_microseconds: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub struct TlsConfig {
|
|
||||||
pub use_tls: bool,
|
|
||||||
pub tls_pkcs12_path: String,
|
|
||||||
pub tls_pkcs12_password: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub struct CleaningConfig {
|
|
||||||
/// Clean peers this often (seconds)
|
|
||||||
pub interval: u64,
|
|
||||||
/// Remove peers that haven't announced for this long (seconds)
|
|
||||||
pub max_peer_age: u64,
|
|
||||||
/// Remove connections that are older than this (seconds)
|
|
||||||
pub max_connection_age: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub struct PrivilegeConfig {
|
|
||||||
/// Chroot and switch user after binding to sockets
|
|
||||||
pub drop_privileges: bool,
|
|
||||||
/// Chroot to this path
|
|
||||||
pub chroot_path: String,
|
|
||||||
/// User to switch to after chrooting
|
|
||||||
pub user: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for HandlerConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
max_requests_per_iter: 10000,
|
|
||||||
channel_recv_timeout_microseconds: 200,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for TlsConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
use_tls: false,
|
|
||||||
tls_pkcs12_path: "".into(),
|
|
||||||
tls_pkcs12_password: "".into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for CleaningConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
interval: 30,
|
|
||||||
max_peer_age: 180,
|
|
||||||
max_connection_age: 180,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for PrivilegeConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
drop_privileges: false,
|
|
||||||
chroot_path: ".".to_string(),
|
|
||||||
user: "nobody".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
pub mod config;
|
|
||||||
pub mod common;
|
|
||||||
pub mod network;
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
pub mod stream;
|
|
||||||
pub mod utils;
|
|
||||||
|
|
@ -17,7 +17,6 @@ path = "src/bin/main.rs"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
aquatic_cli_helpers = { path = "../aquatic_cli_helpers" }
|
aquatic_cli_helpers = { path = "../aquatic_cli_helpers" }
|
||||||
aquatic_common = { path = "../aquatic_common" }
|
aquatic_common = { path = "../aquatic_common" }
|
||||||
aquatic_common_tcp = { path = "../aquatic_common_tcp" }
|
|
||||||
aquatic_http_protocol = { path = "../aquatic_http_protocol" }
|
aquatic_http_protocol = { path = "../aquatic_http_protocol" }
|
||||||
either = "1"
|
either = "1"
|
||||||
flume = "0.7"
|
flume = "0.7"
|
||||||
|
|
@ -35,6 +34,7 @@ rand = { version = "0.7", features = ["small_rng"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
simplelog = "0.8"
|
simplelog = "0.8"
|
||||||
smartstring = "0.2"
|
smartstring = "0.2"
|
||||||
|
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "0.9"
|
||||||
|
|
|
||||||
|
|
@ -169,4 +169,4 @@ impl ResponseChannelSender {
|
||||||
|
|
||||||
|
|
||||||
pub type SocketWorkerStatus = Option<Result<(), String>>;
|
pub type SocketWorkerStatus = Option<Result<(), String>>;
|
||||||
pub type SocketWorkerStatuses = Arc<Mutex<Vec<SocketWorkerStatus>>>;
|
pub type SocketWorkerStatuses = Arc<Mutex<Vec<SocketWorkerStatus>>>;
|
||||||
|
|
@ -2,7 +2,24 @@ use std::net::SocketAddr;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
pub use aquatic_common_tcp::config::*;
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum LogLevel {
|
||||||
|
Off,
|
||||||
|
Error,
|
||||||
|
Warn,
|
||||||
|
Info,
|
||||||
|
Debug,
|
||||||
|
Trace
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for LogLevel {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
|
@ -21,6 +38,15 @@ pub struct Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct TlsConfig {
|
||||||
|
pub use_tls: bool,
|
||||||
|
pub tls_pkcs12_path: String,
|
||||||
|
pub tls_pkcs12_password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct NetworkConfig {
|
pub struct NetworkConfig {
|
||||||
|
|
@ -46,6 +72,41 @@ pub struct ProtocolConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct HandlerConfig {
|
||||||
|
/// Maximum number of requests to receive from channel before locking
|
||||||
|
/// mutex and starting work
|
||||||
|
pub max_requests_per_iter: usize,
|
||||||
|
pub channel_recv_timeout_microseconds: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct CleaningConfig {
|
||||||
|
/// Clean peers this often (seconds)
|
||||||
|
pub interval: u64,
|
||||||
|
/// Remove peers that haven't announced for this long (seconds)
|
||||||
|
pub max_peer_age: u64,
|
||||||
|
/// Remove connections that are older than this (seconds)
|
||||||
|
pub max_connection_age: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct PrivilegeConfig {
|
||||||
|
/// Chroot and switch user after binding to sockets
|
||||||
|
pub drop_privileges: bool,
|
||||||
|
/// Chroot to this path
|
||||||
|
pub chroot_path: String,
|
||||||
|
/// User to switch to after chrooting
|
||||||
|
pub user: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -82,4 +143,47 @@ impl Default for ProtocolConfig {
|
||||||
peer_announce_interval: 120,
|
peer_announce_interval: 120,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for HandlerConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
max_requests_per_iter: 10000,
|
||||||
|
channel_recv_timeout_microseconds: 200,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for CleaningConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
interval: 30,
|
||||||
|
max_peer_age: 180,
|
||||||
|
max_connection_age: 180,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for PrivilegeConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
drop_privileges: false,
|
||||||
|
chroot_path: ".".to_string(),
|
||||||
|
user: "nobody".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for TlsConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
use_tls: false,
|
||||||
|
tls_pkcs12_path: "".into(),
|
||||||
|
tls_pkcs12_password: "".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ use anyhow::Context;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use privdrop::PrivDrop;
|
use privdrop::PrivDrop;
|
||||||
|
|
||||||
use aquatic_common_tcp::network::utils::create_tls_acceptor;
|
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod handler;
|
pub mod handler;
|
||||||
|
|
@ -16,6 +14,7 @@ pub mod tasks;
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
use network::utils::create_tls_acceptor;
|
||||||
|
|
||||||
|
|
||||||
pub fn run(config: Config) -> anyhow::Result<()> {
|
pub fn run(config: Config) -> anyhow::Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@ use mio::Token;
|
||||||
use mio::net::TcpStream;
|
use mio::net::TcpStream;
|
||||||
use native_tls::{TlsAcceptor, MidHandshakeTlsStream};
|
use native_tls::{TlsAcceptor, MidHandshakeTlsStream};
|
||||||
|
|
||||||
use aquatic_common_tcp::network::stream::Stream;
|
|
||||||
use aquatic_http_protocol::request::{Request, RequestParseError};
|
use aquatic_http_protocol::request::{Request, RequestParseError};
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
|
use super::stream::Stream;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RequestReadError {
|
pub enum RequestReadError {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
pub mod connection;
|
|
||||||
|
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -11,13 +9,17 @@ use native_tls::TlsAcceptor;
|
||||||
use mio::{Events, Poll, Interest, Token};
|
use mio::{Events, Poll, Interest, Token};
|
||||||
use mio::net::TcpListener;
|
use mio::net::TcpListener;
|
||||||
|
|
||||||
use aquatic_common_tcp::network::utils::create_listener;
|
|
||||||
use aquatic_http_protocol::response::*;
|
use aquatic_http_protocol::response::*;
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
|
pub mod connection;
|
||||||
|
pub mod stream;
|
||||||
|
pub mod utils;
|
||||||
|
|
||||||
use connection::*;
|
use connection::*;
|
||||||
|
use utils::*;
|
||||||
|
|
||||||
|
|
||||||
pub fn run_socket_worker(
|
pub fn run_socket_worker(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue