Skip to content

Commit a57fe6b

Browse files
committed
Refactors loader processing and adds common utils
Removes `bincode` dependency. Introduces common utilities for loader processing to reduce code duplication. This includes CAS URL handling, version change detection, and manifest merging. Refactors Forge and NeoForge to utilize the shared utilities. Adds types for Forge and renames some Forge types. Removes `extract_hash_from_cas_url` and `should_ignore_artifact` from Forge module. Improves code organization and maintainability.
1 parent a8577e7 commit a57fe6b

29 files changed

Lines changed: 3369 additions & 1714 deletions

daedalus/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ bytes = "1"
2626
thiserror = "1"
2727
tokio = { version = "1", features = ["full"] }
2828
sha1 = { version = "0.6.1", features = ["std"] }
29-
bincode = { version = "2.0.0-rc.3", features = ["serde"], optional = true }
3029
once_cell = "1"
3130
url = "2"
3231
lenient_semver = "0"

daedalus/src/lib.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ pub mod modded;
2020
/// Custom version comparison for Minecraft versions
2121
pub mod version;
2222

23+
/// HTTP client configuration constants
24+
/// TCP keepalive interval for persistent connections
25+
const TCP_KEEPALIVE_SECS: u64 = 10;
26+
/// Overall request timeout including reading response
27+
const REQUEST_TIMEOUT_SECS: u64 = 120;
28+
/// Connection establishment timeout
29+
const CONNECT_TIMEOUT_SECS: u64 = 30;
30+
/// Maximum idle connections per host in the pool
31+
const MAX_IDLE_CONNECTIONS_PER_HOST: usize = 10;
32+
2333
/// Your branding, used for the user agent and similar
2434
#[derive(Debug)]
2535
pub struct Branding {
@@ -33,6 +43,11 @@ pub struct Branding {
3343
pub static BRANDING: OnceCell<Branding> = OnceCell::new();
3444

3545
/// Global HTTP client with connection pooling and TCP keepalive
46+
///
47+
/// # Panics
48+
/// Panics if the HTTP client fails to initialize. This is intentional as
49+
/// the application cannot function without a working HTTP client (e.g., if
50+
/// TLS initialization fails, which is extremely rare on modern systems).
3651
static HTTP_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
3752
let mut headers = reqwest::header::HeaderMap::new();
3853
if let Ok(header) = reqwest::header::HeaderValue::from_str(
@@ -42,11 +57,11 @@ static HTTP_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
4257
}
4358

4459
reqwest::Client::builder()
45-
.tcp_keepalive(Some(Duration::from_secs(10)))
46-
.timeout(Duration::from_secs(120))
47-
.connect_timeout(Duration::from_secs(30))
60+
.tcp_keepalive(Some(Duration::from_secs(TCP_KEEPALIVE_SECS)))
61+
.timeout(Duration::from_secs(REQUEST_TIMEOUT_SECS))
62+
.connect_timeout(Duration::from_secs(CONNECT_TIMEOUT_SECS))
4863
.default_headers(headers)
49-
.pool_max_idle_per_host(10)
64+
.pool_max_idle_per_host(MAX_IDLE_CONNECTIONS_PER_HOST)
5065
.build()
5166
.expect("Failed to create HTTP client")
5267
});
@@ -121,7 +136,6 @@ pub enum Error {
121136
MirrorsFailed(String),
122137
}
123138

124-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
125139
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Default)]
126140
/// A specifier string for Gradle
127141
pub struct GradleSpecifier {
@@ -205,7 +219,7 @@ impl GradleSpecifier {
205219
"{}:{}:{}",
206220
self.package,
207221
self.artifact,
208-
self.identifier.clone().unwrap_or("".to_string())
222+
self.identifier.as_deref().unwrap_or("")
209223
)
210224
}
211225

@@ -214,17 +228,12 @@ impl GradleSpecifier {
214228
/// Returns Ordering::Greater if self is greater than other
215229
/// Returns Ordering::Less if self is less than other
216230
pub fn compare_versions(&self, other: &Self) -> Result<Ordering, Error> {
217-
let x = lenient_semver::parse(self.version.as_str());
218-
let y = lenient_semver::parse(other.version.as_str());
219-
220-
if x.is_err() || y.is_err() {
221-
return Err(Error::ParseError(
222-
"Unable to parse version".to_string(),
223-
));
224-
}
231+
let x = lenient_semver::parse(self.version.as_str())
232+
.map_err(|_| Error::ParseError("Unable to parse version".to_string()))?;
233+
let y = lenient_semver::parse(other.version.as_str())
234+
.map_err(|_| Error::ParseError("Unable to parse version".to_string()))?;
225235

226-
// safe to unwrap because we already checked for errors
227-
Ok(x.unwrap().cmp(&y.unwrap()))
236+
Ok(x.cmp(&y))
228237
}
229238
}
230239

0 commit comments

Comments
 (0)