Optimized p2p connections a bit.

pull/99/head
Revertron 3 years ago
parent 9b6a6f1718
commit c0e49bbab5

@ -1,6 +1,6 @@
[package]
name = "alfis"
version = "0.4.26"
version = "0.4.27"
authors = ["Revertron <alfis@revertron.com>"]
edition = "2018"
build = "build.rs"

@ -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
threads = 0
# Set lower priority for mining threads
lower = true
lower = true

@ -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 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;

@ -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.
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 {
// We need to sleep a bit, otherwise it can eat CPU
let delay = Duration::from_millis(10);
thread::sleep(delay);
continue;
} else {
break;

Loading…
Cancel
Save