Use host for nameserver

This commit is contained in:
Daniel Sanchez Quiros 2022-10-25 10:23:21 +02:00
parent ebe9060d8b
commit e9711c0201
2 changed files with 11 additions and 7 deletions

View File

@ -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<Host>,
timeout: Option<Duration>,
) -> Result<Vec<Multiaddr>> {
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

View File

@ -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<Running> {
pub fn dns_discovery(
&self,
url: &Url,
nameserver: Option<&str>,
nameserver: Option<Host>,
timeout: Option<Duration>,
) -> Result<Vec<Multiaddr>> {
discovery::waku_dns_discovery(url, nameserver, timeout)