test fixes

This commit is contained in:
John Smith
2022-06-08 20:07:26 -04:00
parent 69d68e900e
commit 86567ea78d
20 changed files with 135 additions and 231 deletions

View File

@@ -78,7 +78,7 @@ impl ApiTracingLayer {
pub fn change_api_log_level(max_level: Option<VeilidLogLevel>) {
if let Some(api_logger) = API_LOGGER.get() {
if let Some(inner) = &mut *api_logger.inner.lock() {
*inner = Self::new_inner(max_level, inner.update_callback.clone());
inner.max_level = max_level;
}
}
}

View File

@@ -46,6 +46,12 @@ pub async fn sleep(millis: u32) {
}
}
pub fn system_boxed<'a, Out>(
future: impl Future<Output = Out> + Send + 'a,
) -> SystemPinBoxFutureLifetime<'a, Out> {
Box::pin(future)
}
pub fn spawn<Out>(future: impl Future<Output = Out> + Send + 'static) -> JoinHandle<Out>
where
Out: Send + 'static,

View File

@@ -99,6 +99,12 @@ pub async fn sleep(millis: u32) {
}
}
pub fn system_boxed<'a, Out>(
future: impl Future<Output = Out> + 'a,
) -> SystemPinBoxFutureLifetime<'a, Out> {
Box::pin(future)
}
pub fn spawn<Out>(future: impl Future<Output = Out> + 'static) -> JoinHandle<Out>
where
Out: Send + 'static,
@@ -203,10 +209,10 @@ pub async fn get_outbound_relay_peer() -> Option<crate::veilid_api::PeerInfo> {
// }
pub async fn txt_lookup<S: AsRef<str>>(host: S) -> Result<Vec<String>, String> {
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> {
pub async fn ptr_lookup(_ip_addr: IpAddr) -> Result<String, String> {
Err("wasm does not support ptr lookup".to_owned())
}

View File

@@ -4,8 +4,8 @@ mod network_udp;
mod protocol;
mod start_protocols;
use super::*;
use crate::intf::*;
use crate::network_manager::*;
use crate::routing_table::*;
use connection_manager::*;
use network_tcp::*;

View File

@@ -224,72 +224,68 @@ impl NetworkConnection {
})
};
let timer = MutableFuture::new(new_timer());
unord.push(timer.clone().boxed());
unord.push(system_boxed(timer.clone()));
loop {
// Add another message sender future if necessary
if need_sender {
need_sender = false;
unord.push(
receiver
.recv_async()
.then(|res| async {
match res {
Ok(message) => {
// send the packet
if let Err(e) = Self::send_internal(
&protocol_connection,
stats.clone(),
message,
)
.await
{
// Sending the packet along can fail, if so, this connection is dead
log_net!(debug e);
RecvLoopAction::Finish
} else {
RecvLoopAction::Send
}
}
Err(e) => {
// All senders gone, shouldn't happen since we store one alongside the join handle
log_net!(warn e);
RecvLoopAction::Finish
}
let sender_fut = receiver.recv_async().then(|res| async {
match res {
Ok(message) => {
// send the packet
if let Err(e) = Self::send_internal(
&protocol_connection,
stats.clone(),
message,
)
.await
{
// Sending the packet along can fail, if so, this connection is dead
log_net!(debug e);
RecvLoopAction::Finish
} else {
RecvLoopAction::Send
}
})
.boxed(),
);
}
Err(e) => {
// All senders gone, shouldn't happen since we store one alongside the join handle
log_net!(warn e);
RecvLoopAction::Finish
}
}
});
unord.push(system_boxed(sender_fut));
}
// Add another message receiver future if necessary
if need_receiver {
need_sender = false;
unord.push(
Self::recv_internal(&protocol_connection, stats.clone())
.then(|res| async {
match res {
Ok(message) => {
// Pass received messages up to the network manager for processing
if let Err(e) = network_manager
.on_recv_envelope(message.as_slice(), descriptor)
.await
{
log_net!(error e);
RecvLoopAction::Finish
} else {
RecvLoopAction::Recv
}
}
Err(e) => {
// Connection unable to receive, closed
log_net!(warn e);
need_receiver = false;
let receiver_fut = Self::recv_internal(&protocol_connection, stats.clone())
.then(|res| async {
match res {
Ok(message) => {
// Pass received messages up to the network manager for processing
if let Err(e) = network_manager
.on_recv_envelope(message.as_slice(), descriptor)
.await
{
log_net!(error e);
RecvLoopAction::Finish
} else {
RecvLoopAction::Recv
}
}
})
.boxed(),
);
Err(e) => {
// Connection unable to receive, closed
log_net!(warn e);
RecvLoopAction::Finish
}
}
});
unord.push(system_boxed(receiver_fut));
}
// Process futures

View File

@@ -1,10 +1,8 @@
mod protocol;
use crate::connection_manager::*;
use crate::network_manager::*;
use super::*;
use crate::routing_table::*;
use crate::intf::*;
use crate::*;
use connection_manager::*;
use protocol::ws::WebsocketProtocolHandler;
pub use protocol::*;
@@ -102,11 +100,11 @@ impl Network {
// Try to send to the exact existing connection if one exists
if let Some(conn) = self.connection_manager().get_connection(descriptor).await {
// connection exists, send over it
conn.send(data).await.map_err(logthru_net!())?;
conn.send_async(data).await.map_err(logthru_net!())?;
// Network accounting
self.network_manager()
.stats_packet_sent(descriptor.remote.to_socket_addr().ip(), data_len as u64);
.stats_packet_sent(descriptor.remote().to_socket_addr().ip(), data_len as u64);
// Data was consumed
Ok(None)
@@ -136,7 +134,7 @@ impl Network {
.get_or_create_connection(None, dial_info.clone())
.await?;
let res = conn.send(data).await.map_err(logthru_net!(error));
let res = conn.send_async(data).await.map_err(logthru_net!(error));
if res.is_ok() {
// Network accounting
self.network_manager()

View File

@@ -1,9 +1,8 @@
pub mod wrtc;
pub mod ws;
use crate::network_connection::*;
use super::*;
use crate::xx::*;
use crate::*;
#[derive(Debug)]
pub enum ProtocolNetworkConnection {
@@ -16,7 +15,7 @@ impl ProtocolNetworkConnection {
pub async fn connect(
local_address: Option<SocketAddr>,
dial_info: DialInfo,
) -> Result<NetworkConnection, String> {
) -> Result<ProtocolNetworkConnection, String> {
match dial_info.protocol_type() {
ProtocolType::UDP => {
panic!("UDP dial info is not support on WASM targets");
@@ -46,6 +45,14 @@ impl ProtocolNetworkConnection {
}
}
}
pub fn descriptor(&self) -> ConnectionDescriptor {
match self {
Self::Dummy(d) => d.descriptor(),
Self::Ws(w) => w.descriptor(),
}
}
pub async fn close(&self) -> Result<(), String> {
match self {
Self::Dummy(d) => d.close(),

View File

@@ -1,8 +1,4 @@
use crate::intf::*;
use crate::network_connection::*;
use crate::network_manager::MAX_MESSAGE_SIZE;
use crate::*;
use alloc::fmt;
use super::*;
use ws_stream_wasm::*;
use futures_util::{StreamExt, SinkExt};
@@ -104,10 +100,9 @@ impl WebsocketProtocolHandler {
// Make our connection descriptor
Ok(ProtocolNetworkConnection::Ws(WebsocketNetworkConnection::new(ConnectionDescriptor {
local: None,
remote: dial_info.to_peer_address(),
}, wsmeta, wsio)))
Ok(ProtocolNetworkConnection::Ws(WebsocketNetworkConnection::new(ConnectionDescriptor::new_no_local(
dial_info.to_peer_address(),
), wsmeta, wsio)))
}
pub async fn send_unbound_message(dial_info: DialInfo, data: Vec<u8>) -> Result<(), String> {

View File

@@ -3,3 +3,8 @@ pub mod test_protected_store;
pub mod test_table_store;
pub mod test_veilid_config;
pub mod test_veilid_core;
use super::*;
pub use dht::tests::*;
pub use network_manager::tests::*;

View File

@@ -1,3 +1,5 @@
pub mod common;
#[cfg(not(target_arch = "wasm32"))]
mod native;
use super::*;

View File

@@ -1133,13 +1133,24 @@ impl DialInfo {
}
};
let socket_addrs = match split_url.host {
SplitUrlHost::Hostname(_) => split_url
.host_port(port)
.to_socket_addrs()
.map_err(|_| parse_error!("couldn't resolve hostname in url", url))?
.collect(),
SplitUrlHost::IpAddr(a) => vec![SocketAddr::new(a, port)],
let socket_addrs = {
// Resolve if possible, WASM doesn't support resolution and doesn't need it to connect to the dialinfo
// This will not be used on signed dialinfo, only for bootstrapping, so we don't need to worry about
// the '0.0.0.0' address being propagated across the routing table
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
vec![SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0,0,0,0)), port)]
} else {
match split_url.host {
SplitUrlHost::Hostname(_) => split_url
.host_port(port)
.to_socket_addrs()
.map_err(|_| parse_error!("couldn't resolve hostname in url", url))?
.collect(),
SplitUrlHost::IpAddr(a) => vec![SocketAddr::new(a, port)],
}
}
}
};
let mut out = Vec::new();

View File

@@ -229,7 +229,7 @@ cfg_if::cfg_if! {
Ok(())
}
} else {
pub fn ensure_file_private_owner<P:AsRef<Path>>(path: P) -> Result<(),String>
pub fn ensure_file_private_owner<P:AsRef<Path>>(_path: P) -> Result<(),String>
{
Ok(())
}