packaging and bootstrap work
This commit is contained in:
@@ -482,6 +482,10 @@ impl Network {
|
||||
self.inner.lock().network_needs_restart
|
||||
}
|
||||
|
||||
pub fn is_started(&self) -> bool {
|
||||
self.inner.lock().network_started
|
||||
}
|
||||
|
||||
pub fn restart_network(&self) {
|
||||
self.inner.lock().network_needs_restart = true;
|
||||
}
|
||||
|
@@ -3,9 +3,14 @@
|
||||
use crate::xx::*;
|
||||
pub use async_executors::JoinHandle;
|
||||
use async_executors::{AsyncStd, LocalSpawnHandleExt, SpawnHandleExt};
|
||||
use async_std_resolver::{config, resolver, AsyncStdResolver};
|
||||
use rand::prelude::*;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref RESOLVER: Arc<AsyncMutex<Option<AsyncStdResolver>>> = Arc::new(AsyncMutex::new(None));
|
||||
}
|
||||
|
||||
pub fn get_timestamp() -> u64 {
|
||||
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||
Ok(n) => n.as_micros() as u64,
|
||||
@@ -111,3 +116,48 @@ where
|
||||
}));
|
||||
}
|
||||
*/
|
||||
|
||||
async fn get_resolver() -> Result<AsyncStdResolver, String> {
|
||||
let mut resolver_lock = RESOLVER.lock().await;
|
||||
if let Some(r) = &*resolver_lock {
|
||||
Ok(r.clone())
|
||||
} else {
|
||||
let resolver = resolver(
|
||||
config::ResolverConfig::default(),
|
||||
config::ResolverOpts::default(),
|
||||
)
|
||||
.await
|
||||
.expect("failed to connect resolver");
|
||||
|
||||
*resolver_lock = Some(resolver.clone());
|
||||
Ok(resolver)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn txt_lookup<S: AsRef<str>>(host: S) -> Result<Vec<String>, String> {
|
||||
let resolver = get_resolver().await?;
|
||||
let txt_result = resolver
|
||||
.txt_lookup(host.as_ref())
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut out = Vec::new();
|
||||
for x in txt_result.iter() {
|
||||
for s in x.txt_data() {
|
||||
out.push(String::from_utf8(s.to_vec()).map_err(|e| e.to_string())?);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub async fn ptr_lookup(ip_addr: IpAddr) -> Result<String, String> {
|
||||
let resolver = get_resolver().await?;
|
||||
let ptr_result = resolver
|
||||
.reverse_lookup(ip_addr)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
if let Some(r) = ptr_result.iter().next() {
|
||||
Ok(r.to_string().trim_end_matches('.').to_string())
|
||||
} else {
|
||||
Err("PTR lookup returned an empty string".to_owned())
|
||||
}
|
||||
}
|
||||
|
@@ -24,12 +24,9 @@ fn veilid_core_setup_internal<'a>(
|
||||
let mut logs: Vec<Box<dyn SharedLogger>> = Vec::new();
|
||||
|
||||
let mut cb = ConfigBuilder::new();
|
||||
cb.add_filter_ignore_str("async_std");
|
||||
cb.add_filter_ignore_str("async_io");
|
||||
cb.add_filter_ignore_str("polling");
|
||||
cb.add_filter_ignore_str("rustls");
|
||||
cb.add_filter_ignore_str("async_tungstenite");
|
||||
cb.add_filter_ignore_str("tungstenite");
|
||||
for ig in veilid_core::DEFAULT_LOG_IGNORE_LIST {
|
||||
cb.add_filter_ignore_str(ig);
|
||||
}
|
||||
|
||||
if let Some(level) = terminal_log {
|
||||
logs.push(TermLogger::new(
|
||||
|
@@ -172,6 +172,10 @@ impl Network {
|
||||
self.inner.lock().network_needs_restart
|
||||
}
|
||||
|
||||
pub fn is_started(&self) -> bool {
|
||||
self.inner.lock().network_started
|
||||
}
|
||||
|
||||
pub fn restart_network(&self) {
|
||||
self.inner.lock().network_needs_restart = true;
|
||||
}
|
||||
|
@@ -200,4 +200,13 @@ pub async fn get_outbound_relay_peer() -> Option<crate::veilid_api::PeerInfo> {
|
||||
// } else {
|
||||
// panic!("WASM requires browser or nodejs environment");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
pub async fn txt_lookup<S: AsRef<str>>(host: S) -> Result<Vec<String>, String> {
|
||||
Err("wasm does not support txt lookup".to_owned())
|
||||
}
|
||||
|
||||
pub async fn ptr_lookup(ip_addr: IpAddr) -> Result<String, String> {
|
||||
Err("wasm does not support ptr lookup".to_owned())
|
||||
}
|
||||
|
Reference in New Issue
Block a user