mod execution;
#[cfg(test)]
mod tests;
mod transport;
mod types;
pub use types::{select_mirrors_by_priority, try_mirrors_with_failover};
use crate::error::Result;
use crate::rate_limiter::RateLimiter;
use crate::request::request_group::{DownloadOptions, RequestGroup};
use crate::util::rwlock_ext::RwLockRecover;
use std::sync::Arc;
use types::FileDownloadInfo;
pub struct MetalinkFileInfo {
pub command: MetalinkDownloadCommand,
pub file_index: usize,
}
pub struct MetalinkDownloadCommand {
pub(crate) group: Arc<std::sync::RwLock<RequestGroup>>,
pub(crate) output_path: std::path::PathBuf,
pub(crate) started: bool,
pub(crate) completed: bool,
pub(crate) completed_bytes: u64,
pub(crate) progress_offset: u64,
pub(crate) file_info: Option<FileDownloadInfo>,
pub(crate) grouped_file_infos: Vec<(std::path::PathBuf, FileDownloadInfo)>,
pub(crate) protocol_runtime: Option<transport::ProtocolRuntime>,
pub(crate) global_limiter: Option<RateLimiter>,
pub(crate) outbound_network_policy: Arc<crate::network::OutboundNetworkPolicy>,
#[cfg(feature = "bittorrent")]
pub(crate) public_tracker_catalog:
Option<Arc<aria2_protocol::bittorrent::tracker::public_list::PublicTrackerList>>,
#[cfg(feature = "bittorrent")]
pub(crate) bt_registry:
Option<Arc<std::sync::RwLock<crate::engine::bittorrent::registry::BtRegistry>>>,
#[cfg(feature = "bittorrent")]
pub(crate) bt_listener:
Option<Arc<crate::engine::bittorrent::peer::listener::BtPeerListenerManager>>,
#[cfg(feature = "bittorrent")]
pub(crate) lpd_manager: Option<Arc<crate::engine::bittorrent::discovery::lpd::LpdManager>>,
#[cfg(feature = "bittorrent")]
pub(crate) open_file_budget: Option<Arc<crate::filesystem::open_file_budget::OpenFileBudget>>,
}
mod constructors;
impl MetalinkDownloadCommand {
pub fn output_path(&self) -> &std::path::Path {
&self.output_path
}
pub fn set_global_limiter(&mut self, limiter: RateLimiter) {
self.global_limiter = Some(limiter);
}
pub(crate) fn set_protocol_runtime(
&mut self,
adapters: crate::engine::protocol_adapter::ProtocolAdapterRegistry,
services: crate::engine::protocol_adapter::ProtocolServices,
) {
self.protocol_runtime = Some(transport::ProtocolRuntime {
adapters: Arc::new(adapters),
services,
});
}
#[cfg(feature = "bittorrent")]
pub fn set_public_tracker_catalog(
&mut self,
catalog: Arc<aria2_protocol::bittorrent::tracker::public_list::PublicTrackerList>,
) {
self.public_tracker_catalog = Some(catalog);
}
#[cfg(feature = "bittorrent")]
pub fn set_bt_registry(
&mut self,
registry: Arc<std::sync::RwLock<crate::engine::bittorrent::registry::BtRegistry>>,
) {
self.bt_registry = Some(registry);
}
#[cfg(feature = "bittorrent")]
pub fn set_bt_listener(
&mut self,
listener: Arc<crate::engine::bittorrent::peer::listener::BtPeerListenerManager>,
) {
self.bt_listener = Some(listener);
}
#[cfg(feature = "bittorrent")]
pub fn set_lpd_manager(
&mut self,
manager: Arc<crate::engine::bittorrent::discovery::lpd::LpdManager>,
) {
self.lpd_manager = Some(manager);
}
#[cfg(feature = "bittorrent")]
pub(crate) fn set_open_file_budget(
&mut self,
budget: Arc<crate::filesystem::open_file_budget::OpenFileBudget>,
) {
self.open_file_budget = Some(budget);
}
pub fn group(&self) -> std::sync::RwLockReadGuard<'_, RequestGroup> {
self.group.recover()
}
pub fn into_group(self) -> Arc<std::sync::RwLock<RequestGroup>> {
self.group
}
}
pub(crate) fn validate_http_client_options(options: &DownloadOptions) -> Result<()> {
let tls = crate::http::client_identity::ClientTlsConfig::from_download_options(options);
let _ = crate::http::client_identity::apply(reqwest::Client::builder(), &tls)?;
Ok(())
}