Changeset 3842
- Timestamp:
- Nov 16, 2007, 9:58:11 PM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-io.c
r3841 r3842 30 30 #define IO_TIMEOUT_SECS 8 31 31 32 #define TR_RDBUF 2048 32 /* arbitrary. */ 33 #define TR_RDBUF (1024*6) 33 34 34 35 /** -
trunk/libtransmission/peer-msgs.c
r3839 r3842 141 141 time_t clientSentAnythingAt; 142 142 143 unsigned int notListening : 1;144 143 unsigned int peerSupportsPex : 1; 145 144 unsigned int clientSentLtepHandshake : 1; … … 875 874 876 875 static int 877 readBtLength( tr_peermsgs * msgs, struct evbuffer * inbuf )876 readBtLength( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) 878 877 { 879 878 uint32_t len; 880 879 881 if( EVBUFFER_LENGTH(inbuf)< sizeof(len) )880 if( inlen < sizeof(len) ) 882 881 return READ_MORE; 883 882 … … 896 895 897 896 static int 898 readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf );897 readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ); 899 898 900 899 static int 901 readBtId( tr_peermsgs * msgs, struct evbuffer * inbuf )900 readBtId( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) 902 901 { 903 902 uint8_t id; 904 903 905 if( EVBUFFER_LENGTH(inbuf)< sizeof(uint8_t) )904 if( inlen < sizeof(uint8_t) ) 906 905 return READ_MORE; 907 906 … … 919 918 return READ_AGAIN; 920 919 } 921 else return readBtMessage( msgs, inbuf );920 else return readBtMessage( msgs, inbuf, inlen-1 ); 922 921 } 923 922 … … 1030 1029 1031 1030 static int 1032 readBtPiece( tr_peermsgs * msgs, struct evbuffer * inbuf )1031 readBtPiece( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) 1033 1032 { 1034 1033 struct peer_request * req = &msgs->incoming.blockReq; … … 1037 1036 if( !req->length ) 1038 1037 { 1039 if( EVBUFFER_LENGTH( inbuf )< 8 )1038 if( inlen < 8 ) 1040 1039 return READ_MORE; 1041 1040 … … 1052 1051 /* read in another chunk of data */ 1053 1052 const size_t nLeft = req->length - EVBUFFER_LENGTH(msgs->incoming.block); 1054 size_t n = MIN( nLeft, EVBUFFER_LENGTH(inbuf));1053 size_t n = MIN( nLeft, inlen ); 1055 1054 uint8_t * buf = tr_new( uint8_t, n ); 1056 1055 tr_peerIoReadBytes( msgs->io, inbuf, buf, n ); … … 1080 1079 1081 1080 static int 1082 readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf )1081 readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) 1083 1082 { 1084 1083 uint32_t ui32; … … 1091 1090 --msglen; // id length 1092 1091 1093 if( EVBUFFER_LENGTH(inbuf)< msglen ) {1092 if( inlen < msglen ) { 1094 1093 dbgmsg( msgs, " too short!!! " ); 1095 1094 return READ_MORE; 1096 1095 } 1097 1096 1098 dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, (int)msglen, (int) EVBUFFER_LENGTH(inbuf));1097 dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, (int)msglen, (int)inlen ); 1099 1098 1100 1099 if( !messageLengthIsCorrect( msgs, id, msglen+1 ) ) … … 1265 1264 } 1266 1265 1267 static int 1268 canDownload( const tr_peermsgs * msgs ) 1269 { 1270 tr_torrent * tor = msgs->torrent; 1266 static size_t 1267 getDownloadMax( const tr_peermsgs * msgs ) 1268 { 1269 static const size_t maxval = ~0; 1270 const tr_torrent * tor = msgs->torrent; 1271 1271 1272 1272 if( tor->downloadLimitMode == TR_SPEEDLIMIT_GLOBAL ) 1273 return !tor->handle->useDownloadLimit || tr_rcCanTransfer( tor->handle->download ); 1273 return tor->handle->useDownloadLimit 1274 ? tr_rcBytesLeft( tor->handle->download ) : maxval; 1274 1275 1275 1276 if( tor->downloadLimitMode == TR_SPEEDLIMIT_SINGLE ) 1276 return tr_rc CanTransfer( tor->download );1277 1278 return TRUE;1277 return tr_rcBytesLeft( tor->download ); 1278 1279 return maxval; 1279 1280 } 1280 1281 … … 1407 1408 tr_peermsgs * msgs = (tr_peermsgs *) vmsgs; 1408 1409 struct evbuffer * inbuf = EVBUFFER_INPUT ( evin ); 1409 1410 dbgmsg( msgs, "canRead, state is %d", msgs->state ); 1411 if( !canDownload( msgs ) ) 1412 { 1413 dbgmsg( msgs, "oh, but canDownload failed" ); 1414 msgs->notListening = 1; 1410 const size_t buflen = EVBUFFER_LENGTH( inbuf ); 1411 const size_t inlen = MIN( buflen, getDownloadMax( msgs ) ); 1412 1413 if( !inlen ) 1414 { 1415 1415 ret = READ_DONE; 1416 1416 } 1417 1417 else switch( msgs->state ) 1418 1418 { 1419 case AWAITING_BT_LENGTH: ret = readBtLength ( msgs, inbuf); break;1420 case AWAITING_BT_ID: ret = readBtId ( msgs, inbuf); break;1421 case AWAITING_BT_MESSAGE: ret = readBtMessage ( msgs, inbuf); break;1422 case AWAITING_BT_PIECE: ret = readBtPiece ( msgs, inbuf); break;1419 case AWAITING_BT_LENGTH: ret = readBtLength ( msgs, inbuf, inlen ); break; 1420 case AWAITING_BT_ID: ret = readBtId ( msgs, inbuf, inlen ); break; 1421 case AWAITING_BT_MESSAGE: ret = readBtMessage( msgs, inbuf, inlen ); break; 1422 case AWAITING_BT_PIECE: ret = readBtPiece ( msgs, inbuf, inlen ); break; 1423 1423 default: assert( 0 ); 1424 1424 } … … 1496 1496 size_t len; 1497 1497 1498 /* if we froze out a downloaded block because of speed limits, 1499 start listening to the peer again */ 1500 if( msgs->notListening && canDownload( msgs ) ) 1501 { 1502 msgs->notListening = 0; 1503 tr_peerIoTryRead( msgs->io ); 1504 } 1498 tr_peerIoTryRead( msgs->io ); 1505 1499 1506 1500 pumpRequestQueue( msgs ); … … 1558 1552 1559 1553 return TRUE; /* loop forever */ 1560 }1561 1562 static void1563 didWrite( struct bufferevent * evin UNUSED, void * vmsgs )1564 {1565 pulse( vmsgs );1566 1554 } 1567 1555 … … 1790 1778 1791 1779 tr_peerIoSetTimeoutSecs( m->io, 150 ); /* timeout after N seconds of inactivity */ 1792 tr_peerIoSetIOFuncs( m->io, canRead, didWrite, gotError, m );1780 tr_peerIoSetIOFuncs( m->io, canRead, NULL, gotError, m ); 1793 1781 ratePulse( m ); 1794 1782 -
trunk/libtransmission/ratecontrol.c
r3815 r3842 31 31 32 32 #define GRANULARITY_MSEC 250 33 #define SHORT_INTERVAL_MSEC 300034 #define LONG_INTERVAL_MSEC 2000033 #define SHORT_INTERVAL_MSEC 2000 34 #define LONG_INTERVAL_MSEC 10000 35 35 #define HISTORY_SIZE (LONG_INTERVAL_MSEC / GRANULARITY_MSEC) 36 36
Note: See TracChangeset
for help on using the changeset viewer.