Optimized logging, fixing #175.

pull/180/head
Revertron 3 years ago
parent e5419541aa
commit ab742885dd

@ -257,6 +257,7 @@ fn setup_logger(opt_matches: &Matches, console_attached: bool) {
.set_time_level(LevelFilter::Error)
.set_time_format_str("%F %T%.3f")
.set_time_to_local(true)
.set_level_padding(LevelPadding::Right)
.build();
match opt_matches.opt_str("l") {
None => {

@ -76,6 +76,9 @@ impl Network {
let mut bootstrap_timer = Instant::now();
let mut connect_timer = Instant::now();
let mut last_events_time = Instant::now();
let mut old_blocks = 0u64;
let mut old_nodes = 0usize;
let mut old_banned = 0usize;
loop {
if self.peers.get_peers_count() == 0 && bootstrap_timer.elapsed().as_secs() > 60 {
warn!("Restarting swarm connections...");
@ -173,9 +176,14 @@ impl Network {
post(crate::event::Event::NetworkStatus { blocks, domains, keys, nodes });
if log_timer.elapsed().as_secs() > LOG_REFRESH_DELAY_SEC {
info!("Active nodes count: {}, banned count: {}, blocks count: {}", nodes, banned, blocks);
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 >= 10 {
if elapsed >= 30 {
warn!("Last network events time {} seconds ago", elapsed);
}
log_timer = Instant::now();
@ -233,7 +241,7 @@ impl Network {
registry.reregister(stream, event.token(), Interest::WRITABLE).unwrap();
peer.set_cipher(chacha);
peer.set_state(State::ServerHandshake);
trace!("Client hello read successfully");
//trace!("Client hello read successfully");
true
}
Err(_) => {
@ -260,7 +268,7 @@ impl Network {
registry.reregister(stream, event.token(), Interest::WRITABLE).unwrap();
peer.set_cipher(chacha);
peer.set_state(State::HandshakeFinished);
trace!("Server hello read successfully");
//trace!("Server hello read successfully");
true
}
Err(_) => {
@ -370,7 +378,7 @@ impl Network {
return false;
}
peer.set_state(State::HandshakeFinished);
trace!("Server handshake sent");
//trace!("Server handshake sent");
}
State::HandshakeFinished => {
//debug!("Connected to peer {}, sending hello...", &peer.get_addr());

@ -60,38 +60,38 @@ impl Peers {
let _ = registry.deregister(stream);
match peer.get_state() {
State::Connecting => {
info!("Peer connection {} to {:?} has timed out", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} has timed out", &token.0, &peer.get_addr());
}
State::Connected => {
info!("Peer connection {} to {:?} disconnected", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} disconnected", &token.0, &peer.get_addr());
}
State::Idle { .. } | State::Message { .. } => {
info!("Peer connection {} to {:?} disconnected", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} disconnected", &token.0, &peer.get_addr());
}
State::Error => {
info!("Peer connection {} to {:?} has shut down on error", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} has shut down on error", &token.0, &peer.get_addr());
}
State::Banned => {
info!("Peer connection {} to {:?} has shut down, banned", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} has shut down, banned", &token.0, &peer.get_addr());
self.ignored.insert(peer.get_addr().ip().clone());
}
State::Offline { .. } => {
info!("Peer connection {} to {:?} is offline", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} is offline", &token.0, &peer.get_addr());
}
State::SendLoop => {
info!("Peer connection {} from {:?} is a loop", &token.0, &peer.get_addr());
debug!("Peer connection {} from {:?} is a loop", &token.0, &peer.get_addr());
}
State::Loop => {
info!("Peer connection {} to {:?} is a loop", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} is a loop", &token.0, &peer.get_addr());
}
State::Twin => {
info!("Peer connection {} to {:?} is a twin", &token.0, &peer.get_addr());
debug!("Peer connection {} to {:?} is a twin", &token.0, &peer.get_addr());
}
State::ServerHandshake => {
info!("Peer connection {} from {:?} didn't shake hands", &token.0, &peer.get_addr());
debug!("Peer connection {} from {:?} didn't shake hands", &token.0, &peer.get_addr());
}
State::HandshakeFinished => {
info!("Peer connection {} from {:?} shaked hands, but then failed", &token.0, &peer.get_addr());
debug!("Peer connection {} from {:?} shook hands, but then failed", &token.0, &peer.get_addr());
}
}
@ -116,8 +116,7 @@ impl Peers {
peers.insert(peer.to_owned());
peers
});
debug!("Got {} peers from exchange", peers.len());
//debug!("Got {} peers: {:?}", peers.len(), &peers);
let mut count = 0;
// TODO make it return error if these peers are wrong and seem like an attack
for peer in peers.iter() {
let addr: SocketAddr = match peer.parse() {
@ -145,7 +144,7 @@ impl Peers {
}
if self.ignored.contains(&addr.ip()) {
info!("Skipping ignored address from exchange: {}", &addr);
debug!("Skipping ignored address from exchange: {}", &addr);
continue;
}
@ -154,6 +153,10 @@ impl Peers {
continue; // Return error in future
}
self.new_peers.push(addr);
count += 1;
}
if count > 0 {
debug!("Got {} new peer(s) from exchange", count);
}
}

Loading…
Cancel
Save