connections: check availability after adding
This commit is contained in:
parent
7ef558a6f1
commit
e235123516
2 changed files with 7 additions and 7 deletions
|
@ -332,7 +332,6 @@ impl ConnectionsContent {
|
||||||
let error = Url::parse(self.ext_node_url_edit.as_str()).is_err();
|
let error = Url::parse(self.ext_node_url_edit.as_str()).is_err();
|
||||||
self.ext_node_url_error = error;
|
self.ext_node_url_error = error;
|
||||||
if !error {
|
if !error {
|
||||||
// Save external connection.
|
|
||||||
let url = self.ext_node_url_edit.to_owned();
|
let url = self.ext_node_url_edit.to_owned();
|
||||||
let secret = if self.ext_node_secret_edit.is_empty() {
|
let secret = if self.ext_node_secret_edit.is_empty() {
|
||||||
None
|
None
|
||||||
|
@ -340,13 +339,14 @@ impl ConnectionsContent {
|
||||||
Some(self.ext_node_secret_edit.to_owned())
|
Some(self.ext_node_secret_edit.to_owned())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update or create new connections.
|
// Update or create new connection.
|
||||||
let mut ext_conn = ExternalConnection::new(url, secret);
|
let mut ext_conn = ExternalConnection::new(url, secret);
|
||||||
|
ext_conn.check_conn_availability();
|
||||||
if let Some(id) = self.ext_conn_id_edit {
|
if let Some(id) = self.ext_conn_id_edit {
|
||||||
ext_conn.id = id;
|
ext_conn.id = id;
|
||||||
}
|
}
|
||||||
ConnectionsConfig::add_ext_conn(ext_conn);
|
|
||||||
self.ext_conn_id_edit = None;
|
self.ext_conn_id_edit = None;
|
||||||
|
ConnectionsConfig::add_ext_conn(ext_conn);
|
||||||
|
|
||||||
// Close modal.
|
// Close modal.
|
||||||
cb.hide_keyboard();
|
cb.hide_keyboard();
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl ExternalConnection {
|
||||||
pub const DEFAULT_MAIN_URL: &'static str = "https://grinnode.live:3413";
|
pub const DEFAULT_MAIN_URL: &'static str = "https://grinnode.live:3413";
|
||||||
|
|
||||||
/// External connections availability check delay.
|
/// External connections availability check delay.
|
||||||
const AVAILABILITY_CHECK_DELAY: Duration = Duration::from_millis(10 * 1000);
|
const AV_CHECK_DELAY: Duration = Duration::from_millis(60 * 1000);
|
||||||
|
|
||||||
/// Create default external connection.
|
/// Create default external connection.
|
||||||
pub fn default_main() -> Self {
|
pub fn default_main() -> Self {
|
||||||
|
@ -53,13 +53,13 @@ impl ExternalConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check connection availability.
|
/// Check connection availability.
|
||||||
fn check_conn_availability(&self) {
|
pub fn check_conn_availability(&self) {
|
||||||
// Check every connection at separate thread.
|
// Check every connection at separate thread.
|
||||||
let conn = self.clone();
|
let conn = self.clone();
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let url = url::Url::parse(conn.url.as_str()).unwrap();
|
let url = url::Url::parse(conn.url.as_str()).unwrap();
|
||||||
if let Ok(addr) = url.socket_addrs(|| None) {
|
if let Ok(addr) = url.socket_addrs(|| None) {
|
||||||
match std::net::TcpStream::connect_timeout(&addr[0], Self::AVAILABILITY_CHECK_DELAY) {
|
match std::net::TcpStream::connect_timeout(&addr[0], Self::AV_CHECK_DELAY) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
ConnectionsConfig::update_ext_conn_availability(conn.id, true);
|
ConnectionsConfig::update_ext_conn_availability(conn.id, true);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ impl ExternalConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause checking for delay value.
|
// Pause checking for delay value.
|
||||||
std::thread::sleep(Self::AVAILABILITY_CHECK_DELAY);
|
std::thread::sleep(Self::AV_CHECK_DELAY);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue