From 60c2c12a95b2de5b15cf57333523711b1c9cd911 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 20 Mar 2024 18:15:35 -0400 Subject: [PATCH] show address for display with onion or localhost --- .../alert/PrivateNotificationManager.java | 2 +- .../main/support/dispute/DisputeView.java | 6 +++--- .../haveno/network/p2p/FileTransferPart.java | 2 +- .../java/haveno/network/p2p/NodeAddress.java | 20 +++++++++++++------ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/haveno/core/alert/PrivateNotificationManager.java b/core/src/main/java/haveno/core/alert/PrivateNotificationManager.java index 0d3274539e..36b7a54244 100644 --- a/core/src/main/java/haveno/core/alert/PrivateNotificationManager.java +++ b/core/src/main/java/haveno/core/alert/PrivateNotificationManager.java @@ -191,7 +191,7 @@ public class PrivateNotificationManager implements MessageListener { @Override public void onFailure(@NotNull Throwable throwable) { - String errorMessage = "Sending ping to " + peersNodeAddress.getHostNameForDisplay() + + String errorMessage = "Sending ping to " + peersNodeAddress.getAddressForDisplay() + " failed. That is expected if the peer is offline.\n\tping=" + ping + ".\n\tException=" + throwable.getMessage(); log.info(errorMessage); diff --git a/desktop/src/main/java/haveno/desktop/main/support/dispute/DisputeView.java b/desktop/src/main/java/haveno/desktop/main/support/dispute/DisputeView.java index f05409ec11..599ed4d267 100644 --- a/desktop/src/main/java/haveno/desktop/main/support/dispute/DisputeView.java +++ b/desktop/src/main/java/haveno/desktop/main/support/dispute/DisputeView.java @@ -1233,7 +1233,7 @@ public abstract class DisputeView extends ActivatableView implements long accountAge = accountAgeWitnessService.getAccountAge(item.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing()); String age = DisplayUtils.formatAccountAge(accountAge); String postFix = CurrencyUtil.isTraditionalCurrency(item.getContract().getOfferPayload().getCurrencyCode()) ? " / " + age : ""; - return buyerNodeAddress.getHostNameWithoutPostFix() + " (" + nrOfDisputes + postFix + ")"; + return buyerNodeAddress.getAddressForDisplay() + " (" + nrOfDisputes + postFix + ")"; } else return Res.get("shared.na"); } else { @@ -1250,7 +1250,7 @@ public abstract class DisputeView extends ActivatableView implements long accountAge = accountAgeWitnessService.getAccountAge(item.getSellerPaymentAccountPayload(), contract.getSellerPubKeyRing()); String age = DisplayUtils.formatAccountAge(accountAge); String postFix = CurrencyUtil.isTraditionalCurrency(item.getContract().getOfferPayload().getCurrencyCode()) ? " / " + age : ""; - return sellerNodeAddress.getHostNameWithoutPostFix() + " (" + nrOfDisputes + postFix + ")"; + return sellerNodeAddress.getAddressForDisplay() + " (" + nrOfDisputes + postFix + ")"; } else return Res.get("shared.na"); } else { @@ -1470,7 +1470,7 @@ public abstract class DisputeView extends ActivatableView implements private PeerInfoIconDispute createAvatar(Integer tableRowId, Dispute dispute, boolean isBuyer) { NodeAddress nodeAddress = isBuyer ? dispute.getContract().getBuyerNodeAddress() : dispute.getContract().getSellerNodeAddress(); - String key = tableRowId + nodeAddress.getHostNameWithoutPostFix() + (isBuyer ? "BUYER" : "SELLER"); + String key = tableRowId + nodeAddress.getAddressForDisplay() + (isBuyer ? "BUYER" : "SELLER"); Long accountAge = isBuyer ? accountAgeWitnessService.getAccountAge(dispute.getBuyerPaymentAccountPayload(), dispute.getContract().getBuyerPubKeyRing()) : accountAgeWitnessService.getAccountAge(dispute.getSellerPaymentAccountPayload(), dispute.getContract().getSellerPubKeyRing()); diff --git a/p2p/src/main/java/haveno/network/p2p/FileTransferPart.java b/p2p/src/main/java/haveno/network/p2p/FileTransferPart.java index 624b782d28..9cc04cefd9 100644 --- a/p2p/src/main/java/haveno/network/p2p/FileTransferPart.java +++ b/p2p/src/main/java/haveno/network/p2p/FileTransferPart.java @@ -96,7 +96,7 @@ public class FileTransferPart extends NetworkEnvelope implements ExtendedDataSiz @Override public String toString() { return "FileTransferPart{" + - "\n senderNodeAddress='" + senderNodeAddress.getHostNameForDisplay() + '\'' + + "\n senderNodeAddress='" + senderNodeAddress.getAddressForDisplay() + '\'' + ",\n uid='" + uid + '\'' + ",\n tradeId='" + tradeId + '\'' + ",\n traderId='" + traderId + '\'' + diff --git a/p2p/src/main/java/haveno/network/p2p/NodeAddress.java b/p2p/src/main/java/haveno/network/p2p/NodeAddress.java index b2d89716e9..37fe311ffb 100644 --- a/p2p/src/main/java/haveno/network/p2p/NodeAddress.java +++ b/p2p/src/main/java/haveno/network/p2p/NodeAddress.java @@ -74,19 +74,27 @@ public final class NodeAddress implements PersistablePayload, NetworkPayload, Us return hostName + ":" + port; } - public String getHostNameWithoutPostFix() { + public String getAddressForDisplay() { + if (hostName.endsWith(".onion")) return getHostNameForDisplay(); + else return shortenAddressForDisplay(getFullAddress()); + } + + private String getHostNameWithoutPostFix() { return hostName.replace(".onion", ""); } // tor v3 onions are too long to display for example in a table grid, so this convenience method // produces a display-friendly format which includes [first 7]..[last 7] characters. // tor v2 and localhost will be displayed in full, as they are 16 chars or fewer. - public String getHostNameForDisplay() { - String work = getHostNameWithoutPostFix(); - if (work.length() > 16) { - return work.substring(0, 7) + ".." + work.substring(work.length() - 7); + private String getHostNameForDisplay() { + return shortenAddressForDisplay(getHostNameWithoutPostFix()); + } + + private String shortenAddressForDisplay(String address) { + if (address.length() > 16) { + return address.substring(0, 7) + ".." + address.substring(address.length() - 7); } - return work; + return address; } // We use just a few chars from the full address to blur the potential receiver for sent network_messages