Skip to content

Commit

Permalink
[pr] Rename Config and add link to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Nov 24, 2022
1 parent 219cb3e commit 06bd2a4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion iroh-gateway/src/bad_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
use hex_literal::hex;
use http::StatusCode;
use iroh_resolver::content_loader::{FullLoader, FullLoaderConfig, GatewayUrl};
use iroh_resolver::dns_resolver::DnsResolverConfig;
use iroh_resolver::dns_resolver::Config as DnsResolverConfig;
use iroh_rpc_client::{Client as RpcClient, Config as RpcClientConfig};

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions iroh-gateway/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iroh_metrics::{
gateway::{GatewayHistograms, GatewayMetrics},
observe, record,
};
use iroh_resolver::dns_resolver::DnsResolverConfig;
use iroh_resolver::dns_resolver::Config;
use iroh_resolver::{
content_loader::ContentLoader,
resolver::{
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<T: ContentLoader + std::marker::Unpin> http_body::Body for PrettyStreamBody
}

impl<T: ContentLoader + std::marker::Unpin> Client<T> {
pub fn new(rpc_client: &T, dns_resolver_config: DnsResolverConfig) -> Self {
pub fn new(rpc_client: &T, dns_resolver_config: Config) -> Self {
Self {
resolver: Resolver::with_dns_resolver(rpc_client.clone(), dns_resolver_config),
}
Expand Down
2 changes: 1 addition & 1 deletion iroh-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use headers::{
AccessControlAllowHeaders, AccessControlAllowMethods, AccessControlAllowOrigin, HeaderMapExt,
};
use iroh_metrics::config::Config as MetricsConfig;
use iroh_resolver::dns_resolver::DnsResolverConfig;
use iroh_resolver::dns_resolver::Config as DnsResolverConfig;
use iroh_rpc_client::Config as RpcClientConfig;
use iroh_rpc_types::{gateway::GatewayServerAddr, Addr};
use iroh_util::insert_into_config_map;
Expand Down
2 changes: 1 addition & 1 deletion iroh-gateway/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use axum::Router;
use iroh_resolver::content_loader::ContentLoader;
use iroh_rpc_types::gateway::GatewayServerAddr;

use iroh_resolver::dns_resolver::DnsResolverConfig;
use iroh_resolver::dns_resolver::Config as DnsResolverConfig;
use std::{collections::HashMap, sync::Arc};
use tokio::sync::RwLock;

Expand Down
15 changes: 8 additions & 7 deletions iroh-resolver/src/dns_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ use trust_dns_resolver::config::{NameServerConfigGroup, ResolverConfig, Resolver
use trust_dns_resolver::{AsyncResolver, TokioAsyncResolver};

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DnsResolverConfig {
pub struct Config {
/// Mapping from TLD to the specific instance of resolver
tld_resolvers: Option<HashMap<String, ResolverConfig>>,
}

impl DnsResolverConfig {
impl Config {
pub fn empty() -> Self {
DnsResolverConfig {
Config {
tld_resolvers: None,
}
}
}

impl Default for DnsResolverConfig {
impl Default for Config {
fn default() -> Self {
DnsResolverConfig {
Config {
/// Documentation on .eth TLD lives on https://eth.link/
tld_resolvers: Some(HashMap::from_iter(vec![(
"eth".to_string(),
ResolverConfig::from_parts(
Expand Down Expand Up @@ -51,7 +52,7 @@ pub struct DnsResolver {

impl DnsResolver {
/// Creates resolver from its config
pub fn from_config(dns_resolver_config: DnsResolverConfig) -> DnsResolver {
pub fn from_config(dns_resolver_config: Config) -> DnsResolver {
let tld_resolvers = dns_resolver_config
.tld_resolvers
.map(|dns_resolver_config| {
Expand Down Expand Up @@ -107,7 +108,7 @@ impl DnsResolver {

impl Default for DnsResolver {
fn default() -> Self {
DnsResolver::from_config(DnsResolverConfig::default())
DnsResolver::from_config(Config::default())
}
}

Expand Down
6 changes: 3 additions & 3 deletions iroh-resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use tokio::sync::Mutex;
use tokio::task::JoinHandle;
use tracing::{debug, trace, warn};

use crate::dns_resolver::{DnsResolver, DnsResolverConfig};
use crate::dns_resolver::{Config, DnsResolver};

use iroh_metrics::{
core::{MObserver, MRecorder},
Expand Down Expand Up @@ -737,10 +737,10 @@ struct InnerLoaderContext {

impl<T: ContentLoader> Resolver<T> {
pub fn new(loader: T) -> Self {
Self::with_dns_resolver(loader, DnsResolverConfig::default())
Self::with_dns_resolver(loader, Config::default())
}

pub fn with_dns_resolver(loader: T, dns_resolver_config: DnsResolverConfig) -> Self {
pub fn with_dns_resolver(loader: T, dns_resolver_config: Config) -> Self {
let (session_closer_s, session_closer_r) = async_channel::bounded(2048);
let loader_thread = loader.clone();
let worker = tokio::task::spawn(async move {
Expand Down

0 comments on commit 06bd2a4

Please sign in to comment.