mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
udp: replace PanicSentinel with loop over JoinHandles
This commit is contained in:
parent
239266ddab
commit
8f838098aa
6 changed files with 97 additions and 58 deletions
|
|
@ -9,7 +9,7 @@ use mio::{Events, Interest, Poll, Token};
|
|||
|
||||
use aquatic_common::{
|
||||
access_list::create_access_list_cache, privileges::PrivilegeDropper, CanonicalSocketAddr,
|
||||
PanicSentinel, ValidUntil,
|
||||
ValidUntil,
|
||||
};
|
||||
use aquatic_udp_protocol::*;
|
||||
|
||||
|
|
@ -49,9 +49,7 @@ pub struct SocketWorker {
|
|||
}
|
||||
|
||||
impl SocketWorker {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn run(
|
||||
_sentinel: PanicSentinel,
|
||||
shared_state: State,
|
||||
config: Config,
|
||||
validator: ConnectionValidator,
|
||||
|
|
@ -59,7 +57,7 @@ impl SocketWorker {
|
|||
request_sender: ConnectedRequestSender,
|
||||
response_receiver: ConnectedResponseReceiver,
|
||||
priv_dropper: PrivilegeDropper,
|
||||
) {
|
||||
) -> anyhow::Result<()> {
|
||||
let socket =
|
||||
UdpSocket::from_std(create_socket(&config, priv_dropper).expect("create socket"));
|
||||
let access_list_cache = create_access_list_cache(&shared_state.access_list);
|
||||
|
|
@ -82,6 +80,8 @@ impl SocketWorker {
|
|||
};
|
||||
|
||||
worker.run_inner();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_inner(&mut self) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ mod uring;
|
|||
mod validator;
|
||||
|
||||
use anyhow::Context;
|
||||
use aquatic_common::{privileges::PrivilegeDropper, PanicSentinel, ServerStartInstant};
|
||||
use aquatic_common::{privileges::PrivilegeDropper, ServerStartInstant};
|
||||
use socket2::{Domain, Protocol, Socket, Type};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -36,9 +36,7 @@ const EXTRA_PACKET_SIZE_IPV4: usize = 8 + 18 + 20 + 8;
|
|||
/// - 8 bit udp header
|
||||
const EXTRA_PACKET_SIZE_IPV6: usize = 8 + 18 + 40 + 8;
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn run_socket_worker(
|
||||
sentinel: PanicSentinel,
|
||||
shared_state: State,
|
||||
config: Config,
|
||||
validator: ConnectionValidator,
|
||||
|
|
@ -46,12 +44,11 @@ pub fn run_socket_worker(
|
|||
request_sender: ConnectedRequestSender,
|
||||
response_receiver: ConnectedResponseReceiver,
|
||||
priv_dropper: PrivilegeDropper,
|
||||
) {
|
||||
) -> anyhow::Result<()> {
|
||||
#[cfg(all(target_os = "linux", feature = "io-uring"))]
|
||||
match self::uring::supported_on_current_kernel() {
|
||||
Ok(()) => {
|
||||
self::uring::SocketWorker::run(
|
||||
sentinel,
|
||||
return self::uring::SocketWorker::run(
|
||||
shared_state,
|
||||
config,
|
||||
validator,
|
||||
|
|
@ -60,8 +57,6 @@ pub fn run_socket_worker(
|
|||
response_receiver,
|
||||
priv_dropper,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
Err(err) => {
|
||||
::log::warn!(
|
||||
|
|
@ -71,8 +66,7 @@ pub fn run_socket_worker(
|
|||
}
|
||||
}
|
||||
|
||||
self::mio::SocketWorker::run(
|
||||
sentinel,
|
||||
return self::mio::SocketWorker::run(
|
||||
shared_state,
|
||||
config,
|
||||
validator,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use io_uring::{IoUring, Probe};
|
|||
|
||||
use aquatic_common::{
|
||||
access_list::create_access_list_cache, privileges::PrivilegeDropper, CanonicalSocketAddr,
|
||||
PanicSentinel, ValidUntil,
|
||||
ValidUntil,
|
||||
};
|
||||
use aquatic_udp_protocol::*;
|
||||
|
||||
|
|
@ -96,9 +96,7 @@ pub struct SocketWorker {
|
|||
}
|
||||
|
||||
impl SocketWorker {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn run(
|
||||
_sentinel: PanicSentinel,
|
||||
shared_state: State,
|
||||
config: Config,
|
||||
validator: ConnectionValidator,
|
||||
|
|
@ -106,7 +104,7 @@ impl SocketWorker {
|
|||
request_sender: ConnectedRequestSender,
|
||||
response_receiver: ConnectedResponseReceiver,
|
||||
priv_dropper: PrivilegeDropper,
|
||||
) {
|
||||
) -> anyhow::Result<()> {
|
||||
let ring_entries = config.network.ring_size.next_power_of_two();
|
||||
// Try to fill up the ring with send requests
|
||||
let send_buffer_entries = ring_entries;
|
||||
|
|
@ -191,6 +189,8 @@ impl SocketWorker {
|
|||
};
|
||||
|
||||
CurrentRing::with(|ring| worker.run_inner(ring));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_inner(&mut self, ring: &mut IoUring) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::io::Write;
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
use anyhow::Context;
|
||||
use aquatic_common::{IndexMap, PanicSentinel};
|
||||
use aquatic_common::IndexMap;
|
||||
use aquatic_udp_protocol::{PeerClient, PeerId};
|
||||
use compact_str::CompactString;
|
||||
use crossbeam_channel::Receiver;
|
||||
|
|
@ -42,11 +42,10 @@ struct TemplateData {
|
|||
}
|
||||
|
||||
pub fn run_statistics_worker(
|
||||
_sentinel: PanicSentinel,
|
||||
config: Config,
|
||||
shared_state: State,
|
||||
statistics_receiver: Receiver<StatisticsMessage>,
|
||||
) {
|
||||
) -> anyhow::Result<()> {
|
||||
let process_peer_client_data = {
|
||||
let mut collect = config.statistics.write_html_to_file;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crossbeam_channel::Receiver;
|
|||
use crossbeam_channel::Sender;
|
||||
use rand::{rngs::SmallRng, SeedableRng};
|
||||
|
||||
use aquatic_common::{CanonicalSocketAddr, PanicSentinel, ValidUntil};
|
||||
use aquatic_common::{CanonicalSocketAddr, ValidUntil};
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::Config;
|
||||
|
|
@ -18,7 +18,6 @@ use crate::config::Config;
|
|||
use storage::TorrentMaps;
|
||||
|
||||
pub struct SwarmWorker {
|
||||
pub _sentinel: PanicSentinel,
|
||||
pub config: Config,
|
||||
pub state: State,
|
||||
pub server_start_instant: ServerStartInstant,
|
||||
|
|
@ -29,7 +28,7 @@ pub struct SwarmWorker {
|
|||
}
|
||||
|
||||
impl SwarmWorker {
|
||||
pub fn run(&mut self) {
|
||||
pub fn run(&mut self) -> anyhow::Result<()> {
|
||||
let mut torrents = TorrentMaps::default();
|
||||
let mut rng = SmallRng::from_entropy();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue