networkresult
This commit is contained in:
@@ -309,10 +309,11 @@ impl Network {
|
||||
let h = RawUdpProtocolHandler::new_unspecified_bound_handler(&peer_socket_addr)
|
||||
.await
|
||||
.wrap_err("create socket failure")?;
|
||||
h.send_message(data, peer_socket_addr)
|
||||
network_result_try!(h
|
||||
.send_message(data, peer_socket_addr)
|
||||
.await
|
||||
.map(NetworkResult::Value)
|
||||
.wrap_err("send message failure")?;
|
||||
.wrap_err("send message failure")?);
|
||||
}
|
||||
ProtocolType::TCP => {
|
||||
let peer_socket_addr = dial_info.to_socket_addr();
|
||||
@@ -323,7 +324,7 @@ impl Network {
|
||||
)
|
||||
.await
|
||||
.wrap_err("connect failure")?);
|
||||
pnc.send(data).await.wrap_err("send failure")?;
|
||||
network_result_try!(pnc.send(data).await.wrap_err("send failure")?);
|
||||
}
|
||||
ProtocolType::WS | ProtocolType::WSS => {
|
||||
let pnc = network_result_try!(WebsocketProtocolHandler::connect(
|
||||
@@ -333,7 +334,7 @@ impl Network {
|
||||
)
|
||||
.await
|
||||
.wrap_err("connect failure")?);
|
||||
pnc.send(data).await.wrap_err("send failure")?;
|
||||
network_result_try!(pnc.send(data).await.wrap_err("send failure")?);
|
||||
}
|
||||
}
|
||||
// Network accounting
|
||||
@@ -408,7 +409,7 @@ impl Network {
|
||||
}
|
||||
});
|
||||
|
||||
pnc.send(data).await.wrap_err("send failure")?;
|
||||
network_result_try!(pnc.send(data).await.wrap_err("send failure")?);
|
||||
self.network_manager()
|
||||
.stats_packet_sent(dial_info.to_ip_addr(), data_len as u64);
|
||||
|
||||
|
@@ -78,18 +78,24 @@ impl DiscoveryContext {
|
||||
#[instrument(level = "trace", skip(self), ret)]
|
||||
async fn request_public_address(&self, node_ref: NodeRef) -> Option<SocketAddress> {
|
||||
let rpc = self.routing_table.rpc_processor();
|
||||
rpc.rpc_call_status(node_ref.clone())
|
||||
.await
|
||||
.map_err(logthru_net!(
|
||||
"failed to get status answer from {:?}",
|
||||
node_ref
|
||||
))
|
||||
.map(|sa| {
|
||||
let ret = sa.answer.socket_address;
|
||||
log_net!("request_public_address: {:?}", ret);
|
||||
ret
|
||||
})
|
||||
.unwrap_or(None)
|
||||
let res = network_result_value_or_log!(debug match rpc.rpc_call_status(node_ref.clone()).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
log_net!(error
|
||||
"failed to get status answer from {:?}: {}",
|
||||
node_ref, e
|
||||
);
|
||||
return None;
|
||||
}
|
||||
} => { return None; }
|
||||
);
|
||||
|
||||
log_net!(
|
||||
"request_public_address {:?}: Value({:?})",
|
||||
node_ref,
|
||||
res.answer
|
||||
);
|
||||
res.answer.socket_address
|
||||
}
|
||||
|
||||
// find fast peers with a particular address type, and ask them to tell us what our external address is
|
||||
|
@@ -189,10 +189,10 @@ pub async fn nonblocking_connect(
|
||||
let async_stream = Async::new(std::net::TcpStream::from(socket))?;
|
||||
|
||||
// The stream becomes writable when connected
|
||||
intf::timeout(timeout_ms, async_stream.writable())
|
||||
timeout_or_try!(intf::timeout(timeout_ms, async_stream.writable())
|
||||
.await
|
||||
.into_timeout_or()
|
||||
.into_result()?;
|
||||
.into_result()?);
|
||||
|
||||
// Check low level error
|
||||
let async_stream = match async_stream.get_ref().take_error()? {
|
||||
@@ -203,9 +203,9 @@ pub async fn nonblocking_connect(
|
||||
// Convert back to inner and then return async version
|
||||
cfg_if! {
|
||||
if #[cfg(feature="rt-async-std")] {
|
||||
Ok(TimeoutOr::Value(TcpStream::from(async_stream.into_inner()?)))
|
||||
Ok(TimeoutOr::value(TcpStream::from(async_stream.into_inner()?)))
|
||||
} else if #[cfg(feature="rt-tokio")] {
|
||||
Ok(TimeoutOr::Value(TcpStream::from_std(async_stream.into_inner()?)?))
|
||||
Ok(TimeoutOr::value(TcpStream::from_std(async_stream.into_inner()?)?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -51,7 +51,7 @@ impl RawTcpNetworkConnection {
|
||||
let len = message.len() as u16;
|
||||
let header = [b'V', b'L', len as u8, (len >> 8) as u8];
|
||||
|
||||
stream.write_all(&header).await.into_network_result()?;
|
||||
network_result_try!(stream.write_all(&header).await.into_network_result()?);
|
||||
stream.write_all(&message).await.into_network_result()
|
||||
}
|
||||
|
||||
@@ -59,21 +59,14 @@ impl RawTcpNetworkConnection {
|
||||
pub async fn send(&self, message: Vec<u8>) -> io::Result<NetworkResult<()>> {
|
||||
let mut stream = self.stream.clone();
|
||||
let out = Self::send_internal(&mut stream, message).await?;
|
||||
tracing::Span::current().record(
|
||||
"network_result",
|
||||
&match &out {
|
||||
NetworkResult::Timeout => "Timeout".to_owned(),
|
||||
NetworkResult::NoConnection(e) => format!("No connection: {}", e),
|
||||
NetworkResult::Value(()) => "Value(())".to_owned(),
|
||||
},
|
||||
);
|
||||
tracing::Span::current().record("network_result", &tracing::field::display(&out));
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
async fn recv_internal(stream: &mut AsyncPeekStream) -> io::Result<NetworkResult<Vec<u8>>> {
|
||||
let mut header = [0u8; 4];
|
||||
|
||||
stream.read_exact(&mut header).await.into_network_result()?;
|
||||
network_result_try!(stream.read_exact(&mut header).await.into_network_result()?);
|
||||
|
||||
if header[0] != b'V' || header[1] != b'L' {
|
||||
bail_io_error_other!("received invalid TCP frame header");
|
||||
@@ -84,7 +77,7 @@ impl RawTcpNetworkConnection {
|
||||
}
|
||||
|
||||
let mut out: Vec<u8> = vec![0u8; len];
|
||||
stream.read_exact(&mut out).await.into_network_result()?;
|
||||
network_result_try!(stream.read_exact(&mut out).await.into_network_result()?);
|
||||
|
||||
Ok(NetworkResult::Value(out))
|
||||
}
|
||||
@@ -93,14 +86,7 @@ impl RawTcpNetworkConnection {
|
||||
pub async fn recv(&self) -> io::Result<NetworkResult<Vec<u8>>> {
|
||||
let mut stream = self.stream.clone();
|
||||
let out = Self::recv_internal(&mut stream).await?;
|
||||
tracing::Span::current().record(
|
||||
"network_result",
|
||||
&match &out {
|
||||
NetworkResult::Timeout => "Timeout".to_owned(),
|
||||
NetworkResult::NoConnection(e) => format!("No connection: {}", e),
|
||||
NetworkResult::Value(v) => format!("Value(len={})", v.len()),
|
||||
},
|
||||
);
|
||||
tracing::Span::current().record("network_result", &tracing::field::display(&out));
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
|
@@ -92,14 +92,7 @@ where
|
||||
.await
|
||||
.map_err(to_io)
|
||||
.into_network_result()?;
|
||||
tracing::Span::current().record(
|
||||
"network_result",
|
||||
&match &out {
|
||||
NetworkResult::Timeout => "Timeout".to_owned(),
|
||||
NetworkResult::NoConnection(e) => format!("No connection: {}", e),
|
||||
NetworkResult::Value(()) => "Value(())".to_owned(),
|
||||
},
|
||||
);
|
||||
tracing::Span::current().record("network_result", &tracing::field::display(&out));
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
@@ -132,14 +125,7 @@ where
|
||||
)),
|
||||
};
|
||||
|
||||
tracing::Span::current().record(
|
||||
"network_result",
|
||||
&match &out {
|
||||
NetworkResult::Timeout => "Timeout".to_owned(),
|
||||
NetworkResult::NoConnection(e) => format!("No connection: {}", e),
|
||||
NetworkResult::Value(v) => format!("Value(len={})", v.len()),
|
||||
},
|
||||
);
|
||||
tracing::Span::current().record("network_result", &tracing::field::display(&out));
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user