diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerID.java b/apps/i2psnark/java/src/org/klomp/snark/PeerID.java index 16dc9224a99730669a8b49b34d2dbb504924805f..0a71450c7c25188549464ff4bf067900488271c0 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerID.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerID.java @@ -52,6 +52,7 @@ class PeerID implements Comparable<PeerID> private boolean triedDestLookup; private final int hash; private final I2PSnarkUtil util; + private String _toStringCache; public PeerID(byte[] id, Destination address) { @@ -216,13 +217,15 @@ class PeerID implements Comparable<PeerID> } /** - * Returns the String "id@address" where id is the base64 encoded id - * and address is the base64 dest (was the base64 hash of the dest) which + * Returns the String "id@address" where id is the first 4 chars of the base64 encoded id + * and address is the first 6 chars of the base64 dest (was the base64 hash of the dest) which * should match what the bytemonsoon tracker reports on its web pages. */ - @Override + @Override public String toString() { + if (_toStringCache != null) + return _toStringCache; if (id == null || address == null) return "unkn@" + Base64.encode(destHash).substring(0, 6); int nonZero = 0; @@ -232,7 +235,8 @@ class PeerID implements Comparable<PeerID> break; } } - return Base64.encode(id, nonZero, id.length-nonZero).substring(0,4) + "@" + address.toBase64().substring(0,6); + _toStringCache = Base64.encode(id, nonZero, id.length-nonZero).substring(0,4) + "@" + address.toBase64().substring(0,6); + return _toStringCache; } /**