Replace logging backend to log4rs and add log rotation (#1789)

* Replace logging backend to flexi-logger and add log rotation
* Changed flexi_logger to log4rs
* Disable logging level filtering in Root logger
* Support different logging levels for file and stdout
* Don't log messages from modules other than Grin-related
* Fix formatting
* Place backed up compressed log copies into log file directory
* Increase default log file size to 16 MiB
* Add comment to config file on log_max_size option
This commit is contained in:
eupn
2018-10-21 23:30:56 +03:00
committed by Ignotus Peverell
parent 0852b0c4cf
commit 1195071f5b
83 changed files with 582 additions and 897 deletions
-3
View File
@@ -31,7 +31,6 @@ use util::RwLock;
use core::ser;
use msg::{read_body, read_exact, read_header, write_all, write_to_buf, MsgHeader, Type};
use types::Error;
use util::LOGGER;
/// A trait to be implemented in order to receive messages from the
/// connection. Allows providing an optional response.
@@ -234,7 +233,6 @@ fn poll<H>(
if let Some(h) = try_break!(error_tx, read_header(conn, None)) {
let msg = Message::from_header(h, conn);
trace!(
LOGGER,
"Received message header, type {:?}, len {}.",
msg.header.msg_type,
msg.header.msg_len
@@ -276,7 +274,6 @@ fn poll<H>(
// check the close channel
if let Ok(_) = close_rx.try_recv() {
debug!(
LOGGER,
"Connection close with {} initiated by us",
conn.peer_addr()
.map(|a| a.to_string())
+1 -3
View File
@@ -25,7 +25,6 @@ use core::pow::Difficulty;
use msg::{read_message, write_message, Hand, Shake, SockAddr, Type, PROTOCOL_VERSION, USER_AGENT};
use peer::Peer;
use types::{Capabilities, Direction, Error, P2PConfig, PeerInfo, PeerLiveInfo};
use util::LOGGER;
const NONCES_CAP: usize = 100;
@@ -115,7 +114,6 @@ impl Handshake {
}
debug!(
LOGGER,
"Connected! Cumulative {} offered from {:?} {:?} {:?}",
shake.total_difficulty.to_num(),
peer_info.addr,
@@ -186,7 +184,7 @@ impl Handshake {
};
write_message(conn, shake, Type::Shake)?;
trace!(LOGGER, "Success handshake with {}.", peer_info.addr);
trace!("Success handshake with {}.", peer_info.addr);
// when more than one protocol version is supported, choosing should go here
Ok(peer_info)
+1 -1
View File
@@ -37,7 +37,7 @@ extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate slog;
extern crate log;
extern crate chrono;
mod conn;
+2 -3
View File
@@ -26,7 +26,6 @@ use core::pow::Difficulty;
use core::ser::{self, Readable, Reader, Writeable, Writer};
use types::{Capabilities, Error, ReasonForBan, MAX_BLOCK_HEADERS, MAX_LOCATORS, MAX_PEER_ADDRS};
use util::LOGGER;
/// Current latest version of the protocol
pub const PROTOCOL_VERSION: u32 = 1;
@@ -207,8 +206,8 @@ pub fn read_header(conn: &mut TcpStream, msg_type: Option<Type>) -> Result<MsgHe
// TODO 4x the limits for now to leave ourselves space to change things
if header.msg_len > max_len * 4 {
error!(
LOGGER,
"Too large read {}, had {}, wanted {}.", header.msg_type as u8, max_len, header.msg_len
"Too large read {}, had {}, wanted {}.",
header.msg_type as u8, max_len, header.msg_len
);
return Err(Error::Serialization(ser::Error::TooLargeReadErr));
}
+22 -41
View File
@@ -28,7 +28,6 @@ use protocol::Protocol;
use types::{
Capabilities, ChainAdapter, Error, NetAdapter, P2PConfig, PeerInfo, ReasonForBan, TxHashSetRead,
};
use util::LOGGER;
const MAX_TRACK_SIZE: usize = 30;
@@ -104,8 +103,8 @@ impl Peer {
if let Some(ref denied) = config.peers_deny {
if denied.contains(&peer) {
debug!(
LOGGER,
"checking peer allowed/denied: {:?} explicitly denied", peer_addr
"checking peer allowed/denied: {:?} explicitly denied",
peer_addr
);
return true;
}
@@ -113,14 +112,14 @@ impl Peer {
if let Some(ref allowed) = config.peers_allow {
if allowed.contains(&peer) {
debug!(
LOGGER,
"checking peer allowed/denied: {:?} explicitly allowed", peer_addr
"checking peer allowed/denied: {:?} explicitly allowed",
peer_addr
);
return false;
} else {
debug!(
LOGGER,
"checking peer allowed/denied: {:?} not explicitly allowed, denying", peer_addr
"checking peer allowed/denied: {:?} not explicitly allowed, denying",
peer_addr
);
return true;
}
@@ -198,13 +197,10 @@ impl Peer {
.unwrap()
.send(ban_reason_msg, msg::Type::BanReason)
{
Ok(_) => debug!(
LOGGER,
"Sent ban reason {:?} to {}", ban_reason, self.info.addr
),
Ok(_) => debug!("Sent ban reason {:?} to {}", ban_reason, self.info.addr),
Err(e) => error!(
LOGGER,
"Could not send ban reason {:?} to {}: {:?}", ban_reason, self.info.addr, e
"Could not send ban reason {:?} to {}: {:?}",
ban_reason, self.info.addr, e
),
};
}
@@ -213,7 +209,7 @@ impl Peer {
/// if the remote peer is known to already have the block.
pub fn send_block(&self, b: &core::Block) -> Result<bool, Error> {
if !self.tracking_adapter.has(b.hash()) {
trace!(LOGGER, "Send block {} to {}", b.hash(), self.info.addr);
trace!("Send block {} to {}", b.hash(), self.info.addr);
self.connection
.as_ref()
.unwrap()
@@ -221,7 +217,6 @@ impl Peer {
Ok(true)
} else {
debug!(
LOGGER,
"Suppress block send {} to {} (already seen)",
b.hash(),
self.info.addr,
@@ -232,12 +227,7 @@ impl Peer {
pub fn send_compact_block(&self, b: &core::CompactBlock) -> Result<bool, Error> {
if !self.tracking_adapter.has(b.hash()) {
trace!(
LOGGER,
"Send compact block {} to {}",
b.hash(),
self.info.addr
);
trace!("Send compact block {} to {}", b.hash(), self.info.addr);
self.connection
.as_ref()
.unwrap()
@@ -245,7 +235,6 @@ impl Peer {
Ok(true)
} else {
debug!(
LOGGER,
"Suppress compact block send {} to {} (already seen)",
b.hash(),
self.info.addr,
@@ -256,7 +245,7 @@ impl Peer {
pub fn send_header(&self, bh: &core::BlockHeader) -> Result<bool, Error> {
if !self.tracking_adapter.has(bh.hash()) {
debug!(LOGGER, "Send header {} to {}", bh.hash(), self.info.addr);
debug!("Send header {} to {}", bh.hash(), self.info.addr);
self.connection
.as_ref()
.unwrap()
@@ -264,7 +253,6 @@ impl Peer {
Ok(true)
} else {
debug!(
LOGGER,
"Suppress header send {} to {} (already seen)",
bh.hash(),
self.info.addr,
@@ -277,7 +265,7 @@ impl Peer {
/// dropped if the remote peer is known to already have the transaction.
pub fn send_transaction(&self, tx: &core::Transaction) -> Result<bool, Error> {
if !self.tracking_adapter.has(tx.hash()) {
debug!(LOGGER, "Send tx {} to {}", tx.hash(), self.info.addr);
debug!("Send tx {} to {}", tx.hash(), self.info.addr);
self.connection
.as_ref()
.unwrap()
@@ -285,7 +273,6 @@ impl Peer {
Ok(true)
} else {
debug!(
LOGGER,
"Not sending tx {} to {} (already seen)",
tx.hash(),
self.info.addr
@@ -298,7 +285,7 @@ impl Peer {
/// Note: tracking adapter is ignored for stem transactions (while under
/// embargo).
pub fn send_stem_transaction(&self, tx: &core::Transaction) -> Result<(), Error> {
debug!(LOGGER, "Send (stem) tx {} to {}", tx.hash(), self.info.addr);
debug!("Send (stem) tx {} to {}", tx.hash(), self.info.addr);
self.connection
.as_ref()
.unwrap()
@@ -316,10 +303,7 @@ impl Peer {
/// Sends a request for a specific block by hash
pub fn send_block_request(&self, h: Hash) -> Result<(), Error> {
debug!(
LOGGER,
"Requesting block {} from peer {}.", h, self.info.addr
);
debug!("Requesting block {} from peer {}.", h, self.info.addr);
self.connection
.as_ref()
.unwrap()
@@ -328,10 +312,7 @@ impl Peer {
/// Sends a request for a specific compact block by hash
pub fn send_compact_block_request(&self, h: Hash) -> Result<(), Error> {
debug!(
LOGGER,
"Requesting compact block {} from {}", h, self.info.addr
);
debug!("Requesting compact block {} from {}", h, self.info.addr);
self.connection
.as_ref()
.unwrap()
@@ -339,7 +320,7 @@ impl Peer {
}
pub fn send_peer_request(&self, capab: Capabilities) -> Result<(), Error> {
debug!(LOGGER, "Asking {} for more peers.", self.info.addr);
debug!("Asking {} for more peers.", self.info.addr);
self.connection.as_ref().unwrap().send(
&GetPeerAddrs {
capabilities: capab,
@@ -350,8 +331,8 @@ impl Peer {
pub fn send_txhashset_request(&self, height: u64, hash: Hash) -> Result<(), Error> {
debug!(
LOGGER,
"Asking {} for txhashset archive at {} {}.", self.info.addr, height, hash
"Asking {} for txhashset archive at {} {}.",
self.info.addr, height, hash
);
self.connection.as_ref().unwrap().send(
&TxHashSetRequest { hash, height },
@@ -378,8 +359,8 @@ impl Peer {
};
if need_stop {
debug!(
LOGGER,
"Client {} corrupted, will disconnect ({:?}).", self.info.addr, e
"Client {} corrupted, will disconnect ({:?}).",
self.info.addr, e
);
self.stop();
}
@@ -396,7 +377,7 @@ impl Peer {
}
};
if need_stop {
debug!(LOGGER, "Client {} connection lost: {:?}", self.info.addr, e);
debug!("Client {} connection lost: {:?}", self.info.addr, e);
self.stop();
}
false
+23 -36
View File
@@ -24,7 +24,6 @@ use chrono::prelude::*;
use core::core;
use core::core::hash::{Hash, Hashed};
use core::pow::Difficulty;
use util::LOGGER;
use peer::Peer;
use store::{PeerData, PeerStore, State};
@@ -71,7 +70,7 @@ impl Peers {
};
addr = peer.info.addr.clone();
}
debug!(LOGGER, "Saving newly connected peer {}.", addr);
debug!("Saving newly connected peer {}.", addr);
self.save_peer(&peer_data)?;
{
@@ -94,11 +93,11 @@ impl Peers {
.write()
.insert(Utc::now().timestamp(), peer.clone());
debug!(
LOGGER,
"Successfully updated Dandelion relay to: {}", peer.info.addr
"Successfully updated Dandelion relay to: {}",
peer.info.addr
);
}
None => debug!(LOGGER, "Could not update dandelion relay"),
None => debug!("Could not update dandelion relay"),
};
}
@@ -238,11 +237,11 @@ impl Peers {
/// Ban a peer, disconnecting it if we're currently connected
pub fn ban_peer(&self, peer_addr: &SocketAddr, ban_reason: ReasonForBan) {
if let Err(e) = self.update_state(*peer_addr, State::Banned) {
error!(LOGGER, "Couldn't ban {}: {:?}", peer_addr, e);
error!("Couldn't ban {}: {:?}", peer_addr, e);
}
if let Some(peer) = self.get_connected_peer(peer_addr) {
debug!(LOGGER, "Banning peer {}", peer_addr);
debug!("Banning peer {}", peer_addr);
// setting peer status will get it removed at the next clean_peer
peer.send_ban_reason(ban_reason);
peer.set_banned();
@@ -256,13 +255,13 @@ impl Peers {
Ok(_) => {
if self.is_banned(*peer_addr) {
if let Err(e) = self.update_state(*peer_addr, State::Healthy) {
error!(LOGGER, "Couldn't unban {}: {:?}", peer_addr, e);
error!("Couldn't unban {}: {:?}", peer_addr, e);
}
} else {
error!(LOGGER, "Couldn't unban {}: peer is not banned", peer_addr);
error!("Couldn't unban {}: peer is not banned", peer_addr);
}
}
Err(e) => error!(LOGGER, "Couldn't unban {}: {:?}", peer_addr, e),
Err(e) => error!("Couldn't unban {}: {:?}", peer_addr, e),
};
}
@@ -278,7 +277,7 @@ impl Peers {
match inner(&p) {
Ok(true) => count += 1,
Ok(false) => (),
Err(e) => debug!(LOGGER, "Error sending {} to peer: {:?}", obj_name, e),
Err(e) => debug!("Error sending {} to peer: {:?}", obj_name, e),
}
if count >= num_peers {
@@ -297,7 +296,6 @@ impl Peers {
let num_peers = self.config.peer_max_count();
let count = self.broadcast("compact block", num_peers, |p| p.send_compact_block(b));
debug!(
LOGGER,
"broadcast_compact_block: {}, {} at {}, to {} peers, done.",
b.hash(),
b.header.pow.total_difficulty,
@@ -315,7 +313,6 @@ impl Peers {
let num_peers = self.config.peer_min_preferred_count();
let count = self.broadcast("header", num_peers, |p| p.send_header(bh));
debug!(
LOGGER,
"broadcast_header: {}, {} at {}, to {} peers, done.",
bh.hash(),
bh.pow.total_difficulty,
@@ -328,7 +325,7 @@ impl Peers {
pub fn broadcast_stem_transaction(&self, tx: &core::Transaction) -> Result<(), Error> {
let dandelion_relay = self.get_dandelion_relay();
if dandelion_relay.is_empty() {
debug!(LOGGER, "No dandelion relay, updating.");
debug!("No dandelion relay, updating.");
self.update_dandelion_relay();
}
// If still return an error, let the caller handle this as they see fit.
@@ -339,10 +336,7 @@ impl Peers {
for relay in dandelion_relay.values() {
if relay.is_connected() {
if let Err(e) = relay.send_stem_transaction(tx) {
debug!(
LOGGER,
"Error sending stem transaction to peer relay: {:?}", e
);
debug!("Error sending stem transaction to peer relay: {:?}", e);
}
}
}
@@ -358,7 +352,6 @@ impl Peers {
let num_peers = self.config.peer_min_preferred_count();
let count = self.broadcast("transaction", num_peers, |p| p.send_transaction(tx));
trace!(
LOGGER,
"broadcast_transaction: {}, to {} peers, done.",
tx.hash(),
count,
@@ -417,15 +410,15 @@ impl Peers {
// build a list of peers to be cleaned up
for peer in self.peers.read().values() {
if peer.is_banned() {
debug!(LOGGER, "clean_peers {:?}, peer banned", peer.info.addr);
debug!("clean_peers {:?}, peer banned", peer.info.addr);
rm.push(peer.clone());
} else if !peer.is_connected() {
debug!(LOGGER, "clean_peers {:?}, not connected", peer.info.addr);
debug!("clean_peers {:?}, not connected", peer.info.addr);
rm.push(peer.clone());
} else {
let (stuck, diff) = peer.is_stuck();
if stuck && diff < self.adapter.total_difficulty() {
debug!(LOGGER, "clean_peers {:?}, stuck peer", peer.info.addr);
debug!("clean_peers {:?}, stuck peer", peer.info.addr);
peer.stop();
let _ = self.update_state(peer.info.addr, State::Defunct);
rm.push(peer.clone());
@@ -497,8 +490,8 @@ impl ChainAdapter for Peers {
// if the peer sent us a block that's intrinsically bad
// they are either mistaken or malevolent, both of which require a ban
debug!(
LOGGER,
"Received a bad block {} from {}, the peer will be banned", hash, peer_addr
"Received a bad block {} from {}, the peer will be banned",
hash, peer_addr
);
self.ban_peer(&peer_addr, ReasonForBan::BadBlock);
false
@@ -513,10 +506,8 @@ impl ChainAdapter for Peers {
// if the peer sent us a block that's intrinsically bad
// they are either mistaken or malevolent, both of which require a ban
debug!(
LOGGER,
"Received a bad compact block {} from {}, the peer will be banned",
hash,
&peer_addr
hash, &peer_addr
);
self.ban_peer(&peer_addr, ReasonForBan::BadCompactBlock);
false
@@ -566,8 +557,8 @@ impl ChainAdapter for Peers {
fn txhashset_write(&self, h: Hash, txhashset_data: File, peer_addr: SocketAddr) -> bool {
if !self.adapter.txhashset_write(h, txhashset_data, peer_addr) {
debug!(
LOGGER,
"Received a bad txhashset data from {}, the peer will be banned", &peer_addr
"Received a bad txhashset data from {}, the peer will be banned",
&peer_addr
);
self.ban_peer(&peer_addr, ReasonForBan::BadTxHashSet);
false
@@ -592,17 +583,13 @@ impl NetAdapter for Peers {
/// addresses.
fn find_peer_addrs(&self, capab: Capabilities) -> Vec<SocketAddr> {
let peers = self.find_peers(State::Healthy, capab, MAX_PEER_ADDRS as usize);
trace!(
LOGGER,
"find_peer_addrs: {} healthy peers picked",
peers.len()
);
trace!("find_peer_addrs: {} healthy peers picked", peers.len());
map_vec!(peers, |p| p.addr)
}
/// A list of peers has been received from one of our peers.
fn peer_addrs_received(&self, peer_addrs: Vec<SocketAddr>) {
trace!(LOGGER, "Received {} peer addrs, saving.", peer_addrs.len());
trace!("Received {} peer addrs, saving.", peer_addrs.len());
for pa in peer_addrs {
if let Ok(e) = self.exists_peer(pa) {
if e {
@@ -618,7 +605,7 @@ impl NetAdapter for Peers {
ban_reason: ReasonForBan::None,
};
if let Err(e) = self.save_peer(&peer) {
error!(LOGGER, "Could not save received peer address: {:?}", e);
error!("Could not save received peer address: {:?}", e);
}
}
}
+18 -34
View File
@@ -30,7 +30,6 @@ use msg::{
TxHashSetArchive, TxHashSetRequest, Type,
};
use types::{Error, NetAdapter};
use util::LOGGER;
pub struct Protocol {
adapter: Arc<NetAdapter>,
@@ -52,10 +51,8 @@ impl MessageHandler for Protocol {
// banned peers up correctly?
if adapter.is_banned(self.addr.clone()) {
debug!(
LOGGER,
"handler: consume: peer {:?} banned, received: {:?}, dropping.",
self.addr,
msg.header.msg_type,
self.addr, msg.header.msg_type,
);
return Ok(None);
}
@@ -82,14 +79,14 @@ impl MessageHandler for Protocol {
Type::BanReason => {
let ban_reason: BanReason = msg.body()?;
error!(LOGGER, "handle_payload: BanReason {:?}", ban_reason);
error!("handle_payload: BanReason {:?}", ban_reason);
Ok(None)
}
Type::Transaction => {
debug!(
LOGGER,
"handle_payload: received tx: msg_len: {}", msg.header.msg_len
"handle_payload: received tx: msg_len: {}",
msg.header.msg_len
);
let tx: core::Transaction = msg.body()?;
adapter.transaction_received(tx, false);
@@ -98,8 +95,8 @@ impl MessageHandler for Protocol {
Type::StemTransaction => {
debug!(
LOGGER,
"handle_payload: received stem tx: msg_len: {}", msg.header.msg_len
"handle_payload: received stem tx: msg_len: {}",
msg.header.msg_len
);
let tx: core::Transaction = msg.body()?;
adapter.transaction_received(tx, true);
@@ -109,7 +106,6 @@ impl MessageHandler for Protocol {
Type::GetBlock => {
let h: Hash = msg.body()?;
trace!(
LOGGER,
"handle_payload: Getblock: {}, msg_len: {}",
h,
msg.header.msg_len,
@@ -124,8 +120,8 @@ impl MessageHandler for Protocol {
Type::Block => {
debug!(
LOGGER,
"handle_payload: received block: msg_len: {}", msg.header.msg_len
"handle_payload: received block: msg_len: {}",
msg.header.msg_len
);
let b: core::Block = msg.body()?;
@@ -145,8 +141,8 @@ impl MessageHandler for Protocol {
Type::CompactBlock => {
debug!(
LOGGER,
"handle_payload: received compact block: msg_len: {}", msg.header.msg_len
"handle_payload: received compact block: msg_len: {}",
msg.header.msg_len
);
let b: core::CompactBlock = msg.body()?;
@@ -218,8 +214,8 @@ impl MessageHandler for Protocol {
Type::TxHashSetRequest => {
let sm_req: TxHashSetRequest = msg.body()?;
debug!(
LOGGER,
"handle_payload: txhashset req for {} at {}", sm_req.hash, sm_req.height
"handle_payload: txhashset req for {} at {}",
sm_req.hash, sm_req.height
);
let txhashset = self.adapter.txhashset_read(sm_req.hash);
@@ -244,15 +240,11 @@ impl MessageHandler for Protocol {
Type::TxHashSetArchive => {
let sm_arch: TxHashSetArchive = msg.body()?;
debug!(
LOGGER,
"handle_payload: txhashset archive for {} at {}. size={}",
sm_arch.hash,
sm_arch.height,
sm_arch.bytes,
sm_arch.hash, sm_arch.height, sm_arch.bytes,
);
if !self.adapter.txhashset_receive_ready() {
error!(
LOGGER,
"handle_payload: txhashset archive received but SyncStatus not on TxHashsetDownload",
);
return Err(Error::BadMessage);
@@ -284,14 +276,13 @@ impl MessageHandler for Protocol {
if let Err(e) = save_txhashset_to_file(tmp.clone()) {
error!(
LOGGER,
"handle_payload: txhashset archive save to file fail. err={:?}", e
"handle_payload: txhashset archive save to file fail. err={:?}",
e
);
return Err(e);
}
trace!(
LOGGER,
"handle_payload: txhashset archive save to file {:?} success",
tmp,
);
@@ -302,18 +293,15 @@ impl MessageHandler for Protocol {
.txhashset_write(sm_arch.hash, tmp_zip, self.addr);
debug!(
LOGGER,
"handle_payload: txhashset archive for {} at {}, DONE. Data Ok: {}",
sm_arch.hash,
sm_arch.height,
res
sm_arch.hash, sm_arch.height, res
);
Ok(None)
}
_ => {
debug!(LOGGER, "unknown message type {:?}", msg.header.msg_type);
debug!("unknown message type {:?}", msg.header.msg_type);
Ok(None)
}
}
@@ -341,12 +329,8 @@ fn headers_header_size(conn: &mut TcpStream, msg_len: u64) -> Result<u64, Error>
let max_size = min_size + 6;
if average_header_size < min_size as u64 || average_header_size > max_size as u64 {
debug!(
LOGGER,
"headers_header_size - size of Vec: {}, average_header_size: {}, min: {}, max: {}",
total_headers,
average_header_size,
min_size,
max_size,
total_headers, average_header_size, min_size, max_size,
);
return Err(Error::Connection(io::Error::new(
io::ErrorKind::InvalidData,
+10 -27
View File
@@ -30,7 +30,6 @@ use peer::Peer;
use peers::Peers;
use store::PeerStore;
use types::{Capabilities, ChainAdapter, Error, NetAdapter, P2PConfig, TxHashSetRead};
use util::LOGGER;
/// P2P server implementation, handling bootstrapping to find and connect to
/// peers, receiving connections from other peers and keep track of all of them.
@@ -64,17 +63,14 @@ impl Server {
// Check that we have block 1
match block_1_hash {
Some(hash) => match adapter.get_block(hash) {
Some(_) => debug!(LOGGER, "Full block 1 found, archive capabilities confirmed"),
Some(_) => debug!("Full block 1 found, archive capabilities confirmed"),
None => {
debug!(
LOGGER,
"Full block 1 not found, archive capabilities disabled"
);
debug!("Full block 1 not found, archive capabilities disabled");
capab.remove(Capabilities::FULL_HIST);
}
},
None => {
debug!(LOGGER, "Block 1 not found, archive capabilities disabled");
debug!("Block 1 not found, archive capabilities disabled");
capab.remove(Capabilities::FULL_HIST);
}
}
@@ -102,12 +98,7 @@ impl Server {
Ok((stream, peer_addr)) => {
if !self.check_banned(&stream) {
if let Err(e) = self.handle_new_peer(stream) {
warn!(
LOGGER,
"Error accepting peer {}: {:?}",
peer_addr.to_string(),
e
);
warn!("Error accepting peer {}: {:?}", peer_addr.to_string(), e);
}
}
}
@@ -115,7 +106,7 @@ impl Server {
// nothing to do, will retry in next iteration
}
Err(e) => {
warn!(LOGGER, "Couldn't establish new client connection: {:?}", e);
warn!("Couldn't establish new client connection: {:?}", e);
}
}
if self.stop.load(Ordering::Relaxed) {
@@ -130,10 +121,7 @@ impl Server {
/// we're already connected to the provided address.
pub fn connect(&self, addr: &SocketAddr) -> Result<Arc<Peer>, Error> {
if Peer::is_denied(&self.config, &addr) {
debug!(
LOGGER,
"connect_peer: peer {} denied, not connecting.", addr
);
debug!("connect_peer: peer {} denied, not connecting.", addr);
return Err(Error::ConnectionClose);
}
@@ -148,12 +136,11 @@ impl Server {
if let Some(p) = self.peers.get_connected_peer(addr) {
// if we're already connected to the addr, just return the peer
trace!(LOGGER, "connect_peer: already connected {}", addr);
trace!("connect_peer: already connected {}", addr);
return Ok(p);
}
trace!(
LOGGER,
"connect_peer: on {}:{}. connecting to {}",
self.config.host,
self.config.port,
@@ -179,12 +166,8 @@ impl Server {
}
Err(e) => {
debug!(
LOGGER,
"connect_peer: on {}:{}. Could not connect to {}: {:?}",
self.config.host,
self.config.port,
addr,
e
self.config.host, self.config.port, addr, e
);
Err(Error::Connection(e))
}
@@ -211,9 +194,9 @@ impl Server {
// peer has been banned, go away!
if let Ok(peer_addr) = stream.peer_addr() {
if self.peers.is_banned(peer_addr) {
debug!(LOGGER, "Peer {} banned, refusing connection.", peer_addr);
debug!("Peer {} banned, refusing connection.", peer_addr);
if let Err(e) = stream.shutdown(Shutdown::Both) {
debug!(LOGGER, "Error shutting down conn: {:?}", e);
debug!("Error shutting down conn: {:?}", e);
}
return true;
}
+1 -2
View File
@@ -26,7 +26,6 @@ use core::ser::{self, Readable, Reader, Writeable, Writer};
use grin_store::{self, option_to_not_found, to_key, Error};
use msg::SockAddr;
use types::{Capabilities, ReasonForBan};
use util::LOGGER;
const STORE_SUBPATH: &'static str = "peers";
@@ -111,7 +110,7 @@ impl PeerStore {
}
pub fn save_peer(&self, p: &PeerData) -> Result<(), Error> {
debug!(LOGGER, "save_peer: {:?} marked {:?}", p.addr, p.flags);
debug!("save_peer: {:?} marked {:?}", p.addr, p.flags);
let batch = self.db.batch()?;
batch.put_ser(&peer_key(p.addr)[..], p)?;