mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
move back SocketConfig to aquatic_http
This commit is contained in:
parent
82378e71f6
commit
b86787ef20
5 changed files with 18 additions and 31 deletions
3
TODO.md
3
TODO.md
|
|
@ -6,7 +6,6 @@
|
|||
and maybe run scripts should be adjusted
|
||||
|
||||
## aquatic_http
|
||||
* move stuff to common crate with ws: what about Request/InMessage etc?
|
||||
* handshake stuff
|
||||
* fix overcomplicated and probably incorrect implementation
|
||||
* support TLS and plain at the same time??
|
||||
|
|
@ -16,6 +15,8 @@
|
|||
* scrape info hash parsing: multiple ought to be accepted
|
||||
* info hashes, peer ids: check that whole deserialization and url decoding
|
||||
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
|
||||
* tests
|
||||
|
|
|
|||
|
|
@ -31,14 +31,6 @@ pub struct HandlerConfig {
|
|||
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)]
|
||||
#[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 {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ pub mod stream;
|
|||
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use anyhow::Context;
|
||||
use native_tls::{Identity, TlsAcceptor};
|
||||
use socket2::{Socket, Domain, Type, Protocol};
|
||||
|
||||
use crate::config::{TlsConfig, SocketConfig};
|
||||
use crate::config::TlsConfig;
|
||||
|
||||
|
||||
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(
|
||||
config: &SocketConfig
|
||||
address: SocketAddr,
|
||||
ipv6_only: bool
|
||||
) -> ::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()))
|
||||
} else {
|
||||
Socket::new(Domain::ipv6(), Type::stream(), Some(Protocol::tcp()))
|
||||
}.context("Couldn't create socket2::Socket")?;
|
||||
|
||||
if config.ipv6_only {
|
||||
if ipv6_only {
|
||||
builder.set_only_v6(true)
|
||||
.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")?;
|
||||
builder.set_reuse_port(true)
|
||||
.context("Couldn't put socket in reuse_port mode")?;
|
||||
builder.bind(&config.address.into()).with_context(||
|
||||
format!("Couldn't bind socket to address {}", config.address)
|
||||
builder.bind(&address.into()).with_context(||
|
||||
format!("Couldn't bind socket to address {}", address)
|
||||
)?;
|
||||
builder.listen(128)
|
||||
.context("Couldn't listen for connections on socket")?;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
pub use aquatic_common_tcp::config::*;
|
||||
|
|
@ -19,12 +21,12 @@ pub struct Config {
|
|||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct NetworkConfig {
|
||||
#[serde(flatten)]
|
||||
pub socket: SocketConfig,
|
||||
/// Bind to this address
|
||||
pub address: SocketAddr,
|
||||
pub ipv6_only: bool,
|
||||
#[serde(flatten)]
|
||||
pub tls: TlsConfig,
|
||||
pub poll_event_capacity: usize,
|
||||
|
|
@ -63,7 +65,8 @@ impl Default for Config {
|
|||
impl Default for NetworkConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
socket: SocketConfig::default(),
|
||||
address: SocketAddr::from(([0, 0, 0, 0], 3000)),
|
||||
ipv6_only: false,
|
||||
tls: TlsConfig::default(),
|
||||
poll_event_capacity: 4096,
|
||||
poll_timeout_milliseconds: 50,
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ pub fn run_socket_worker(
|
|||
response_channel_receiver: ResponseChannelReceiver,
|
||||
opt_tls_acceptor: Option<TlsAcceptor>,
|
||||
){
|
||||
match create_listener(&config.network.socket){
|
||||
match create_listener(config.network.address, config.network.ipv6_only){
|
||||
Ok(listener) => {
|
||||
socket_worker_statuses.lock()[socket_worker_index] = Some(Ok(()));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue