Changeset 10332 for trunk/libtransmission/peer-msgs.c
- Timestamp:
- Mar 8, 2010, 4:29:58 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-msgs.c
r10325 r10332 675 675 **/ 676 676 677 static tr_bool678 isPieceInteresting( const tr_peermsgs * msgs,679 tr_piece_index_t piece )680 {681 const tr_torrent * torrent = msgs->torrent;682 683 return ( !torrent->info.pieces[piece].dnd ) /* we want it */684 && ( !tr_cpPieceIsComplete( &torrent->completion, piece ) ) /* !have */685 && ( tr_bitsetHas( &msgs->peer->have, piece ) ); /* peer has it */686 }687 688 /* "interested" means we'll ask for piece data if they unchoke us */689 static tr_bool690 isPeerInteresting( const tr_peermsgs * msgs )691 {692 tr_piece_index_t i;693 const tr_torrent * torrent;694 const tr_bitfield * bitfield;695 const int clientIsSeed = tr_torrentIsSeed( msgs->torrent );696 697 if( clientIsSeed )698 return FALSE;699 700 if( !tr_torrentIsPieceTransferAllowed( msgs->torrent, TR_PEER_TO_CLIENT ) )701 return FALSE;702 703 torrent = msgs->torrent;704 bitfield = tr_cpPieceBitfield( &torrent->completion );705 706 for( i = 0; i < torrent->info.pieceCount; ++i )707 if( isPieceInteresting( msgs, i ) )708 return TRUE;709 710 return FALSE;711 }712 713 677 static void 714 678 sendInterest( tr_peermsgs * msgs, tr_bool clientIsInterested ) … … 729 693 730 694 static void 731 updateInterest( tr_peermsgs * msgs ) 732 { 733 const int i = isPeerInteresting( msgs ); 734 735 if( i != msgs->peer->clientIsInterested ) 736 sendInterest( msgs, i ); 695 updateInterest( tr_peermsgs * msgs UNUSED ) 696 { 697 /* FIXME -- might need to poke the mgr on startup */ 698 } 699 700 void 701 tr_peerMsgsSetInterested( tr_peermsgs * msgs, int isInterested ) 702 { 703 assert( tr_isBool( isInterested ) ); 704 705 if( isInterested != msgs->peer->clientIsInterested ) 706 sendInterest( msgs, isInterested ); 737 707 } 738 708 … … 838 808 { 839 809 struct peer_request req; 810 /*fprintf( stderr, "SENDING CANCEL MESSAGE FOR BLOCK %zu\n\t\tFROM PEER %p ------------------------------------\n", (size_t)block, msgs->peer );*/ 840 811 blockToReq( msgs->torrent, block, &req ); 841 812 protocolSendCancel( msgs, &req ); … … 1469 1440 int i; 1470 1441 struct peer_request r; 1442 const uint64_t now_msec = tr_date( ); 1471 1443 tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.index ); 1472 1444 tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset ); 1473 1445 tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length ); 1446 tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 ); 1447 tr_historyAdd( msgs->peer->cancelsSentToClient, now_msec, 1 ); 1474 1448 dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length ); 1475 1449 … … 1953 1927 else 1954 1928 { 1929 const uint64_t now_msec = tr_date( ); 1955 1930 dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length ); 1956 1931 EVBUFFER_LENGTH(out) += req.length; … … 1959 1934 bytesWritten += EVBUFFER_LENGTH( out ); 1960 1935 msgs->clientSentAnythingAt = now; 1936 tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 ); 1937 tr_historyAdd( msgs->peer->blocksSentToPeer, now_msec, 1 ); 1961 1938 } 1962 1939
Note: See TracChangeset
for help on using the changeset viewer.