Changeset 14169


Ignore:
Timestamp:
Aug 18, 2013, 1:06:39 PM (8 years ago)
Author:
jordan
Message:

add inline wrapper functions to tr_torrent to decouple the rest of the code from tr_completion

Location:
trunk/libtransmission
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r14138 r14169  
    920920    req->corrupt = tier->byteCounts[TR_ANN_CORRUPT];
    921921    req->leftUntilComplete = tr_torrentHasMetadata (tor)
    922             ? tor->info.totalSize - tr_cpHaveTotal (&tor->completion)
     922            ? tor->info.totalSize - tr_torrentHaveTotal (tor)
    923923            : ~ (uint64_t)0;
    924924    req->event = event;
    925925    req->numwant = event == TR_ANNOUNCE_EVENT_STOPPED ? 0 : NUMWANT;
    926926    req->key = announcer->key;
    927     req->partial_seed = tr_cpGetStatus (&tor->completion) == TR_PARTIAL_SEED;
     927    req->partial_seed = tr_torrentGetCompleteness (tor) == TR_PARTIAL_SEED;
    928928    tier_build_log_name (tier, req->log_name, sizeof (req->log_name));
    929929    return req;
  • trunk/libtransmission/cache.c

    r13909 r14169  
    106106      const struct cache_block * b = blocks[i-1];
    107107      info->last_block_time = b->time;
    108       info->is_piece_done = tr_cpPieceIsComplete (&b->tor->completion, b->piece);
     108      info->is_piece_done = tr_torrentPieceIsComplete (b->tor, b->piece);
    109109      info->is_multi_piece = b->piece != blocks[pos]->piece ? true : false;
    110110      info->len = i - pos;
  • trunk/libtransmission/completion.h

    r14151 r14169  
    2424typedef struct tr_completion
    2525{
    26     tr_torrent * tor;
     26  tr_torrent * tor;
    2727
    28     tr_bitfield blockBitfield;
     28  tr_bitfield blockBitfield;
    2929
    30     /* number of bytes we'll have when done downloading. [0..info.totalSize]
    31        DON'T access this directly; it's a lazy field.
    32        use tr_cpSizeWhenDone () instead! */
    33     uint64_t sizeWhenDoneLazy;
     30  /* number of bytes we'll have when done downloading. [0..info.totalSize]
     31     DON'T access this directly; it's a lazy field.
     32     use tr_cpSizeWhenDone () instead! */
     33  uint64_t sizeWhenDoneLazy;
    3434
    35     /* whether or not sizeWhenDone needs to be recalculated */
    36     bool sizeWhenDoneIsDirty;
     35  /* whether or not sizeWhenDone needs to be recalculated */
     36  bool sizeWhenDoneIsDirty;
    3737
    38     /* number of bytes we'll have when done downloading. [0..info.totalSize]
    39        DON'T access this directly; it's a lazy field.
    40        use tr_cpHaveValid () instead! */
    41     uint64_t haveValidLazy;
     38  /* number of bytes we'll have when done downloading. [0..info.totalSize]
     39     DON'T access this directly; it's a lazy field.
     40     use tr_cpHaveValid () instead! */
     41  uint64_t haveValidLazy;
    4242
    43     /* whether or not haveValidLazy needs to be recalculated */
    44     bool haveValidIsDirty;
     43  /* whether or not haveValidLazy needs to be recalculated */
     44  bool haveValidIsDirty;
    4545
    46     /* number of bytes we want or have now. [0..sizeWhenDone] */
    47     uint64_t sizeNow;
     46  /* number of bytes we want or have now. [0..sizeWhenDone] */
     47  uint64_t sizeNow;
    4848}
    4949tr_completion;
     
    6060tr_cpDestruct (tr_completion * cp)
    6161{
    62     tr_bitfieldDestruct (&cp->blockBitfield);
     62  tr_bitfieldDestruct (&cp->blockBitfield);
    6363}
    6464
     
    8787tr_cpHaveTotal (const tr_completion * cp)
    8888{
    89     return cp->sizeNow;
     89  return cp->sizeNow;
    9090}
    9191
    9292static inline bool tr_cpHasAll (const tr_completion * cp)
    9393{
    94     return tr_torrentHasMetadata (cp->tor)
    95         && tr_bitfieldHasAll (&cp->blockBitfield);
     94  return tr_torrentHasMetadata (cp->tor)
     95      && tr_bitfieldHasAll (&cp->blockBitfield);
    9696}
    9797
    9898static inline bool tr_cpHasNone (const tr_completion * cp)
    9999{
    100     return !tr_torrentHasMetadata (cp->tor)
    101         || tr_bitfieldHasNone (&cp->blockBitfield);
     100  return !tr_torrentHasMetadata (cp->tor)
     101      || tr_bitfieldHasNone (&cp->blockBitfield);
    102102}
    103103
     
    117117tr_cpPieceIsComplete (const tr_completion * cp, tr_piece_index_t i)
    118118{
    119     return tr_cpMissingBlocksInPiece (cp, i) == 0;
     119  return tr_cpMissingBlocksInPiece (cp, i) == 0;
    120120}
    121121
     
    129129tr_cpBlockIsComplete (const tr_completion * cp, tr_block_index_t i)
    130130{
    131     return tr_bitfieldHas (&cp->blockBitfield, i);
     131  return tr_bitfieldHas (&cp->blockBitfield, i);
    132132}
    133133
     
    143143tr_cpInvalidateDND (tr_completion * cp)
    144144{
    145     cp->sizeWhenDoneIsDirty = true;
     145  cp->sizeWhenDoneIsDirty = true;
    146146}
    147147
  • trunk/libtransmission/peer-mgr.c

    r14167 r14169  
    882882     we've got requested is >= the number of bytes left to download */
    883883  return (s->requestCount * s->tor->blockSize)
    884                >= tr_cpLeftUntilDone (&s->tor->completion);
     884               >= tr_torrentGetLeftUntilDone (s->tor);
    885885}
    886886
     
    956956
    957957  /* primary key: weight */
    958   missing = tr_cpMissingBlocksInPiece (&tor->completion, a->index);
     958  missing = tr_torrentMissingBlocksInPiece (tor, a->index);
    959959  pending = a->requestCount;
    960960  ia = missing > pending ? missing - pending : (tor->blockCountInPiece + pending);
    961   missing = tr_cpMissingBlocksInPiece (&tor->completion, b->index);
     961  missing = tr_torrentMissingBlocksInPiece (tor, b->index);
    962962  pending = b->requestCount;
    963963  ib = missing > pending ? missing - pending : (tor->blockCountInPiece + pending);
     
    10921092      for (i=0; i<inf->pieceCount; ++i)
    10931093        if (!inf->pieces[i].dnd)
    1094           if (!tr_cpPieceIsComplete (&tor->completion, i))
     1094          if (!tr_torrentPieceIsComplete (tor, i))
    10951095            pool[poolCount++] = i;
    10961096      pieceCount = poolCount;
     
    13761376
    13771377              /* don't request blocks we've already got */
    1378               if (tr_cpBlockIsComplete (&tor->completion, b))
     1378              if (tr_torrentBlockIsComplete (tor, b))
    13791379                continue;
    13801380
     
    15811581
    15821582    /* don't ask for it if we've already got it */
    1583     if (tr_cpPieceIsComplete (t->tor->completion, pieceIndex))
     1583    if (tr_torrentPieceIsComplete (t->tor, pieceIndex))
    15841584        return;
    15851585
     
    16031603        for (b=first; b<=last; ++b)
    16041604        {
    1605             if (!tr_cpBlockIsComplete (tor->completion, b))
     1605            if (tr_torrentBlockIsComplete (tor, b))
    16061606            {
    16071607                const uint32_t offset = getBlockOffsetInPiece (tor, b);
     
    25452545      const tr_peer ** peers = (const tr_peer**) tr_ptrArrayBase (&tor->swarm->peers);
    25462546      const float interval = tor->info.pieceCount / (float)tabCount;
    2547       const bool isSeed = tr_cpGetStatus (&tor->completion) == TR_SEED;
     2547      const bool isSeed = tr_torrentGetCompleteness (tor) == TR_SEED;
    25482548
    25492549      for (i=0; i<tabCount; ++i)
     
    25512551          const int piece = i * interval;
    25522552
    2553           if (isSeed || tr_cpPieceIsComplete (&tor->completion, piece))
     2553          if (isSeed || tr_torrentPieceIsComplete (tor, piece))
    25542554            {
    25552555              tab[i] = -1;
     
    26362636      for (i=0; i<n; ++i)
    26372637        if (peers[i]->atom && atomIsSeed (peers[i]->atom))
    2638           return tr_cpLeftUntilDone (&tor->completion);
     2638          return tr_torrentGetLeftUntilDone (tor);
    26392639    }
    26402640
     
    26472647  for (i=0, n=MIN (tor->info.pieceCount, s->pieceReplicationSize); i<n; ++i)
    26482648    if (!tor->info.pieces[i].dnd && (s->pieceReplication[i] > 0))
    2649       desiredAvailable += tr_cpMissingBytesInPiece (&tor->completion, i);
     2649      desiredAvailable += tr_torrentMissingBytesInPiece (tor, i);
    26502650
    26512651  assert (desiredAvailable <= tor->info.totalSize);
     
    29192919      piece_is_interesting = tr_new (bool, n);
    29202920      for (i=0; i<n; i++)
    2921         piece_is_interesting[i] = !tor->info.pieces[i].dnd && !tr_cpPieceIsComplete (&tor->completion, i);
     2921        piece_is_interesting[i] = !tor->info.pieces[i].dnd && !tr_torrentPieceIsComplete (tor, i);
    29222922
    29232923      /* decide WHICH peers to be interested in (based on their cancel-to-block ratio) */
  • trunk/libtransmission/peer-msgs.c

    r14114 r14169  
    13401340    const bool fext = tr_peerIoSupportsFEXT (msgs->io);
    13411341    const int reqIsValid = requestIsValid (msgs, req);
    1342     const int clientHasPiece = reqIsValid && tr_cpPieceIsComplete (&msgs->torrent->completion, req->index);
     1342    const int clientHasPiece = reqIsValid && tr_torrentPieceIsComplete (msgs->torrent, req->index);
    13431343    const int peerIsChoked = msgs->peer_is_choked;
    13441344
     
    17091709        return 0;
    17101710    }
    1711     if (tr_cpPieceIsComplete (&msgs->torrent->completion, req->index)) {
     1711    if (tr_torrentPieceIsComplete (msgs->torrent, req->index)) {
    17121712        dbgmsg (msgs, "we did ask for this message, but the piece is already complete...");
    17131713        return 0;
     
    20072007
    20082008        if (requestIsValid (msgs, &req)
    2009             && tr_cpPieceIsComplete (&msgs->torrent->completion, req.index))
     2009            && tr_torrentPieceIsComplete (msgs->torrent, req.index))
    20102010        {
    20112011            int err;
     
    21272127    assert (tr_torrentHasMetadata (msgs->torrent));
    21282128
    2129     bytes = tr_cpCreatePieceBitfield (&msgs->torrent->completion, &byte_count);
     2129    bytes = tr_torrentCreatePieceBitfield (msgs->torrent, &byte_count);
    21302130    evbuffer_add_uint32 (out, sizeof (uint8_t) + byte_count);
    21312131    evbuffer_add_uint8 (out, BT_BITFIELD);
     
    21422142    const bool fext = tr_peerIoSupportsFEXT (msgs->io);
    21432143
    2144     if (fext && tr_cpHasAll (&msgs->torrent->completion))
     2144    if (fext && tr_torrentHasAll (msgs->torrent))
    21452145    {
    21462146        protocolSendHaveAll (msgs);
    21472147    }
    2148     else if (fext && tr_cpHasNone (&msgs->torrent->completion))
     2148    else if (fext && tr_torrentHasNone (msgs->torrent))
    21492149    {
    21502150        protocolSendHaveNone (msgs);
    21512151    }
    2152     else if (!tr_cpHasNone (&msgs->torrent->completion))
     2152    else if (!tr_torrentHasNone (msgs->torrent))
    21532153    {
    21542154        sendBitfield (msgs);
  • trunk/libtransmission/rpcimpl.c

    r14165 r14169  
    747747          {
    748748            size_t byte_count = 0;
    749             void * bytes = tr_cpCreatePieceBitfield (&tor->completion, &byte_count);
     749            void * bytes = tr_torrentCreatePieceBitfield (tor, &byte_count);
    750750            char * str = tr_base64_encode (bytes, byte_count, NULL);
    751751            tr_variantDictAddStr (d, key, str!=NULL ? str : "");
  • trunk/libtransmission/torrent.c

    r14156 r14169  
    839839setLocalErrorIfFilesDisappeared (tr_torrent * tor)
    840840{
    841   const bool disappeared = (tr_cpHaveTotal (&tor->completion) > 0) && !hasAnyLocalData (tor);
     841  const bool disappeared = (tr_torrentHaveTotal (tor) > 0) && !hasAnyLocalData (tor);
    842842
    843843  if (disappeared)
     
    12941294
    12951295  s->percentDone         = tr_cpPercentDone (&tor->completion);
    1296   s->leftUntilDone       = tr_cpLeftUntilDone (&tor->completion);
     1296  s->leftUntilDone       = tr_torrentGetLeftUntilDone (tor);
    12971297  s->sizeWhenDone        = tr_cpSizeWhenDone (&tor->completion);
    12981298  s->recheckProgress     = s->activity == TR_STATUS_CHECK ? getVerifyProgress (tor) : 0;
     
    13091309  s->uploadedEver     = tor->uploadedCur   + tor->uploadedPrev;
    13101310  s->haveValid        = tr_cpHaveValid (&tor->completion);
    1311   s->haveUnchecked    = tr_cpHaveTotal (&tor->completion) - s->haveValid;
     1311  s->haveUnchecked    = tr_torrentHaveTotal (tor) - s->haveValid;
    13121312  s->desiredAvailable = tr_peerMgrGetDesiredAvailable (tor);
    13131313
     
    14131413      if (first == last)
    14141414        {
    1415           if (tr_cpBlockIsComplete (&tor->completion, first))
     1415          if (tr_torrentBlockIsComplete (tor, first))
    14161416            total = f->length;
    14171417        }
     
    14191419        {
    14201420          /* the first block */
    1421           if (tr_cpBlockIsComplete (&tor->completion, first))
     1421          if (tr_torrentBlockIsComplete (tor, first))
    14221422            total += tor->blockSize - (f->offset % tor->blockSize);
    14231423
     
    14311431
    14321432          /* the last block */
    1433           if (tr_cpBlockIsComplete (&tor->completion, last))
     1433          if (tr_torrentBlockIsComplete (tor, last))
    14341434            total += (f->offset + f->length) - ((uint64_t)tor->blockSize * last);
    14351435        }
     
    32253225tr_torrentGotBlock (tr_torrent * tor, tr_block_index_t block)
    32263226{
    3227   const bool block_is_new = !tr_cpBlockIsComplete (&tor->completion, block);
     3227  const bool block_is_new = !tr_torrentBlockIsComplete (tor, block);
    32283228
    32293229  assert (tr_isTorrent (tor));
     
    32383238
    32393239      p = tr_torBlockPiece (tor, block);
    3240       if (tr_cpPieceIsComplete (&tor->completion, p))
     3240      if (tr_torrentPieceIsComplete (tor, p))
    32413241        {
    32423242          tr_logAddTorDbg (tor, "[LAZY] checking just-completed piece %zu", (size_t)p);
  • trunk/libtransmission/torrent.h

    r14108 r14169  
    324324}
    325325
     326static inline tr_completeness
     327tr_torrentGetCompleteness (const tr_torrent * tor)
     328{
     329    return tor->completeness;
     330}
     331
    326332static inline bool
    327333tr_torrentIsSeed (const tr_torrent * tor)
    328334{
    329     return tor->completeness != TR_LEECH;
     335    return tr_torrentGetCompleteness(tor) != TR_LEECH;
    330336}
    331337
     
    440446const unsigned char * tr_torrentGetPeerId (tr_torrent * tor);
    441447
     448static inline uint64_t
     449tr_torrentGetLeftUntilDone (const tr_torrent * tor)
     450{
     451  return tr_cpLeftUntilDone (&tor->completion);
     452}
     453
     454static inline bool
     455tr_torrentHasAll (const tr_torrent * tor)
     456{
     457  return tr_cpHasAll (&tor->completion);
     458}
     459
     460static inline bool
     461tr_torrentHasNone (const tr_torrent * tor)
     462{
     463  return tr_cpHasNone (&tor->completion);
     464}
     465
     466static inline bool
     467tr_torrentPieceIsComplete (const tr_torrent * tor, tr_piece_index_t i)
     468{
     469  return tr_cpPieceIsComplete (&tor->completion, i);
     470}
     471
     472static inline bool
     473tr_torrentBlockIsComplete (const tr_torrent * tor, tr_block_index_t i)
     474{
     475  return tr_cpBlockIsComplete (&tor->completion, i);
     476}
     477
     478static inline size_t
     479tr_torrentMissingBlocksInPiece (const tr_torrent * tor, tr_piece_index_t i)
     480{
     481  return tr_cpMissingBlocksInPiece (&tor->completion, i);
     482}
     483
     484static inline size_t
     485tr_torrentMissingBytesInPiece (const tr_torrent * tor, tr_piece_index_t i)
     486{
     487  return tr_cpMissingBytesInPiece (&tor->completion, i);
     488}
     489
     490static inline void *
     491tr_torrentCreatePieceBitfield (const tr_torrent * tor, size_t * byte_count)
     492{
     493  return tr_cpCreatePieceBitfield (&tor->completion, byte_count);
     494}
     495
     496static inline uint64_t
     497tr_torrentHaveTotal (const tr_torrent * tor)
     498{
     499  return tr_cpHaveTotal (&tor->completion);
     500}
     501
    442502
    443503static inline bool
    444504tr_torrentIsQueued (const tr_torrent * tor)
    445505{
    446     return tor->isQueued;
     506  return tor->isQueued;
    447507}
    448508
     
    450510tr_torrentGetQueueDirection (const tr_torrent * tor)
    451511{
    452     return tr_torrentIsSeed (tor) ? TR_UP : TR_DOWN;
     512  return tr_torrentIsSeed (tor) ? TR_UP : TR_DOWN;
    453513}
    454514
  • trunk/libtransmission/verify.c

    r13915 r14169  
    7171      /* if we're starting a new piece... */
    7272      if (piecePos == 0)
    73         hadPiece = tr_cpPieceIsComplete (&tor->completion, pieceIndex);
     73        hadPiece = tr_torrentPieceIsComplete (tor, pieceIndex);
    7474
    7575      /* if we're starting a new file... */
Note: See TracChangeset for help on using the changeset viewer.