diff --git a/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java b/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java index e3dc251..91bbc61 100644 --- a/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java +++ b/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java @@ -50,9 +50,9 @@ import static ch.dissem.bitmessage.networking.Connection.State.*; * A connection to a specific node */ public class Connection implements Runnable { + public static final int READ_TIMEOUT = 2000; private final static Logger LOG = LoggerFactory.getLogger(Connection.class); - private static final int CONNECT_TIMEOUT = 10000; - + private static final int CONNECT_TIMEOUT = 5000; private InternalContext ctx; private Mode mode; @@ -106,8 +106,10 @@ public class Connection implements Runnable { public void run() { try (Socket socket = this.socket) { if (!socket.isConnected()) { + LOG.debug("Trying to connect to node " + node); socket.connect(new InetSocketAddress(node.toInetAddress(), node.getPort()), CONNECT_TIMEOUT); } + socket.setSoTimeout(READ_TIMEOUT); this.in = socket.getInputStream(); this.out = socket.getOutputStream(); if (mode == CLIENT) { @@ -171,8 +173,8 @@ public class Connection implements Runnable { } } } catch (IOException | NodeException e) { - LOG.debug("disconnection from node " + node + ": " + e.getMessage(), e); disconnect(); + LOG.debug("Disconnected from node " + node + ": " + e.getMessage()); } catch (RuntimeException e) { disconnect(); throw e; @@ -180,6 +182,7 @@ public class Connection implements Runnable { } private void activateConnection() { + LOG.info("Successfully established connection with node " + node); state = ACTIVE; sendAddresses(); sendInventory(); @@ -188,7 +191,9 @@ public class Connection implements Runnable { } private void sendQueue() { - LOG.debug("Sending " + sendingQueue.size() + " messages to node " + node); + if (sendingQueue.size() > 0) { + LOG.debug("Sending " + sendingQueue.size() + " messages to node " + node); + } for (MessagePayload msg = sendingQueue.poll(); msg != null; msg = sendingQueue.poll()) { send(msg); } diff --git a/networking/src/main/java/ch/dissem/bitmessage/networking/NetworkNode.java b/networking/src/main/java/ch/dissem/bitmessage/networking/NetworkNode.java index e8e32ab..47c01f6 100644 --- a/networking/src/main/java/ch/dissem/bitmessage/networking/NetworkNode.java +++ b/networking/src/main/java/ch/dissem/bitmessage/networking/NetworkNode.java @@ -131,7 +131,7 @@ public class NetworkNode implements NetworkHandler, ContextHolder { c.disconnect(); } } - pool.shutdownNow(); + pool.shutdown(); } private void startConnection(Connection c) { diff --git a/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcConfig.java b/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcConfig.java index c991bb7..80e079b 100644 --- a/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcConfig.java +++ b/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcConfig.java @@ -45,11 +45,7 @@ public class JdbcConfig { this("jdbc:h2:~/jabit;AUTO_SERVER=TRUE", "sa", null); } - public Connection getConnection() { - try { - return DriverManager.getConnection(dbUrl, dbUser, dbPassword); - } catch (SQLException e) { - throw new RuntimeException(e); - } + public Connection getConnection() throws SQLException { + return DriverManager.getConnection(dbUrl, dbUser, dbPassword); } }