Optimized p2p connections a bit.

This commit is contained in:
Revertron
2021-04-24 19:02:24 +02:00
parent 9b6a6f1718
commit c0e49bbab5
4 changed files with 7 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "alfis" name = "alfis"
version = "0.4.26" version = "0.4.27"
authors = ["Revertron <alfis@revertron.com>"] authors = ["Revertron <alfis@revertron.com>"]
edition = "2018" edition = "2018"
build = "build.rs" build = "build.rs"
+1 -1
View File
@@ -33,4 +33,4 @@ forwarders = ["94.140.14.14:53", "94.140.15.15:53"]
# How many CPU threads to spawn for mining, zero = number of CPU cores # How many CPU threads to spawn for mining, zero = number of CPU cores
threads = 0 threads = 0
# Set lower priority for mining threads # Set lower priority for mining threads
lower = true lower = true
+1 -1
View File
@@ -43,5 +43,5 @@ pub const LOG_REFRESH_DELAY_SEC: u64 = 60;
pub const POLL_TIMEOUT: Option<Duration> = Some(Duration::from_millis(250)); pub const POLL_TIMEOUT: Option<Duration> = Some(Duration::from_millis(250));
pub const MAX_PACKET_SIZE: usize = 1 * 1024 * 1024; // 1 Mb pub const MAX_PACKET_SIZE: usize = 1 * 1024 * 1024; // 1 Mb
pub const MAX_READ_BLOCK_TIME: u128 = 500; pub const MAX_READ_BLOCK_TIME: u128 = 200;
pub const MAX_NODES: usize = 15; pub const MAX_NODES: usize = 15;
+4 -1
View File
@@ -353,8 +353,11 @@ fn read_message(stream: &mut TcpStream) -> Result<Vec<u8>, ()> {
} }
// Would block "errors" are the OS's way of saying that the connection is not actually ready to perform this I/O operation. // Would block "errors" are the OS's way of saying that the connection is not actually ready to perform this I/O operation.
Err(ref err) if would_block(err) => { Err(ref err) if would_block(err) => {
// We give every connection no more than 500ms to read a message // We give every connection no more than 200ms to read a message
if instant.elapsed().as_millis() < MAX_READ_BLOCK_TIME { if instant.elapsed().as_millis() < MAX_READ_BLOCK_TIME {
// We need to sleep a bit, otherwise it can eat CPU
let delay = Duration::from_millis(10);
thread::sleep(delay);
continue; continue;
} else { } else {
break; break;