Skip to content

Commit

Permalink
feat(BOUN-1168): add dynamic route provider (Discovery Library) (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolay-komarevskiy committed Jul 31, 2024
1 parent 07e7c81 commit 3010732
Show file tree
Hide file tree
Showing 18 changed files with 2,075 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.37.1] - 2024-07-25

* Bug fix: Add `api/v2` prefix to read_state requests for hyper transport

## [0.37.0] - 2024-07-23
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
]

[workspace.package]
version = "0.37.0"
version = "0.37.1"
authors = ["DFINITY Stiftung <[email protected]>"]
edition = "2021"
repository = "https://github.com/dfinity/agent-rs"
Expand All @@ -22,9 +22,9 @@ rust-version = "1.75.0"
license = "Apache-2.0"

[workspace.dependencies]
ic-agent = { path = "ic-agent", version = "0.37.0", default-features = false }
ic-utils = { path = "ic-utils", version = "0.37.0" }
ic-transport-types = { path = "ic-transport-types", version = "0.37.0" }
ic-agent = { path = "ic-agent", version = "0.37.1", default-features = false }
ic-utils = { path = "ic-utils", version = "0.37.1" }
ic-transport-types = { path = "ic-transport-types", version = "0.37.1" }

ic-certification = "2.2"
candid = "0.10.1"
Expand Down
8 changes: 7 additions & 1 deletion ic-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ hyper-rustls = { version = "0.27", default-features = false, features = [
"http1",
"http2",
], optional = true }
tokio = { version = "1.24.2", features = ["time"] }
tokio = { version = "1.24.2", features = ["macros", "time"] }
tower = { version = "0.4.13", optional = true }
async-trait = "^0.1.0"
tracing = "^0.1.0"
arc-swap = "^1.0.0"
simple_moving_average = "^1.0.0"
tracing-subscriber = "^0.2.0"
tokio-util = { version = "^0.7.0", features = ["rt"] }
rustls-webpki = "0.102"

[target.'cfg(target_family = "wasm")'.dependencies]
Expand Down
32 changes: 32 additions & 0 deletions ic-agent/src/agent/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ impl AgentBuilder {
Agent::new(self.config)
}

#[cfg(all(feature = "reqwest", not(target_family = "wasm")))]
/// Set the dynamic transport layer for the [`Agent`], performing continuos discovery of the API boundary nodes and routing traffic via them based on the latencies.
pub async fn with_discovery_transport(self, client: reqwest::Client) -> Self {
use crate::agent::http_transport::{
dynamic_routing::{
dynamic_route_provider::{DynamicRouteProviderBuilder, IC0_SEED_DOMAIN},
node::Node,
snapshot::latency_based_routing::LatencyRoutingSnapshot,
},
route_provider::RouteProvider,
ReqwestTransport,
};

// TODO: This is a temporary solution to get the seed node.
let seed = Node::new(IC0_SEED_DOMAIN).unwrap();

let route_provider = DynamicRouteProviderBuilder::new(
LatencyRoutingSnapshot::new(),
vec![seed],
client.clone(),
)
.build()
.await;

let route_provider = Arc::new(route_provider) as Arc<dyn RouteProvider>;

let transport = ReqwestTransport::create_with_client_route(route_provider, client)
.expect("failed to create transport");

self.with_transport(transport)
}

/// Set the URL of the [Agent].
#[cfg(feature = "reqwest")]
pub fn with_url<S: Into<String>>(self, url: S) -> Self {
Expand Down
Loading

0 comments on commit 3010732

Please sign in to comment.