Working on Auto Reconnect to Omikron
This commit is contained in:
parent
8dd376e050
commit
fe0b3f0315
5 changed files with 17 additions and 20 deletions
|
|
@ -127,9 +127,7 @@ pub async fn complete_register(user_profile: &UserProfile, iota_id: &str) -> boo
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("Status: {}", res.status());
|
||||
let body = res.text().await.unwrap();
|
||||
println!("Response body:\n{}", body);
|
||||
|
||||
CommunicationValue::from_json(&body).is_type(CommunicationType::success)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ pub static APP_STATE: LazyLock<Arc<Mutex<AppState>>> =
|
|||
LazyLock::new(|| Arc::new(Mutex::new(AppState::new())));
|
||||
|
||||
pub static SHUTDOWN: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
|
||||
pub static RECONNECT: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
|
||||
|
||||
#[tokio::main(flavor = "multi_thread", worker_threads = 8)]
|
||||
#[allow(unused_must_use, dead_code)]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::SHUTDOWN;
|
||||
use crate::auth::local_auth;
|
||||
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
|
||||
use crate::gui::log_panel::{log_cv, log_message, log_message_trans};
|
||||
|
|
@ -8,6 +7,7 @@ use crate::users::user_community_util::UserCommunityUtil;
|
|||
use crate::util::chat_files;
|
||||
use crate::util::chats_util::{get_user, get_users, mod_user};
|
||||
use crate::util::file_util::{get_children, load_file, save_file};
|
||||
use crate::{RECONNECT, SHUTDOWN};
|
||||
use futures::Stream;
|
||||
use futures::stream::{SplitSink, SplitStream};
|
||||
use futures_util::sink::Sink;
|
||||
|
|
@ -91,6 +91,9 @@ impl OmikronConnection {
|
|||
if *SHUTDOWN.read().await {
|
||||
break;
|
||||
}
|
||||
if *RECONNECT.read().await {
|
||||
break;
|
||||
}
|
||||
match connect_async("wss://app.tensamin.net/ws/iota/").await {
|
||||
Ok((ws_stream, _)) => {
|
||||
let (write_half, read_half) = ws_stream.split();
|
||||
|
|
@ -105,6 +108,9 @@ impl OmikronConnection {
|
|||
if *SHUTDOWN.read().await {
|
||||
break;
|
||||
}
|
||||
if *RECONNECT.read().await {
|
||||
break;
|
||||
}
|
||||
cloned_self.send_ping().await;
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
|
|
@ -149,6 +155,9 @@ impl OmikronConnection {
|
|||
if *SHUTDOWN.read().await {
|
||||
break;
|
||||
}
|
||||
if *RECONNECT.read().await {
|
||||
break;
|
||||
}
|
||||
let waiting = waiting_out.clone();
|
||||
let writer = writer_out.clone();
|
||||
let is_connected = is_connected_out.clone();
|
||||
|
|
|
|||
|
|
@ -202,23 +202,8 @@ impl Service<HttpRequest<Incoming>> for HttpService {
|
|||
}
|
||||
|
||||
fn is_local_network(addr: IpAddr) -> bool {
|
||||
if addr.is_loopback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
if let IpAddr::V4(ipv4) = addr {
|
||||
if ipv4.octets()[0] == 169 && ipv4.octets()[1] == 254 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if let IpAddr::V6(ipv6) = addr {
|
||||
if (ipv6.segments()[0] & 0xfe00) == 0xfc00 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
// PLACEHOLDER
|
||||
return true;
|
||||
}
|
||||
|
||||
async fn run_http_server(port: u16) -> bool {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use crate::RECONNECT;
|
||||
use crate::auth::{auth_connector, crypto_helper};
|
||||
use crate::gui::log_panel::log_message;
|
||||
use crate::users::user_profile::UserProfile;
|
||||
use crate::util::config_util::CONFIG;
|
||||
use crate::util::file_util::{load_file, save_file};
|
||||
|
|
@ -71,6 +73,8 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
);
|
||||
|
||||
auth_connector::complete_register(&up, &CONFIG.read().await.get_iota_id().to_string()).await;
|
||||
*RECONNECT.write().await = true;
|
||||
log_message("Created User");
|
||||
save_file(
|
||||
"",
|
||||
&format!("{}.tu", username),
|
||||
|
|
|
|||
Loading…
Reference in a new issue