I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit e9b3577e authored by zzz's avatar zzz
Browse files

snark: cache PeerID.toString()

parent 36225014
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment