hash caching

This commit is contained in:
zzz
2012-06-05 01:03:39 +00:00
parent 3f40487c99
commit 6a1b90f8f8
3 changed files with 12 additions and 12 deletions

View File

@ -405,8 +405,8 @@ public class I2PSnarkUtil {
if (sess != null) { if (sess != null) {
byte[] b = Base32.decode(ip.substring(0, BASE32_HASH_LENGTH)); byte[] b = Base32.decode(ip.substring(0, BASE32_HASH_LENGTH));
if (b != null) { if (b != null) {
Hash h = new Hash(b); //Hash h = new Hash(b);
//Hash h = Hash.create(b); Hash h = Hash.create(b);
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Using existing session for lookup of " + ip); _log.info("Using existing session for lookup of " + ip);
try { try {

View File

@ -393,7 +393,8 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
public void announce(byte[] ih, byte[] peerHash) { public void announce(byte[] ih, byte[] peerHash) {
InfoHash iHash = new InfoHash(ih); InfoHash iHash = new InfoHash(ih);
_tracker.announce(iHash, new Hash(peerHash)); _tracker.announce(iHash, new Hash(peerHash));
// _tracker.announce(iHash, Hash.create(peerHash)); // Do NOT do this, corrupts the Hash cache and the Peer ID
//_tracker.announce(iHash, Hash.create(peerHash));
} }
/** /**
@ -1185,8 +1186,8 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
List<Hash> rv = new ArrayList(peers.size()); List<Hash> rv = new ArrayList(peers.size());
for (BEValue bev : peers) { for (BEValue bev : peers) {
byte[] b = bev.getBytes(); byte[] b = bev.getBytes();
Hash h = new Hash(b); //Hash h = new Hash(b);
//Hash h = Hash.create(b); Hash h = Hash.create(b);
rv.add(h); rv.add(h);
} }
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))

View File

@ -101,8 +101,8 @@ class NodeInfo extends SimpleDataStructure {
byte[] h = Base64.decode(parts[1]); byte[] h = Base64.decode(parts[1]);
if (h == null) if (h == null)
throw new DataFormatException("Bad hash"); throw new DataFormatException("Bad hash");
hash = new Hash(h); //hash = new Hash(h);
//hash = Hash.create(h); hash = Hash.create(h);
if (parts[2].length() > 0) if (parts[2].length() > 0)
dest = new Destination(parts[2]); dest = new Destination(parts[2]);
try { try {
@ -123,11 +123,10 @@ class NodeInfo extends SimpleDataStructure {
byte[] ndata = new byte[NID.HASH_LENGTH]; byte[] ndata = new byte[NID.HASH_LENGTH];
System.arraycopy(compactInfo, 0, ndata, 0, NID.HASH_LENGTH); System.arraycopy(compactInfo, 0, ndata, 0, NID.HASH_LENGTH);
this.nID = new NID(ndata); this.nID = new NID(ndata);
//3 lines or... //byte[] hdata = new byte[Hash.HASH_LENGTH];
byte[] hdata = new byte[Hash.HASH_LENGTH]; //System.arraycopy(compactInfo, NID.HASH_LENGTH, hdata, 0, Hash.HASH_LENGTH);
System.arraycopy(compactInfo, NID.HASH_LENGTH, hdata, 0, Hash.HASH_LENGTH); //this.hash = new Hash(hdata);
this.hash = new Hash(hdata); this.hash = Hash.create(compactInfo, NID.HASH_LENGTH);
//this.hash = Hash.create(compactInfo, NID.HASH_LENGTH);
this.port = (int) DataHelper.fromLong(compactInfo, NID.HASH_LENGTH + Hash.HASH_LENGTH, 2); this.port = (int) DataHelper.fromLong(compactInfo, NID.HASH_LENGTH + Hash.HASH_LENGTH, 2);
if (port <= 0 || port >= 65535) if (port <= 0 || port >= 65535)
throw new IllegalArgumentException("Bad port"); throw new IllegalArgumentException("Bad port");