Ignore:
Timestamp:
Mar 28, 2011, 4:31:05 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) break the mac build and introduce new crashes.

This is partially to address #4145 "Downloads stuck at 100%" by refactoring the bitset, bitfield, and tr_completion; however, the ripple effect is larger than usual so things may get worse in the short term before getting better.

livings124: to fix the mac build, remove bitset.[ch] from xcode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r12233 r12248  
    1414#include <errno.h>
    1515#include <stdarg.h>
    16 #include <stdio.h>
    1716#include <stdlib.h>
    1817#include <string.h>
     
    217216***
    218217**/
    219 
    220 #if 0
    221 static tr_bitfield*
    222 getHave( const struct tr_peermsgs * msgs )
    223 {
    224     if( msgs->peer->have == NULL )
    225         msgs->peer->have = tr_bitfieldNew( msgs->torrent->info.pieceCount );
    226     return msgs->peer->have;
    227 }
    228 #endif
    229218
    230219static inline tr_session*
     
    14181407
    14191408            /* a peer can send the same HAVE message twice... */
    1420             if( !tr_bitsetHas( &msgs->peer->have, ui32 ) ) {
    1421                 tr_bitsetAdd( &msgs->peer->have, ui32 );
     1409            if( !tr_bitfieldHas( &msgs->peer->have, ui32 ) ) {
     1410                tr_bitfieldAdd( &msgs->peer->have, ui32 );
    14221411                fireClientGotHave( msgs, ui32 );
    14231412            }
     
    14261415
    14271416        case BT_BITFIELD: {
    1428             tr_bitfield tmp = TR_BITFIELD_INIT;
    1429             const size_t bitCount = tr_torrentHasMetadata( msgs->torrent )
    1430                                   ? msgs->torrent->info.pieceCount
    1431                                   : msglen * 8;
    1432             tr_bitfieldConstruct( &tmp, bitCount );
     1417            uint8_t * tmp = tr_new( uint8_t, msglen );
    14331418            dbgmsg( msgs, "got a bitfield" );
    1434             tr_peerIoReadBytes( msgs->peer->io, inbuf, tmp.bits, msglen );
    1435             tr_bitsetSetBitfield( &msgs->peer->have, &tmp );
    1436             fireClientGotBitfield( msgs, &tmp );
    1437             tr_bitfieldDestruct( &tmp );
     1419            tr_peerIoReadBytes( msgs->peer->io, inbuf, tmp, msglen );
     1420            tr_bitfieldSetRaw( &msgs->peer->have, tmp, msglen );
     1421            fireClientGotBitfield( msgs, &msgs->peer->have );
    14381422            updatePeerProgress( msgs );
     1423            tr_free( tmp );
    14391424            break;
    14401425        }
     
    15111496            dbgmsg( msgs, "Got a BT_FEXT_HAVE_ALL" );
    15121497            if( fext ) {
    1513                 tr_bitsetSetHaveAll( &msgs->peer->have );
     1498                tr_bitfieldSetHasAll( &msgs->peer->have );
     1499assert( tr_bitfieldHasAll( &msgs->peer->have ) );
    15141500                fireClientGotHaveAll( msgs );
    15151501                updatePeerProgress( msgs );
     
    15231509            dbgmsg( msgs, "Got a BT_FEXT_HAVE_NONE" );
    15241510            if( fext ) {
    1525                 tr_bitsetSetHaveNone( &msgs->peer->have );
     1511                tr_bitfieldSetHasNone( &msgs->peer->have );
    15261512                fireClientGotHaveNone( msgs );
    15271513                updatePeerProgress( msgs );
     
    15661552}
    15671553
    1568 static void
    1569 addPeerToBlamefield( tr_peermsgs * msgs, uint32_t index )
    1570 {
    1571     if( !msgs->peer->blame )
    1572          msgs->peer->blame = tr_bitfieldNew( msgs->torrent->info.pieceCount );
    1573     tr_bitfieldAdd( msgs->peer->blame, index );
    1574 }
    1575 
    15761554/* returns 0 on success, or an errno on failure */
    15771555static int
     
    16111589        return err;
    16121590
    1613     addPeerToBlamefield( msgs, req->index );
     1591    tr_bitfieldAdd( &msgs->peer->blame, req->index );
    16141592    fireGotBlock( msgs, req );
    16151593    return 0;
     
    20161994sendBitfield( tr_peermsgs * msgs )
    20171995{
     1996    size_t byte_count = 0;
    20181997    struct evbuffer * out = msgs->outMessages;
    2019     tr_bitfield * bf = tr_cpCreatePieceBitfield( &msgs->torrent->completion );
    2020 
    2021     evbuffer_add_uint32( out, sizeof( uint8_t ) + bf->byteCount );
     1998    void * bytes = tr_cpCreatePieceBitfield( &msgs->torrent->completion, &byte_count );
     1999
     2000    evbuffer_add_uint32( out, sizeof( uint8_t ) + byte_count );
    20222001    evbuffer_add_uint8 ( out, BT_BITFIELD );
    2023     evbuffer_add       ( out, bf->bits, bf->byteCount );
     2002    evbuffer_add       ( out, bytes, byte_count );
    20242003    dbgmsg( msgs, "sending bitfield... outMessage size is now %zu", evbuffer_get_length( out ) );
    20252004    pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS );
    20262005
    2027     tr_bitfieldFree( bf );
     2006    tr_free( bytes );
    20282007}
    20292008
     
    20332012    const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
    20342013
    2035     if( fext && ( tr_cpBlockBitset( &msgs->torrent->completion )->haveAll ) )
     2014    if( fext && tr_cpHasAll( &msgs->torrent->completion ) )
    20362015    {
    20372016        protocolSendHaveAll( msgs );
    20382017    }
    2039     else if( fext && ( tr_cpBlockBitset( &msgs->torrent->completion )->haveNone ) )
     2018    else if( fext && tr_cpHasNone( &msgs->torrent->completion ) )
    20402019    {
    20412020        protocolSendHaveNone( msgs );
    20422021    }
    2043     else
     2022    else if( !tr_cpHasNone( &msgs->torrent->completion ) )
    20442023    {
    20452024        sendBitfield( msgs );
Note: See TracChangeset for help on using the changeset viewer.