Skip to content

Commit d1a8a24

Browse files
authored
Merge pull request #2755 from input-output-hk/djo/2640/shared-aggregator-client-for-signer-aggregrator
refactor: use shared aggregator client for signer and aggregrator
2 parents 0625621 + fcd8891 commit d1a8a24

File tree

38 files changed

+1186
-2615
lines changed

38 files changed

+1186
-2615
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mithril-aggregator-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator-client"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "Client to request data from a Mithril Aggregator"
55
authors.workspace = true
66
documentation.workspace = true
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
# Mithril-aggregator-client [![CI workflow](https://github.com/input-output-hk/mithril/actions/workflows/ci.yml/badge.svg)](https://github.com/input-output-hk/mithril/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/input-output-hk/mithril/blob/main/LICENSE) [![Discord](https://img.shields.io/discord/500028886025895936.svg?logo=discord&style=flat-square)](https://discord.gg/5kaErDKDRq)
22

3-
This crate provides a client to request data from a Mithril Aggregator.
3+
This crate provides a client to request data from a Mithril Aggregator over http.
4+
5+
## Configuration of http features
6+
7+
Reqwest is used as the backend for the http client. Its default features are disabled to let the user control
8+
which [features to enable](https://docs.rs/reqwest/latest/reqwest/#optional-features).
9+
10+
To enable a reqwest feature, add the following to your `Cargo.toml`:
11+
12+
```toml
13+
reqwest = { version = "x.yy", features = ["feature_a", "feature_b"] }
14+
```
15+
16+
for example, if reqwest is a workspace dependency, and you want to enable the `default` feature and the compression features:
17+
18+
```toml
19+
reqwest = { workspace = true, features = [
20+
"default",
21+
"gzip",
22+
"zstd",
23+
"deflate",
24+
"brotli"
25+
] }
26+
```
27+
28+
### Unused dependency warning
29+
30+
You should add the `reqwest` dependency even if you don't use it directly in your code.
31+
If you are using [`cargo machete`](https://github.com/bnjbvr/cargo-machete) to track unused dependencies, it will raise a warning.
32+
33+
To avoid this warning, add the following to your `Cargo.toml`:
34+
35+
```toml
36+
[package.metadata.cargo-machete]
37+
# reqwest: for features configuration, indirect dependency via `mithril-aggregator-client`
38+
ignored = ["reqwest"]
39+
```

internal/mithril-aggregator-client/src/builder.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ use anyhow::Context;
22
use reqwest::{Client, IntoUrl, Proxy, Url};
33
use slog::{Logger, o};
44
use std::collections::HashMap;
5+
use std::sync::Arc;
56
use std::time::Duration;
67

78
use mithril_common::StdResult;
89
use mithril_common::api_version::APIVersionProvider;
910

10-
use crate::client::AggregatorClient;
11+
use crate::client::AggregatorHttpClient;
1112

12-
/// A builder of [AggregatorClient]
13+
/// A builder of [AggregatorHttpClient]
1314
pub struct AggregatorClientBuilder {
1415
aggregator_url_result: reqwest::Result<Url>,
15-
api_version_provider: Option<APIVersionProvider>,
16+
api_version_provider: Option<Arc<APIVersionProvider>>,
1617
additional_headers: Option<HashMap<String, String>>,
1718
timeout_duration: Option<Duration>,
1819
relay_endpoint: Option<String>,
@@ -41,7 +42,10 @@ impl AggregatorClientBuilder {
4142
}
4243

4344
/// Set the [APIVersionProvider] to use.
44-
pub fn with_api_version_provider(mut self, api_version_provider: APIVersionProvider) -> Self {
45+
pub fn with_api_version_provider(
46+
mut self,
47+
api_version_provider: Arc<APIVersionProvider>,
48+
) -> Self {
4549
self.api_version_provider = Some(api_version_provider);
4650
self
4751
}
@@ -59,13 +63,13 @@ impl AggregatorClientBuilder {
5963
}
6064

6165
/// Set the address of the relay
62-
pub fn with_relay_endpoint(mut self, relay_endpoint: String) -> Self {
63-
self.relay_endpoint = Some(relay_endpoint);
66+
pub fn with_relay_endpoint(mut self, relay_endpoint: Option<String>) -> Self {
67+
self.relay_endpoint = relay_endpoint;
6468
self
6569
}
6670

67-
/// Returns an [AggregatorClient] based on the builder configuration
68-
pub fn build(self) -> StdResult<AggregatorClient> {
71+
/// Returns an [AggregatorHttpClient] based on the builder configuration
72+
pub fn build(self) -> StdResult<AggregatorHttpClient> {
6973
let aggregator_endpoint =
7074
enforce_trailing_slash(self.aggregator_url_result.with_context(
7175
|| "Invalid aggregator endpoint, it must be a correctly formed url",
@@ -80,7 +84,7 @@ impl AggregatorClientBuilder {
8084
.proxy(Proxy::all(relay_endpoint).with_context(|| "Relay proxy creation failed")?)
8185
}
8286

83-
Ok(AggregatorClient {
87+
Ok(AggregatorHttpClient {
8488
aggregator_endpoint,
8589
api_version_provider,
8690
additional_headers: (&additional_headers)

0 commit comments

Comments
 (0)