pub struct SnapshotDownloader { /* private fields */ }
Expand description
Downloads snapshot archives from HTTP/HTTPS and file:// URLs.
Provides secure, reliable downloading with automatic retry logic for network sources and direct file copying for local sources.
§Features
- HTTP/HTTPS: Automatic retry with exponential backoff, progress tracking
- Local Files: Direct copying from file:// URLs with validation
- Safety: Size limits, disk space checks, timeout protection
- Monitoring: Progress reporting and detailed error messages
§Examples
use std::path::Path;
use hopr_chain_indexer::snapshot::download::SnapshotDownloader;
let downloader = SnapshotDownloader::new()?;
// Download from HTTPS
downloader
.download_snapshot(
"https://snapshots.hoprnet.org/logs.tar.xz",
Path::new("/tmp/snapshot.tar.xz"),
)
.await?;
// Copy from local file
downloader
.download_snapshot("file:///backups/snapshot.tar.xz", Path::new("/tmp/snapshot.tar.xz"))
.await?;
Implementations§
Source§impl SnapshotDownloader
impl SnapshotDownloader
Sourcepub fn new() -> SnapshotResult<Self>
pub fn new() -> SnapshotResult<Self>
Creates a new snapshot downloader with default configuration
Sourcepub fn with_config(config: DownloadConfig) -> SnapshotResult<Self>
pub fn with_config(config: DownloadConfig) -> SnapshotResult<Self>
Creates a new snapshot downloader with custom configuration
Sourcepub async fn download_snapshot(
&self,
url: &str,
target_path: &Path,
) -> SnapshotResult<()>
pub async fn download_snapshot( &self, url: &str, target_path: &Path, ) -> SnapshotResult<()>
Downloads a snapshot from the given URL to the target path.
Supports HTTP/HTTPS URLs with retry logic and file:// URLs for local files.
§Arguments
url
- Source URL (http://, https://, or file:// scheme)target_path
- Destination file path
§Errors
Returns SnapshotError
for network failures, file system errors, or validation failures.
Sourcepub async fn download_snapshot_with_retry(
&self,
url: &str,
target_path: &Path,
max_retries: u32,
) -> SnapshotResult<()>
pub async fn download_snapshot_with_retry( &self, url: &str, target_path: &Path, max_retries: u32, ) -> SnapshotResult<()>
Downloads a snapshot with configurable retry logic.
Implements exponential backoff between retry attempts for HTTP/HTTPS URLs. Local file:// URLs are handled without retry logic. Certain errors (like 4xx HTTP status codes or insufficient disk space) will not be retried.
§Arguments
url
- The HTTP/HTTPS or file:// URL to download/copy fromtarget_path
- Local path where the downloaded file will be savedmax_retries
- Maximum number of retry attempts (ignored for file:// URLs)
§Errors
Returns SnapshotError
for various failure conditions including:
- Network errors (with retry)
- HTTP errors (4xx without retry, 5xx with retry)
- Insufficient disk space (without retry)
- File size exceeding limits (without retry)
Sourcepub async fn check_disk_space(&self, dir: &Path) -> SnapshotResult<()>
pub async fn check_disk_space(&self, dir: &Path) -> SnapshotResult<()>
Checks if there’s sufficient disk space available for download and extraction.
Validates that the target directory has at least 3x the maximum download size available to account for:
- The downloaded archive
- Extracted files
- Safety margin for system operations
§Arguments
dir
- Directory to check for available space
§Errors
Returns SnapshotError::InsufficientSpace
if available space is below requirements
Auto Trait Implementations§
impl Freeze for SnapshotDownloader
impl !RefUnwindSafe for SnapshotDownloader
impl Send for SnapshotDownloader
impl Sync for SnapshotDownloader
impl Unpin for SnapshotDownloader
impl !UnwindSafe for SnapshotDownloader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more