pub async fn download_from_dirport(
endpoint: &DirPort,
resource: &str,
compression: &[Compression],
request_timeout: Option<Duration>,
) -> Result<DownloadResult, Error>Expand description
Downloads a resource from a directory port.
This is the low-level download function that handles HTTP communication
with a single endpoint. Higher-level functions like download_consensus()
use this internally with retry logic.
§Arguments
endpoint- The directory port to download fromresource- The URL path to request (e.g., “/tor/status-vote/current/consensus”)compression- List of acceptable compression formats, in preference orderrequest_timeout- Optional timeout for the entire request
§Returns
A DownloadResult containing the response body and metadata.
§Errors
Returns Error::Download if:
- Connection to the endpoint fails
- The HTTP response indicates an error (non-200 status)
- The response is malformed
Returns Error::DownloadTimeout if the request exceeds the timeout.
§Example
use stem_rs::descriptor::remote::{download_from_dirport, DirPort, Compression};
use std::time::Duration;
let endpoint = DirPort::new("128.31.0.39".parse().unwrap(), 9131);
let result = download_from_dirport(
&endpoint,
"/tor/status-vote/current/consensus",
&[Compression::Gzip, Compression::Plaintext],
Some(Duration::from_secs(30)),
).await?;
println!("Downloaded {} bytes", result.content.len());