Websocket fixes
This commit is contained in:
parent
ce19a1bfbf
commit
c0f94ea2b3
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -5358,9 +5358,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.81"
|
version = "0.2.82"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
|
checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"serde",
|
"serde",
|
||||||
@ -5370,13 +5370,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-backend"
|
name = "wasm-bindgen-backend"
|
||||||
version = "0.2.81"
|
version = "0.2.82"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a"
|
checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
@ -5397,9 +5397,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.81"
|
version = "0.2.82"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa"
|
checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"wasm-bindgen-macro-support",
|
"wasm-bindgen-macro-support",
|
||||||
@ -5407,9 +5407,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro-support"
|
name = "wasm-bindgen-macro-support"
|
||||||
version = "0.2.81"
|
version = "0.2.82"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048"
|
checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -5420,9 +5420,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-shared"
|
name = "wasm-bindgen-shared"
|
||||||
version = "0.2.81"
|
version = "0.2.82"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be"
|
checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-test"
|
name = "wasm-bindgen-test"
|
||||||
|
@ -10,7 +10,18 @@ struct WebsocketNetworkConnectionInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn to_io(err: WsErr) -> io::Error {
|
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)]
|
#[derive(Clone)]
|
||||||
@ -115,20 +126,19 @@ impl WebsocketProtocolHandler {
|
|||||||
let fut = SendWrapper::new(timeout(timeout_ms, async move {
|
let fut = SendWrapper::new(timeout(timeout_ms, async move {
|
||||||
WsMeta::connect(request, None).await.map_err(to_io)
|
WsMeta::connect(request, None).await.map_err(to_io)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let (wsmeta, wsio) = network_result_try!(network_result_try!(fut
|
let (wsmeta, wsio) = network_result_try!(network_result_try!(fut
|
||||||
.await
|
.await
|
||||||
.into_network_result())
|
.into_network_result())
|
||||||
.into_network_result()?);
|
.into_network_result()?);
|
||||||
|
|
||||||
// Make our connection descriptor
|
// Make our connection descriptor
|
||||||
|
|
||||||
let wnc = WebsocketNetworkConnection::new(
|
let wnc = WebsocketNetworkConnection::new(
|
||||||
ConnectionDescriptor::new_no_local(dial_info.to_peer_address())
|
ConnectionDescriptor::new_no_local(dial_info.to_peer_address())
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::AddrNotAvailable, e))?,
|
.map_err(|e| io::Error::new(io::ErrorKind::AddrNotAvailable, e))?,
|
||||||
wsmeta,
|
wsmeta,
|
||||||
wsio,
|
wsio,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(NetworkResult::Value(ProtocolNetworkConnection::Ws(wnc)))
|
Ok(NetworkResult::Value(ProtocolNetworkConnection::Ws(wnc)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -641,6 +641,12 @@ impl Address {
|
|||||||
Address::IPV6(v6) => format!("[{}]:{}", v6, port),
|
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 {
|
pub fn is_global(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Address::IPV4(v4) => ipv4addr_is_global(v4) && !ipv4addr_is_multicast(v4),
|
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> {
|
fn validate_peer_scope(remote: PeerAddress) -> Result<(), VeilidAPIError> {
|
||||||
// Verify address is in one of our peer scopes we care about
|
// Verify address is in one of our peer scopes we care about
|
||||||
let addr = remote.socket_address.address();
|
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() {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1556,6 +1574,14 @@ impl ConnectionDescriptor {
|
|||||||
}
|
}
|
||||||
pub fn peer_scope(&self) -> PeerScope {
|
pub fn peer_scope(&self) -> PeerScope {
|
||||||
let addr = self.remote.socket_address.address();
|
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() {
|
if addr.is_global() {
|
||||||
return PeerScope::Global;
|
return PeerScope::Global;
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ class _MyAppState extends State<MyApp> with UiLoggy {
|
|||||||
labelText: 'Debug Command'),
|
labelText: 'Debug Command'),
|
||||||
textInputAction: TextInputAction.send,
|
textInputAction: TextInputAction.send,
|
||||||
onSubmitted: (String v) async {
|
onSubmitted: (String v) async {
|
||||||
loggy.debug(await Veilid.instance.debug(v));
|
loggy.info(await Veilid.instance.debug(v));
|
||||||
})),
|
})),
|
||||||
DropdownButton<LogLevel>(
|
DropdownButton<LogLevel>(
|
||||||
value: loggy.level.logLevel,
|
value: loggy.level.logLevel,
|
||||||
|
@ -199,11 +199,12 @@ pub fn change_log_level(layer: String, log_level: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
pub fn startup_veilid_core(update_callback: Function, json_config: String) -> Promise {
|
pub fn startup_veilid_core(update_callback_js: Function, json_config: String) -> Promise {
|
||||||
|
let update_callback_js = SendWrapper::new(update_callback_js);
|
||||||
wrap_api_future(async move {
|
wrap_api_future(async move {
|
||||||
let update_callback = Arc::new(move |update: VeilidUpdate| {
|
let update_callback = Arc::new(move |update: VeilidUpdate| {
|
||||||
let _ret =
|
let _ret =
|
||||||
match Function::call1(&update_callback, &JsValue::UNDEFINED, &to_json(update)) {
|
match Function::call1(&update_callback_js, &JsValue::UNDEFINED, &to_json(update)) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("calling update callback failed: {:?}", e);
|
error!("calling update callback failed: {:?}", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user