fix wss: on tauri

pull/19/head
Niko PLP 1 year ago
parent ce9069ebb0
commit 00dda8a63d
  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", "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]] [[package]]
name = "async-oneshot" name = "async-oneshot"
version = "0.5.0" version = "0.5.0"
@ -410,6 +422,7 @@ name = "async-tungstenite"
version = "0.22.2" version = "0.22.2"
source = "git+https://git.nextgraph.org/NextGraph/async-tungstenite.git?branch=nextgraph#979de8e77d365af4630607dfdc721d5d9aeea42e" source = "git+https://git.nextgraph.org/NextGraph/async-tungstenite.git?branch=nextgraph#979de8e77d365af4630607dfdc721d5d9aeea42e"
dependencies = [ dependencies = [
"async-native-tls",
"async-std", "async-std",
"futures-io", "futures-io",
"futures-util", "futures-util",
@ -3042,6 +3055,7 @@ name = "ng-app"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-std", "async-std",
"async-tungstenite",
"ng-wallet", "ng-wallet",
"p2p-client-ws", "p2p-client-ws",
"p2p-net", "p2p-net",
@ -5588,6 +5602,7 @@ dependencies = [
"http", "http",
"httparse", "httparse",
"log", "log",
"native-tls",
"rand 0.8.5", "rand 0.8.5",
"sha1", "sha1",
"thiserror", "thiserror",

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

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

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

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

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

Loading…
Cancel
Save