diff --git a/core/java/src/net/i2p/client/naming/LookupDest.java b/core/java/src/net/i2p/client/naming/LookupDest.java index d131efade..e412f20ed 100644 --- a/core/java/src/net/i2p/client/naming/LookupDest.java +++ b/core/java/src/net/i2p/client/naming/LookupDest.java @@ -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(); diff --git a/core/java/src/net/i2p/data/Certificate.java b/core/java/src/net/i2p/data/Certificate.java index d7ceabaeb..522200098 100644 --- a/core/java/src/net/i2p/data/Certificate.java +++ b/core/java/src/net/i2p/data/Certificate.java @@ -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 diff --git a/core/java/src/net/i2p/data/Destination.java b/core/java/src/net/i2p/data/Destination.java index a8c176df6..3c823a52b 100644 --- a/core/java/src/net/i2p/data/Destination.java +++ b/core/java/src/net/i2p/data/Destination.java @@ -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; } diff --git a/core/java/src/net/i2p/data/PublicKey.java b/core/java/src/net/i2p/data/PublicKey.java index 13b0217f5..a52f6a50b 100644 --- a/core/java/src/net/i2p/data/PublicKey.java +++ b/core/java/src/net/i2p/data/PublicKey.java @@ -25,6 +25,15 @@ public class PublicKey extends SimpleDataStructure { private static final SDSCache _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 diff --git a/core/java/src/net/i2p/data/SigningPublicKey.java b/core/java/src/net/i2p/data/SigningPublicKey.java index 8187b1c18..e2e0cf367 100644 --- a/core/java/src/net/i2p/data/SigningPublicKey.java +++ b/core/java/src/net/i2p/data/SigningPublicKey.java @@ -26,6 +26,15 @@ public class SigningPublicKey extends SimpleDataStructure { private static final SDSCache _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 diff --git a/core/java/src/net/i2p/data/i2cp/DestReplyMessage.java b/core/java/src/net/i2p/data/i2cp/DestReplyMessage.java index 7aaba9c89..788fb36a0 100644 --- a/core/java/src/net/i2p/data/i2cp/DestReplyMessage.java +++ b/core/java/src/net/i2p/data/i2cp/DestReplyMessage.java @@ -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); diff --git a/history.txt b/history.txt index 63449fd25..2796a8d01 100644 --- a/history.txt +++ b/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 diff --git a/router/java/src/net/i2p/router/Blocklist.java b/router/java/src/net/i2p/router/Blocklist.java index 0f68355db..d401f1532 100644 --- a/router/java/src/net/i2p/router/Blocklist.java +++ b/router/java/src/net/i2p/router/Blocklist.java @@ -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) { diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 4e28a2c8d..c10128fe6 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -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 = ""; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java index 0172dfcc6..429489cf0 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java @@ -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 diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index a43d830ce..b55d845ad 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -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++; }