diff --git a/common/src/main/java/io/bitsquare/app/Log.java b/common/src/main/java/io/bitsquare/app/Log.java index f437f9f706..66485f286d 100644 --- a/common/src/main/java/io/bitsquare/app/Log.java +++ b/common/src/main/java/io/bitsquare/app/Log.java @@ -48,7 +48,7 @@ public class Log { rollingPolicy.start(); triggeringPolicy = new SizeBasedTriggeringPolicy(); - triggeringPolicy.setMaxFileSize("1MB"); + triggeringPolicy.setMaxFileSize("10MB"); triggeringPolicy.start(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); @@ -63,7 +63,7 @@ public class Log { logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); //TODO for now use always trace - logbackLogger.setLevel(useDetailedLogging ? Level.INFO : Level.INFO); + logbackLogger.setLevel(useDetailedLogging ? Level.TRACE : Level.INFO); // logbackLogger.setLevel(useDetailedLogging ? Level.TRACE : Level.DEBUG); logbackLogger.addAppender(appender); } diff --git a/common/src/main/java/io/bitsquare/common/FrameRateTimer.java b/common/src/main/java/io/bitsquare/common/FrameRateTimer.java index 6a1ecbb9cb..6de4425a17 100644 --- a/common/src/main/java/io/bitsquare/common/FrameRateTimer.java +++ b/common/src/main/java/io/bitsquare/common/FrameRateTimer.java @@ -4,6 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.time.Duration; +import java.util.UUID; /** * We simulate a global frame rate timer similar to FXTimer to avoid creation of threads for each timer call. @@ -16,26 +17,30 @@ public class FrameRateTimer implements Timer, Runnable { private Runnable runnable; private long startTs; private boolean isPeriodically; + private String uid = UUID.randomUUID().toString(); + private volatile boolean stopped; public FrameRateTimer() { } @Override public void run() { - try { - long currentTimeMillis = System.currentTimeMillis(); - if ((currentTimeMillis - startTs) >= interval) { - runnable.run(); - if (isPeriodically) - startTs = currentTimeMillis; - else - stop(); + if (!stopped) { + try { + long currentTimeMillis = System.currentTimeMillis(); + if ((currentTimeMillis - startTs) >= interval) { + runnable.run(); + if (isPeriodically) + startTs = currentTimeMillis; + else + stop(); + } + } catch (Throwable t) { + log.error(t.getMessage()); + t.printStackTrace(); + stop(); + throw t; } - } catch (Throwable t) { - log.error(t.getMessage()); - t.printStackTrace(); - stop(); - throw t; } } @@ -60,6 +65,24 @@ public class FrameRateTimer implements Timer, Runnable { @Override public void stop() { + stopped = true; MasterTimer.removeListener(this); } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FrameRateTimer)) return false; + + FrameRateTimer that = (FrameRateTimer) o; + + return !(uid != null ? !uid.equals(that.uid) : that.uid != null); + + } + + @Override + public int hashCode() { + return uid != null ? uid.hashCode() : 0; + } } diff --git a/common/src/main/java/io/bitsquare/common/MasterTimer.java b/common/src/main/java/io/bitsquare/common/MasterTimer.java index 17a67e959c..a39fc50099 100644 --- a/common/src/main/java/io/bitsquare/common/MasterTimer.java +++ b/common/src/main/java/io/bitsquare/common/MasterTimer.java @@ -10,15 +10,16 @@ import java.util.concurrent.CopyOnWriteArraySet; public class MasterTimer { private final static Logger log = LoggerFactory.getLogger(MasterTimer.class); private static final java.util.Timer timer = new java.util.Timer(); - public static long FRAME_INTERVAL_MS = 16; + // frame rate of 60 fps is about 16 ms but we don't need such a short interval, 100 ms should be good enough + public static final long FRAME_INTERVAL_MS = 100; static { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { - listeners.stream().forEach(UserThread::execute); + UserThread.execute(() -> listeners.stream().forEach(Runnable::run)); } - }, FRAME_INTERVAL_MS, FRAME_INTERVAL_MS); // frame rate of 60 fps is about 16 ms + }, FRAME_INTERVAL_MS, FRAME_INTERVAL_MS); } private static Set listeners = new CopyOnWriteArraySet<>(); @@ -30,6 +31,4 @@ public class MasterTimer { public static void removeListener(Runnable runnable) { listeners.remove(runnable); } - - } diff --git a/gui/src/main/java/io/bitsquare/gui/main/settings/network/P2pNetworkListItem.java b/gui/src/main/java/io/bitsquare/gui/main/settings/network/P2pNetworkListItem.java index 45d4736e3c..47372515c5 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/settings/network/P2pNetworkListItem.java +++ b/gui/src/main/java/io/bitsquare/gui/main/settings/network/P2pNetworkListItem.java @@ -35,7 +35,7 @@ public class P2pNetworkListItem { private final Statistic statistic; private final Connection connection; - private final Subscription sentBytesSubscription, receivedBytesSubscription, onionAddressSubscription; + private final Subscription sentBytesSubscription, receivedBytesSubscription, onionAddressSubscription, roundTripTimeSubscription; private final Clock clock; private final BSFormatter formatter; @@ -44,6 +44,9 @@ public class P2pNetworkListItem { private final StringProperty receivedBytes = new SimpleStringProperty(); private final StringProperty peerType = new SimpleStringProperty(); private final StringProperty connectionType = new SimpleStringProperty(); + + + private final StringProperty roundTripTime = new SimpleStringProperty(); private final StringProperty onionAddress = new SimpleStringProperty(); private final Clock.Listener listener; @@ -59,6 +62,8 @@ public class P2pNetworkListItem { e -> receivedBytes.set(formatter.formatBytes((int) e))); onionAddressSubscription = EasyBind.subscribe(connection.peersNodeAddressProperty(), nodeAddress -> onionAddress.set(nodeAddress != null ? nodeAddress.getFullAddress() : "Not known yet")); + roundTripTimeSubscription = EasyBind.subscribe(statistic.roundTripTimeProperty(), + roundTripTime -> this.roundTripTime.set(DurationFormatUtils.formatDuration((long) roundTripTime, "ss.SSS"))); listener = new Clock.Listener() { @Override @@ -90,6 +95,7 @@ public class P2pNetworkListItem { sentBytesSubscription.unsubscribe(); receivedBytesSubscription.unsubscribe(); onionAddressSubscription.unsubscribe(); + roundTripTimeSubscription.unsubscribe(); clock.removeListener(listener); } @@ -158,4 +164,11 @@ public class P2pNetworkListItem { return receivedBytes; } + public String getRoundTripTime() { + return roundTripTime.get(); + } + + public StringProperty roundTripTimeProperty() { + return roundTripTime; + } } diff --git a/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java b/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java index 372fb9d771..822dd5e724 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java @@ -17,6 +17,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.*; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -67,7 +68,7 @@ public class BroadcastHandler implements PeerManager.Listener { private Listener listener; private int numOfPeers; private Timer timeoutTimer; - private Set broadcastQueue = new HashSet<>(); + private Set broadcastQueue = new CopyOnWriteArraySet<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -99,30 +100,32 @@ public class BroadcastHandler implements PeerManager.Listener { Log.traceCall("Sender=" + sender + "\n\t" + "Message=" + StringUtils.abbreviate(message.toString(), 100)); - Set receivers = networkNode.getConfirmedConnections() + Set connectedPeers = networkNode.getConfirmedConnections() .stream() .filter(connection -> !connection.getPeersNodeAddressOptional().get().equals(sender)) .collect(Collectors.toSet()); - if (!receivers.isEmpty()) { + if (!connectedPeers.isEmpty()) { numOfCompletedBroadcasts = 0; if (isDataOwner) { // the data owner sends to all and immediately - receivers.stream().forEach(connection -> sendToPeer(connection, message)); - numOfPeers = receivers.size(); + connectedPeers.stream().forEach(connection -> sendToPeer(connection, message)); + numOfPeers = connectedPeers.size(); log.info("Broadcast message to {} peers.", numOfPeers); } else { // for relay nodes we limit to 2 recipients and use a delay - List list = new ArrayList<>(receivers); + List list = new ArrayList<>(connectedPeers); Collections.shuffle(list); - list = list.subList(0, Math.min(2, list.size())); + int size = list.size(); + if (size > 1) + list = list.subList(0, size / 2); numOfPeers = list.size(); log.info("Broadcast message to {} peers.", numOfPeers); list.stream().forEach(connection -> UserThread.runAfterRandomDelay(() -> sendToPeer(connection, message), DELAY_MS, DELAY_MS * 2, TimeUnit.MILLISECONDS)); } - long timeoutDelay = TIMEOUT_PER_PEER_SEC * receivers.size(); + long timeoutDelay = TIMEOUT_PER_PEER_SEC * numOfPeers; timeoutTimer = UserThread.runAfter(() -> { String errorMessage = "Timeout: Broadcast did not complete after " + timeoutDelay + " sec."; @@ -145,50 +148,54 @@ public class BroadcastHandler implements PeerManager.Listener { String errorMessage = "Message not broadcasted because we have stopped the handler already.\n\t" + "message = " + StringUtils.abbreviate(message.toString(), 100); if (!stopped) { - NodeAddress nodeAddress = connection.getPeersNodeAddressOptional().get(); - log.trace("Broadcast message to " + nodeAddress + "."); - broadcastQueue.add(nodeAddress.getFullAddress()); - SettableFuture future = networkNode.sendMessage(connection, message); - Futures.addCallback(future, new FutureCallback() { - @Override - public void onSuccess(Connection connection) { - numOfCompletedBroadcasts++; - broadcastQueue.remove(nodeAddress.getFullAddress()); - if (!stopped) { - log.trace("Broadcast to " + nodeAddress + " succeeded."); + if (!connection.isStopped()) { + NodeAddress nodeAddress = connection.getPeersNodeAddressOptional().get(); + log.trace("Broadcast message to " + nodeAddress + "."); + broadcastQueue.add(nodeAddress.getFullAddress()); + SettableFuture future = networkNode.sendMessage(connection, message); + Futures.addCallback(future, new FutureCallback() { + @Override + public void onSuccess(Connection connection) { + numOfCompletedBroadcasts++; + broadcastQueue.remove(nodeAddress.getFullAddress()); + if (!stopped) { + log.trace("Broadcast to " + nodeAddress + " succeeded."); - if (listener != null) - listener.onBroadcasted(message, numOfCompletedBroadcasts); - - if (listener != null && numOfCompletedBroadcasts == 1) - listener.onBroadcastedToFirstPeer(message); - - if (numOfCompletedBroadcasts + numOfFailedBroadcasts == numOfPeers) { if (listener != null) - listener.onBroadcastCompleted(message, numOfCompletedBroadcasts, numOfFailedBroadcasts); + listener.onBroadcasted(message, numOfCompletedBroadcasts); - cleanup(); - resultHandler.onCompleted(BroadcastHandler.this); + if (listener != null && numOfCompletedBroadcasts == 1) + listener.onBroadcastedToFirstPeer(message); + + if (numOfCompletedBroadcasts + numOfFailedBroadcasts == numOfPeers) { + if (listener != null) + listener.onBroadcastCompleted(message, numOfCompletedBroadcasts, numOfFailedBroadcasts); + + cleanup(); + resultHandler.onCompleted(BroadcastHandler.this); + } + } else { + onFault("stopped at onSuccess: " + errorMessage); } - } else { - onFault("stopped at onSuccess: " + errorMessage); } - } - @Override - public void onFailure(@NotNull Throwable throwable) { - numOfFailedBroadcasts++; - broadcastQueue.remove(nodeAddress.getFullAddress()); - if (!stopped) { - log.info("Broadcast to " + nodeAddress + " failed.\n\t" + - "ErrorMessage=" + throwable.getMessage()); - if (numOfCompletedBroadcasts + numOfFailedBroadcasts == numOfPeers) + @Override + public void onFailure(@NotNull Throwable throwable) { + numOfFailedBroadcasts++; + broadcastQueue.remove(nodeAddress.getFullAddress()); + if (!stopped) { + log.info("Broadcast to " + nodeAddress + " failed.\n\t" + + "ErrorMessage=" + throwable.getMessage()); + if (numOfCompletedBroadcasts + numOfFailedBroadcasts == numOfPeers) + onFault("stopped at onFailure: " + errorMessage); + } else { onFault("stopped at onFailure: " + errorMessage); - } else { - onFault("stopped at onFailure: " + errorMessage); + } } - } - }); + }); + } else { + onFault("Connection stopped already"); + } } else { onFault("stopped at sendToPeer: " + errorMessage); } @@ -231,6 +238,8 @@ public class BroadcastHandler implements PeerManager.Listener { } private void onFault(String errorMessage, boolean logWarning) { + cleanup(); + if (logWarning) log.warn(errorMessage); else @@ -242,7 +251,6 @@ public class BroadcastHandler implements PeerManager.Listener { if (listener != null && (numOfCompletedBroadcasts + numOfFailedBroadcasts == numOfPeers || stopped)) listener.onBroadcastCompleted(message, numOfCompletedBroadcasts, numOfFailedBroadcasts); - cleanup(); resultHandler.onFault(this); } diff --git a/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java b/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java index 7a93e98ef4..8f26991c25 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java @@ -6,7 +6,7 @@ import io.bitsquare.common.Timer; import io.bitsquare.common.UserThread; import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.network.*; -import io.bitsquare.p2p.peers.peerexchange.ReportedPeer; +import io.bitsquare.p2p.peers.peerexchange.Peer; import io.bitsquare.storage.Storage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,10 +76,10 @@ public class PeerManager implements ConnectionListener { private final NetworkNode networkNode; private Clock clock; private final Set seedNodeAddresses; - private final Storage> dbStorage; + private final Storage> dbStorage; - private final HashSet persistedPeers = new HashSet<>(); - private final Set reportedPeers = new HashSet<>(); + private final HashSet persistedPeers = new HashSet<>(); + private final Set reportedPeers = new HashSet<>(); private Timer checkMaxConnectionsTimer; private final Clock.Listener listener; private final List listeners = new CopyOnWriteArrayList<>(); @@ -96,7 +96,7 @@ public class PeerManager implements ConnectionListener { this.seedNodeAddresses = new HashSet<>(seedNodeAddresses); networkNode.addConnectionListener(this); dbStorage = new Storage<>(storageDir); - HashSet persistedPeers = dbStorage.initAndGetPersisted("PersistedPeers"); + HashSet persistedPeers = dbStorage.initAndGetPersisted("PersistedPeers"); if (persistedPeers != null) { log.info("We have persisted reported peers. persistedPeers.size()=" + persistedPeers.size()); this.persistedPeers.addAll(persistedPeers); @@ -310,18 +310,18 @@ public class PeerManager implements ConnectionListener { // Reported peers /////////////////////////////////////////////////////////////////////////////////////////// - private boolean removeReportedPeer(ReportedPeer reportedPeer) { + private boolean removeReportedPeer(Peer reportedPeer) { boolean contained = reportedPeers.remove(reportedPeer); printReportedPeers(); return contained; } @Nullable - private ReportedPeer removeReportedPeer(NodeAddress nodeAddress) { - Optional reportedPeerOptional = reportedPeers.stream() + private Peer removeReportedPeer(NodeAddress nodeAddress) { + Optional reportedPeerOptional = reportedPeers.stream() .filter(e -> e.nodeAddress.equals(nodeAddress)).findAny(); if (reportedPeerOptional.isPresent()) { - ReportedPeer reportedPeer = reportedPeerOptional.get(); + Peer reportedPeer = reportedPeerOptional.get(); removeReportedPeer(reportedPeer); return reportedPeer; } else { @@ -331,17 +331,17 @@ public class PeerManager implements ConnectionListener { private void removeTooOldReportedPeers() { Log.traceCall(); - Set reportedPeersToRemove = reportedPeers.stream() + Set reportedPeersToRemove = reportedPeers.stream() .filter(reportedPeer -> new Date().getTime() - reportedPeer.date.getTime() > MAX_AGE) .collect(Collectors.toSet()); reportedPeersToRemove.forEach(this::removeReportedPeer); } - public Set getReportedPeers() { + public Set getReportedPeers() { return reportedPeers; } - public void addToReportedPeers(HashSet reportedPeersToAdd, Connection connection) { + public void addToReportedPeers(HashSet reportedPeersToAdd, Connection connection) { printNewReportedPeers(reportedPeersToAdd); // We check if the reported msg is not violating our rules @@ -371,10 +371,10 @@ public class PeerManager implements ConnectionListener { log.trace("We have already {} reported peers which exceeds our limit of {}." + "We remove random peers from the reported peers list.", size, limit); int diff = size - limit; - List list = new ArrayList<>(reportedPeers); + List list = new ArrayList<>(reportedPeers); // we dont use sorting by lastActivityDate to keep it more random for (int i = 0; i < diff; i++) { - ReportedPeer toRemove = list.remove(new Random().nextInt(list.size())); + Peer toRemove = list.remove(new Random().nextInt(list.size())); removeReportedPeer(toRemove); } } else { @@ -395,7 +395,7 @@ public class PeerManager implements ConnectionListener { } } - private void printNewReportedPeers(HashSet reportedPeers) { + private void printNewReportedPeers(HashSet reportedPeers) { if (printReportedPeersDetails) { StringBuilder result = new StringBuilder("We received new reportedPeers:"); reportedPeers.stream().forEach(e -> result.append("\n\t").append(e)); @@ -409,7 +409,7 @@ public class PeerManager implements ConnectionListener { // Persisted peers /////////////////////////////////////////////////////////////////////////////////////////// - private boolean removePersistedPeer(ReportedPeer persistedPeer) { + private boolean removePersistedPeer(Peer persistedPeer) { if (persistedPeers.contains(persistedPeer)) { persistedPeers.remove(persistedPeer); @@ -423,18 +423,18 @@ public class PeerManager implements ConnectionListener { } private boolean removePersistedPeer(NodeAddress nodeAddress) { - Optional persistedPeerOptional = getPersistedPeerOptional(nodeAddress); + Optional persistedPeerOptional = getPersistedPeerOptional(nodeAddress); return persistedPeerOptional.isPresent() && removePersistedPeer(persistedPeerOptional.get()); } - private Optional getPersistedPeerOptional(NodeAddress nodeAddress) { + private Optional getPersistedPeerOptional(NodeAddress nodeAddress) { return persistedPeers.stream() .filter(e -> e.nodeAddress.equals(nodeAddress)).findAny(); } private void removeTooOldPersistedPeers() { Log.traceCall(); - Set persistedPeersToRemove = persistedPeers.stream() + Set persistedPeersToRemove = persistedPeers.stream() .filter(reportedPeer -> new Date().getTime() - reportedPeer.date.getTime() > MAX_AGE) .collect(Collectors.toSet()); persistedPeersToRemove.forEach(this::removePersistedPeer); @@ -448,10 +448,10 @@ public class PeerManager implements ConnectionListener { log.trace("We have already {} persisted peers which exceeds our limit of {}." + "We remove random peers from the persisted peers list.", size, limit); int diff = size - limit; - List list = new ArrayList<>(persistedPeers); + List list = new ArrayList<>(persistedPeers); // we dont use sorting by lastActivityDate to avoid attack vectors and keep it more random for (int i = 0; i < diff; i++) { - ReportedPeer toRemove = list.remove(new Random().nextInt(list.size())); + Peer toRemove = list.remove(new Random().nextInt(list.size())); removePersistedPeer(toRemove); } } else { @@ -459,7 +459,7 @@ public class PeerManager implements ConnectionListener { } } - public Set getPersistedPeers() { + public Set getPersistedPeers() { return persistedPeers; } @@ -472,7 +472,7 @@ public class PeerManager implements ConnectionListener { return networkNode.getNodeAddressesOfConfirmedConnections().size() >= MIN_CONNECTIONS; } - public boolean isSeedNode(ReportedPeer reportedPeer) { + public boolean isSeedNode(Peer reportedPeer) { return seedNodeAddresses.contains(reportedPeer.nodeAddress); } @@ -484,7 +484,7 @@ public class PeerManager implements ConnectionListener { return connection.hasPeersNodeAddress() && seedNodeAddresses.contains(connection.getPeersNodeAddressOptional().get()); } - public boolean isSelf(ReportedPeer reportedPeer) { + public boolean isSelf(Peer reportedPeer) { return isSelf(reportedPeer.nodeAddress); } @@ -492,7 +492,7 @@ public class PeerManager implements ConnectionListener { return nodeAddress.equals(networkNode.getNodeAddress()); } - public boolean isConfirmed(ReportedPeer reportedPeer) { + public boolean isConfirmed(Peer reportedPeer) { return isConfirmed(reportedPeer.nodeAddress); } @@ -512,10 +512,10 @@ public class PeerManager implements ConnectionListener { public void handleConnectionFault(NodeAddress nodeAddress, @Nullable Connection connection) { Log.traceCall("nodeAddress=" + nodeAddress); boolean doRemovePersistedPeer = false; - ReportedPeer reportedPeer = removeReportedPeer(nodeAddress); - Optional persistedPeerOptional = getPersistedPeerOptional(nodeAddress); + Peer reportedPeer = removeReportedPeer(nodeAddress); + Optional persistedPeerOptional = getPersistedPeerOptional(nodeAddress); if (persistedPeerOptional.isPresent()) { - ReportedPeer persistedPeer = persistedPeerOptional.get(); + Peer persistedPeer = persistedPeerOptional.get(); persistedPeer.increaseFailedConnectionAttempts(); doRemovePersistedPeer = persistedPeer.tooManyFailedConnectionAttempts(); } @@ -541,7 +541,7 @@ public class PeerManager implements ConnectionListener { .ifPresent(connection -> connection.shutDown(closeConnectionReason)); } - public HashSet getConnectedNonSeedNodeReportedPeers(NodeAddress excludedNodeAddress) { + public HashSet getConnectedNonSeedNodeReportedPeers(NodeAddress excludedNodeAddress) { return new HashSet<>(getConnectedNonSeedNodeReportedPeers().stream() .filter(e -> !e.nodeAddress.equals(excludedNodeAddress)) .collect(Collectors.toSet())); @@ -551,15 +551,15 @@ public class PeerManager implements ConnectionListener { // Private /////////////////////////////////////////////////////////////////////////////////////////// - private Set getConnectedReportedPeers() { + private Set getConnectedReportedPeers() { // networkNode.getConfirmedConnections includes: // filter(connection -> connection.getPeersNodeAddressOptional().isPresent()) return networkNode.getConfirmedConnections().stream() - .map(c -> new ReportedPeer(c.getPeersNodeAddressOptional().get())) + .map(c -> new Peer(c.getPeersNodeAddressOptional().get())) .collect(Collectors.toSet()); } - private HashSet getConnectedNonSeedNodeReportedPeers() { + private HashSet getConnectedNonSeedNodeReportedPeers() { return new HashSet<>(getConnectedReportedPeers().stream() .filter(e -> !isSeedNode(e)) .collect(Collectors.toSet())); diff --git a/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java b/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java index a6b03b5d83..29bf92f5b7 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java @@ -8,7 +8,7 @@ import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.network.*; import io.bitsquare.p2p.peers.PeerManager; import io.bitsquare.p2p.peers.getdata.messages.GetDataRequest; -import io.bitsquare.p2p.peers.peerexchange.ReportedPeer; +import io.bitsquare.p2p.peers.peerexchange.Peer; import io.bitsquare.p2p.storage.P2PDataStorage; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -324,7 +324,7 @@ public class RequestDataManager implements MessageListener, ConnectionListener, } } - private List getSortedNodeAddresses(Collection collection) { + private List getSortedNodeAddresses(Collection collection) { return collection.stream() .collect(Collectors.toList()) .stream() diff --git a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/ReportedPeer.java b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/Peer.java similarity index 87% rename from network/src/main/java/io/bitsquare/p2p/peers/peerexchange/ReportedPeer.java rename to network/src/main/java/io/bitsquare/p2p/peers/peerexchange/Peer.java index dd1a6b88a4..21d9ae960d 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/ReportedPeer.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/Peer.java @@ -7,7 +7,7 @@ import io.bitsquare.p2p.NodeAddress; import java.util.Date; -public final class ReportedPeer implements Payload, Persistable { +public final class Peer implements Payload, Persistable { // That object is sent over the wire, so we need to take care of version compatibility. private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; private static final int MAX_FAILED_CONNECTION_ATTEMPTS = 5; @@ -16,7 +16,7 @@ public final class ReportedPeer implements Payload, Persistable { public final Date date; transient private int failedConnectionAttempts = 0; - public ReportedPeer(NodeAddress nodeAddress) { + public Peer(NodeAddress nodeAddress) { this.nodeAddress = nodeAddress; this.date = new Date(); } @@ -32,9 +32,9 @@ public final class ReportedPeer implements Payload, Persistable { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof ReportedPeer)) return false; + if (!(o instanceof Peer)) return false; - ReportedPeer that = (ReportedPeer) o; + Peer that = (Peer) o; return !(nodeAddress != null ? !nodeAddress.equals(that.nodeAddress) : that.nodeAddress != null); diff --git a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeHandler.java b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeHandler.java index 9a8d0cee29..319efc2af2 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeHandler.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeHandler.java @@ -89,10 +89,11 @@ class PeerExchangeHandler implements MessageListener { @Override public void onSuccess(Connection connection) { if (!stopped) { - if (!connection.getPeersNodeAddressOptional().isPresent()) { + //TODO + /*if (!connection.getPeersNodeAddressOptional().isPresent()) { connection.setPeersNodeAddress(nodeAddress); log.warn("sendGetPeersRequest: !connection.getPeersNodeAddressOptional().isPresent()"); - } + }*/ PeerExchangeHandler.this.connection = connection; connection.addMessageListener(PeerExchangeHandler.this); diff --git a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java index c5c2a959b1..4d023d5b0c 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java @@ -313,7 +313,7 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener, } } - private List getNodeAddresses(Collection collection) { + private List getNodeAddresses(Collection collection) { return collection.stream() .map(e -> e.nodeAddress) .collect(Collectors.toList()); diff --git a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersRequest.java b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersRequest.java index 95c2c8d882..52d84df510 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersRequest.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersRequest.java @@ -3,7 +3,7 @@ package io.bitsquare.p2p.peers.peerexchange.messages; import io.bitsquare.app.Version; import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.network.messages.SendersNodeAddressMessage; -import io.bitsquare.p2p.peers.peerexchange.ReportedPeer; +import io.bitsquare.p2p.peers.peerexchange.Peer; import java.util.HashSet; @@ -15,9 +15,9 @@ public final class GetPeersRequest extends PeerExchangeMessage implements Sender private final NodeAddress senderNodeAddress; public final int nonce; - public final HashSet reportedPeers; + public final HashSet reportedPeers; - public GetPeersRequest(NodeAddress senderNodeAddress, int nonce, HashSet reportedPeers) { + public GetPeersRequest(NodeAddress senderNodeAddress, int nonce, HashSet reportedPeers) { checkNotNull(senderNodeAddress, "senderNodeAddress must not be null at GetPeersRequest"); this.senderNodeAddress = senderNodeAddress; this.nonce = nonce; diff --git a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersResponse.java b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersResponse.java index 1983331cb7..6f38b73499 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersResponse.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/messages/GetPeersResponse.java @@ -1,7 +1,7 @@ package io.bitsquare.p2p.peers.peerexchange.messages; import io.bitsquare.app.Version; -import io.bitsquare.p2p.peers.peerexchange.ReportedPeer; +import io.bitsquare.p2p.peers.peerexchange.Peer; import java.util.HashSet; @@ -10,9 +10,9 @@ public final class GetPeersResponse extends PeerExchangeMessage { private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; public final int requestNonce; - public final HashSet reportedPeers; + public final HashSet reportedPeers; - public GetPeersResponse(int requestNonce, HashSet reportedPeers) { + public GetPeersResponse(int requestNonce, HashSet reportedPeers) { this.requestNonce = requestNonce; this.reportedPeers = reportedPeers; }