mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Copy peers in a new hashset to avoid concurrent modification exc at serialisation
Remove final Cleanups
This commit is contained in:
parent
c7f23e8deb
commit
f53290b817
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Capabilities> 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 {
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -47,8 +47,14 @@ public final class GetPeersRequest extends NetworkEnvelope implements PeerExchan
|
||||
@Nullable
|
||||
private final Capabilities supportedCapabilities;
|
||||
|
||||
public GetPeersRequest(NodeAddress senderNodeAddress, int nonce, Set<Peer> reportedPeers) {
|
||||
this(senderNodeAddress, nonce, reportedPeers, Capabilities.app, Version.getP2PMessageVersion());
|
||||
public GetPeersRequest(NodeAddress senderNodeAddress,
|
||||
int nonce,
|
||||
Set<Peer> reportedPeers) {
|
||||
this(senderNodeAddress,
|
||||
nonce,
|
||||
reportedPeers,
|
||||
Capabilities.app,
|
||||
Version.getP2PMessageVersion());
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,8 +43,12 @@ public final class GetPeersResponse extends NetworkEnvelope implements PeerExcha
|
||||
@Nullable
|
||||
private final Capabilities supportedCapabilities;
|
||||
|
||||
public GetPeersResponse(int requestNonce, Set<Peer> reportedPeers) {
|
||||
this(requestNonce, reportedPeers, Capabilities.app, Version.getP2PMessageVersion());
|
||||
public GetPeersResponse(int requestNonce,
|
||||
Set<Peer> reportedPeers) {
|
||||
this(requestNonce,
|
||||
reportedPeers,
|
||||
Capabilities.app,
|
||||
Version.getP2PMessageVersion());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user