diff --git a/p2p/src/main/java/bisq/network/p2p/network/SynchronizedProtoOutputStream.java b/p2p/src/main/java/bisq/network/p2p/network/SynchronizedProtoOutputStream.java index 4614e20f79..96d944c75f 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/SynchronizedProtoOutputStream.java +++ b/p2p/src/main/java/bisq/network/p2p/network/SynchronizedProtoOutputStream.java @@ -50,11 +50,11 @@ class SynchronizedProtoOutputStream extends ProtoOutputStream { } catch (InterruptedException e) { Thread currentThread = Thread.currentThread(); currentThread.interrupt(); - final String msg = "Thread " + currentThread + " was interrupted. InterruptedException=" + e; + String msg = "Thread " + currentThread + " was interrupted. InterruptedException=" + e; log.error(msg); throw new BisqRuntimeException(msg, e); } catch (ExecutionException e) { - final String msg = "Failed to write envelope. ExecutionException " + e; + String msg = "Failed to write envelope. ExecutionException " + e; log.error(msg); throw new BisqRuntimeException(msg, e); } @@ -65,7 +65,7 @@ class SynchronizedProtoOutputStream extends ProtoOutputStream { executorService.shutdownNow(); super.onConnectionShutdown(); } catch (Throwable t) { - log.error("Failed to handle connection shutdown. Throwable={}", t); + log.error("Failed to handle connection shutdown. Throwable={}", t.toString()); } } } diff --git a/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java b/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java index 9b82beaf29..737f7d0d80 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java @@ -401,7 +401,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost // We look up first our connections as that is our own data. If not found there we look up the peers which // include reported peers. Optional optionalCapabilities = networkNode.findPeersCapabilities(nodeAddress); - if (optionalCapabilities.isPresent()) { + if (optionalCapabilities.isPresent() && !optionalCapabilities.get().isEmpty()) { return optionalCapabilities; } @@ -415,7 +415,8 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost // attack all users have a strong incentive to update ;-). return getAllPeers().stream() .filter(peer -> peer.getNodeAddress().equals(nodeAddress)) - .findAny().map(Peer::getCapabilities); + .findAny() + .map(Peer::getCapabilities); } private void applyCapabilities(Connection connection, Capabilities capabilities) { @@ -647,7 +648,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost private boolean removePersistedPeer(Peer persistedPeer) { if (getPersistedPeers().contains(persistedPeer)) { - getPersistedPeers().remove(persistedPeer); + //getPersistedPeers().remove(persistedPeer); requestPersistence(); return true; } else { diff --git a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/GetPeersRequestHandler.java b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/GetPeersRequestHandler.java index f280587c86..2b11b0c64a 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/GetPeersRequestHandler.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/GetPeersRequestHandler.java @@ -32,6 +32,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; +import java.util.HashSet; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; @@ -83,11 +84,11 @@ class GetPeersRequestHandler { // API /////////////////////////////////////////////////////////////////////////////////////////// - public void handle(GetPeersRequest getPeersRequest, final Connection connection) { + public void handle(GetPeersRequest getPeersRequest, Connection connection) { checkArgument(connection.getPeersNodeAddressOptional().isPresent(), "The peers address must have been already set at the moment"); GetPeersResponse getPeersResponse = new GetPeersResponse(getPeersRequest.getNonce(), - peerManager.getLivePeers(connection.getPeersNodeAddressOptional().get())); + new HashSet<>(peerManager.getLivePeers(connection.getPeersNodeAddressOptional().get()))); checkArgument(timeoutTimer == null, "onGetPeersRequest must not be called twice."); timeoutTimer = UserThread.runAfter(() -> { // setup before sending to avoid race conditions diff --git a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeHandler.java b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeHandler.java index df6b685dec..384f05c34c 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeHandler.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeHandler.java @@ -35,6 +35,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; +import java.util.HashSet; import java.util.Random; import java.util.concurrent.TimeUnit; @@ -104,7 +105,9 @@ class PeerExchangeHandler implements MessageListener { log.debug("sendGetPeersRequest to nodeAddress={}", nodeAddress); if (!stopped) { if (networkNode.getNodeAddress() != null) { - GetPeersRequest getPeersRequest = new GetPeersRequest(networkNode.getNodeAddress(), nonce, peerManager.getLivePeers(nodeAddress)); + GetPeersRequest getPeersRequest = new GetPeersRequest(networkNode.getNodeAddress(), + nonce, + new HashSet<>(peerManager.getLivePeers(nodeAddress))); if (timeoutTimer == null) { timeoutTimer = UserThread.runAfter(() -> { // setup before sending to avoid race conditions if (!stopped) { diff --git a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersRequest.java b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersRequest.java index 2f23ef4308..90f31b97da 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersRequest.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersRequest.java @@ -47,8 +47,14 @@ public final class GetPeersRequest extends NetworkEnvelope implements PeerExchan @Nullable private final Capabilities supportedCapabilities; - public GetPeersRequest(NodeAddress senderNodeAddress, int nonce, Set reportedPeers) { - this(senderNodeAddress, nonce, reportedPeers, Capabilities.app, Version.getP2PMessageVersion()); + public GetPeersRequest(NodeAddress senderNodeAddress, + int nonce, + Set reportedPeers) { + this(senderNodeAddress, + nonce, + reportedPeers, + Capabilities.app, + Version.getP2PMessageVersion()); } diff --git a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersResponse.java b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersResponse.java index 5a41fe91f4..149bcb4946 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersResponse.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/messages/GetPeersResponse.java @@ -43,8 +43,12 @@ public final class GetPeersResponse extends NetworkEnvelope implements PeerExcha @Nullable private final Capabilities supportedCapabilities; - public GetPeersResponse(int requestNonce, Set reportedPeers) { - this(requestNonce, reportedPeers, Capabilities.app, Version.getP2PMessageVersion()); + public GetPeersResponse(int requestNonce, + Set reportedPeers) { + this(requestNonce, + reportedPeers, + Capabilities.app, + Version.getP2PMessageVersion()); }