fix wss: on tauri

master
Niko PLP 5 months ago
parent 8b28dd4218
commit aed16dddc5
  1. 15
      Cargo.lock
  2. 1
      ng-app/src-tauri/Cargo.toml
  3. 2
      ng-app/src-tauri/src/lib.rs
  4. 31
      ng-wallet/src/lib.rs
  5. 11
      p2p-client-ws/src/remote_ws.rs
  6. 1
      p2p-net/src/types.rs

15
Cargo.lock generated

@ -322,6 +322,18 @@ dependencies = [
"event-listener",
]
[[package]]
name = "async-native-tls"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9343dc5acf07e79ff82d0c37899f079db3534d99f189a1837c8e549c99405bec"
dependencies = [
"futures-util",
"native-tls",
"thiserror",
"url",
]
[[package]]
name = "async-oneshot"
version = "0.5.0"
@ -410,6 +422,7 @@ name = "async-tungstenite"
version = "0.22.2"
source = "git+https://git.nextgraph.org/NextGraph/async-tungstenite.git?branch=nextgraph#979de8e77d365af4630607dfdc721d5d9aeea42e"
dependencies = [
"async-native-tls",
"async-std",
"futures-io",
"futures-util",
@ -3042,6 +3055,7 @@ name = "ng-app"
version = "0.1.0"
dependencies = [
"async-std",
"async-tungstenite",
"ng-wallet",
"p2p-client-ws",
"p2p-net",
@ -5588,6 +5602,7 @@ dependencies = [
"http",
"httparse",
"log",
"native-tls",
"rand 0.8.5",
"sha1",
"thiserror",

@ -32,6 +32,7 @@ ng-wallet = { path = "../../ng-wallet" }
async-std = { version = "1.12.0", features = ["attributes", "unstable"] }
# tauri-plugin-window = { git = "https://git.nextgraph.org/NextGraph/plugins-workspace.git", branch="window-alpha.1-nextgraph" }
tauri-plugin-window = "2.0.0-alpha.1"
async-tungstenite = { git = "https://git.nextgraph.org/NextGraph/async-tungstenite.git", branch = "nextgraph", features = ["async-std-runtime", "async-native-tls"] }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem

@ -433,7 +433,7 @@ async fn broker_connect(
info,
session,
opened_wallet,
location,
None,
Box::new(ConnectionWebSocket {}),
)
.await?;

@ -458,7 +458,7 @@ pub async fn connect_wallet(
let arc_cnx = Arc::new(cnx);
match opened_wallet {
EncryptedWallet::V0(wallet) => {
log_debug!("XXXX {} {:?}", client.to_string(), wallet);
log_info!("XXXX {} {:?}", client.to_string(), wallet);
let auto_open = &wallet
.clients
.get(&client.to_string())
@ -501,10 +501,12 @@ pub async fn connect_wallet(
continue;
}
let broker = broker.unwrap();
let mut tried: Option<(String, String, String, Option<String>, f64)> = None;
for broker_info in broker {
match broker_info {
BrokerInfoV0::ServerV0(server) => {
let url = server.get_ws_url(&location).await;
log_debug!("URL {:?}", url);
//Option<(String, Vec<BindAddress>)>
if url.is_some() {
let url = url.unwrap();
@ -515,13 +517,13 @@ pub async fn connect_wallet(
.await
.connect(
arc_cnx.clone(),
peer_key,
peer_key.clone(),
peer_id,
server_key,
StartConfig::Client(ClientConfig {
url: url.0.clone(),
user: *user,
user_priv,
user_priv: user_priv.clone(),
client,
info: info.clone(),
registration: Some(core.1),
@ -530,23 +532,38 @@ pub async fn connect_wallet(
.await;
log_debug!("broker.connect : {:?}", res);
result.push((
user_id,
tried = Some((
user_id.clone(),
core.0.to_string(),
url.0.into(),
match res {
match &res {
Ok(_) => None,
Err(e) => Some(e.to_string()),
},
get_unix_time(),
));
}
break; // TODO implement failover
if tried.is_some() && tried.as_ref().unwrap().3.is_none() {
// successful. we can stop here
break;
} else {
log_debug!("Failed connection {:?}", tried);
}
}
}
_ => {}
}
}
if tried.is_none() {
tried = Some((
user_id,
core.0.to_string(),
"".into(),
Some("No broker found".into()),
get_unix_time(),
));
}
result.push(tried.unwrap());
}
_ => unimplemented!(),
}

@ -13,7 +13,6 @@
use std::sync::Arc;
use async_std::net::TcpStream;
use async_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
use async_tungstenite::tungstenite::protocol::CloseFrame;
use async_tungstenite::WebSocketStream;
@ -33,7 +32,7 @@ use p2p_repo::log::*;
use p2p_repo::types::*;
use p2p_repo::utils::{generate_keypair, now_timestamp};
use async_tungstenite::async_std::connect_async;
use async_tungstenite::async_std::{connect_async, ConnectStream};
use async_tungstenite::tungstenite::{Error, Message};
pub struct ConnectionWebSocket {}
@ -125,7 +124,7 @@ impl IConnect for ConnectionWebSocket {
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
impl IAccept for ConnectionWebSocket {
type Socket = WebSocketStream<TcpStream>;
type Socket = WebSocketStream<ConnectStream>;
async fn accept(
&self,
remote_bind_address: BindAddress,
@ -161,7 +160,7 @@ impl IAccept for ConnectionWebSocket {
}
async fn close_ws(
stream: &mut WebSocketStream<TcpStream>,
stream: &mut WebSocketStream<ConnectStream>,
receiver: &mut Sender<ConnectionCommand>,
code: u16,
reason: &str,
@ -191,12 +190,12 @@ async fn close_ws(
}
async fn ws_loop(
mut ws: WebSocketStream<TcpStream>,
mut ws: WebSocketStream<ConnectStream>,
sender: Receiver<ConnectionCommand>,
mut receiver: Sender<ConnectionCommand>,
) -> Result<(), NetError> {
async fn inner_loop(
stream: &mut WebSocketStream<TcpStream>,
stream: &mut WebSocketStream<ConnectStream>,
mut sender: Receiver<ConnectionCommand>,
receiver: &mut Sender<ConnectionCommand>,
) -> Result<ProtocolError, NetError> {

@ -20,6 +20,7 @@ use crate::utils::{
use crate::{actor::EActor, actors::*, errors::ProtocolError};
use core::fmt;
use p2p_repo::errors::NgError;
use p2p_repo::log::*;
use p2p_repo::types::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

Loading…
Cancel
Save