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:
Joakim Frostegård 2020-07-21 23:01:34 +02:00
parent 32402a4dca
commit f1f708465a
15 changed files with 117 additions and 162 deletions

15
Cargo.lock generated
View file

@ -54,19 +54,6 @@ dependencies = [
"rand",
]
[[package]]
name = "aquatic_common_tcp"
version = "0.1.0"
dependencies = [
"anyhow",
"aquatic_common",
"mio",
"native-tls",
"parking_lot",
"serde",
"socket2",
]
[[package]]
name = "aquatic_http"
version = "0.1.0"
@ -74,7 +61,6 @@ dependencies = [
"anyhow",
"aquatic_cli_helpers",
"aquatic_common",
"aquatic_common_tcp",
"aquatic_http_protocol",
"either",
"flume",
@ -94,6 +80,7 @@ dependencies = [
"serde",
"simplelog",
"smartstring",
"socket2",
]
[[package]]

View file

@ -3,7 +3,6 @@
members = [
"aquatic_cli_helpers",
"aquatic_common",
"aquatic_common_tcp",
"aquatic_http",
"aquatic_http_load_test",
"aquatic_http_protocol",

View file

@ -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"] }

View file

@ -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>>>;

View file

@ -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(),
}
}
}

View file

@ -1,3 +0,0 @@
pub mod config;
pub mod common;
pub mod network;

View file

@ -1,2 +0,0 @@
pub mod stream;
pub mod utils;

View file

@ -17,7 +17,6 @@ path = "src/bin/main.rs"
anyhow = "1"
aquatic_cli_helpers = { path = "../aquatic_cli_helpers" }
aquatic_common = { path = "../aquatic_common" }
aquatic_common_tcp = { path = "../aquatic_common_tcp" }
aquatic_http_protocol = { path = "../aquatic_http_protocol" }
either = "1"
flume = "0.7"
@ -35,6 +34,7 @@ rand = { version = "0.7", features = ["small_rng"] }
serde = { version = "1", features = ["derive"] }
simplelog = "0.8"
smartstring = "0.2"
socket2 = { version = "0.3", features = ["reuseport"] }
[dev-dependencies]
quickcheck = "0.9"

View file

@ -2,7 +2,24 @@ use std::net::SocketAddr;
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)]
@ -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)]
#[serde(default)]
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 {
fn default() -> Self {
Self {
@ -83,3 +144,46 @@ impl Default for ProtocolConfig {
}
}
}
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(),
}
}
}

View file

@ -6,8 +6,6 @@ use anyhow::Context;
use parking_lot::Mutex;
use privdrop::PrivDrop;
use aquatic_common_tcp::network::utils::create_tls_acceptor;
pub mod common;
pub mod config;
pub mod handler;
@ -16,6 +14,7 @@ pub mod tasks;
use common::*;
use config::Config;
use network::utils::create_tls_acceptor;
pub fn run(config: Config) -> anyhow::Result<()> {

View file

@ -8,11 +8,12 @@ use mio::Token;
use mio::net::TcpStream;
use native_tls::{TlsAcceptor, MidHandshakeTlsStream};
use aquatic_common_tcp::network::stream::Stream;
use aquatic_http_protocol::request::{Request, RequestParseError};
use crate::common::*;
use super::stream::Stream;
#[derive(Debug)]
pub enum RequestReadError {

View file

@ -1,5 +1,3 @@
pub mod connection;
use std::time::{Duration, Instant};
use std::io::ErrorKind;
use std::sync::Arc;
@ -11,13 +9,17 @@ use native_tls::TlsAcceptor;
use mio::{Events, Poll, Interest, Token};
use mio::net::TcpListener;
use aquatic_common_tcp::network::utils::create_listener;
use aquatic_http_protocol::response::*;
use crate::common::*;
use crate::config::Config;
pub mod connection;
pub mod stream;
pub mod utils;
use connection::*;
use utils::*;
pub fn run_socket_worker(

View file

@ -1,4 +1,3 @@
use std::fs::File;
use std::io::Read;
use std::net::SocketAddr;