diff --git a/.travis.yml b/_deactivated_.travis.yml similarity index 100% rename from .travis.yml rename to _deactivated_.travis.yml diff --git a/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java b/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java index da5477b7e9..f383b00bb1 100644 --- a/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java +++ b/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java @@ -168,9 +168,9 @@ public class OpenOfferManager { executor.allowCoreThreadTimeOut(true); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); - checkArgument(Offer.TTL > 60000, "Offer.TTL <= 60"); + checkArgument(Offer.TTL > 120000, "Offer.TTL <= 120"); long period = Offer.TTL - 120000; // 2 min before TTL expires - executor.scheduleAtFixedRate(this::rePublishOffers, 0, period, TimeUnit.SECONDS); + executor.scheduleAtFixedRate(this::rePublishOffers, 500, period, TimeUnit.MILLISECONDS); } private void rePublishOffers() { diff --git a/network/src/main/java/io/bitsquare/p2p/network/Connection.java b/network/src/main/java/io/bitsquare/p2p/network/Connection.java index 75fdfb97d0..3f7ee5e6df 100644 --- a/network/src/main/java/io/bitsquare/p2p/network/Connection.java +++ b/network/src/main/java/io/bitsquare/p2p/network/Connection.java @@ -348,9 +348,6 @@ public class Connection { reportIllegalRequest(IllegalRequest.MaxSizeExceeded); } } catch (IOException | ClassNotFoundException e) { - log.error("Exception at Connection.InputHandler. Connection=" + Connection.this.toString()); - log.error("Exception=" + e.getMessage()); - e.printStackTrace(); inputHandlerStopped = true; handleConnectionException(e); } diff --git a/network/src/main/java/io/bitsquare/p2p/routing/Routing.java b/network/src/main/java/io/bitsquare/p2p/routing/Routing.java index c34b0e0dd4..40fd0a198a 100644 --- a/network/src/main/java/io/bitsquare/p2p/routing/Routing.java +++ b/network/src/main/java/io/bitsquare/p2p/routing/Routing.java @@ -179,6 +179,7 @@ public class Routing { public void broadcast(BroadcastMessage message, @Nullable Address sender) { log.trace("Broadcast message to " + connectedNeighbors.values().size() + " neighbors."); log.trace("message = " + message); + log.trace("connectedNeighbors = " + connectedNeighbors); connectedNeighbors.values().parallelStream() .filter(e -> !e.address.equals(sender)) .forEach(neighbor -> { @@ -369,9 +370,9 @@ public class Routing { public void onSuccess(Connection connection) { log.trace("GetNeighborsMessage sent successfully from " + getAddress() + " to " + peerAddress); - // we wait to get the success to reduce the time span of the moment of + /* // we wait to get the success to reduce the time span of the moment of // authentication at both sides of the connection - setAuthenticated(connection, peerAddress); + setAuthenticated(connection, peerAddress);*/ } @Override @@ -392,7 +393,7 @@ public class Routing { setAuthenticated(connection, peerAddress); purgeReportedNeighbors(); SettableFuture future = networkNode.sendMessage(peerAddress, - new NeighborsMessage(getAllNeighborAddresses())); + new NeighborsMessage(getAddress(), getAllNeighborAddresses())); log.trace("sent NeighborsMessage to " + peerAddress + " from " + getAddress() + " with allNeighbors=" + getAllNeighborAddresses()); Futures.addCallback(future, new FutureCallback() { @@ -417,7 +418,8 @@ public class Routing { } } else if (message instanceof NeighborsMessage) { log.trace("NeighborsMessage from " + connection.getPeerAddress() + " at " + getAddress()); - ArrayList
neighborAddresses = ((NeighborsMessage) message).neighborAddresses; + NeighborsMessage neighborsMessage = (NeighborsMessage) message; + ArrayList
neighborAddresses = neighborsMessage.neighborAddresses; log.trace("Received neighbors: " + neighborAddresses); // remove ourselves neighborAddresses.remove(getAddress()); @@ -427,6 +429,10 @@ public class Routing { + " authenticated (" + connection.getObjectId() + "). Took " + (System.currentTimeMillis() - startAuthTs) + " ms. \n\n"); + // we wait until the handshake is completed before setting the authenticate flag + // authentication at both sides of the connection + setAuthenticated(connection, neighborsMessage.address); + Runnable authenticationCompleteHandler = authenticationCompleteHandlers.remove(connection.getPeerAddress()); if (authenticationCompleteHandler != null) authenticationCompleteHandler.run(); @@ -461,22 +467,33 @@ public class Routing { private List
getNotConnectedNeighborAddresses() { ArrayList
reportedNeighborsList = new ArrayList<>(getAllNeighborAddresses()); + log.debug("## getNotConnectedNeighborAddresses "); + log.debug("## reportedNeighborsList=" + reportedNeighborsList); connectedNeighbors.values().stream().forEach(e -> reportedNeighborsList.remove(e.address)); + log.debug("## connectedNeighbors=" + connectedNeighbors); + log.debug("## reportedNeighborsList=" + reportedNeighborsList); return reportedNeighborsList; } private void authenticateToNextRandomNeighbor() { - if (getConnectedNeighbors().size() <= MAX_CONNECTIONS) { - Address randomNotConnectedNeighborAddress = getRandomNotConnectedNeighborAddress(); - if (randomNotConnectedNeighborAddress != null) { - log.info("We try to build an authenticated connection to a random neighbor. " + randomNotConnectedNeighborAddress); - authenticateToPeer(randomNotConnectedNeighborAddress, null, () -> authenticateToNextRandomNeighbor()); - } else { - log.info("No more neighbors available for connecting."); + executorService.submit(() -> { + try { + Thread.sleep(new Random().nextInt(200) + 200); + } catch (InterruptedException ignored) { + Thread.currentThread().interrupt(); } - } else { - log.info("We have already enough connections."); - } + if (getConnectedNeighbors().size() <= MAX_CONNECTIONS) { + Address randomNotConnectedNeighborAddress = getRandomNotConnectedNeighborAddress(); + if (randomNotConnectedNeighborAddress != null) { + log.info("We try to build an authenticated connection to a random neighbor. " + randomNotConnectedNeighborAddress); + authenticateToPeer(randomNotConnectedNeighborAddress, null, () -> authenticateToNextRandomNeighbor()); + } else { + log.info("No more neighbors available for connecting."); + } + } else { + log.info("We have already enough connections."); + } + }); } public void authenticateToPeer(Address address, @Nullable Runnable authenticationCompleteHandler, @Nullable Runnable faultHandler) { diff --git a/network/src/main/java/io/bitsquare/p2p/routing/messages/NeighborsMessage.java b/network/src/main/java/io/bitsquare/p2p/routing/messages/NeighborsMessage.java index 19d563e17d..b82565794a 100644 --- a/network/src/main/java/io/bitsquare/p2p/routing/messages/NeighborsMessage.java +++ b/network/src/main/java/io/bitsquare/p2p/routing/messages/NeighborsMessage.java @@ -9,9 +9,11 @@ public final class NeighborsMessage implements AuthenticationMessage { // That object is sent over the wire, so we need to take care of version compatibility. private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION; + public final Address address; public final ArrayList
neighborAddresses; - public NeighborsMessage(ArrayList
neighborAddresses) { + public NeighborsMessage(Address address, ArrayList
neighborAddresses) { + this.address = address; this.neighborAddresses = neighborAddresses; }