Small p2p optimizations.
This commit is contained in:
@@ -39,7 +39,7 @@ pub const LISTEN_PORT: u16 = 4244;
|
||||
pub const UI_REFRESH_DELAY_MS: u128 = 500;
|
||||
pub const LOG_REFRESH_DELAY_SEC: u64 = 60;
|
||||
|
||||
pub const POLL_TIMEOUT: Option<Duration> = Some(Duration::from_millis(500));
|
||||
pub const POLL_TIMEOUT: Option<Duration> = Some(Duration::from_millis(200));
|
||||
pub const WAIT_FOR_INTERNET: Duration = Duration::from_secs(10);
|
||||
/// We start syncing blocks only when we got 4 and more connected nodes
|
||||
pub const MIN_CONNECTED_NODES_START_SYNC: usize = 4;
|
||||
|
||||
+3
-6
@@ -216,19 +216,16 @@ fn main() {
|
||||
let miner: Arc<Mutex<Miner>> = Arc::new(Mutex::new(miner_obj));
|
||||
|
||||
let mut network = Network::new(Arc::clone(&context));
|
||||
thread::spawn(move || {
|
||||
let network = thread::Builder::new().name(String::from("Network")).spawn(move || {
|
||||
// Give UI some time to appear :)
|
||||
thread::sleep(Duration::from_millis(1000));
|
||||
network.start();
|
||||
});
|
||||
}).expect("Could not start network thread!");
|
||||
|
||||
create_genesis_if_needed(&context, &miner);
|
||||
if no_gui {
|
||||
print_my_domains(&context);
|
||||
let sleep = Duration::from_millis(1000);
|
||||
loop {
|
||||
thread::sleep(sleep);
|
||||
}
|
||||
let _ = network.join();
|
||||
} else {
|
||||
if !dns_server_ok {
|
||||
thread::spawn(|| {
|
||||
|
||||
+12
-8
@@ -78,6 +78,8 @@ impl Network {
|
||||
let mut connect_timer = Instant::now();
|
||||
let mut last_events_time = Instant::now();
|
||||
let mut old_blocks = 0u64;
|
||||
let mut old_domains = 0i64;
|
||||
let mut old_keys = 0i64;
|
||||
let mut old_nodes = 0usize;
|
||||
let mut old_banned = 0usize;
|
||||
loop {
|
||||
@@ -171,15 +173,17 @@ impl Network {
|
||||
|
||||
let keys = context.chain.get_users_count();
|
||||
let domains = context.chain.get_domains_count();
|
||||
post(crate::event::Event::NetworkStatus { blocks, domains, keys, nodes });
|
||||
if old_nodes != nodes || old_blocks != blocks || old_banned != banned || old_domains != domains || old_keys != keys {
|
||||
info!("Active nodes: {}, banned: {}, blocks: {}, domains: {}, keys: {}", nodes, banned, blocks, domains, keys);
|
||||
post(crate::event::Event::NetworkStatus { blocks, domains, keys, nodes });
|
||||
old_nodes = nodes;
|
||||
old_blocks = blocks;
|
||||
old_domains = domains;
|
||||
old_keys = keys;
|
||||
old_banned = banned;
|
||||
}
|
||||
|
||||
if log_timer.elapsed().as_secs() > LOG_REFRESH_DELAY_SEC {
|
||||
if old_nodes != nodes || old_blocks != blocks || old_banned != banned {
|
||||
info!("Active nodes count: {}, banned count: {}, blocks count: {}", nodes, banned, blocks);
|
||||
old_nodes = nodes;
|
||||
old_blocks = blocks;
|
||||
old_banned = banned;
|
||||
}
|
||||
let elapsed = last_events_time.elapsed().as_secs();
|
||||
if elapsed >= 30 {
|
||||
warn!("Last network events time {} seconds ago", elapsed);
|
||||
@@ -454,7 +458,7 @@ impl Network {
|
||||
let app_version = self.context.lock().unwrap().app_version.clone();
|
||||
State::message(Message::shake(&app_version, &origin, version, me_public, &my_id, my_height))
|
||||
} else {
|
||||
warn!("Handshake from unsupported chain or version");
|
||||
warn!("Handshake from unsupported chain or version: {}, {}", &origin, version);
|
||||
State::Banned
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user