From ff0ccc21e25c0b6e5a729f37c07c97295aa3095c Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 6 Jul 2024 08:45:28 -0400 Subject: [PATCH] fix error popup on delete outdated tor files --- .../p2p/peers/getdata/RequestDataHandler.java | 55 ++++++++++-------- .../peerexchange/PeerExchangeHandler.java | 58 ++++++++++--------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/p2p/src/main/java/haveno/network/p2p/peers/getdata/RequestDataHandler.java b/p2p/src/main/java/haveno/network/p2p/peers/getdata/RequestDataHandler.java index 85a1cc89ca..f155c0e8ce 100644 --- a/p2p/src/main/java/haveno/network/p2p/peers/getdata/RequestDataHandler.java +++ b/p2p/src/main/java/haveno/network/p2p/peers/getdata/RequestDataHandler.java @@ -140,33 +140,38 @@ class RequestDataHandler implements MessageListener { getDataRequestType = getDataRequest.getClass().getSimpleName(); log.info("\n\n>> We send a {} to peer {}\n", getDataRequestType, nodeAddress); networkNode.addMessageListener(this); - SettableFuture future = networkNode.sendMessage(nodeAddress, getDataRequest); - //noinspection UnstableApiUsage - Futures.addCallback(future, new FutureCallback<>() { - @Override - public void onSuccess(Connection connection) { - if (!stopped) { - log.trace("Send {} to {} succeeded.", getDataRequest, nodeAddress); - } else { - log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call." + - "Might be caused by a previous timeout."); - } - } - @Override - public void onFailure(@NotNull Throwable throwable) { - if (!stopped) { - String errorMessage = "Sending getDataRequest to " + nodeAddress + - " failed. That is expected if the peer is offline.\n\t" + - "getDataRequest=" + getDataRequest + "." + - "\n\tException=" + throwable.getMessage(); - handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_FAILURE); - } else { - log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call. " + - "Might be caused by a previous timeout."); + try { + SettableFuture future = networkNode.sendMessage(nodeAddress, getDataRequest); + //noinspection UnstableApiUsage + Futures.addCallback(future, new FutureCallback<>() { + @Override + public void onSuccess(Connection connection) { + if (!stopped) { + log.trace("Send {} to {} succeeded.", getDataRequest, nodeAddress); + } else { + log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call." + + "Might be caused by a previous timeout."); + } } - } - }, MoreExecutors.directExecutor()); + + @Override + public void onFailure(@NotNull Throwable throwable) { + if (!stopped) { + String errorMessage = "Sending getDataRequest to " + nodeAddress + + " failed. That is expected if the peer is offline.\n\t" + + "getDataRequest=" + getDataRequest + "." + + "\n\tException=" + throwable.getMessage(); + handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_FAILURE); + } else { + log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call. " + + "Might be caused by a previous timeout."); + } + } + }, MoreExecutors.directExecutor()); + } catch (Exception e) { + if (!networkNode.isShutDownStarted()) throw e; + } } else { log.warn("We have stopped already. We ignore that requestData call."); } diff --git a/p2p/src/main/java/haveno/network/p2p/peers/peerexchange/PeerExchangeHandler.java b/p2p/src/main/java/haveno/network/p2p/peers/peerexchange/PeerExchangeHandler.java index cd12c17a20..1a929289a0 100644 --- a/p2p/src/main/java/haveno/network/p2p/peers/peerexchange/PeerExchangeHandler.java +++ b/p2p/src/main/java/haveno/network/p2p/peers/peerexchange/PeerExchangeHandler.java @@ -115,35 +115,39 @@ class PeerExchangeHandler implements MessageListener { TIMEOUT, TimeUnit.SECONDS); } - SettableFuture future = networkNode.sendMessage(nodeAddress, getPeersRequest); - Futures.addCallback(future, new FutureCallback() { - @Override - public void onSuccess(Connection connection) { - if (!stopped) { - //TODO - /*if (!connection.getPeersNodeAddressOptional().isPresent()) { - connection.setPeersNodeAddress(nodeAddress); - log.warn("sendGetPeersRequest: !connection.getPeersNodeAddressOptional().isPresent()"); - }*/ - - PeerExchangeHandler.this.connection = connection; - connection.addMessageListener(PeerExchangeHandler.this); - } else { - log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest.onSuccess call."); + try { + SettableFuture future = networkNode.sendMessage(nodeAddress, getPeersRequest); + Futures.addCallback(future, new FutureCallback() { + @Override + public void onSuccess(Connection connection) { + if (!stopped) { + //TODO + /*if (!connection.getPeersNodeAddressOptional().isPresent()) { + connection.setPeersNodeAddress(nodeAddress); + log.warn("sendGetPeersRequest: !connection.getPeersNodeAddressOptional().isPresent()"); + }*/ + + PeerExchangeHandler.this.connection = connection; + connection.addMessageListener(PeerExchangeHandler.this); + } else { + log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest.onSuccess call."); + } } - } - - @Override - public void onFailure(@NotNull Throwable throwable) { - if (!stopped) { - String errorMessage = "Sending getPeersRequest to " + nodeAddress + - " failed. That is expected if the peer is offline. Exception=" + throwable.getMessage(); - handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, nodeAddress); - } else { - log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest.onFailure call."); + + @Override + public void onFailure(@NotNull Throwable throwable) { + if (!stopped) { + String errorMessage = "Sending getPeersRequest to " + nodeAddress + + " failed. That is expected if the peer is offline. Exception=" + throwable.getMessage(); + handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, nodeAddress); + } else { + log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest.onFailure call."); + } } - } - }, MoreExecutors.directExecutor()); + }, MoreExecutors.directExecutor()); + } catch (Exception e) { + if (!networkNode.isShutDownStarted()) throw e; + } } else { log.debug("My node address is still null at sendGetPeersRequest. We ignore that call."); }