Changeset 3330


Ignore:
Timestamp:
Oct 8, 2007, 4:10:10 PM (15 years ago)
Author:
charles
Message:
  • fix a bug with uploading encrypted pice data to another peer
  • extra sanity tests when uploading data
File:
1 edited

Legend:

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

    r3317 r3330  
    227227    tr_peerIoWriteUint32( io, out, sizeof(uint8_t) );
    228228    tr_peerIoWriteUint8 ( io, out, choke ? BT_CHOKE : BT_UNCHOKE );
     229}
     230
     231static void
     232protocolSendPiece( tr_peermsgs                * msgs,
     233                   const struct peer_request  * r,
     234                   const uint8_t              * pieceData )
     235{
     236    tr_peerIo * io = msgs->io;
     237    struct evbuffer * out = evbuffer_new( );
     238
     239    dbgmsg( msgs, "sending block %u:%u->%u", r->index, r->offset, r->length );
     240    tr_peerIoWriteUint32( io, out, sizeof(uint8_t) + 2*sizeof(uint32_t) + r->length );
     241    tr_peerIoWriteUint8 ( io, out, BT_PIECE );
     242    tr_peerIoWriteUint32( io, out, r->index );
     243    tr_peerIoWriteUint32( io, out, r->offset );
     244    tr_peerIoWriteBytes ( io, out, pieceData, r->length );
     245    tr_peerIoWriteBuf   ( io, out );
     246
     247    evbuffer_free( out );
    229248}
    230249
     
    13841403        {
    13851404            struct peer_request * r = tr_list_pop_front( &msgs->peerAskedFor );
    1386             uint8_t * tmp = tr_new( uint8_t, r->length );
    1387             const uint32_t msglen = sizeof(uint8_t) + 2*sizeof(uint32_t) + r->length;
    1388             struct evbuffer * out = evbuffer_new( );
    1389             assert( requestIsValid( msgs, r ) );
    1390 
    1391             tr_peerIoWriteUint32( msgs->io, out, msglen );
    1392             tr_peerIoWriteUint8 ( msgs->io, out, BT_PIECE );
    1393             tr_peerIoWriteUint32( msgs->io, out, r->index );
    1394             tr_peerIoWriteUint32( msgs->io, out, r->offset );
    1395             tr_peerIoWriteBuf( msgs->io, out );
    1396 
    1397             tr_ioRead( msgs->torrent, r->index, r->offset, r->length, tmp );
    1398             tr_peerIoWrite( msgs->io, tmp, r->length );
    1399             peerGotBytes( msgs, r->length );
    1400 
    1401             dbgmsg( msgs, "Sending block %u:%u->%u (%d blocks left to send)", r->index, r->offset, r->length, tr_list_size(msgs->peerAskedFor) );
    1402 
     1405            uint8_t * buf = tr_new( uint8_t, r->length );
     1406
     1407            if( requestIsValid( msgs, r )
     1408                && tr_bitfieldHas( msgs->info->have, r->index )
     1409                && !tr_ioRead( msgs->torrent, r->index, r->offset, r->length, buf ) )
     1410            {
     1411                protocolSendPiece( msgs, r, buf );
     1412                peerGotBytes( msgs, r->length );
     1413            }
     1414
     1415            tr_free( buf );
    14031416            tr_free( r );
    1404             tr_free( tmp );
    1405             evbuffer_free( out );
    14061417        }
    14071418    }
Note: See TracChangeset for help on using the changeset viewer.