node: ability to reset peers data
This commit is contained in:
parent
119ca7d201
commit
55011c31de
4 changed files with 58 additions and 24 deletions
|
@ -274,6 +274,8 @@ network_settings:
|
||||||
ban_window_desc: The decision to ban is made by node, based on the correctness of the data received from the peer.
|
ban_window_desc: The decision to ban is made by node, based on the correctness of the data received from the peer.
|
||||||
max_inbound_count: 'Maximum number of inbound peer connections:'
|
max_inbound_count: 'Maximum number of inbound peer connections:'
|
||||||
max_outbound_count: 'Maximum number of outbound peer connections:'
|
max_outbound_count: 'Maximum number of outbound peer connections:'
|
||||||
|
reset_peers_desc: Reset peers data. Use it only if there are problems with finding peers.
|
||||||
|
reset_peers: Reset peers
|
||||||
modal:
|
modal:
|
||||||
cancel: Cancel
|
cancel: Cancel
|
||||||
save: Save
|
save: Save
|
||||||
|
|
|
@ -274,6 +274,8 @@ network_settings:
|
||||||
ban_window_desc: Решение о запрете принимается узлом, основываясь на корректности данных полученных от пира.
|
ban_window_desc: Решение о запрете принимается узлом, основываясь на корректности данных полученных от пира.
|
||||||
max_inbound_count: 'Максимальное количество входящих подключений пиров:'
|
max_inbound_count: 'Максимальное количество входящих подключений пиров:'
|
||||||
max_outbound_count: 'Максимальное количество исходящих подключений к пирам:'
|
max_outbound_count: 'Максимальное количество исходящих подключений к пирам:'
|
||||||
|
reset_peers_desc: Сбросить данные пиров. Использовать только при наличии проблем с поиском пиров.
|
||||||
|
reset_peers: Сбросить пиры
|
||||||
modal:
|
modal:
|
||||||
cancel: Отмена
|
cancel: Отмена
|
||||||
save: Сохранить
|
save: Сохранить
|
||||||
|
|
|
@ -63,6 +63,9 @@ pub struct P2PSetup {
|
||||||
/// Maximum number of outbound peer connections.
|
/// Maximum number of outbound peer connections.
|
||||||
max_outbound_count: String,
|
max_outbound_count: String,
|
||||||
|
|
||||||
|
/// Flag to check if reset of peers was called.
|
||||||
|
peers_reset: bool,
|
||||||
|
|
||||||
/// [`Modal`] identifiers allowed at this ui container.
|
/// [`Modal`] identifiers allowed at this ui container.
|
||||||
modal_ids: Vec<&'static str>
|
modal_ids: Vec<&'static str>
|
||||||
}
|
}
|
||||||
|
@ -107,6 +110,7 @@ impl Default for P2PSetup {
|
||||||
ban_window_edit: NodeConfig::get_p2p_ban_window(),
|
ban_window_edit: NodeConfig::get_p2p_ban_window(),
|
||||||
max_inbound_count: NodeConfig::get_max_inbound_peers(),
|
max_inbound_count: NodeConfig::get_max_inbound_peers(),
|
||||||
max_outbound_count: NodeConfig::get_max_outbound_peers(),
|
max_outbound_count: NodeConfig::get_max_outbound_peers(),
|
||||||
|
peers_reset: false,
|
||||||
modal_ids: vec![
|
modal_ids: vec![
|
||||||
PORT_MODAL,
|
PORT_MODAL,
|
||||||
CUSTOM_SEED_MODAL,
|
CUSTOM_SEED_MODAL,
|
||||||
|
@ -222,6 +226,15 @@ impl P2PSetup {
|
||||||
|
|
||||||
// Show maximum outbound peers value setup.
|
// Show maximum outbound peers value setup.
|
||||||
self.max_outbound_ui(ui, cb);
|
self.max_outbound_ui(ui, cb);
|
||||||
|
|
||||||
|
if !Node::is_restarting() && !self.peers_reset {
|
||||||
|
ui.add_space(6.0);
|
||||||
|
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||||
|
ui.add_space(6.0);
|
||||||
|
|
||||||
|
// Show peers data reset content.
|
||||||
|
self.reset_peers_ui(ui);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,6 +735,22 @@ impl P2PSetup {
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draw content to reset peers data.
|
||||||
|
fn reset_peers_ui(&mut self, ui: &mut egui::Ui) {
|
||||||
|
ui.add_space(4.0);
|
||||||
|
|
||||||
|
let button_text = format!("{} {}", TRASH, t!("network_settings.reset_peers"));
|
||||||
|
View::colored_text_button(ui, button_text, Colors::RED, Colors::BUTTON, || {
|
||||||
|
Node::reset_peers(false);
|
||||||
|
self.peers_reset = true;
|
||||||
|
});
|
||||||
|
ui.add_space(6.0);
|
||||||
|
ui.label(RichText::new(t!("network_settings.reset_peers_desc"))
|
||||||
|
.size(16.0)
|
||||||
|
.color(Colors::INACTIVE_TEXT)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw peer list item.
|
/// Draw peer list item.
|
||||||
|
|
|
@ -55,8 +55,8 @@ pub struct Node {
|
||||||
stop_needed: AtomicBool,
|
stop_needed: AtomicBool,
|
||||||
/// Flag to check if app exit is needed after [`Server`] stop.
|
/// Flag to check if app exit is needed after [`Server`] stop.
|
||||||
exit_after_stop: AtomicBool,
|
exit_after_stop: AtomicBool,
|
||||||
/// Flag to clean-up peers and restart the [`Server`].
|
/// Flag to reset peers data and restart the [`Server`].
|
||||||
clean_up_peers: AtomicBool,
|
reset_peers: AtomicBool,
|
||||||
|
|
||||||
/// An error occurred on [`Server`] start.
|
/// An error occurred on [`Server`] start.
|
||||||
error: Arc<RwLock<Option<Error>>>
|
error: Arc<RwLock<Option<Error>>>
|
||||||
|
@ -74,7 +74,7 @@ impl Default for Node {
|
||||||
exit_after_stop: AtomicBool::new(false),
|
exit_after_stop: AtomicBool::new(false),
|
||||||
start_stratum_needed: AtomicBool::new(false),
|
start_stratum_needed: AtomicBool::new(false),
|
||||||
error: Arc::new(RwLock::new(None)),
|
error: Arc::new(RwLock::new(None)),
|
||||||
clean_up_peers: AtomicBool::new(false),
|
reset_peers: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,12 +147,12 @@ impl Node {
|
||||||
|
|
||||||
/// Check if [`Node`] is restarting.
|
/// Check if [`Node`] is restarting.
|
||||||
pub fn is_restarting() -> bool {
|
pub fn is_restarting() -> bool {
|
||||||
NODE_STATE.restart_needed.load(Ordering::Relaxed)
|
NODE_STATE.restart_needed.load(Ordering::Relaxed) || Self::reset_peers_needed()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if clean-up of [`Server`] peers is needed.
|
/// Check if reset of [`Server`] peers is needed.
|
||||||
fn clean_up_peers_needed() -> bool {
|
fn reset_peers_needed() -> bool {
|
||||||
NODE_STATE.clean_up_peers.load(Ordering::Relaxed)
|
NODE_STATE.reset_peers.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get node [`Server`] statistics.
|
/// Get node [`Server`] statistics.
|
||||||
|
@ -175,7 +175,7 @@ impl Node {
|
||||||
return Some(SyncStatus::Shutdown);
|
return Some(SyncStatus::Shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Initial status when node is starting or restarting.
|
// Return Initial status when node is starting or restarting or peers are deleting.
|
||||||
if Self::is_starting() || Self::is_restarting() {
|
if Self::is_starting() || Self::is_restarting() {
|
||||||
return Some(SyncStatus::Initial);
|
return Some(SyncStatus::Initial);
|
||||||
}
|
}
|
||||||
|
@ -231,21 +231,19 @@ impl Node {
|
||||||
fn start_server_thread() {
|
fn start_server_thread() {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
NODE_STATE.starting.store(true, Ordering::Relaxed);
|
NODE_STATE.starting.store(true, Ordering::Relaxed);
|
||||||
|
|
||||||
// Start the server.
|
// Start the server.
|
||||||
match start_node_server() {
|
match start_node_server() {
|
||||||
Ok(mut server) => {
|
Ok(mut server) => {
|
||||||
let mut first_start = true;
|
let mut first_start = true;
|
||||||
loop {
|
loop {
|
||||||
// Restart server if request or peers clean up is needed
|
// Restart server if request or peers clean up is needed
|
||||||
let clean_up_peers = Self::clean_up_peers_needed();
|
if Self::is_restarting() {
|
||||||
if Self::is_restarting() || clean_up_peers {
|
|
||||||
server.stop();
|
server.stop();
|
||||||
// Wait server after stop.
|
// Wait server after stop.
|
||||||
thread::sleep(Duration::from_millis(5000));
|
thread::sleep(Duration::from_millis(5000));
|
||||||
// Clean-up peers of requested.
|
// Reset peers data if requested.
|
||||||
if clean_up_peers {
|
if Self::reset_peers_needed() {
|
||||||
Node::clean_up_peers(true);
|
Node::reset_peers(true);
|
||||||
}
|
}
|
||||||
// Reset stratum stats.
|
// Reset stratum stats.
|
||||||
{
|
{
|
||||||
|
@ -310,6 +308,7 @@ impl Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset stratum server start flag.
|
||||||
if stratum_start_requested && NODE_STATE.stratum_stats.read().is_running {
|
if stratum_start_requested && NODE_STATE.stratum_stats.read().is_running {
|
||||||
NODE_STATE.start_stratum_needed.store(false, Ordering::Relaxed);
|
NODE_STATE.start_stratum_needed.store(false, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
@ -380,24 +379,24 @@ impl Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clean-up [`Server`] peers from storage.
|
/// Reset [`Server`] peers data.
|
||||||
pub fn clean_up_peers(force: bool) {
|
pub fn reset_peers(force: bool) {
|
||||||
if force || !Node::is_running() {
|
if force || !Node::is_running() {
|
||||||
NODE_STATE.clean_up_peers.store(false, Ordering::Relaxed);
|
|
||||||
// Get saved server config.
|
// Get saved server config.
|
||||||
let config = NodeConfig::node_server_config();
|
let config = NodeConfig::node_server_config();
|
||||||
let mut server_config = config.server.clone();
|
let mut server_config = config.server.clone();
|
||||||
// Remove peers folder.
|
// Remove peers folder.
|
||||||
let mut tmp_dir = PathBuf::from(&server_config.db_root);
|
let mut peers_dir = PathBuf::from(&server_config.db_root);
|
||||||
tmp_dir.push("peers");
|
peers_dir.push("peer");
|
||||||
if tmp_dir.exists() {
|
if peers_dir.exists() {
|
||||||
match fs::remove_dir_all(tmp_dir) {
|
match fs::remove_dir_all(peers_dir) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_) => { println!("Cannot remove peers dir") }
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NODE_STATE.reset_peers.store(false, Ordering::Relaxed);
|
||||||
} else {
|
} else {
|
||||||
NODE_STATE.clean_up_peers.store(true, Ordering::Relaxed);
|
NODE_STATE.reset_peers.store(true, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,9 +525,11 @@ fn start_node_server() -> Result<Server, Error> {
|
||||||
// Get saved server config.
|
// Get saved server config.
|
||||||
let config = NodeConfig::node_server_config();
|
let config = NodeConfig::node_server_config();
|
||||||
let mut server_config = config.server.clone();
|
let mut server_config = config.server.clone();
|
||||||
|
|
||||||
// Fix to avoid too many opened files.
|
// Fix to avoid too many opened files.
|
||||||
server_config.p2p_config.peer_min_preferred_outbound_count =
|
server_config.p2p_config.peer_min_preferred_outbound_count =
|
||||||
server_config.p2p_config.peer_max_outbound_count;
|
server_config.p2p_config.peer_max_outbound_count;
|
||||||
|
|
||||||
// Remove temporary file dir.
|
// Remove temporary file dir.
|
||||||
{
|
{
|
||||||
let mut tmp_dir = PathBuf::from(&server_config.db_root);
|
let mut tmp_dir = PathBuf::from(&server_config.db_root);
|
||||||
|
@ -537,7 +538,7 @@ fn start_node_server() -> Result<Server, Error> {
|
||||||
if tmp_dir.exists() {
|
if tmp_dir.exists() {
|
||||||
match fs::remove_dir_all(tmp_dir) {
|
match fs::remove_dir_all(tmp_dir) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_) => { println!("Cannot remove tmp dir") }
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue