Websocket fixes
This commit is contained in:
@@ -10,7 +10,18 @@ struct WebsocketNetworkConnectionInner {
|
||||
}
|
||||
|
||||
fn to_io(err: WsErr) -> io::Error {
|
||||
io::Error::new(io::ErrorKind::Other, err.to_string())
|
||||
match err {
|
||||
WsErr::InvalidWsState { supplied: _ } => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
|
||||
WsErr::ConnectionNotOpen => io::Error::new(io::ErrorKind::NotConnected, err.to_string()),
|
||||
WsErr::InvalidUrl { supplied: _ } => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
|
||||
WsErr::InvalidCloseCode { supplied: _ } => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
|
||||
WsErr::ReasonStringToLong => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
|
||||
WsErr::ConnectionFailed { event: _ } => io::Error::new(io::ErrorKind::ConnectionRefused, err.to_string()),
|
||||
WsErr::InvalidEncoding => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
|
||||
WsErr::CantDecodeBlob => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
|
||||
WsErr::UnknownDataType => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
|
||||
_ => io::Error::new(io::ErrorKind::Other, err.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -115,20 +126,19 @@ impl WebsocketProtocolHandler {
|
||||
let fut = SendWrapper::new(timeout(timeout_ms, async move {
|
||||
WsMeta::connect(request, None).await.map_err(to_io)
|
||||
}));
|
||||
|
||||
let (wsmeta, wsio) = network_result_try!(network_result_try!(fut
|
||||
.await
|
||||
.into_network_result())
|
||||
.into_network_result()?);
|
||||
|
||||
// Make our connection descriptor
|
||||
|
||||
let wnc = WebsocketNetworkConnection::new(
|
||||
ConnectionDescriptor::new_no_local(dial_info.to_peer_address())
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::AddrNotAvailable, e))?,
|
||||
wsmeta,
|
||||
wsio,
|
||||
);
|
||||
|
||||
Ok(NetworkResult::Value(ProtocolNetworkConnection::Ws(wnc)))
|
||||
}
|
||||
}
|
||||
|
@@ -641,6 +641,12 @@ impl Address {
|
||||
Address::IPV6(v6) => format!("[{}]:{}", v6, port),
|
||||
}
|
||||
}
|
||||
pub fn is_unspecified(&self) -> bool {
|
||||
match self {
|
||||
Address::IPV4(v4) => ipv4addr_is_unspecified(v4),
|
||||
Address::IPV6(v6) => ipv6addr_is_unspecified(v6),
|
||||
}
|
||||
}
|
||||
pub fn is_global(&self) -> bool {
|
||||
match self {
|
||||
Address::IPV4(v4) => ipv4addr_is_global(v4) && !ipv4addr_is_multicast(v4),
|
||||
@@ -1519,8 +1525,20 @@ impl ConnectionDescriptor {
|
||||
fn validate_peer_scope(remote: PeerAddress) -> Result<(), VeilidAPIError> {
|
||||
// Verify address is in one of our peer scopes we care about
|
||||
let addr = remote.socket_address.address();
|
||||
|
||||
// Allow WASM to have unresolved addresses, for bootstraps
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
if addr.is_unspecified() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
if !addr.is_global() && !addr.is_local() {
|
||||
return Err(VeilidAPIError::generic("not a valid peer scope"));
|
||||
return Err(VeilidAPIError::generic(format!(
|
||||
"not a valid peer scope: {:?}",
|
||||
addr
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1556,6 +1574,14 @@ impl ConnectionDescriptor {
|
||||
}
|
||||
pub fn peer_scope(&self) -> PeerScope {
|
||||
let addr = self.remote.socket_address.address();
|
||||
// Allow WASM to have unresolved addresses, for bootstraps
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
if addr.is_unspecified() {
|
||||
return PeerScope::Global;
|
||||
}
|
||||
}
|
||||
}
|
||||
if addr.is_global() {
|
||||
return PeerScope::Global;
|
||||
}
|
||||
|
Reference in New Issue
Block a user