Changeset ee0951b5


Ignore:
Timestamp:
Dec 17, 2005 9:22:07 AM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c287bace
Parents:
1eb3ae5
git-author:
jrandom <jrandom> (12/17/05 09:22:07)
git-committer:
zzz <zzz@…> (12/17/05 09:22:07)
Message:

2005-12-17 jrandom

  • Use our faster SHA1, rather than the JVM's within I2PSnark, and let 'piece' sizes grow larger than before.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java

    r1eb3ae5 ree0951b5  
    3636import net.i2p.data.Base64;
    3737import net.i2p.util.Log;
     38import net.i2p.crypto.SHA1;
    3839
    3940/**
     
    299300  public boolean checkPiece(int piece, byte[] bs, int off, int length)
    300301  {
     302    if (true)
     303        return fast_checkPiece(piece, bs, off, length);
     304    else
     305        return orig_checkPiece(piece, bs, off, length);
     306  }
     307  private boolean orig_checkPiece(int piece, byte[] bs, int off, int length) {
    301308    // Check digest
    302309    MessageDigest sha1;
     
    309316        throw new InternalError("No SHA digest available: " + nsae);
    310317      }
     318
     319    sha1.update(bs, off, length);
     320    byte[] hash = sha1.digest();
     321    for (int i = 0; i < 20; i++)
     322      if (hash[i] != piece_hashes[20 * piece + i])
     323        return false;
     324    return true;
     325  }
     326 
     327  private boolean fast_checkPiece(int piece, byte[] bs, int off, int length) {
     328    SHA1 sha1 = new SHA1();
    311329
    312330    sha1.update(bs, off, length);
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r1eb3ae5 ree0951b5  
    320320        } else if (info.getPieces() <= 0) {
    321321            return "No pieces in " + info.getName() + "?  deleting it";
    322         } else if (info.getPieceLength(0) > 1024*1024) {
     322        } else if (info.getPieceLength(0) > 10*1024*1024) {
    323323            return "Pieces are too large in " + info.getName() + " (" + info.getPieceLength(0)/1024 + "KB, deleting it";
    324324        } else if (info.getTotalLength() > 10*1024*1024*1024l) {
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    r1eb3ae5 ree0951b5  
    2626import java.security.NoSuchAlgorithmException;
    2727
     28import net.i2p.crypto.SHA1;
     29
    2830/**
    2931 * Maintains pieces on disk. Can be used to store and retrieve pieces.
     
    130132  private void create() throws IOException
    131133  {
     134    if (true) {
     135        fast_digestCreate();
     136    } else {
     137        orig_digestCreate();
     138    }
     139  }
     140 
     141  private void orig_digestCreate() throws IOException {
    132142    // Calculate piece_hashes
    133143    MessageDigest digest = null;
     
    140150        throw new InternalError(nsa.toString());
    141151      }
     152
     153    byte[] piece_hashes = metainfo.getPieceHashes();
     154
     155    byte[] piece = new byte[piece_size];
     156    for (int i = 0; i < pieces; i++)
     157      {
     158        int length = getUncheckedPiece(i, piece, 0);
     159        digest.update(piece, 0, length);
     160        byte[] hash = digest.digest();
     161        for (int j = 0; j < 20; j++)
     162          piece_hashes[20 * i + j] = hash[j];
     163
     164        bitfield.set(i);
     165
     166        if (listener != null)
     167          listener.storageChecked(this, i, true);
     168      }
     169
     170    if (listener != null)
     171      listener.storageAllChecked(this);
     172
     173    // Reannounce to force recalculating the info_hash.
     174    metainfo = metainfo.reannounce(metainfo.getAnnounce());
     175  }
     176
     177  private void fast_digestCreate() throws IOException {
     178    // Calculate piece_hashes
     179    SHA1 digest = new SHA1();
    142180
    143181    byte[] piece_hashes = metainfo.getPieceHashes();
  • history.txt

    r1eb3ae5 ree0951b5  
    1 $Id: history.txt,v 1.360 2005/12/16 18:18:56 jrandom Exp $
     1$Id: history.txt,v 1.361 2005/12/16 22:47:04 jrandom Exp $
     2
     32005-12-17  jrandom
     4    * Use our faster SHA1, rather than the JVM's within I2PSnark, and let
     5      'piece' sizes grow larger than before.
    26
    372005-12-16  jrandom
Note: See TracChangeset for help on using the changeset viewer.