mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 13:37:24 +00:00
Don't log stack traces for expected network problems. Clean up the logging a bit. Resolves issue 69.
This commit is contained in:
@@ -26,7 +26,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.ConnectException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -236,15 +238,24 @@ public class PeerGroup {
|
|||||||
Runnable command = new Runnable() {
|
Runnable command = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
log.info("connecting to " + peer);
|
log.info("Connecting to " + peer);
|
||||||
peer.connect();
|
peer.connect();
|
||||||
peers.add(peer);
|
peers.add(peer);
|
||||||
handleNewPeer(peer);
|
handleNewPeer(peer);
|
||||||
log.info("running " + peer);
|
|
||||||
peer.run();
|
peer.run();
|
||||||
} catch (PeerException ex) {
|
} catch (PeerException ex) {
|
||||||
// do not propagate PeerException - log and try next peer
|
// Do not propagate PeerException - log and try next peer. Suppress stack traces for
|
||||||
log.error("error while talking to peer", ex);
|
// exceptions we expect as part of normal network behaviour.
|
||||||
|
final Throwable cause = ex.getCause();
|
||||||
|
if (cause instanceof SocketTimeoutException) {
|
||||||
|
log.info("Timeout talking to " + peer + ": " + cause.getMessage());
|
||||||
|
} else if (cause instanceof ConnectException) {
|
||||||
|
log.info("Could not connect to " + peer + ": " + cause.getMessage());
|
||||||
|
} else if (cause instanceof IOException) {
|
||||||
|
log.info("Error talking to " + peer + ": " + cause.getMessage());
|
||||||
|
} else {
|
||||||
|
log.error("Unexpected exception whilst talking to " + peer, ex);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// In all cases, disconnect and put the address back on the queue.
|
// In all cases, disconnect and put the address back on the queue.
|
||||||
// We will retry this peer after all other peers have been tried.
|
// We will retry this peer after all other peers have been tried.
|
||||||
|
|||||||
Reference in New Issue
Block a user