show address for display with onion or localhost

This commit is contained in:
woodser 2024-03-20 18:15:35 -04:00
parent 1647a582f5
commit 60c2c12a95
4 changed files with 19 additions and 11 deletions

View file

@ -191,7 +191,7 @@ public class PrivateNotificationManager implements MessageListener {
@Override @Override
public void onFailure(@NotNull Throwable throwable) { 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 + " failed. That is expected if the peer is offline.\n\tping=" + ping +
".\n\tException=" + throwable.getMessage(); ".\n\tException=" + throwable.getMessage();
log.info(errorMessage); log.info(errorMessage);

View file

@ -1233,7 +1233,7 @@ public abstract class DisputeView extends ActivatableView<VBox, Void> implements
long accountAge = accountAgeWitnessService.getAccountAge(item.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing()); long accountAge = accountAgeWitnessService.getAccountAge(item.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing());
String age = DisplayUtils.formatAccountAge(accountAge); String age = DisplayUtils.formatAccountAge(accountAge);
String postFix = CurrencyUtil.isTraditionalCurrency(item.getContract().getOfferPayload().getCurrencyCode()) ? " / " + age : ""; String postFix = CurrencyUtil.isTraditionalCurrency(item.getContract().getOfferPayload().getCurrencyCode()) ? " / " + age : "";
return buyerNodeAddress.getHostNameWithoutPostFix() + " (" + nrOfDisputes + postFix + ")"; return buyerNodeAddress.getAddressForDisplay() + " (" + nrOfDisputes + postFix + ")";
} else } else
return Res.get("shared.na"); return Res.get("shared.na");
} else { } else {
@ -1250,7 +1250,7 @@ public abstract class DisputeView extends ActivatableView<VBox, Void> implements
long accountAge = accountAgeWitnessService.getAccountAge(item.getSellerPaymentAccountPayload(), contract.getSellerPubKeyRing()); long accountAge = accountAgeWitnessService.getAccountAge(item.getSellerPaymentAccountPayload(), contract.getSellerPubKeyRing());
String age = DisplayUtils.formatAccountAge(accountAge); String age = DisplayUtils.formatAccountAge(accountAge);
String postFix = CurrencyUtil.isTraditionalCurrency(item.getContract().getOfferPayload().getCurrencyCode()) ? " / " + age : ""; String postFix = CurrencyUtil.isTraditionalCurrency(item.getContract().getOfferPayload().getCurrencyCode()) ? " / " + age : "";
return sellerNodeAddress.getHostNameWithoutPostFix() + " (" + nrOfDisputes + postFix + ")"; return sellerNodeAddress.getAddressForDisplay() + " (" + nrOfDisputes + postFix + ")";
} else } else
return Res.get("shared.na"); return Res.get("shared.na");
} else { } else {
@ -1470,7 +1470,7 @@ public abstract class DisputeView extends ActivatableView<VBox, Void> implements
private PeerInfoIconDispute createAvatar(Integer tableRowId, Dispute dispute, boolean isBuyer) { private PeerInfoIconDispute createAvatar(Integer tableRowId, Dispute dispute, boolean isBuyer) {
NodeAddress nodeAddress = isBuyer ? dispute.getContract().getBuyerNodeAddress() : dispute.getContract().getSellerNodeAddress(); 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 ? Long accountAge = isBuyer ?
accountAgeWitnessService.getAccountAge(dispute.getBuyerPaymentAccountPayload(), dispute.getContract().getBuyerPubKeyRing()) : accountAgeWitnessService.getAccountAge(dispute.getBuyerPaymentAccountPayload(), dispute.getContract().getBuyerPubKeyRing()) :
accountAgeWitnessService.getAccountAge(dispute.getSellerPaymentAccountPayload(), dispute.getContract().getSellerPubKeyRing()); accountAgeWitnessService.getAccountAge(dispute.getSellerPaymentAccountPayload(), dispute.getContract().getSellerPubKeyRing());

View file

@ -96,7 +96,7 @@ public class FileTransferPart extends NetworkEnvelope implements ExtendedDataSiz
@Override @Override
public String toString() { public String toString() {
return "FileTransferPart{" + return "FileTransferPart{" +
"\n senderNodeAddress='" + senderNodeAddress.getHostNameForDisplay() + '\'' + "\n senderNodeAddress='" + senderNodeAddress.getAddressForDisplay() + '\'' +
",\n uid='" + uid + '\'' + ",\n uid='" + uid + '\'' +
",\n tradeId='" + tradeId + '\'' + ",\n tradeId='" + tradeId + '\'' +
",\n traderId='" + traderId + '\'' + ",\n traderId='" + traderId + '\'' +

View file

@ -74,19 +74,27 @@ public final class NodeAddress implements PersistablePayload, NetworkPayload, Us
return hostName + ":" + port; 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", ""); return hostName.replace(".onion", "");
} }
// tor v3 onions are too long to display for example in a table grid, so this convenience method // 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. // 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. // tor v2 and localhost will be displayed in full, as they are 16 chars or fewer.
public String getHostNameForDisplay() { private String getHostNameForDisplay() {
String work = getHostNameWithoutPostFix(); return shortenAddressForDisplay(getHostNameWithoutPostFix());
if (work.length() > 16) { }
return work.substring(0, 7) + ".." + work.substring(work.length() - 7);
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 // We use just a few chars from the full address to blur the potential receiver for sent network_messages