Skip to main content

Crate hpr_net

Crate hpr_net 

Source
Expand description

Optional online data sources with an on-disk cache and an explicit offline mode: weather, soundings, elevation, ThrustCurve and motor stock.

Online data and the cache says what works today and what is planned.

Status: pre-alpha, with six data sources:

This crate does network and file I/O, so it’s never a dependency of the pure core. A Client asks a Transport for a URL’s bytes only when it’s Mode::Online and its Cache holds no fresh copy. In Mode::Offline it never calls the transport. It answers from the cache, stale or not, and says which. The http feature adds Http, the transport over HTTP and HTTPS (rustls, no OpenSSL). Cache::platform_dir names the platform’s usual cache folder.

use hpr_net::{Cache, Client, Freshness, Mode, NetError, Source, Transport};

/// A transport that answers every URL with the same bytes.
struct Canned;
impl Transport for Canned {
    fn get(&self, _url: &str) -> Result<Vec<u8>, String> {
        Ok(b"42".to_vec())
    }
}

let dir = std::env::temp_dir().join(format!("hpr-net-doc-{}", std::process::id()));
let source = Source {
    name: "Example".into(),
    attribution: "Example data".into(),
    ttl_s: 3600,
};
let url = "https://example.test/x";
let online = Client::new(Canned, Cache::new(&dir), Mode::Online);
assert_eq!(online.fetch(&source, url, 1_000)?.freshness, Freshness::Fetched);

let offline = Client::new(Canned, Cache::new(&dir), Mode::Offline);
let later = offline.fetch(&source, url, 1_000 + 7_200)?;
assert_eq!((later.freshness, later.body.as_slice()), (Freshness::Stale, &b"42"[..]));

Modules§

catalog_update
The solid motors and data files ThrustCurve.org lists that the bundled catalog lacks (M5.7d, hpr motors update; ADR-288 §4).
elevation
A launch site’s elevation (height above sea level) from Open-Meteo’s elevation API.
motor_finder
Motor stock and prices from motor.fusionspace.co’s public API.
nomads
Weather from NOAA’s GFS and RAP forecasts: a small GRIB2 cut from NOMADS’ grib filter around a launch site, turned into a SoundingProfile.
on_demand
One motor found by name on ThrustCurve.org, with the curve file to fly it by: for a simulator that lacks the motor’s curve (M4.5b, motors on demand; ADR-154, the decision on fetching them).
open_meteo
Weather from Open-Meteo: a launch site’s forecast (or a past day’s archived forecast) on pressure levels, turned into a SoundingProfile.
thrustcurve
Motor records and thrust curves from ThrustCurve.org’s API, and the join that gives a motor in stock its curve.
wyoming
Weather-balloon soundings from the University of Wyoming’s radiosonde archive, turned into a SoundingProfile.

Structs§

Cache
A directory of cached responses, keyed by URL.
CacheEntry
What the cache knows about one URL.
Client
A cache in front of a transport.
Fetched
A body and where it came from.
Http
A Transport that fetches over HTTP and HTTPS, behind the crate’s http feature.
HttpConfig
How an Http transport behaves. Start from HttpConfig::default and change fields.
Replay
A transport that replays recorded responses from a directory, for tests and offline demos.
Source
One online data source: its name, the credit its terms ask for, and how long a copy stays fresh.

Enums§

Freshness
How a Fetched body relates to its source.
Mode
Whether the client may use the network.
NetError
Why a fetch failed.

Constants§

SOCKS_REFUSED
The words a Transport::get refusal holds when the environment’s proxy is SOCKS, which this transport doesn’t speak: reason.contains(SOCKS_REFUSED) tells that refusal from a failed connection.

Traits§

Transport
Something that fetches a URL’s bytes: Http with the http feature, Replay’s recorded responses in tests.