Add check if list is not empty. Reset DevEnv flags.

This commit is contained in:
Manfred Karrer 2017-11-28 19:19:22 -05:00
parent bf87dc3713
commit 714565c990
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
3 changed files with 70 additions and 67 deletions

View File

@ -10,7 +10,7 @@ public class DevEnv {
// peer (click user icon and alt+r), filter/block offers by various data like offer ID (cmd + f).
// The user can set a program argument to ignore all of those privileged network_messages. They are intended for
// emergency cases only (beside update message and arbitrator registration).
public static final boolean USE_DEV_PRIVILEGE_KEYS = true;
public static final boolean USE_DEV_PRIVILEGE_KEYS = false;
public static final String DEV_PRIVILEGE_PUB_KEY = "027a381b5333a56e1cc3d90d3a7d07f26509adf7029ed06fc997c656621f8da1ee";
public static final String DEV_PRIVILEGE_PRIV_KEY = "6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a";
@ -18,8 +18,8 @@ public class DevEnv {
// If set to true we ignore several UI behavior like confirmation popups as well dummy accounts are created and
// offers are filled with default values. Intended to make dev testing faster.
@SuppressWarnings("PointlessBooleanExpression")
public static final boolean DEV_MODE = STRESS_TEST_MODE || true;
public static final boolean DEV_MODE = STRESS_TEST_MODE || false;
public static final boolean DAO_PHASE2_ACTIVATED = true;
public static final boolean DAO_TRADING_ACTIVATED = true;
public static final boolean DAO_PHASE2_ACTIVATED = false;
public static final boolean DAO_TRADING_ACTIVATED = false;
}

View File

@ -19,7 +19,6 @@ package io.bisq.gui.main.dao;
import io.bisq.common.app.DevEnv;
import io.bisq.common.locale.Res;
import io.bisq.core.app.BisqEnvironment;
import io.bisq.gui.Navigation;
import io.bisq.gui.common.model.Activatable;
import io.bisq.gui.common.view.*;
@ -64,7 +63,7 @@ public class DaoView extends ActivatableViewAndModel<TabPane, Activatable> {
votingTab.setClosable(false);
root.getTabs().addAll(compensationTab, votingTab);
if (BisqEnvironment.isDAOActivatedAndBaseCurrencySupportingBsq() && !DevEnv.DAO_PHASE2_ACTIVATED) {
if (!DevEnv.DAO_PHASE2_ACTIVATED) {
votingTab.setDisable(true);
compensationTab.setDisable(true);
}

View File

@ -169,15 +169,15 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
@Override
public void onConnection(Connection connection) {
Log.logIfStressTests("onConnection to peer " +
(connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get() : "PeersNode unknown") +
" / No. of connections: " + networkNode.getAllConnections().size());
(connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get() : "PeersNode unknown") +
" / No. of connections: " + networkNode.getAllConnections().size());
final boolean seedNode = isSeedNode(connection);
final Optional<NodeAddress> addressOptional = connection.getPeersNodeAddressOptional();
log.debug("onConnection: peer = {}{}",
(addressOptional.isPresent() ? addressOptional.get().getFullAddress() : "not known yet (connection id=" + connection.getUid() + ")"),
seedNode ? " (SeedNode)" : "");
(addressOptional.isPresent() ? addressOptional.get().getFullAddress() : "not known yet (connection id=" + connection.getUid() + ")"),
seedNode ? " (SeedNode)" : "");
if (seedNode)
connection.setPeerType(Connection.PeerType.SEED_NODE);
@ -194,15 +194,15 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
@Override
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
Log.logIfStressTests("onDisconnect of peer " +
(connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get() : "PeersNode unknown") +
" / No. of connections: " + networkNode.getAllConnections().size() +
" / closeConnectionReason: " + closeConnectionReason);
(connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get() : "PeersNode unknown") +
" / No. of connections: " + networkNode.getAllConnections().size() +
" / closeConnectionReason: " + closeConnectionReason);
final Optional<NodeAddress> addressOptional = connection.getPeersNodeAddressOptional();
log.debug("onDisconnect: peer = {}{} / closeConnectionReason: {}",
(addressOptional.isPresent() ? addressOptional.get().getFullAddress() : "not known yet (connection id=" + connection.getUid() + ")"),
isSeedNode(connection) ? " (SeedNode)" : "",
closeConnectionReason);
(addressOptional.isPresent() ? addressOptional.get().getFullAddress() : "not known yet (connection id=" + connection.getUid() + ")"),
isSeedNode(connection) ? " (SeedNode)" : "",
closeConnectionReason);
handleConnectionFault(connection);
@ -222,7 +222,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
public boolean isNodeBanned(CloseConnectionReason closeConnectionReason, Connection connection) {
return closeConnectionReason == CloseConnectionReason.PEER_BANNED &&
connection.getPeersNodeAddressOptional().isPresent();
connection.getPeersNodeAddressOptional().isPresent();
}
@Override
@ -260,33 +260,33 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
if (size > limit) {
log.debug("We have too many connections open.\n\t" +
"Lets try first to remove the inbound connections of type PEER.");
"Lets try first to remove the inbound connections of type PEER.");
List<Connection> candidates = allConnections.stream()
.filter(e -> e instanceof InboundConnection)
.filter(e -> e.getPeerType() == Connection.PeerType.PEER)
.collect(Collectors.toList());
.filter(e -> e instanceof InboundConnection)
.filter(e -> e.getPeerType() == Connection.PeerType.PEER)
.collect(Collectors.toList());
if (candidates.size() == 0) {
log.debug("No candidates found. We check if we exceed our " +
"maxConnectionsPeer limit of {}", maxConnectionsPeer);
"maxConnectionsPeer limit of {}", maxConnectionsPeer);
if (size > maxConnectionsPeer) {
log.debug("Lets try to remove ANY connection of type PEER.");
candidates = allConnections.stream()
.filter(e -> e.getPeerType() == Connection.PeerType.PEER)
.collect(Collectors.toList());
.filter(e -> e.getPeerType() == Connection.PeerType.PEER)
.collect(Collectors.toList());
if (candidates.size() == 0) {
log.debug("No candidates found. We check if we exceed our " +
"maxConnectionsNonDirect limit of {}", maxConnectionsNonDirect);
"maxConnectionsNonDirect limit of {}", maxConnectionsNonDirect);
if (size > maxConnectionsNonDirect) {
log.debug("Lets try to remove any connection which is not of type DIRECT_MSG_PEER or INITIAL_DATA_REQUEST.");
candidates = allConnections.stream()
.filter(e -> e.getPeerType() != Connection.PeerType.DIRECT_MSG_PEER && e.getPeerType() != Connection.PeerType.INITIAL_DATA_REQUEST)
.collect(Collectors.toList());
.filter(e -> e.getPeerType() != Connection.PeerType.DIRECT_MSG_PEER && e.getPeerType() != Connection.PeerType.INITIAL_DATA_REQUEST)
.collect(Collectors.toList());
if (candidates.size() == 0) {
log.debug("No candidates found. We check if we exceed our " +
"maxConnectionsAbsolute limit of {}", maxConnectionsAbsolute);
"maxConnectionsAbsolute limit of {}", maxConnectionsAbsolute);
if (size > maxConnectionsAbsolute) {
log.debug("Lets try to remove any connection.");
candidates = allConnections.stream().collect(Collectors.toList());
@ -307,8 +307,8 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
return true;
} else {
log.warn("No candidates found to remove (That case should not be possible as we use in the " +
"last case all connections).\n\t" +
"allConnections=", allConnections);
"last case all connections).\n\t" +
"allConnections=", allConnections);
return false;
}
} else {
@ -320,15 +320,15 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
private void removeAnonymousPeers() {
Log.traceCall();
networkNode.getAllConnections().stream()
.filter(connection -> !connection.hasPeersNodeAddress())
.forEach(connection -> UserThread.runAfter(() -> {
// We give 30 seconds delay and check again if still no address is set
if (!connection.hasPeersNodeAddress() && !connection.isStopped()) {
log.debug("We close the connection as the peer address is still unknown.\n\t" +
"connection=" + connection);
connection.shutDown(CloseConnectionReason.UNKNOWN_PEER_ADDRESS);
}
}, REMOVE_ANONYMOUS_PEER_SEC));
.filter(connection -> !connection.hasPeersNodeAddress())
.forEach(connection -> UserThread.runAfter(() -> {
// We give 30 seconds delay and check again if still no address is set
if (!connection.hasPeersNodeAddress() && !connection.isStopped()) {
log.debug("We close the connection as the peer address is still unknown.\n\t" +
"connection=" + connection);
connection.shutDown(CloseConnectionReason.UNKNOWN_PEER_ADDRESS);
}
}, REMOVE_ANONYMOUS_PEER_SEC));
}
private void removeSuperfluousSeedNodes() {
@ -337,8 +337,8 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
Set<Connection> connections = networkNode.getConfirmedConnections();
if (hasSufficientConnections()) {
List<Connection> candidates = connections.stream()
.filter(this::isSeedNode)
.collect(Collectors.toList());
.filter(this::isSeedNode)
.collect(Collectors.toList());
if (candidates.size() > 1) {
candidates.sort((o1, o2) -> ((Long) o1.getStatistic().getLastActivityTimestamp()).compareTo(((Long) o2.getStatistic().getLastActivityTimestamp())));
@ -367,7 +367,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
private Peer removeReportedPeer(NodeAddress nodeAddress) {
List<Peer> reportedPeersClone = new ArrayList<>(reportedPeers);
Optional<Peer> reportedPeerOptional = reportedPeersClone.stream()
.filter(e -> e.getNodeAddress().equals(nodeAddress)).findAny();
.filter(e -> e.getNodeAddress().equals(nodeAddress)).findAny();
if (reportedPeerOptional.isPresent()) {
Peer reportedPeer = reportedPeerOptional.get();
removeReportedPeer(reportedPeer);
@ -381,8 +381,8 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
Log.traceCall();
List<Peer> reportedPeersClone = new ArrayList<>(reportedPeers);
Set<Peer> reportedPeersToRemove = reportedPeersClone.stream()
.filter(reportedPeer -> new Date().getTime() - reportedPeer.getDate().getTime() > MAX_AGE)
.collect(Collectors.toSet());
.filter(reportedPeer -> new Date().getTime() - reportedPeer.getDate().getTime() > MAX_AGE)
.collect(Collectors.toSet());
reportedPeersToRemove.forEach(this::removeReportedPeer);
}
@ -417,13 +417,15 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
int limit = MAX_REPORTED_PEERS - maxConnectionsAbsolute;
if (size > limit) {
log.trace("We have already {} reported peers which exceeds our limit of {}." +
"We remove random peers from the reported peers list.", size, limit);
"We remove random peers from the reported peers list.", size, limit);
int diff = size - limit;
List<Peer> list = new ArrayList<>(reportedPeers);
// we dont use sorting by lastActivityDate to keep it more random
for (int i = 0; i < diff; i++) {
Peer toRemove = list.remove(new Random().nextInt(list.size()));
removeReportedPeer(toRemove);
if (!list.isEmpty()) {
Peer toRemove = list.remove(new Random().nextInt(list.size()));
removeReportedPeer(toRemove);
}
}
} else {
log.trace("No need to purge reported peers.\n\tWe don't have more then {} reported peers yet.", MAX_REPORTED_PEERS);
@ -435,7 +437,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
//noinspection ConstantConditions
if (PRINT_REPORTED_PEERS_DETAILS) {
StringBuilder result = new StringBuilder("\n\n------------------------------------------------------------\n" +
"Collected reported peers:");
"Collected reported peers:");
List<Peer> reportedPeersClone = new ArrayList<>(reportedPeers);
reportedPeersClone.stream().forEach(e -> result.append("\n").append(e));
result.append("\n------------------------------------------------------------\n");
@ -479,14 +481,14 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
private Optional<Peer> getPersistedPeerOptional(NodeAddress nodeAddress) {
return persistedPeers.stream()
.filter(e -> e.getNodeAddress().equals(nodeAddress)).findAny();
.filter(e -> e.getNodeAddress().equals(nodeAddress)).findAny();
}
private void removeTooOldPersistedPeers() {
Log.traceCall();
Set<Peer> persistedPeersToRemove = persistedPeers.stream()
.filter(reportedPeer -> new Date().getTime() - reportedPeer.getDate().getTime() > MAX_AGE)
.collect(Collectors.toSet());
.filter(reportedPeer -> new Date().getTime() - reportedPeer.getDate().getTime() > MAX_AGE)
.collect(Collectors.toSet());
persistedPeersToRemove.forEach(this::removePersistedPeer);
}
@ -496,13 +498,15 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
int limit = MAX_PERSISTED_PEERS;
if (size > limit) {
log.trace("We have already {} persisted peers which exceeds our limit of {}." +
"We remove random peers from the persisted peers list.", size, limit);
"We remove random peers from the persisted peers list.", size, limit);
int diff = size - limit;
List<Peer> 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++) {
Peer toRemove = list.remove(new Random().nextInt(list.size()));
removePersistedPeer(toRemove);
if (!list.isEmpty()) {
Peer toRemove = list.remove(new Random().nextInt(list.size()));
removePersistedPeer(toRemove);
}
}
} else {
log.trace("No need to purge persisted peers.\n\tWe don't have more then {} persisted peers yet.", MAX_PERSISTED_PEERS);
@ -584,17 +588,17 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
public void shutDownConnection(NodeAddress peersNodeAddress, CloseConnectionReason closeConnectionReason) {
networkNode.getAllConnections().stream()
.filter(connection -> connection.getPeersNodeAddressOptional().isPresent() &&
connection.getPeersNodeAddressOptional().get().equals(peersNodeAddress) &&
connection.getPeerType() != Connection.PeerType.DIRECT_MSG_PEER)
.findAny()
.ifPresent(connection -> connection.shutDown(closeConnectionReason));
.filter(connection -> connection.getPeersNodeAddressOptional().isPresent() &&
connection.getPeersNodeAddressOptional().get().equals(peersNodeAddress) &&
connection.getPeerType() != Connection.PeerType.DIRECT_MSG_PEER)
.findAny()
.ifPresent(connection -> connection.shutDown(closeConnectionReason));
}
public HashSet<Peer> getConnectedNonSeedNodeReportedPeers(NodeAddress excludedNodeAddress) {
return new HashSet<>(getConnectedNonSeedNodeReportedPeers().stream()
.filter(e -> !e.getNodeAddress().equals(excludedNodeAddress))
.collect(Collectors.toSet()));
.filter(e -> !e.getNodeAddress().equals(excludedNodeAddress))
.collect(Collectors.toSet()));
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -605,14 +609,14 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
// networkNode.getConfirmedConnections includes:
// filter(connection -> connection.getPeersNodeAddressOptional().isPresent())
return networkNode.getConfirmedConnections().stream()
.map(c -> new Peer(c.getPeersNodeAddressOptional().get()))
.collect(Collectors.toSet());
.map(c -> new Peer(c.getPeersNodeAddressOptional().get()))
.collect(Collectors.toSet());
}
private HashSet<Peer> getConnectedNonSeedNodeReportedPeers() {
return new HashSet<>(getConnectedReportedPeers().stream()
.filter(e -> !isSeedNode(e))
.collect(Collectors.toSet()));
.filter(e -> !isSeedNode(e))
.collect(Collectors.toSet()));
}
private void stopCheckMaxConnectionsTimer() {
@ -625,9 +629,9 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
private void printConnectedPeers() {
if (!networkNode.getConfirmedConnections().isEmpty()) {
StringBuilder result = new StringBuilder("\n\n------------------------------------------------------------\n" +
"Connected peers for node " + networkNode.getNodeAddress() + ":");
"Connected peers for node " + networkNode.getNodeAddress() + ":");
networkNode.getConfirmedConnections().stream().forEach(e -> result.append("\n")
.append(e.getPeersNodeAddressOptional().get()).append(" ").append(e.getPeerType()));
.append(e.getPeersNodeAddressOptional().get()).append(" ").append(e.getPeerType()));
result.append("\n------------------------------------------------------------\n");
log.debug(result.toString());
}