From 5c7aa80afaaf244c0757852d8305890a91db5986 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 00:43:02 -0500 Subject: [PATCH 01/27] Add deviation to persistent warnings/alerts --- .../java/bisq/inventory/InventoryWebServer.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java index a4df7cc7ef4..c10a877403c 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java +++ b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java @@ -360,17 +360,19 @@ private String getLine(String title, List requestInfoList = map.get(seedNode); String historicalWarnings = ""; String historicalAlerts = ""; - List warningsAtRequestNumber = new ArrayList<>(); - List alertsAtRequestNumber = new ArrayList<>(); + List warningsAtRequestNumber = new ArrayList<>(); + List alertsAtRequestNumber = new ArrayList<>(); if (requestInfoList != null) { for (int i = 0; i < requestInfoList.size(); i++) { RequestInfo reqInfo = requestInfoList.get(i); Map deviationInfoMap = reqInfo.getDataMap(); if (deviationInfoMap.containsKey(inventoryItem)) { - if (deviationInfoMap.get(inventoryItem).isPersistentWarning()) { - warningsAtRequestNumber.add(i + 1); - } else if (deviationInfoMap.get(inventoryItem).isPersistentAlert()) { - alertsAtRequestNumber.add(i + 1); + RequestInfo.Data data = deviationInfoMap.get(inventoryItem); + String deviationAsPercent = getDeviationAsPercentString(data.getDeviation()); + if (data.isPersistentWarning()) { + warningsAtRequestNumber.add((i + 1) + " (" + deviationAsPercent + ")"); + } else if (data.isPersistentAlert()) { + alertsAtRequestNumber.add((i + 1) + " (" + deviationAsPercent + ")"); } } } From 850f73aad5a1bf0935ced160c0c61be581413a17 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 01:39:57 -0500 Subject: [PATCH 02/27] Fix formatting --- .../src/main/java/bisq/inventory/InventoryWebServer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java index c10a877403c..fe4d39325da 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java +++ b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java @@ -370,9 +370,9 @@ private String getLine(String title, RequestInfo.Data data = deviationInfoMap.get(inventoryItem); String deviationAsPercent = getDeviationAsPercentString(data.getDeviation()); if (data.isPersistentWarning()) { - warningsAtRequestNumber.add((i + 1) + " (" + deviationAsPercent + ")"); + warningsAtRequestNumber.add((i + 1) + deviationAsPercent); } else if (data.isPersistentAlert()) { - alertsAtRequestNumber.add((i + 1) + " (" + deviationAsPercent + ")"); + alertsAtRequestNumber.add((i + 1) + deviationAsPercent); } } } From 4d17e986a2246badcfe151c794ba0d2e67a50672 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 11:00:02 -0500 Subject: [PATCH 03/27] Update COMMIT_HASH to 04440f95 (after merged master) --- .../java/bisq/core/network/p2p/inventory/model/RequestInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java index 448121456a7..78675293297 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java @@ -29,7 +29,7 @@ @Getter public class RequestInfo { // Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field) - public static final String COMMIT_HASH = "d789282b"; + public static final String COMMIT_HASH = "04440f95"; private final long requestStartTime; @Setter From ac955e1875ae35d0ece0fd43a7ad033973597b21 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 11:46:13 -0500 Subject: [PATCH 04/27] Reduce TTL for ack and mailbox messages --- p2p/src/main/java/bisq/network/p2p/AckMessage.java | 2 +- .../bisq/network/p2p/storage/payload/MailboxStoragePayload.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/AckMessage.java b/p2p/src/main/java/bisq/network/p2p/AckMessage.java index af1815e1031..ca62210ed5f 100644 --- a/p2p/src/main/java/bisq/network/p2p/AckMessage.java +++ b/p2p/src/main/java/bisq/network/p2p/AckMessage.java @@ -147,7 +147,7 @@ public static AckMessage fromProto(protobuf.AckMessage proto, int messageVersion @Override public long getTTL() { - return TimeUnit.DAYS.toMillis(10); + return TimeUnit.DAYS.toMillis(2); } @Override diff --git a/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java b/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java index a2e3eadd7ad..5bed966ee2d 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java @@ -117,6 +117,6 @@ public static MailboxStoragePayload fromProto(protobuf.MailboxStoragePayload pro @Override public long getTTL() { - return TimeUnit.DAYS.toMillis(15); + return TimeUnit.DAYS.toMillis(7); } } From b09ebdeeba35fa7870d5f61f2ff6e08d8f538ab7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 11:46:49 -0500 Subject: [PATCH 05/27] Update COMMIT_HASH to fd2a04a2 --- .../java/bisq/core/network/p2p/inventory/model/RequestInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java index 78675293297..0f30325e63d 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java @@ -29,7 +29,7 @@ @Getter public class RequestInfo { // Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field) - public static final String COMMIT_HASH = "04440f95"; + public static final String COMMIT_HASH = "fd2a04a2"; private final long requestStartTime; @Setter From 012c54cf0241f627b7324216b69dc1fe6f131be6 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 11:57:49 -0500 Subject: [PATCH 06/27] Fix log at startup --- common/src/main/java/bisq/common/setup/CommonSetup.java | 2 +- seednode/src/main/java/bisq/seednode/SeedNodeMain.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index 5562787ff78..b56613bd560 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -48,8 +48,8 @@ public class CommonSetup { public static void setup(Config config, GracefulShutDownHandler gracefulShutDownHandler) { - AsciiLogo.showAsciiLogo(); setupLog(config); + AsciiLogo.showAsciiLogo(); Version.setBaseCryptoNetworkId(config.baseCurrencyNetwork.ordinal()); Version.printVersion(); maybePrintPathOfCodeSource(); diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index 37c75da5885..e1b5bf9ba20 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -41,7 +41,7 @@ public SeedNodeMain() { } public static void main(String[] args) { - log.info("SeedNode.VERSION: " + VERSION); + System.out.println("SeedNode.VERSION: " + VERSION); new SeedNodeMain().execute(args); } From f10d2318f308cb8221d99a31acf6d8f57273e292 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 12:02:38 -0500 Subject: [PATCH 07/27] Log when we remove expired entries --- .../bisq/network/p2p/storage/P2PDataStorage.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java index bba3c44e289..d4258980893 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java @@ -511,10 +511,12 @@ void removeExpiredEntries() { // Batch processing can cause performance issues, so do all of the removes first, then update the listeners // to let them know about the removes. - toRemoveList.forEach(toRemoveItem -> { - log.debug("We found an expired data entry. We remove the protectedData:\n\t" + - Utilities.toTruncatedString(toRemoveItem.getValue())); - }); + if (log.isDebugEnabled()) { + toRemoveList.forEach(toRemoveItem -> { + log.debug("We found an expired data entry. We remove the protectedData:\n\t{}", + Utilities.toTruncatedString(toRemoveItem.getValue())); + }); + } removeFromMapAndDataStore(toRemoveList); if (sequenceNumberMap.size() > this.maxSequenceNumberMapSizeBeforePurge) { @@ -937,6 +939,8 @@ private void removeFromMapAndDataStore( if (entriesToRemoveWithPayloadHash.isEmpty()) return; + log.info("Remove {} expired data entries", entriesToRemoveWithPayloadHash.size()); + ArrayList entriesForSignal = new ArrayList<>(entriesToRemoveWithPayloadHash.size()); entriesToRemoveWithPayloadHash.forEach(entryToRemoveWithPayloadHash -> { ByteArray hashOfPayload = entryToRemoveWithPayloadHash.getKey(); From 4bececeb4ca24e7722f1235d0ea95b5418ef0283 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 12:30:14 -0500 Subject: [PATCH 08/27] Increase MAX_PERMITTED_MESSAGE_SIZE to 15 MB, increase SOCKET_TIMEOUT to 6 min --- p2p/src/main/java/bisq/network/p2p/network/Connection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/network/Connection.java b/p2p/src/main/java/bisq/network/p2p/network/Connection.java index 3a03fd0231f..8870340b808 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -120,9 +120,9 @@ public enum PeerType { // Leaving some constants package-private for tests to know limits. private static final int PERMITTED_MESSAGE_SIZE = 200 * 1024; // 200 kb - private static final int MAX_PERMITTED_MESSAGE_SIZE = 10 * 1024 * 1024; // 10 MB (425 offers resulted in about 660 kb, mailbox msg will add more to it) offer has usually 2 kb, mailbox 3kb. + private static final int MAX_PERMITTED_MESSAGE_SIZE = 15 * 1024 * 1024; // 15 MB (425 offers resulted in about 660 kb, mailbox msg will add more to it) offer has usually 2 kb, mailbox 3kb. //TODO decrease limits again after testing - private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(180); + private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(360); public static int getPermittedMessageSize() { return PERMITTED_MESSAGE_SIZE; From b002c93d784e6fb3cd30c11aa08e46fcf69ff23d Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 12:30:33 -0500 Subject: [PATCH 09/27] Increase SOCKET_TIMEOUT to 6 min --- .../bisq/network/p2p/peers/getdata/GetDataRequestHandler.java | 2 +- .../java/bisq/network/p2p/peers/getdata/RequestDataHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java b/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java index 93fca1d8083..e7433ad6a68 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java @@ -41,7 +41,7 @@ @Slf4j public class GetDataRequestHandler { - private static final long TIMEOUT = 180; + private static final long TIMEOUT = 360; private static final int MAX_ENTRIES = 10000; diff --git a/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java b/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java index e00fdd67bf9..807b45035ed 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java @@ -53,7 +53,7 @@ @Slf4j class RequestDataHandler implements MessageListener { - private static final long TIMEOUT = 180; + private static final long TIMEOUT = 360; private NodeAddress peersNodeAddress; private String getDataRequestType; From a1c84741f3b32b0de56734d0506cf9c131c0971e Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 12:34:43 -0500 Subject: [PATCH 10/27] Add comments, revert TTL change at AckMessage as it has no effect anyway --- p2p/src/main/java/bisq/network/p2p/AckMessage.java | 7 ++++++- .../network/p2p/storage/payload/MailboxStoragePayload.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/p2p/src/main/java/bisq/network/p2p/AckMessage.java b/p2p/src/main/java/bisq/network/p2p/AckMessage.java index ca62210ed5f..fea3fa0a33f 100644 --- a/p2p/src/main/java/bisq/network/p2p/AckMessage.java +++ b/p2p/src/main/java/bisq/network/p2p/AckMessage.java @@ -34,6 +34,10 @@ import javax.annotation.Nullable; +// TODO ExpirablePayload has no effect here as it is either a direct msg or packed into MailboxStoragePayload +// We could extend the TTL by setting the TTL in MailboxStoragePayload from the type of msg which gets into the +// SealedAndSigned data. + // We exclude uid from hashcode and equals to detect duplicate entries of the same AckMessage @EqualsAndHashCode(callSuper = true, exclude = {"uid"}) @Value @@ -145,9 +149,10 @@ public static AckMessage fromProto(protobuf.AckMessage proto, int messageVersion // API /////////////////////////////////////////////////////////////////////////////////////////// + //TODO has no effect, see comment at class definition @Override public long getTTL() { - return TimeUnit.DAYS.toMillis(2); + return TimeUnit.DAYS.toMillis(10); } @Override diff --git a/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java b/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java index 5bed966ee2d..f50a5697a5c 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/payload/MailboxStoragePayload.java @@ -47,6 +47,7 @@ * That is the typical requirement for a mailbox like system. *

* Typical payloads are trade or dispute network_messages to be stored when the peer is offline. + * Size depends on payload but typical size is 2000-3000 bytes */ @Getter @EqualsAndHashCode From 33e378accdbd575ef6352c076a534c84d2d3cb83 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 4 Nov 2020 12:36:12 -0500 Subject: [PATCH 11/27] Update COMMIT_HASH to fec8f6e3 --- .../java/bisq/core/network/p2p/inventory/model/RequestInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java index 0f30325e63d..36f0b302015 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java @@ -29,7 +29,7 @@ @Getter public class RequestInfo { // Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field) - public static final String COMMIT_HASH = "fd2a04a2"; + public static final String COMMIT_HASH = "fec8f6e3"; private final long requestStartTime; @Setter From 16880b2f6abb72d8cd08ff171598a1434815abdb Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 12:51:36 -0500 Subject: [PATCH 12/27] Change deviation limits for OfferPayload --- .../bisq/core/network/p2p/inventory/model/InventoryItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java index 7d7e4b7937b..ee2405d7ba1 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java @@ -32,7 +32,7 @@ public enum InventoryItem { // Percentage deviation OfferPayload("OfferPayload", true, - new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 5), + new DeviationByPercentage(0.8, 1.2, 0.9, 1.1), 5), MailboxStoragePayload("MailboxStoragePayload", true, new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2), From 86a853bfb996c2377a346e161b522d4a26edb195 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 16:00:39 -0500 Subject: [PATCH 13/27] Set response time only in non error case --- .../src/main/java/bisq/inventory/InventoryMonitor.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/inventory/src/main/java/bisq/inventory/InventoryMonitor.java b/inventory/src/main/java/bisq/inventory/InventoryMonitor.java index 1b866c67e8d..c807b351cf7 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryMonitor.java +++ b/inventory/src/main/java/bisq/inventory/InventoryMonitor.java @@ -154,16 +154,17 @@ private void processResponse(NodeAddress nodeAddress, RequestInfo requestInfo, @Nullable Map result, @Nullable String errorMessage) { - if (errorMessage != null) { + long responseTime = System.currentTimeMillis(); + if (errorMessage != null && !errorMessage.isEmpty()) { log.warn("Error at connection to peer {}: {}", nodeAddress, errorMessage); requestInfo.setErrorMessage(errorMessage); + } else { + requestInfo.setResponseTime(responseTime); } boolean ignoreDeviationAtStartup; if (result != null) { log.info("nodeAddress={}, result={}", nodeAddress, result.toString()); - long responseTime = System.currentTimeMillis(); - requestInfo.setResponseTime(responseTime); // If seed just started up we ignore the deviation as it can be expected that seed is still syncing // DAO state/blocks. P2P data should be ready but as we received it from other seeds it is not that From a0565425df6175e2e95d1e705596fb05f3327670 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 16:06:54 -0500 Subject: [PATCH 14/27] Add historical data for error msg Rename 'Number of responses' to 'Number of requests' Rename timeout err msg @jmacxx: See comment at `getErrorMsgLine`... If you need those historical error msg data in the json as well we need to refactor a bit more... --- .../p2p/inventory/GetInventoryRequester.java | 2 +- .../bisq/inventory/InventoryWebServer.java | 122 ++++++++++++++---- 2 files changed, 100 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java index a4961e824dc..3309703f7fa 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java @@ -70,7 +70,7 @@ public void request() { } private void onTimeOut() { - errorMessageHandler.handleErrorMessage("Timeout got triggered (" + TIMEOUT_SEC + " sec)"); + errorMessageHandler.handleErrorMessage("Request timeout"); shutDown(); } diff --git a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java index fe4d39325da..4b1d6451ca4 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java +++ b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java @@ -17,6 +17,8 @@ package bisq.inventory; +import bisq.core.network.p2p.inventory.model.DeviationByIntegerDiff; +import bisq.core.network.p2p.inventory.model.DeviationByPercentage; import bisq.core.network.p2p.inventory.model.DeviationSeverity; import bisq.core.network.p2p.inventory.model.InventoryItem; import bisq.core.network.p2p.inventory.model.RequestInfo; @@ -37,6 +39,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import lombok.extern.slf4j.Slf4j; @@ -50,6 +53,8 @@ @Slf4j public class InventoryWebServer { private final static String CLOSE_TAG = "
"; + private final static String WARNING_ICON = "⚠ "; + private final static String ALERT_ICON = "☠ "; // ⚡ ⚡ private final List seedNodes; private final Map operatorByNodeAddress = new HashMap<>(); @@ -122,10 +127,10 @@ private String generateHtml(Map> map) { html.append(""); if (map.containsKey(seedNode) && !map.get(seedNode).isEmpty()) { List list = map.get(seedNode); - int numResponses = list.size(); - RequestInfo requestInfo = list.get(numResponses - 1); + int numRequests = list.size(); + RequestInfo requestInfo = list.get(numRequests - 1); html.append("").append(getSeedNodeInfo(seedNode, requestInfo)).append("") - .append("").append(getRequestInfo(requestInfo, numResponses)).append("") + .append("").append(getRequestInfo(seedNode, requestInfo, numRequests, map)).append("") .append("").append(getDataInfo(seedNode, requestInfo, map)).append("") .append("").append(getDaoInfo(seedNode, requestInfo, map)).append("") .append("").append(getNetworkInfo(seedNode, requestInfo, map)).append(""); @@ -194,16 +199,19 @@ private String getSeedNodeInfo(NodeAddress nodeAddress, return sb.toString(); } - private String getRequestInfo(RequestInfo requestInfo, int numResponses) { + private String getRequestInfo(NodeAddress seedNode, + RequestInfo requestInfo, + int numRequests, + Map> map) { StringBuilder sb = new StringBuilder(); - DeviationSeverity deviationSeverity = numResponses == requestCounter ? + DeviationSeverity deviationSeverity = numRequests == requestCounter ? DeviationSeverity.OK : - requestCounter - numResponses > 4 ? + requestCounter - numRequests > 4 ? DeviationSeverity.ALERT : DeviationSeverity.WARN; - sb.append("Number of responses: ").append(getColorTagByDeviationSeverity(deviationSeverity)) - .append(numResponses).append(CLOSE_TAG); + sb.append("Number of requests: ").append(getColorTagByDeviationSeverity(deviationSeverity)) + .append(numRequests).append(CLOSE_TAG); DeviationSeverity rrtDeviationSeverity = DeviationSeverity.OK; String rrtString = "n/a"; @@ -228,11 +236,7 @@ private String getRequestInfo(RequestInfo requestInfo, int numResponses) { "n/a"; sb.append("Response received at: ").append(responseTime).append("
"); - String errorMessage = requestInfo.getErrorMessage(); - if (errorMessage != null && !errorMessage.isEmpty()) { - sb.append("Error message: ").append(getColorTagByDeviationSeverity(DeviationSeverity.ALERT)) - .append(errorMessage).append(CLOSE_TAG); - } + sb.append(getErrorMsgLine(seedNode, requestInfo, map)); return sb.toString(); } @@ -353,7 +357,7 @@ private String getLine(String title, DeviationSeverity deviationSeverity = DeviationSeverity.OK; if (requestInfo.getDataMap().containsKey(inventoryItem)) { RequestInfo.Data data = requestInfo.getDataMap().get(inventoryItem); - deviationAsPercentString = getDeviationAsPercentString(data.getDeviation()); + deviationAsPercentString = getDeviationAsPercentString(inventoryItem, data); deviationSeverity = data.getDeviationSeverity(); } @@ -368,7 +372,7 @@ private String getLine(String title, Map deviationInfoMap = reqInfo.getDataMap(); if (deviationInfoMap.containsKey(inventoryItem)) { RequestInfo.Data data = deviationInfoMap.get(inventoryItem); - String deviationAsPercent = getDeviationAsPercentString(data.getDeviation()); + String deviationAsPercent = getDeviationAsPercentString(inventoryItem, data); if (data.isPersistentWarning()) { warningsAtRequestNumber.add((i + 1) + deviationAsPercent); } else if (data.isPersistentAlert()) { @@ -378,18 +382,16 @@ private String getLine(String title, } if (!warningsAtRequestNumber.isEmpty()) { - historicalWarnings = inventoryItem.getDeviationTolerance() + " repeated warning(s) at request(s) " + Joiner.on(", ").join(warningsAtRequestNumber); + historicalWarnings = warningsAtRequestNumber.size() + " repeated warning(s) at request(s) " + Joiner.on(", ").join(warningsAtRequestNumber); } if (!alertsAtRequestNumber.isEmpty()) { - historicalAlerts = inventoryItem.getDeviationTolerance() + " repeated alert(s) at request(s): " + Joiner.on(", ").join(alertsAtRequestNumber); + historicalAlerts = alertsAtRequestNumber.size() + " repeated alert(s) at request(s): " + Joiner.on(", ").join(alertsAtRequestNumber); } } - String warningIcon = "⚠ "; String historicalWarningsHtml = warningsAtRequestNumber.isEmpty() ? "" : - ", " + warningIcon + warningsAtRequestNumber.size() + ""; - String errorIcon = "☠ "; // ⚡ ⚡ + ", " + WARNING_ICON + warningsAtRequestNumber.size() + ""; String historicalAlertsHtml = alertsAtRequestNumber.isEmpty() ? "" : - ", " + errorIcon + alertsAtRequestNumber.size() + ""; + ", " + ALERT_ICON + alertsAtRequestNumber.size() + ""; return title + getColorTagByDeviationSeverity(deviationSeverity) + @@ -400,14 +402,29 @@ private String getLine(String title, CLOSE_TAG; } - private String getDeviationAsPercentString(@Nullable Double deviation) { - if (deviation == null) { + private String getDeviationAsPercentString(InventoryItem inventoryItem, RequestInfo.Data data) { + Double deviation = data.getDeviation(); + if (deviation == null || deviation == 1) { return ""; } + if (inventoryItem.getDeviationType() instanceof DeviationByPercentage) { + return getDeviationInRoundedPercent(deviation); + } else if (inventoryItem.getDeviationType() instanceof DeviationByIntegerDiff) { + // For larger numbers like chain height we need to show all decimals as diff can be very small + return getDeviationInExactPercent(deviation); + } else { + return ""; + } + } + private String getDeviationInRoundedPercent(double deviation) { return " (" + MathUtils.roundDouble(100 * deviation, 2) + " %)"; } + private String getDeviationInExactPercent(double deviation) { + return " (" + 100 * deviation + " %)"; + } + private String getColorTagByDeviationSeverity(@Nullable DeviationSeverity deviationSeverity) { if (deviationSeverity == null) { return ""; @@ -444,4 +461,63 @@ private void setupOperatorMap(BufferedReader seedNodeFile) { } }); } + + // We use here a bit diff. model as with other historical data alerts/warnings as we do not store it in the data + // object as we do with normal inventoryItems. So the historical error msg are not available in the json file. + // If we need it we have to move that handling here to the InventoryMonitor and change the data model to support the + // missing data for error messages. + private String getErrorMsgLine(NodeAddress seedNode, + RequestInfo requestInfo, + Map> map) { + boolean isError = requestInfo.getErrorMessage() != null && + !requestInfo.getErrorMessage().isEmpty(); + String errorMessage = isError ? requestInfo.getErrorMessage() : "-"; + List requestInfoList = map.get(seedNode); + List errorsAtRequestNumber = new ArrayList<>(); + String historicalErrorsHtml = ""; + if (requestInfoList != null) { + for (int i = 0; i < requestInfoList.size(); i++) { + RequestInfo requestInfo1 = requestInfoList.get(i); + + // We ignore old errors as at startup timeouts are expected and each node restarts once a day + if (requestInfo1.getRequestStartTime() > 0 && + System.currentTimeMillis() - requestInfo1.getRequestStartTime() > TimeUnit.HOURS.toMillis(24)) { + continue; + } + + boolean isError1 = requestInfo1.getErrorMessage() != null && + !requestInfo1.getErrorMessage().isEmpty(); + if (isError1) { + errorsAtRequestNumber.add((i + 1) + " (" + requestInfo1.getErrorMessage() + ")"); + } + } + + if (!errorsAtRequestNumber.isEmpty()) { + String errorIcon; + String type; + String style; + if (errorsAtRequestNumber.size() > 4) { + errorIcon = ALERT_ICON; + type = "alert"; + style = "alert"; + } else { + errorIcon = WARNING_ICON; + type = "warning"; + style = "warn"; + } + String historicalAlerts = errorsAtRequestNumber.size() + " repeated " + type + "(s) at request(s): " + Joiner.on(", ").join(errorsAtRequestNumber); + historicalErrorsHtml = errorsAtRequestNumber.isEmpty() ? "" : + ", " + errorIcon + errorsAtRequestNumber.size() + ""; + } + } + DeviationSeverity deviationSeverity = isError ? + errorsAtRequestNumber.size() > 4 ? DeviationSeverity.ALERT : DeviationSeverity.WARN + : DeviationSeverity.OK; + + return "Error message: " + + getColorTagByDeviationSeverity(deviationSeverity) + + errorMessage + + historicalErrorsHtml + + CLOSE_TAG; + } } From 1eca9dff4b6ea471f1430aac7fbba9068b1435b3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 16:16:19 -0500 Subject: [PATCH 15/27] Use dash for empty filteredSeedNodes value --- .../src/main/java/bisq/inventory/InventoryWebServer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java index 4b1d6451ca4..cfb74bf2405 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java +++ b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java @@ -191,8 +191,12 @@ private String getSeedNodeInfo(NodeAddress nodeAddress, "n/a"; sb.append("Run duration: ").append(duration).append("
"); + String filteredSeedNodes = requestInfo.getDisplayValue(InventoryItem.filteredSeeds).replace(System.getProperty("line.separator"), "
"); + if (filteredSeedNodes.isEmpty()) { + filteredSeedNodes = "-"; + } sb.append("Filtered seed nodes: ") - .append(requestInfo.getDisplayValue(InventoryItem.filteredSeeds).replace(System.getProperty("line.separator"), "
")) + .append(filteredSeedNodes) .append("
"); } From 5e4156910a893da39f718ce482dbcd9337cded38 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 16:23:05 -0500 Subject: [PATCH 16/27] Add hasError util method Reformattings, cleanups --- .../p2p/inventory/model/RequestInfo.java | 4 +++ .../java/bisq/inventory/InventoryMonitor.java | 3 +- .../bisq/inventory/InventoryWebServer.java | 35 ++++++++++--------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java index 36f0b302015..925fec690a1 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java @@ -56,6 +56,10 @@ public String getValue(InventoryItem inventoryItem) { null; } + public boolean hasError() { + return errorMessage != null && !errorMessage.isEmpty(); + } + @Value public static class Data { private final String value; diff --git a/inventory/src/main/java/bisq/inventory/InventoryMonitor.java b/inventory/src/main/java/bisq/inventory/InventoryMonitor.java index c807b351cf7..9f863fc8c5b 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryMonitor.java +++ b/inventory/src/main/java/bisq/inventory/InventoryMonitor.java @@ -154,12 +154,11 @@ private void processResponse(NodeAddress nodeAddress, RequestInfo requestInfo, @Nullable Map result, @Nullable String errorMessage) { - long responseTime = System.currentTimeMillis(); if (errorMessage != null && !errorMessage.isEmpty()) { log.warn("Error at connection to peer {}: {}", nodeAddress, errorMessage); requestInfo.setErrorMessage(errorMessage); } else { - requestInfo.setResponseTime(responseTime); + requestInfo.setResponseTime(System.currentTimeMillis()); } boolean ignoreDeviationAtStartup; diff --git a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java index cfb74bf2405..6e6f665cafa 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java +++ b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java @@ -191,7 +191,8 @@ private String getSeedNodeInfo(NodeAddress nodeAddress, "n/a"; sb.append("Run duration: ").append(duration).append("
"); - String filteredSeedNodes = requestInfo.getDisplayValue(InventoryItem.filteredSeeds).replace(System.getProperty("line.separator"), "
"); + String filteredSeedNodes = requestInfo.getDisplayValue(InventoryItem.filteredSeeds) + .replace(System.getProperty("line.separator"), "
"); if (filteredSeedNodes.isEmpty()) { filteredSeedNodes = "-"; } @@ -386,16 +387,20 @@ private String getLine(String title, } if (!warningsAtRequestNumber.isEmpty()) { - historicalWarnings = warningsAtRequestNumber.size() + " repeated warning(s) at request(s) " + Joiner.on(", ").join(warningsAtRequestNumber); + historicalWarnings = warningsAtRequestNumber.size() + " repeated warning(s) at request(s) " + + Joiner.on(", ").join(warningsAtRequestNumber); } if (!alertsAtRequestNumber.isEmpty()) { - historicalAlerts = alertsAtRequestNumber.size() + " repeated alert(s) at request(s): " + Joiner.on(", ").join(alertsAtRequestNumber); + historicalAlerts = alertsAtRequestNumber.size() + " repeated alert(s) at request(s): " + + Joiner.on(", ").join(alertsAtRequestNumber); } } String historicalWarningsHtml = warningsAtRequestNumber.isEmpty() ? "" : - ", " + WARNING_ICON + warningsAtRequestNumber.size() + ""; + ", " + WARNING_ICON + + warningsAtRequestNumber.size() + ""; String historicalAlertsHtml = alertsAtRequestNumber.isEmpty() ? "" : - ", " + ALERT_ICON + alertsAtRequestNumber.size() + ""; + ", " + ALERT_ICON + + alertsAtRequestNumber.size() + ""; return title + getColorTagByDeviationSeverity(deviationSeverity) + @@ -473,9 +478,7 @@ private void setupOperatorMap(BufferedReader seedNodeFile) { private String getErrorMsgLine(NodeAddress seedNode, RequestInfo requestInfo, Map> map) { - boolean isError = requestInfo.getErrorMessage() != null && - !requestInfo.getErrorMessage().isEmpty(); - String errorMessage = isError ? requestInfo.getErrorMessage() : "-"; + String errorMessage = requestInfo.hasError() ? requestInfo.getErrorMessage() : "-"; List requestInfoList = map.get(seedNode); List errorsAtRequestNumber = new ArrayList<>(); String historicalErrorsHtml = ""; @@ -484,14 +487,12 @@ private String getErrorMsgLine(NodeAddress seedNode, RequestInfo requestInfo1 = requestInfoList.get(i); // We ignore old errors as at startup timeouts are expected and each node restarts once a day - if (requestInfo1.getRequestStartTime() > 0 && - System.currentTimeMillis() - requestInfo1.getRequestStartTime() > TimeUnit.HOURS.toMillis(24)) { + long duration = System.currentTimeMillis() - requestInfo1.getRequestStartTime(); + if (requestInfo1.getRequestStartTime() > 0 && duration > TimeUnit.HOURS.toMillis(24)) { continue; } - boolean isError1 = requestInfo1.getErrorMessage() != null && - !requestInfo1.getErrorMessage().isEmpty(); - if (isError1) { + if (requestInfo1.hasError()) { errorsAtRequestNumber.add((i + 1) + " (" + requestInfo1.getErrorMessage() + ")"); } } @@ -509,12 +510,14 @@ private String getErrorMsgLine(NodeAddress seedNode, type = "warning"; style = "warn"; } - String historicalAlerts = errorsAtRequestNumber.size() + " repeated " + type + "(s) at request(s): " + Joiner.on(", ").join(errorsAtRequestNumber); + String historicalAlerts = errorsAtRequestNumber.size() + " repeated " + type + "(s) at request(s): " + + Joiner.on(", ").join(errorsAtRequestNumber); historicalErrorsHtml = errorsAtRequestNumber.isEmpty() ? "" : - ", " + errorIcon + errorsAtRequestNumber.size() + ""; + ", " + errorIcon + + errorsAtRequestNumber.size() + ""; } } - DeviationSeverity deviationSeverity = isError ? + DeviationSeverity deviationSeverity = requestInfo.hasError() ? errorsAtRequestNumber.size() > 4 ? DeviationSeverity.ALERT : DeviationSeverity.WARN : DeviationSeverity.OK; From 04ab5077830864e546393b325bec56e0c84d7bef Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 16:23:31 -0500 Subject: [PATCH 17/27] Update COMMIT_HASH to 627888f0 --- .../java/bisq/core/network/p2p/inventory/model/RequestInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java index 925fec690a1..f52aaafe041 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java @@ -29,7 +29,7 @@ @Getter public class RequestInfo { // Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field) - public static final String COMMIT_HASH = "fec8f6e3"; + public static final String COMMIT_HASH = "627888f0"; private final long requestStartTime; @Setter From 86a204528408a81e05cb2989ff2d93007bd5b976 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 22:26:01 -0500 Subject: [PATCH 18/27] Fix wrong kb display --- .../src/main/java/bisq/inventory/InventoryWebServer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java index 6e6f665cafa..e267fed8ce4 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryWebServer.java +++ b/inventory/src/main/java/bisq/inventory/InventoryWebServer.java @@ -305,9 +305,9 @@ private String getNetworkInfo(NodeAddress seedNode, sb.append(getLine("Received messages/sec: ", InventoryItem.receivedMessagesPerSec, seedNode, requestInfo, map, this::getRounded)); sb.append(getLine("Sent kB/sec: ", - InventoryItem.sentBytesPerSec, seedNode, requestInfo, map, this::getRounded)); + InventoryItem.sentBytesPerSec, seedNode, requestInfo, map, this::getKbRounded)); sb.append(getLine("Received kB/sec: ", - InventoryItem.receivedBytesPerSec, seedNode, requestInfo, map, this::getRounded)); + InventoryItem.receivedBytesPerSec, seedNode, requestInfo, map, this::getKbRounded)); sb.append(getLine("Sent data: ", InventoryItem.sentBytes, seedNode, requestInfo, map, value -> Utilities.readableFileSize(Long.parseLong(value)))); @@ -460,6 +460,10 @@ private String getRounded(String value) { return String.valueOf(MathUtils.roundDouble(Double.parseDouble(value), 2)); } + private String getKbRounded(String bytes) { + return String.valueOf(MathUtils.roundDouble(Double.parseDouble(bytes) / 1000, 2)); + } + private void setupOperatorMap(BufferedReader seedNodeFile) { seedNodeFile.lines().forEach(line -> { if (!line.startsWith("#")) { From 69802e232ddfbb3bb371a9f1172cc9bc148787cf Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 8 Nov 2020 22:39:24 -0500 Subject: [PATCH 19/27] Reduce timeout --- .../bisq/core/network/p2p/inventory/GetInventoryRequester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java index 3309703f7fa..9c53375293f 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java @@ -41,7 +41,7 @@ @Slf4j public class GetInventoryRequester implements MessageListener, ConnectionListener { - private final static int TIMEOUT_SEC = 90; + private final static int TIMEOUT_SEC = 45; private final NetworkNode networkNode; private final NodeAddress nodeAddress; From bb095d413ca8e81138eb69c65594aa002249e3f7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 10 Nov 2020 13:07:46 -0500 Subject: [PATCH 20/27] Increase timout to 90 sec --- .../bisq/core/network/p2p/inventory/GetInventoryRequester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java index 9c53375293f..3309703f7fa 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequester.java @@ -41,7 +41,7 @@ @Slf4j public class GetInventoryRequester implements MessageListener, ConnectionListener { - private final static int TIMEOUT_SEC = 45; + private final static int TIMEOUT_SEC = 90; private final NetworkNode networkNode; private final NodeAddress nodeAddress; From 6a2583d5fa20c3a8090785ba988d0b3ec68fda9b Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 10 Nov 2020 13:15:22 -0500 Subject: [PATCH 21/27] Decrease deviationTolerance for numAllConnectionsLostEvents --- .../bisq/core/network/p2p/inventory/model/InventoryItem.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java index ee2405d7ba1..bcdd0d2b4f9 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/InventoryItem.java @@ -102,7 +102,7 @@ public enum InventoryItem { new DeviationByPercentage(0, 3, 0, 2.5), 2), numAllConnectionsLostEvents("numAllConnectionsLostEvents", true, - new DeviationByIntegerDiff(1, 2), 3), + new DeviationByIntegerDiff(1, 2), 1), sentBytesPerSec("sentBytesPerSec", true, new DeviationByPercentage(), 5), @@ -137,6 +137,7 @@ public enum InventoryItem { // The number of past requests we check to see if there have been repeated alerts or warnings. The higher the // number the more repeated alert need to have happened to cause a notification alert. + // Smallest number is 1, as that takes only the last request data and does not look further back. @Getter private int deviationTolerance = 1; From 1b7c1ce49a60f2c3796fdda98ef1caf3dc142660 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 10 Nov 2020 13:17:03 -0500 Subject: [PATCH 22/27] Only reset numAllConnectionsLostEvents if we have nodes connected --- .../network/p2p/inventory/GetInventoryRequestHandler.java | 2 +- p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java index fee82faf2a2..6bd646bc296 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java @@ -141,7 +141,7 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) { inventory.put(InventoryItem.numConnections, String.valueOf(networkNode.getAllConnections().size())); inventory.put(InventoryItem.peakNumConnections, String.valueOf(peerManager.getPeakNumConnections())); inventory.put(InventoryItem.numAllConnectionsLostEvents, String.valueOf(peerManager.getNumAllConnectionsLostEvents())); - peerManager.resetNumAllConnectionsLostEvents(); + peerManager.maybeResetNumAllConnectionsLostEvents(); inventory.put(InventoryItem.sentBytes, String.valueOf(Statistic.totalSentBytesProperty().get())); inventory.put(InventoryItem.sentBytesPerSec, String.valueOf(Statistic.totalSentBytesPerSecProperty().get())); inventory.put(InventoryItem.receivedBytes, String.valueOf(Statistic.totalReceivedBytesProperty().get())); 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 39755d5f04e..de5acc41b9f 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java @@ -326,8 +326,10 @@ private void maybeRemoveBannedPeer(CloseConnectionReason closeConnectionReason, } } - public void resetNumAllConnectionsLostEvents() { - numAllConnectionsLostEvents = 0; + public void maybeResetNumAllConnectionsLostEvents() { + if (!networkNode.getAllConnections().isEmpty()) { + numAllConnectionsLostEvents = 0; + } } From 2486bd512fdf12fb6af30a0eab59e7ce960d38a8 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 10 Nov 2020 14:32:16 -0500 Subject: [PATCH 23/27] Shut down if more then 1 all connections lost events --- .../main/java/bisq/seednode/SeedNodeMain.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index e1b5bf9ba20..2debfb6c21e 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -22,7 +22,9 @@ import bisq.network.p2p.P2PService; import bisq.network.p2p.P2PServiceListener; +import bisq.network.p2p.peers.PeerManager; +import bisq.common.Timer; import bisq.common.UserThread; import bisq.common.app.AppModule; import bisq.common.app.Capabilities; @@ -33,8 +35,10 @@ @Slf4j public class SeedNodeMain extends ExecutableForAppWithP2p { + private static final long CHECK_CONNECTION_LOSS_SEC = 30; private static final String VERSION = "1.4.2"; private SeedNode seedNode; + private Timer checkConnectionLossTime; public SeedNodeMain() { super("Bisq Seednode", "bisq-seednode", "bisq_seednode", VERSION); @@ -126,6 +130,7 @@ public void onTorNodeReady() { @Override public void onHiddenServicePublished() { startShutDownInterval(SeedNodeMain.this); + UserThread.runAfter(() -> setupConnectionLossCheck(), 60); } @Override @@ -140,6 +145,19 @@ public void onRequestCustomBridges() { }); } + private void setupConnectionLossCheck() { + if (checkConnectionLossTime != null) { + return; + } + + checkConnectionLossTime = UserThread.runPeriodically(() -> { + if (injector.getInstance(PeerManager.class).getNumAllConnectionsLostEvents() > 1) { + shutDown(this); + } + }, CHECK_CONNECTION_LOSS_SEC); + + } + @Override public void gracefulShutDown(ResultHandler resultHandler) { seedNode.shutDown(); From 8bc78c852b9a94021409d43f0fce296c83849387 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 10 Nov 2020 14:37:23 -0500 Subject: [PATCH 24/27] Cleanup tor dir if all connections lost --- seednode/src/main/java/bisq/seednode/SeedNodeMain.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index 2debfb6c21e..063369bd07e 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -17,6 +17,7 @@ package bisq.seednode; +import bisq.core.app.TorSetup; import bisq.core.app.misc.ExecutableForAppWithP2p; import bisq.core.app.misc.ModuleForAppWithP2p; @@ -152,7 +153,11 @@ private void setupConnectionLossCheck() { checkConnectionLossTime = UserThread.runPeriodically(() -> { if (injector.getInstance(PeerManager.class).getNumAllConnectionsLostEvents() > 1) { - shutDown(this); + // Removing cache files help in case the node got flagged from Tor's dos protection + injector.getInstance(TorSetup.class).cleanupTorFiles(() -> { + log.info("Tor directory reset"); + shutDown(this); + }, log::error); } }, CHECK_CONNECTION_LOSS_SEC); From 2b807769d4590389bf9ca5bfb4a130deaebd7d5a Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 10 Nov 2020 14:39:04 -0500 Subject: [PATCH 25/27] Update commit hash to 7f83d1b3 --- .../java/bisq/core/network/p2p/inventory/model/RequestInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java index f52aaafe041..5bccb8998f3 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java @@ -29,7 +29,7 @@ @Getter public class RequestInfo { // Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field) - public static final String COMMIT_HASH = "627888f0"; + public static final String COMMIT_HASH = "7f83d1b3"; private final long requestStartTime; @Setter From ee5fca95324ebd125193a787d70e1c2c1cd1eb75 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 12 Nov 2020 16:01:30 -0500 Subject: [PATCH 26/27] Revert timeout changes and MAX_PERMITTED_MESSAGE_SIZE change --- p2p/src/main/java/bisq/network/p2p/network/Connection.java | 4 ++-- .../bisq/network/p2p/peers/getdata/GetDataRequestHandler.java | 2 +- .../bisq/network/p2p/peers/getdata/RequestDataHandler.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/network/Connection.java b/p2p/src/main/java/bisq/network/p2p/network/Connection.java index 8870340b808..3a03fd0231f 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -120,9 +120,9 @@ public enum PeerType { // Leaving some constants package-private for tests to know limits. private static final int PERMITTED_MESSAGE_SIZE = 200 * 1024; // 200 kb - private static final int MAX_PERMITTED_MESSAGE_SIZE = 15 * 1024 * 1024; // 15 MB (425 offers resulted in about 660 kb, mailbox msg will add more to it) offer has usually 2 kb, mailbox 3kb. + private static final int MAX_PERMITTED_MESSAGE_SIZE = 10 * 1024 * 1024; // 10 MB (425 offers resulted in about 660 kb, mailbox msg will add more to it) offer has usually 2 kb, mailbox 3kb. //TODO decrease limits again after testing - private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(360); + private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(180); public static int getPermittedMessageSize() { return PERMITTED_MESSAGE_SIZE; diff --git a/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java b/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java index e7433ad6a68..93fca1d8083 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/getdata/GetDataRequestHandler.java @@ -41,7 +41,7 @@ @Slf4j public class GetDataRequestHandler { - private static final long TIMEOUT = 360; + private static final long TIMEOUT = 180; private static final int MAX_ENTRIES = 10000; diff --git a/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java b/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java index 807b45035ed..e00fdd67bf9 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/getdata/RequestDataHandler.java @@ -53,7 +53,7 @@ @Slf4j class RequestDataHandler implements MessageListener { - private static final long TIMEOUT = 360; + private static final long TIMEOUT = 180; private NodeAddress peersNodeAddress; private String getDataRequestType; From ccfcc351f4b25cfd4989cd753363e252d08ddaaa Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 17 Nov 2020 20:17:44 -0500 Subject: [PATCH 27/27] Clean tor dir at startup --- .../java/bisq/inventory/InventoryMonitor.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/inventory/src/main/java/bisq/inventory/InventoryMonitor.java b/inventory/src/main/java/bisq/inventory/InventoryMonitor.java index 9f863fc8c5b..4eacd79991f 100644 --- a/inventory/src/main/java/bisq/inventory/InventoryMonitor.java +++ b/inventory/src/main/java/bisq/inventory/InventoryMonitor.java @@ -18,6 +18,7 @@ package bisq.inventory; +import bisq.core.app.TorSetup; import bisq.core.network.p2p.inventory.GetInventoryRequestManager; import bisq.core.network.p2p.inventory.model.Average; import bisq.core.network.p2p.inventory.model.DeviationSeverity; @@ -61,8 +62,8 @@ public class InventoryMonitor implements SetupListener { private final File appDir; private final boolean useLocalhostForP2P; private final int intervalSec; - private final NetworkNode networkNode; - private final GetInventoryRequestManager getInventoryRequestManager; + private NetworkNode networkNode; + private GetInventoryRequestManager getInventoryRequestManager; private ArrayList seedNodes; private InventoryWebServer inventoryWebServer; @@ -82,20 +83,25 @@ public InventoryMonitor(File appDir, this.useLocalhostForP2P = useLocalhostForP2P; this.intervalSec = intervalSec; - networkNode = getNetworkNode(appDir); - getInventoryRequestManager = new GetInventoryRequestManager(networkNode); - - // We maintain our own list as we want to monitor also old v2 nodes which are not part of the normal seed - // node list anymore. - String networkName = network.name().toLowerCase(); - String fileName = network.isMainnet() ? "inv_" + networkName : networkName; - DefaultSeedNodeRepository.readSeedNodePropertyFile(fileName) - .ifPresent(bufferedReader -> { - seedNodes = new ArrayList<>(DefaultSeedNodeRepository.getSeedNodeAddressesFromPropertyFile(fileName)); - addJsonFileManagers(seedNodes); - inventoryWebServer = new InventoryWebServer(port, seedNodes, bufferedReader); - networkNode.start(this); - }); + // We get more connectivity issues. Cleaning tor cache files helps usually for those problems. + File torDir = new File(appDir, "tor"); + TorSetup torSetup = new TorSetup(torDir); + torSetup.cleanupTorFiles(() -> { + networkNode = getNetworkNode(torDir); + getInventoryRequestManager = new GetInventoryRequestManager(networkNode); + + // We maintain our own list as we want to monitor also old v2 nodes which are not part of the normal seed + // node list anymore. + String networkName = network.name().toLowerCase(); + String fileName = network.isMainnet() ? "inv_" + networkName : networkName; + DefaultSeedNodeRepository.readSeedNodePropertyFile(fileName) + .ifPresent(bufferedReader -> { + seedNodes = new ArrayList<>(DefaultSeedNodeRepository.getSeedNodeAddressesFromPropertyFile(fileName)); + addJsonFileManagers(seedNodes); + inventoryWebServer = new InventoryWebServer(port, seedNodes, bufferedReader); + networkNode.start(this); + }); + }, log::error); } @@ -247,8 +253,7 @@ private void addJsonFileManagers(List seedNodes) { }); } - private NetworkNode getNetworkNode(File appDir) { - File torDir = new File(appDir, "tor"); + private NetworkNode getNetworkNode(File torDir) { CoreNetworkProtoResolver networkProtoResolver = new CoreNetworkProtoResolver(Clock.systemDefaultZone()); return new NetworkNodeProvider(networkProtoResolver, ArrayList::new,