From e9711c020134f27a7eda050553f3c5d0fda77c0e Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Tue, 25 Oct 2022 10:23:21 +0200 Subject: [PATCH] Use host for nameserver --- waku/src/node/discovery.rs | 14 +++++++++----- waku/src/node/mod.rs | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/waku/src/node/discovery.rs b/waku/src/node/discovery.rs index b86f798..715bcc7 100644 --- a/waku/src/node/discovery.rs +++ b/waku/src/node/discovery.rs @@ -3,7 +3,7 @@ use std::ffi::{CStr, CString}; use std::time::Duration; // crates use multiaddr::Multiaddr; -use url::Url; +use url::{Host, Url}; // internal use crate::general::JsonResponse; use crate::Result; @@ -12,7 +12,7 @@ use crate::Result; /// The nameserver can optionally be specified to resolve the enrtree url. Otherwise uses the default system dns. pub fn waku_dns_discovery( url: &Url, - server: Option<&str>, + server: Option, timeout: Option, ) -> Result> { let result = unsafe { @@ -20,9 +20,13 @@ pub fn waku_dns_discovery( CString::new(url.to_string()) .expect("CString should build properly from a valid Url") .into_raw(), - CString::new(server.unwrap_or("")) - .expect("CString should build properly from a String nameserver") - .into_raw(), + CString::new( + server + .map(|host| host.to_string()) + .unwrap_or_else(|| "".to_string()), + ) + .expect("CString should build properly from a String nameserver") + .into_raw(), timeout .map(|timeout| { timeout diff --git a/waku/src/node/mod.rs b/waku/src/node/mod.rs index 238c681..a0ecf26 100644 --- a/waku/src/node/mod.rs +++ b/waku/src/node/mod.rs @@ -17,7 +17,7 @@ use std::marker::PhantomData; use std::sync::Mutex; use std::time::Duration; // crates -use url::Url; +use url::{Host, Url}; // internal use crate::general::{ @@ -324,7 +324,7 @@ impl WakuNodeHandle { pub fn dns_discovery( &self, url: &Url, - nameserver: Option<&str>, + nameserver: Option, timeout: Option, ) -> Result> { discovery::waku_dns_discovery(url, nameserver, timeout)