From bdbb857c3fe01b882eef44c4138dd8fe83cc1a3d Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 20:00:43 -0500 Subject: [PATCH 1/8] Add more logs Signed-off-by: HenrikJannsen --- .../java/bisq/network/p2p/network/Connection.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 049c690e04..a0e134558f 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -202,6 +202,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { if (peersNodeAddress != null) { setPeersNodeAddress(peersNodeAddress); if (networkFilter != null && networkFilter.isPeerBanned(peersNodeAddress)) { + log.warn("We created an outbound connection with a banned peer"); reportInvalidRequest(RuleViolation.PEER_BANNED); } } @@ -232,6 +233,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { if (networkFilter != null && peersNodeAddressOptional.isPresent() && networkFilter.isPeerBanned(peersNodeAddressOptional.get())) { + log.warn("We tried to send a message to a banned peer. message={}", networkEnvelope.getClass().getSimpleName()); reportInvalidRequest(RuleViolation.PEER_BANNED); return; } @@ -678,6 +680,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { } if (networkFilter != null && networkFilter.isPeerBanned(senderNodeAddress)) { + log.warn("We got a message from a banned peer. message={}", sendersNodeAddressMessage.getClass().getSimpleName()); reportInvalidRequest(RuleViolation.PEER_BANNED); return false; } @@ -743,6 +746,8 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { if (networkFilter != null && peersNodeAddressOptional.isPresent() && networkFilter.isPeerBanned(peersNodeAddressOptional.get())) { + + log.warn("We got a message from a banned peer. proto={}", proto); reportInvalidRequest(RuleViolation.PEER_BANNED); return; } @@ -751,7 +756,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { long now = System.currentTimeMillis(); long elapsed = now - lastReadTimeStamp; if (elapsed < 10) { - log.debug("We got 2 network_messages received in less than 10 ms. We set the thread to sleep " + + log.info("We got 2 network_messages received in less than 10 ms. We set the thread to sleep " + "for 20 ms to avoid getting flooded by our peer. lastReadTimeStamp={}, now={}, elapsed={}", lastReadTimeStamp, now, elapsed); Thread.sleep(20); @@ -833,6 +838,10 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { return; } + if (!(networkEnvelope instanceof SendersNodeAddressMessage) && peersNodeAddressOptional.isEmpty()) { + log.info("We got a {} from a peer with yet unknown address on connection with uid={}", networkEnvelope.getClass().getSimpleName(), uid); + } + onMessage(networkEnvelope, this); UserThread.execute(() -> connectionStatistics.addReceivedMsgMetrics(System.currentTimeMillis() - ts, size)); } From 7387b3ac2da9944c60a95c5d365dbe7133b8d690 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 20:19:55 -0500 Subject: [PATCH 2/8] Increase timeout at RequestStateHashesHandler from 2 min. to 3 min Signed-off-by: HenrikJannsen --- .../core/dao/monitoring/network/RequestStateHashesHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/dao/monitoring/network/RequestStateHashesHandler.java b/core/src/main/java/bisq/core/dao/monitoring/network/RequestStateHashesHandler.java index 602677121b..970c893302 100644 --- a/core/src/main/java/bisq/core/dao/monitoring/network/RequestStateHashesHandler.java +++ b/core/src/main/java/bisq/core/dao/monitoring/network/RequestStateHashesHandler.java @@ -46,7 +46,7 @@ import org.jetbrains.annotations.Nullable; @Slf4j abstract class RequestStateHashesHandler implements MessageListener { - private static final long TIMEOUT = 120; + private static final long TIMEOUT = 180; /////////////////////////////////////////////////////////////////////////////////////////// From d3c573fc55663c8c4f24e21417bca16674c97507 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 20:34:01 -0500 Subject: [PATCH 3/8] Add more detail logs Signed-off-by: HenrikJannsen --- .../bisq/network/p2p/network/Connection.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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 a0e134558f..bdd596a649 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -400,9 +400,12 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { List networkEnvelopes = bundleOfEnvelopes.getEnvelopes(); for (NetworkEnvelope networkEnvelope : networkEnvelopes) { // If SendersNodeAddressMessage we do some verifications and apply if successful, otherwise we return false. - if (networkEnvelope instanceof SendersNodeAddressMessage && - !processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope)) { - continue; + if (networkEnvelope instanceof SendersNodeAddressMessage) { + boolean isValid = processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope); + if (!isValid) { + log.warn("Received an invalid {} at processing BundleOfEnvelopes", networkEnvelope.getClass().getSimpleName()); + continue; + } } if (networkEnvelope instanceof AddPersistableNetworkPayloadMessage) { @@ -833,9 +836,12 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { // If SendersNodeAddressMessage we do some verifications and apply if successful, // otherwise we return false. - if (networkEnvelope instanceof SendersNodeAddressMessage && - !processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope)) { - return; + if (networkEnvelope instanceof SendersNodeAddressMessage) { + boolean isValid = processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope); + if (!isValid) { + log.warn("Received invalid {}", networkEnvelope.getClass().getSimpleName()); + return; + } } if (!(networkEnvelope instanceof SendersNodeAddressMessage) && peersNodeAddressOptional.isEmpty()) { From 1497b5ed6acbd82908209881648f79dbd5c0385f Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 21:08:00 -0500 Subject: [PATCH 4/8] Add uid to thread name, shorten address in thread name Signed-off-by: HenrikJannsen --- p2p/src/main/java/bisq/network/p2p/network/Connection.java | 4 ++-- p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java | 6 +++--- 2 files changed, 5 insertions(+), 5 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 bdd596a649..0396621a6a 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -707,10 +707,10 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { @Override public void run() { try { - Thread.currentThread().setName("InputHandler"); + Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(uid, 10)); while (!stopped && !Thread.currentThread().isInterrupted()) { if (!threadNameSet && getPeersNodeAddressOptional().isPresent()) { - Thread.currentThread().setName("InputHandler-" + getPeersNodeAddressOptional().get().getFullAddress()); + Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(getPeersNodeAddressOptional().get().getFullAddress(), 10)); threadNameSet = true; } try { diff --git a/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java b/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java index 4401347f67..86ed00c846 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java +++ b/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java @@ -141,8 +141,7 @@ public abstract class NetworkNode implements MessageListener { SettableFuture resultFuture = SettableFuture.create(); ListenableFuture future = connectionExecutor.submit(() -> { - Thread.currentThread().setName("NetworkNode.connectionExecutor:SendMessage-to-" + peersNodeAddress.getFullAddress()); - + Thread.currentThread().setName("NetworkNode.connectionExecutor:SendMessage-to-" + Utilities.toTruncatedString(peersNodeAddress.getFullAddress(), 10)); if (peersNodeAddress.equals(getNodeAddress())) { log.warn("We are sending a message to ourselves"); } @@ -305,7 +304,8 @@ public abstract class NetworkNode implements MessageListener { try { ListenableFuture future = executor.submit(() -> { String id = connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get().getFullAddress() : connection.getUid(); - Thread.currentThread().setName("NetworkNode:SendMessage-to-" + id); + Thread.currentThread().setName("NetworkNode:SendMessage-to-" + Utilities.toTruncatedString(id, 10)); + connection.sendMessage(networkEnvelope); return connection; }); From 4888ae15ea6ae72cd3d96863e679f31ea429fba9 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 21:13:37 -0500 Subject: [PATCH 5/8] Truncate to length 15 instead of 10 Signed-off-by: HenrikJannsen --- p2p/src/main/java/bisq/network/p2p/network/Connection.java | 4 ++-- p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java | 4 ++-- 2 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 0396621a6a..a6e046b5a1 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -707,10 +707,10 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { @Override public void run() { try { - Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(uid, 10)); + Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(uid, 15)); while (!stopped && !Thread.currentThread().isInterrupted()) { if (!threadNameSet && getPeersNodeAddressOptional().isPresent()) { - Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(getPeersNodeAddressOptional().get().getFullAddress(), 10)); + Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(getPeersNodeAddressOptional().get().getFullAddress(), 15)); threadNameSet = true; } try { diff --git a/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java b/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java index 86ed00c846..71ad6632d7 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java +++ b/p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java @@ -141,7 +141,7 @@ public abstract class NetworkNode implements MessageListener { SettableFuture resultFuture = SettableFuture.create(); ListenableFuture future = connectionExecutor.submit(() -> { - Thread.currentThread().setName("NetworkNode.connectionExecutor:SendMessage-to-" + Utilities.toTruncatedString(peersNodeAddress.getFullAddress(), 10)); + Thread.currentThread().setName("NetworkNode.connectionExecutor:SendMessage-to-" + Utilities.toTruncatedString(peersNodeAddress.getFullAddress(), 15)); if (peersNodeAddress.equals(getNodeAddress())) { log.warn("We are sending a message to ourselves"); } @@ -304,7 +304,7 @@ public abstract class NetworkNode implements MessageListener { try { ListenableFuture future = executor.submit(() -> { String id = connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get().getFullAddress() : connection.getUid(); - Thread.currentThread().setName("NetworkNode:SendMessage-to-" + Utilities.toTruncatedString(id, 10)); + Thread.currentThread().setName("NetworkNode:SendMessage-to-" + Utilities.toTruncatedString(id, 15)); connection.sendMessage(networkEnvelope); return connection; From 7a147ff9e87eaeb726d1d25e1afcee09d045a3f1 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 21:59:24 -0500 Subject: [PATCH 6/8] Reduce log level Signed-off-by: HenrikJannsen --- .../java/bisq/network/p2p/network/Connection.java | 11 ++++------- .../main/java/bisq/network/p2p/peers/PeerManager.java | 2 +- .../p2p/peers/peerexchange/PeerExchangeManager.java | 2 +- 3 files changed, 6 insertions(+), 9 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 a6e046b5a1..6765d0f79e 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -609,13 +609,11 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { if (numRuleViolations >= ruleViolation.maxTolerance) { log.warn("We close connection as we received too many corrupt requests. " + - "numRuleViolations={} " + - "corruptRequest={} " + - "corruptRequests={} " + - "connection with address{} and uid {}", numRuleViolations, ruleViolation, ruleViolations, this.getPeersNodeAddressProperty(), this.getUid()); + "ruleViolations={} " + + "connection with address{} and uid {}", ruleViolations, peersNodeAddressProperty, uid); this.ruleViolation = ruleViolation; if (ruleViolation == RuleViolation.PEER_BANNED) { - log.warn("We close connection due RuleViolation.PEER_BANNED. peersNodeAddress={}", getPeersNodeAddressOptional()); + log.debug("We close connection due RuleViolation.PEER_BANNED. peersNodeAddress={}", getPeersNodeAddressOptional()); shutDown(CloseConnectionReason.PEER_BANNED); } else if (ruleViolation == RuleViolation.INVALID_CLASS) { log.warn("We close connection due RuleViolation.INVALID_CLASS"); @@ -759,7 +757,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { long now = System.currentTimeMillis(); long elapsed = now - lastReadTimeStamp; if (elapsed < 10) { - log.info("We got 2 network_messages received in less than 10 ms. We set the thread to sleep " + + log.debug("We got 2 network_messages received in less than 10 ms. We set the thread to sleep " + "for 20 ms to avoid getting flooded by our peer. lastReadTimeStamp={}, now={}, elapsed={}", lastReadTimeStamp, now, elapsed); Thread.sleep(20); @@ -839,7 +837,6 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { if (networkEnvelope instanceof SendersNodeAddressMessage) { boolean isValid = processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope); if (!isValid) { - log.warn("Received invalid {}", networkEnvelope.getClass().getSimpleName()); return; } } 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 7d9e649b89..3cd8e00ade 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java @@ -234,7 +234,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost @Override public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) { - log.info("onDisconnect called: nodeAddress={}, closeConnectionReason={}", + log.debug("onDisconnect called: nodeAddress={}, closeConnectionReason={}", connection.getPeersNodeAddressOptional(), closeConnectionReason); handleConnectionFault(connection); diff --git a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeManager.java b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeManager.java index 59e00581bf..e195a34f6f 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeManager.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/peerexchange/PeerExchangeManager.java @@ -136,7 +136,7 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener, @Override public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) { - log.info("onDisconnect closeConnectionReason={}, nodeAddressOpt={}", closeConnectionReason, connection.getPeersNodeAddressOptional()); + log.debug("onDisconnect closeConnectionReason={}, nodeAddressOpt={}", closeConnectionReason, connection.getPeersNodeAddressOptional()); closeHandler(connection); if (retryTimer == null) { From 69b0bfa676c3b3d2033ab10958616dabd2fada3e Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 22:12:55 -0500 Subject: [PATCH 7/8] remove stacktrace Signed-off-by: HenrikJannsen --- p2p/src/main/java/bisq/network/p2p/network/Connection.java | 1 - 1 file changed, 1 deletion(-) 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 6765d0f79e..de8b961c0c 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -854,7 +854,6 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { reportInvalidRequest(RuleViolation.INVALID_CLASS); } catch (ProtobufferException | NoClassDefFoundError | InvalidProtocolBufferException e) { log.error(e.getMessage()); - e.printStackTrace(); reportInvalidRequest(RuleViolation.INVALID_DATA_TYPE); } catch (Throwable t) { handleException(t); From ef7bb81b29b8d783ef3eb434b9ebc648b795b759 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 22:18:21 -0500 Subject: [PATCH 8/8] truncate logged proto Signed-off-by: HenrikJannsen --- p2p/src/main/java/bisq/network/p2p/network/Connection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 de8b961c0c..a96cf7df10 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -748,7 +748,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { peersNodeAddressOptional.isPresent() && networkFilter.isPeerBanned(peersNodeAddressOptional.get())) { - log.warn("We got a message from a banned peer. proto={}", proto); + log.warn("We got a message from a banned peer. proto={}", Utilities.toTruncatedString(proto)); reportInvalidRequest(RuleViolation.PEER_BANNED); return; }