mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Improve privilege dropping; run cargo fmt
This commit is contained in:
parent
2ad1418175
commit
c888017072
9 changed files with 70 additions and 92 deletions
|
|
@ -2,11 +2,11 @@ use std::cell::RefCell;
|
|||
use std::collections::BTreeMap;
|
||||
use std::os::unix::prelude::{FromRawFd, IntoRawFd};
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache};
|
||||
use aquatic_common::privileges::PrivilegeDropper;
|
||||
use aquatic_common::rustls_config::RustlsConfig;
|
||||
use aquatic_common::CanonicalSocketAddr;
|
||||
use aquatic_http_protocol::common::InfoHash;
|
||||
|
|
@ -58,13 +58,12 @@ pub async fn run_socket_worker(
|
|||
tls_config: Arc<RustlsConfig>,
|
||||
request_mesh_builder: MeshBuilder<ChannelRequest, Partial>,
|
||||
response_mesh_builder: MeshBuilder<ChannelResponse, Partial>,
|
||||
num_bound_sockets: Arc<AtomicUsize>,
|
||||
priv_dropper: PrivilegeDropper,
|
||||
) {
|
||||
let config = Rc::new(config);
|
||||
let access_list = state.access_list;
|
||||
|
||||
let listener = create_tcp_listener(&config);
|
||||
num_bound_sockets.fetch_add(1, Ordering::SeqCst);
|
||||
let listener = create_tcp_listener(&config, priv_dropper);
|
||||
|
||||
let (request_senders, _) = request_mesh_builder.join(Role::Producer).await.unwrap();
|
||||
let request_senders = Rc::new(request_senders);
|
||||
|
|
@ -485,7 +484,7 @@ fn calculate_request_consumer_index(config: &Config, info_hash: InfoHash) -> usi
|
|||
(info_hash.0[0] as usize) % config.request_workers
|
||||
}
|
||||
|
||||
fn create_tcp_listener(config: &Config) -> TcpListener {
|
||||
fn create_tcp_listener(config: &Config, priv_dropper: PrivilegeDropper) -> TcpListener {
|
||||
let domain = if config.network.address.is_ipv4() {
|
||||
socket2::Domain::IPV4
|
||||
} else {
|
||||
|
|
@ -509,5 +508,7 @@ fn create_tcp_listener(config: &Config) -> TcpListener {
|
|||
.listen(config.network.tcp_backlog)
|
||||
.unwrap_or_else(|err| panic!("socket: listen {}: {:?}", config.network.address, err));
|
||||
|
||||
priv_dropper.after_socket_creation();
|
||||
|
||||
unsafe { TcpListener::from_raw_fd(socket.into_raw_fd()) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue