forked from I2P_Developers/i2p.i2p
* Data Structures: More caching and cleanups
This commit is contained in:
@@ -54,7 +54,7 @@ class LookupDest {
|
||||
|
||||
/** @param h 32 byte hash */
|
||||
static Destination lookupHash(I2PAppContext ctx, byte[] h) {
|
||||
Hash key = new Hash(h);
|
||||
Hash key = Hash.create(h);
|
||||
Destination rv = null;
|
||||
try {
|
||||
I2PClient client = new I2PSimpleClient();
|
||||
|
@@ -43,6 +43,24 @@ public class Certificate extends DataStructureImpl {
|
||||
/** Contains multiple certs */
|
||||
public final static int CERTIFICATE_TYPE_MULTIPLE = 4;
|
||||
|
||||
/**
|
||||
* Pull from cache or return new
|
||||
* @throws AIOOBE if not enough bytes
|
||||
* @since 0.8.3
|
||||
*/
|
||||
public static Certificate create(byte[] data, int off) {
|
||||
int type = data[off] & 0xff;
|
||||
int length = (int) DataHelper.fromLong(data, off + 1, 2);
|
||||
if (type == 0 && length == 0)
|
||||
return NULL_CERT;
|
||||
// from here down roughly the same as readBytes() below
|
||||
if (length == 0)
|
||||
return new Certificate(type, null);
|
||||
byte[] payload = new byte[length];
|
||||
System.arraycopy(data, off = 3, payload, 0, length);
|
||||
return new Certificate(type, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* If null cert, return immutable static instance, else create new
|
||||
* @since 0.8.3
|
||||
|
@@ -49,20 +49,14 @@ public class Destination extends KeysAndCert {
|
||||
throw new DataFormatException("Not enough data (len=" + source.length + " off=" + offset + ")");
|
||||
int cur = offset;
|
||||
|
||||
_publicKey = new PublicKey();
|
||||
byte buf[] = new byte[PublicKey.KEYSIZE_BYTES];
|
||||
System.arraycopy(source, cur, buf, 0, PublicKey.KEYSIZE_BYTES);
|
||||
_publicKey.setData(buf);
|
||||
_publicKey = PublicKey.create(source, cur);
|
||||
cur += PublicKey.KEYSIZE_BYTES;
|
||||
|
||||
_signingKey = new SigningPublicKey();
|
||||
buf = new byte[SigningPublicKey.KEYSIZE_BYTES];
|
||||
System.arraycopy(source, cur, buf, 0, SigningPublicKey.KEYSIZE_BYTES);
|
||||
_signingKey.setData(buf);
|
||||
_signingKey = SigningPublicKey.create(source, cur);
|
||||
cur += SigningPublicKey.KEYSIZE_BYTES;
|
||||
|
||||
_certificate = new Certificate();
|
||||
cur += _certificate.readBytes(source, cur);
|
||||
_certificate = Certificate.create(source, cur);
|
||||
cur += _certificate.size();
|
||||
|
||||
return cur - offset;
|
||||
}
|
||||
|
@@ -25,6 +25,15 @@ public class PublicKey extends SimpleDataStructure {
|
||||
|
||||
private static final SDSCache<PublicKey> _cache = new SDSCache(PublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);
|
||||
|
||||
/**
|
||||
* Pull from cache or return new
|
||||
* @throws AIOOBE if not enough bytes
|
||||
* @since 0.8.3
|
||||
*/
|
||||
public static PublicKey create(byte[] data, int off) {
|
||||
return _cache.get(data, off);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull from cache or return new
|
||||
* @since 0.8.3
|
||||
|
@@ -26,6 +26,15 @@ public class SigningPublicKey extends SimpleDataStructure {
|
||||
|
||||
private static final SDSCache<SigningPublicKey> _cache = new SDSCache(SigningPublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);
|
||||
|
||||
/**
|
||||
* Pull from cache or return new
|
||||
* @throws AIOOBE if not enough bytes
|
||||
* @since 0.8.3
|
||||
*/
|
||||
public static SigningPublicKey create(byte[] data, int off) {
|
||||
return _cache.get(data, off);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull from cache or return new
|
||||
* @since 0.8.3
|
||||
|
@@ -60,9 +60,7 @@ public class DestReplyMessage extends I2CPMessageImpl {
|
||||
} else {
|
||||
try {
|
||||
if (size == Hash.HASH_LENGTH) {
|
||||
Hash h = new Hash();
|
||||
h.readBytes(in);
|
||||
_hash = h;
|
||||
_hash = Hash.create(in);
|
||||
} else {
|
||||
Destination d = new Destination();
|
||||
d.readBytes(in);
|
||||
|
Reference in New Issue
Block a user