Ignore:
Timestamp:
Jul 1, 2007, 2:04:18 PM (15 years ago)
Author:
charles
Message:

Fix makemeta infinite loop reported by BentMyWookie?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/makemeta.c

    r2229 r2268  
    7575
    7676static int
    77 bestPieceSize( uint64_t totalSize, int fileCount )
    78 {
    79     const int minPieceSize = 65536; /* arbitrary; 2^16 */
    80     const int maxPieceSize = 16777216; /* arbitrary; 2^24 */
    81     const int desiredMinPiecesPerFile = 10; /* arbitrary */
    82     const unsigned int desiredPieces = fileCount * desiredMinPiecesPerFile;
    83 
    84     /* a good starting range is to have (1024..2048] pieces... */
    85     int pieceSize = 1;
    86     uint64_t log = totalSize;
    87     while( log > 2048 ) {
    88         log >>= 1;
    89         pieceSize <<= 1;
    90     }
    91 
    92     /* now try to have N pieces per average file size...
    93        this will reduce overhead on selective downloading
    94        and increase swarm speed. */
    95     while( ( totalSize / pieceSize ) < desiredPieces )
    96         pieceSize >>= 1;
    97 
    98     /* clamp to our desired range to make sure we
    99        haven't gone too far astray... */
    100     if( pieceSize < minPieceSize ) pieceSize = minPieceSize;
    101     if( pieceSize > maxPieceSize ) pieceSize = maxPieceSize;
    102 
    103     return pieceSize;
     77bestPieceSize( uint64_t totalSize )
     78{
     79    static const uint64_t GiB = 1073741824;
     80    static const uint64_t MiB = 1048576;
     81    static const uint64_t KiB = 1024;
     82
     83    if( totalSize >= (8*GiB) )
     84        return MiB;
     85
     86    if( totalSize <= (8*MiB) )
     87        return 256 * KiB;
     88
     89    return 512 * KiB;
    10490}
    10591
     
    161147           builderFileCompare );
    162148
    163     ret->pieceSize = bestPieceSize( ret->totalSize, ret->fileCount );
     149    ret->pieceSize = bestPieceSize( ret->totalSize );
    164150    ret->pieceCount = ret->pieceSize
    165151        ? (int)( ret->totalSize / ret->pieceSize)
Note: See TracChangeset for help on using the changeset viewer.