Skip to content

Commit 386d353

Browse files
Merge branch 'dfinity:dynamic_route' into dynamic_route
2 parents 7e9489a + 3010732 commit 386d353

15 files changed

+2063
-1
lines changed

ic-agent/Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,14 @@ hyper-rustls = { version = "0.27", default-features = false, features = [
7474
"http1",
7575
"http2",
7676
], optional = true }
77-
tokio = { version = "1.24.2", features = ["time"] }
77+
tokio = { version = "1.24.2", features = ["macros", "time"] }
7878
tower = { version = "0.4.13", optional = true }
79+
async-trait = "^0.1.0"
80+
tracing = "^0.1.0"
81+
arc-swap = "^1.0.0"
82+
simple_moving_average = "^1.0.0"
83+
tracing-subscriber = "^0.2.0"
84+
tokio-util = { version = "^0.7.0", features = ["rt"] }
7985
rustls-webpki = "0.102"
8086

8187
[target.'cfg(target_family = "wasm")'.dependencies]

ic-agent/src/agent/builder.rs

+32
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@ impl AgentBuilder {
1616
Agent::new(self.config)
1717
}
1818

19+
#[cfg(all(feature = "reqwest", not(target_family = "wasm")))]
20+
/// 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.
21+
pub async fn with_discovery_transport(self, client: reqwest::Client) -> Self {
22+
use crate::agent::http_transport::{
23+
dynamic_routing::{
24+
dynamic_route_provider::{DynamicRouteProviderBuilder, IC0_SEED_DOMAIN},
25+
node::Node,
26+
snapshot::latency_based_routing::LatencyRoutingSnapshot,
27+
},
28+
route_provider::RouteProvider,
29+
ReqwestTransport,
30+
};
31+
32+
// TODO: This is a temporary solution to get the seed node.
33+
let seed = Node::new(IC0_SEED_DOMAIN).unwrap();
34+
35+
let route_provider = DynamicRouteProviderBuilder::new(
36+
LatencyRoutingSnapshot::new(),
37+
vec![seed],
38+
client.clone(),
39+
)
40+
.build()
41+
.await;
42+
43+
let route_provider = Arc::new(route_provider) as Arc<dyn RouteProvider>;
44+
45+
let transport = ReqwestTransport::create_with_client_route(route_provider, client)
46+
.expect("failed to create transport");
47+
48+
self.with_transport(transport)
49+
}
50+
1951
/// Set the URL of the [Agent].
2052
#[cfg(feature = "reqwest")]
2153
pub fn with_url<S: Into<String>>(self, url: S) -> Self {

0 commit comments

Comments
 (0)