From 2ae1e561d810fb2141ac77a9d8a54ed19190f549 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 4 May 2017 07:24:26 +0200 Subject: [PATCH] Minor improvements for logging and debugging --- .../java/ch/dissem/bitmessage/utils/TTL.java | 2 +- .../networking/nio/NioNetworkHandler.java | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java b/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java index d1feb8a..c4fab9c 100644 --- a/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java +++ b/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java @@ -38,7 +38,7 @@ public class TTL { } private static long validate(long ttl) { - if (ttl < 0 || ttl > 28 * DAY) throw new IllegalArgumentException("TTL must be between 1 and 28 days"); + if (ttl < 0 || ttl > 28 * DAY) throw new IllegalArgumentException("TTL must be between 0 seconds and 28 days"); return ttl; } } diff --git a/networking/src/main/java/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.java b/networking/src/main/java/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.java index b79174b..04e6d4d 100644 --- a/networking/src/main/java/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.java +++ b/networking/src/main/java/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.java @@ -254,7 +254,7 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex } } } catch (CancelledKeyException e) { - LOG.error(e.getMessage(), e); + LOG.debug(e.getMessage(), e); } } else { // handle read/write @@ -287,11 +287,15 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex } // set interest ops for (Map.Entry e : connections.entrySet()) { - if (e.getValue().isValid() - && (e.getValue().interestOps() & OP_WRITE) == 0 - && (e.getValue().interestOps() & OP_CONNECT) == 0 - && !e.getKey().getSendingQueue().isEmpty()) { - e.getValue().interestOps(OP_READ | OP_WRITE); + try { + if (e.getValue().isValid() + && (e.getValue().interestOps() & OP_WRITE) == 0 + && (e.getValue().interestOps() & OP_CONNECT) == 0 + && !e.getKey().getSendingQueue().isEmpty()) { + e.getValue().interestOps(OP_READ | OP_WRITE); + } + } catch (CancelledKeyException x) { + e.getKey().disconnect(); } } // start new connections