forked from I2P_Developers/i2p.i2p
snark: cache PeerID.toString()
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user