mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
http, http_private: rename request workers to swarm workers
This commit is contained in:
parent
fb2794643d
commit
c89406179b
12 changed files with 31 additions and 33 deletions
|
|
@ -14,12 +14,12 @@ use aquatic_common::cli::LogLevel;
|
|||
#[serde(default)]
|
||||
pub struct Config {
|
||||
/// Socket workers receive requests from the socket, parse them and send
|
||||
/// them on to the request workers. They then receive responses from the
|
||||
/// request workers, encode them and send them back over the socket.
|
||||
/// them on to the swarm workers. They then receive responses from the
|
||||
/// swarm workers, encode them and send them back over the socket.
|
||||
pub socket_workers: usize,
|
||||
/// Request workers receive a number of requests from socket workers,
|
||||
/// Swarm workers receive a number of requests from socket workers,
|
||||
/// generate responses and send them back to the socket workers.
|
||||
pub request_workers: usize,
|
||||
pub swarm_workers: usize,
|
||||
pub log_level: LogLevel,
|
||||
pub network: NetworkConfig,
|
||||
pub protocol: ProtocolConfig,
|
||||
|
|
@ -33,7 +33,7 @@ impl Default for Config {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
socket_workers: 1,
|
||||
request_workers: 1,
|
||||
swarm_workers: 1,
|
||||
log_level: LogLevel::default(),
|
||||
network: NetworkConfig::default(),
|
||||
protocol: ProtocolConfig::default(),
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
update_access_list(&config.access_list, &state.access_list)?;
|
||||
|
||||
let num_peers = config.socket_workers + config.request_workers;
|
||||
let num_peers = config.socket_workers + config.swarm_workers;
|
||||
|
||||
let request_mesh_builder = MeshBuilder::partial(num_peers, SHARED_CHANNEL_SIZE);
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let placement = get_worker_placement(
|
||||
&config.cpu_pinning,
|
||||
config.socket_workers,
|
||||
config.request_workers,
|
||||
config.swarm_workers,
|
||||
WorkerIndex::SocketWorker(i),
|
||||
)?;
|
||||
let builder = LocalExecutorBuilder::new(placement).name("socket");
|
||||
|
|
@ -81,7 +81,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
executors.push(executor);
|
||||
}
|
||||
|
||||
for i in 0..(config.request_workers) {
|
||||
for i in 0..(config.swarm_workers) {
|
||||
let sentinel = sentinel.clone();
|
||||
let config = config.clone();
|
||||
let state = state.clone();
|
||||
|
|
@ -90,14 +90,14 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let placement = get_worker_placement(
|
||||
&config.cpu_pinning,
|
||||
config.socket_workers,
|
||||
config.request_workers,
|
||||
config.swarm_workers,
|
||||
WorkerIndex::SwarmWorker(i),
|
||||
)?;
|
||||
let builder = LocalExecutorBuilder::new(placement).name("request");
|
||||
|
||||
let executor = builder
|
||||
.spawn(move || async move {
|
||||
workers::request::run_request_worker(sentinel, config, state, request_mesh_builder)
|
||||
workers::swarm::run_swarm_worker(sentinel, config, state, request_mesh_builder)
|
||||
.await
|
||||
})
|
||||
.map_err(|err| anyhow::anyhow!("Spawning executor failed: {:#}", err))?;
|
||||
|
|
@ -109,7 +109,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
set_affinity_for_util_worker(
|
||||
&config.cpu_pinning,
|
||||
config.socket_workers,
|
||||
config.request_workers,
|
||||
config.swarm_workers,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
pub mod request;
|
||||
pub mod socket;
|
||||
pub mod swarm;
|
||||
|
|
|
|||
|
|
@ -264,10 +264,10 @@ impl Connection {
|
|||
/// Take a request and:
|
||||
/// - Update connection ValidUntil
|
||||
/// - Return error response if request is not allowed
|
||||
/// - If it is an announce request, send it to request workers an await a
|
||||
/// - If it is an announce request, send it to swarm workers an await a
|
||||
/// response
|
||||
/// - If it is a scrape requests, split it up, pass on the parts to
|
||||
/// relevant request workers and await a response
|
||||
/// relevant swarm workers and await a response
|
||||
async fn handle_request(&mut self, request: Request) -> anyhow::Result<Response> {
|
||||
if let Ok(mut slab) = self.connection_slab.try_borrow_mut() {
|
||||
if let Some(reference) = slab.get_mut(self.connection_id.0) {
|
||||
|
|
@ -448,7 +448,7 @@ impl Connection {
|
|||
}
|
||||
|
||||
fn calculate_request_consumer_index(config: &Config, info_hash: InfoHash) -> usize {
|
||||
(info_hash.0[0] as usize) % config.request_workers
|
||||
(info_hash.0[0] as usize) % config.swarm_workers
|
||||
}
|
||||
|
||||
fn create_tcp_listener(
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ impl TorrentMaps {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn run_request_worker(
|
||||
pub async fn run_swarm_worker(
|
||||
_sentinel: PanicSentinel,
|
||||
config: Config,
|
||||
state: State,
|
||||
|
|
@ -235,7 +235,7 @@ async fn handle_request_stream<S>(
|
|||
);
|
||||
|
||||
if let Err(err) = response_sender.connect().await.send(response).await {
|
||||
::log::error!("request worker could not send announce response: {:#}", err);
|
||||
::log::error!("swarm worker could not send announce response: {:#}", err);
|
||||
}
|
||||
}
|
||||
ChannelRequest::Scrape {
|
||||
|
|
@ -247,7 +247,7 @@ async fn handle_request_stream<S>(
|
|||
handle_scrape_request(&config, &mut torrents.borrow_mut(), peer_addr, request);
|
||||
|
||||
if let Err(err) = response_sender.connect().await.send(response).await {
|
||||
::log::error!("request worker could not send scrape response: {:#}", err);
|
||||
::log::error!("swarm worker could not send scrape response: {:#}", err);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue