move back SocketConfig to aquatic_http

This commit is contained in:
Joakim Frostegård 2020-07-02 17:06:34 +02:00
parent 82378e71f6
commit b86787ef20
5 changed files with 18 additions and 31 deletions

View file

@ -6,7 +6,6 @@
and maybe run scripts should be adjusted and maybe run scripts should be adjusted
## aquatic_http ## aquatic_http
* move stuff to common crate with ws: what about Request/InMessage etc?
* handshake stuff * handshake stuff
* fix overcomplicated and probably incorrect implementation * fix overcomplicated and probably incorrect implementation
* support TLS and plain at the same time?? * support TLS and plain at the same time??
@ -16,6 +15,8 @@
* scrape info hash parsing: multiple ought to be accepted * scrape info hash parsing: multiple ought to be accepted
* info hashes, peer ids: check that whole deserialization and url decoding * info hashes, peer ids: check that whole deserialization and url decoding
works as it should. There are suspicously many `\u{fffd}` works as it should. There are suspicously many `\u{fffd}`
* move stuff to common crate with ws: what about Request/InMessage etc?
* don't overdo this
## aquatic_ws ## aquatic_ws
* tests * tests

View file

@ -31,14 +31,6 @@ pub struct HandlerConfig {
pub channel_recv_timeout_microseconds: u64, pub channel_recv_timeout_microseconds: u64,
} }
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct SocketConfig {
/// Bind to this address
pub address: SocketAddr,
pub ipv6_only: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)] #[serde(default)]
@ -83,16 +75,6 @@ impl Default for HandlerConfig {
} }
impl Default for SocketConfig {
fn default() -> Self {
Self {
address: SocketAddr::from(([0, 0, 0, 0], 3000)),
ipv6_only: false,
}
}
}
impl Default for TlsConfig { impl Default for TlsConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {

View file

@ -2,12 +2,13 @@ pub mod stream;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::net::SocketAddr;
use anyhow::Context; use anyhow::Context;
use native_tls::{Identity, TlsAcceptor}; use native_tls::{Identity, TlsAcceptor};
use socket2::{Socket, Domain, Type, Protocol}; use socket2::{Socket, Domain, Type, Protocol};
use crate::config::{TlsConfig, SocketConfig}; use crate::config::TlsConfig;
pub fn create_tls_acceptor( pub fn create_tls_acceptor(
@ -36,17 +37,17 @@ pub fn create_tls_acceptor(
} }
// will be almost identical to ws version
pub fn create_listener( pub fn create_listener(
config: &SocketConfig address: SocketAddr,
ipv6_only: bool
) -> ::anyhow::Result<::std::net::TcpListener> { ) -> ::anyhow::Result<::std::net::TcpListener> {
let builder = if config.address.is_ipv4(){ let builder = if address.is_ipv4(){
Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())) Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp()))
} else { } else {
Socket::new(Domain::ipv6(), Type::stream(), Some(Protocol::tcp())) Socket::new(Domain::ipv6(), Type::stream(), Some(Protocol::tcp()))
}.context("Couldn't create socket2::Socket")?; }.context("Couldn't create socket2::Socket")?;
if config.ipv6_only { if ipv6_only {
builder.set_only_v6(true) builder.set_only_v6(true)
.context("Couldn't put socket in ipv6 only mode")? .context("Couldn't put socket in ipv6 only mode")?
} }
@ -55,8 +56,8 @@ pub fn create_listener(
.context("Couldn't put socket in non-blocking mode")?; .context("Couldn't put socket in non-blocking mode")?;
builder.set_reuse_port(true) builder.set_reuse_port(true)
.context("Couldn't put socket in reuse_port mode")?; .context("Couldn't put socket in reuse_port mode")?;
builder.bind(&config.address.into()).with_context(|| builder.bind(&address.into()).with_context(||
format!("Couldn't bind socket to address {}", config.address) format!("Couldn't bind socket to address {}", address)
)?; )?;
builder.listen(128) builder.listen(128)
.context("Couldn't listen for connections on socket")?; .context("Couldn't listen for connections on socket")?;

View file

@ -1,3 +1,5 @@
use std::net::SocketAddr;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
pub use aquatic_common_tcp::config::*; pub use aquatic_common_tcp::config::*;
@ -19,12 +21,12 @@ pub struct Config {
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)] #[serde(default)]
pub struct NetworkConfig { pub struct NetworkConfig {
#[serde(flatten)] /// Bind to this address
pub socket: SocketConfig, pub address: SocketAddr,
pub ipv6_only: bool,
#[serde(flatten)] #[serde(flatten)]
pub tls: TlsConfig, pub tls: TlsConfig,
pub poll_event_capacity: usize, pub poll_event_capacity: usize,
@ -63,7 +65,8 @@ impl Default for Config {
impl Default for NetworkConfig { impl Default for NetworkConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
socket: SocketConfig::default(), address: SocketAddr::from(([0, 0, 0, 0], 3000)),
ipv6_only: false,
tls: TlsConfig::default(), tls: TlsConfig::default(),
poll_event_capacity: 4096, poll_event_capacity: 4096,
poll_timeout_milliseconds: 50, poll_timeout_milliseconds: 50,

View file

@ -69,7 +69,7 @@ pub fn run_socket_worker(
response_channel_receiver: ResponseChannelReceiver, response_channel_receiver: ResponseChannelReceiver,
opt_tls_acceptor: Option<TlsAcceptor>, opt_tls_acceptor: Option<TlsAcceptor>,
){ ){
match create_listener(&config.network.socket){ match create_listener(config.network.address, config.network.ipv6_only){
Ok(listener) => { Ok(listener) => {
socket_worker_statuses.lock()[socket_worker_index] = Some(Ok(())); socket_worker_statuses.lock()[socket_worker_index] = Some(Ok(()));