* 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);
|
||||
|
14
history.txt
14
history.txt
@ -1,3 +1,17 @@
|
||||
2010-12-31 zzz
|
||||
* Console:
|
||||
- Make themes and history.txt return 403 on error,
|
||||
not 500, to avoid the new error page
|
||||
- Add logging, enable with routerconsole.log=filename
|
||||
- Link to full history.txt on help page
|
||||
* Data Structures: Caching cleanups
|
||||
* Datagram Dissector: Fix RuntimeException caused by reuse,
|
||||
preventing iMule from connecting on UDP
|
||||
(thanks devzero)
|
||||
* i2psnark:
|
||||
- Send cache directive for in-war icons
|
||||
* OCMOSJ: Refactor cache keys for efficiency
|
||||
|
||||
2010-12-30 zzz
|
||||
* Data Structures:
|
||||
- New SDSCache for SimpleDataStructures
|
||||
|
@ -305,7 +305,7 @@ public class Blocklist {
|
||||
if (end1 - start1 == 44 && buf.substring(start1).indexOf(".") < 0) {
|
||||
byte b[] = Base64.decode(buf.substring(start1));
|
||||
if (b != null)
|
||||
return new Entry(comment, new Hash(b), null, null);
|
||||
return new Entry(comment, Hash.create(b), null, null);
|
||||
}
|
||||
index = buf.indexOf("-", start1);
|
||||
if (index >= 0) {
|
||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 5;
|
||||
public final static long BUILD = 6;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
|
@ -18,6 +18,7 @@ import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataStructure;
|
||||
import net.i2p.data.Hash;
|
||||
@ -481,8 +482,12 @@ class PersistentDataStore extends TransientDataStore {
|
||||
try {
|
||||
String key = filename.substring(prefix.length());
|
||||
key = key.substring(0, key.length() - suffix.length());
|
||||
Hash h = new Hash();
|
||||
h.fromBase64(key);
|
||||
//Hash h = new Hash();
|
||||
//h.fromBase64(key);
|
||||
byte[] b = Base64.decode(key);
|
||||
if (b == null)
|
||||
return null;
|
||||
Hash h = Hash.create(b);
|
||||
return h;
|
||||
} catch (Exception e) {
|
||||
// static
|
||||
|
@ -937,11 +937,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
RouterAddress addr = _externalAddress;
|
||||
UDPAddress ua = new UDPAddress(addr);
|
||||
int valid = 0;
|
||||
Hash peerHash = new Hash();
|
||||
for (int i = 0; i < ua.getIntroducerCount(); i++) {
|
||||
// warning: this is only valid as long as we use the ident hash as their key.
|
||||
peerHash.setData(ua.getIntroducerKey(i));
|
||||
PeerState peer = getPeerState(peerHash);
|
||||
PeerState peer = getPeerState(Hash.create(ua.getIntroducerKey(i)));
|
||||
if (peer != null)
|
||||
valid++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user