Changeset 7618
- Timestamp:
- Jan 5, 2009, 4:27:54 AM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bandwidth.c
r7614 r7618 34 34 35 35 static float 36 getSpeed( const struct bratecontrol * r, int interval_msec )36 getSpeed( const struct bratecontrol * r, int interval_msec, uint64_t now ) 37 37 { 38 38 uint64_t bytes = 0; 39 const uint64_t cutoff = tr_date () - interval_msec;39 const uint64_t cutoff = (now?now:tr_date()) - interval_msec; 40 40 int i = r->newest; 41 41 … … 205 205 peers = (struct tr_peerIo**) tr_ptrArrayBase( &tmp ); 206 206 peerCount = tr_ptrArraySize( &tmp ); 207 208 for( i=0; i<peerCount; ++i ) 209 tr_peerIoRef( peers[i] ); 207 210 208 211 /* Stop all peers from listening for the socket to be ready for IO. … … 247 250 tr_peerIoSetEnabled( peers[i], dir, TRUE ); 248 251 252 for( i=0; i<peerCount; ++i ) 253 tr_peerIoUnref( peers[i] ); 254 249 255 /* cleanup */ 250 256 tr_ptrArrayDestruct( &tmp, NULL ); … … 285 291 286 292 double 287 tr_bandwidthGetRawSpeed( const tr_bandwidth * b, tr_direction dir )288 { 289 assert( tr_isBandwidth( b ) ); 290 assert( tr_isDirection( dir ) ); 291 292 return getSpeed( &b->band[dir].raw, HISTORY_MSEC );293 tr_bandwidthGetRawSpeed( const tr_bandwidth * b, const uint64_t now, const tr_direction dir ) 294 { 295 assert( tr_isBandwidth( b ) ); 296 assert( tr_isDirection( dir ) ); 297 298 return getSpeed( &b->band[dir].raw, HISTORY_MSEC, now ); 293 299 } 294 300 295 301 double 296 tr_bandwidthGetPieceSpeed( const tr_bandwidth * b, tr_direction dir )297 { 298 assert( tr_isBandwidth( b ) ); 299 assert( tr_isDirection( dir ) ); 300 301 return getSpeed( &b->band[dir].piece, HISTORY_MSEC );302 tr_bandwidthGetPieceSpeed( const tr_bandwidth * b, const uint64_t now, const tr_direction dir ) 303 { 304 assert( tr_isBandwidth( b ) ); 305 assert( tr_isDirection( dir ) ); 306 307 return getSpeed( &b->band[dir].piece, HISTORY_MSEC, now ); 302 308 } 303 309 -
trunk/libtransmission/bandwidth.h
r7580 r7618 203 203 /** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */ 204 204 double tr_bandwidthGetRawSpeed( const tr_bandwidth * bandwidth, 205 tr_direction direction ); 205 const uint64_t now, 206 const tr_direction direction ); 206 207 207 208 /** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */ 208 209 double tr_bandwidthGetPieceSpeed( const tr_bandwidth * bandwidth, 209 tr_direction direction ); 210 const uint64_t now, 211 const tr_direction direction ); 210 212 211 213 /** -
trunk/libtransmission/handshake.c
r7549 r7618 1096 1096 { 1097 1097 if( handshake->io ) 1098 tr_peerIo Free( handshake->io );1098 tr_peerIoUnref( handshake->io ); 1099 1099 1100 1100 tr_free( handshake ); -
trunk/libtransmission/peer-io.c
r7607 r7618 119 119 dbgmsg( io, "canRead" ); 120 120 121 tr_peerIoRef( io ); 122 121 123 /* try to consume the input buffer */ 122 124 if( io->canRead ) … … 160 162 tr_globalUnlock( session ); 161 163 } 164 165 tr_peerIoUnref( io ); 162 166 } 163 167 … … 167 171 return ( io != NULL ) 168 172 && ( io->magicNumber == MAGIC_NUMBER ) 173 && ( io->refCount > 0 ) 169 174 && ( tr_isBandwidth( &io->bandwidth ) ) 170 175 && ( tr_isAddress( &io->addr ) ) … … 345 350 io = tr_new0( tr_peerIo, 1 ); 346 351 io->magicNumber = MAGIC_NUMBER; 352 io->refCount = 1; 347 353 io->crypto = tr_cryptoNew( torrentHash, isIncoming ); 348 354 io->session = session; … … 425 431 } 426 432 427 void433 static void 428 434 tr_peerIoFree( tr_peerIo * io ) 429 435 { … … 435 441 tr_runInEventThread( io->session, io_dtor, io ); 436 442 } 443 } 444 445 void 446 tr_peerIoRef( tr_peerIo * io ) 447 { 448 assert( tr_isPeerIo( io ) ); 449 450 ++io->refCount; 451 } 452 453 void 454 tr_peerIoUnref( tr_peerIo * io ) 455 { 456 assert( tr_isPeerIo( io ) ); 457 458 if( !--io->refCount ) 459 tr_peerIoFree( io ); 437 460 } 438 461 … … 570 593 571 594 static size_t 572 getDesiredOutputBufferSize( const tr_peerIo * io )595 getDesiredOutputBufferSize( const tr_peerIo * io, uint64_t now ) 573 596 { 574 597 /* this is all kind of arbitrary, but what seems to work well is … … 577 600 * It's okay to tweak this as needed */ 578 601 const double maxBlockSize = 16 * 1024; /* 16 KiB is from BT spec */ 579 const double currentSpeed = tr_bandwidthGetPieceSpeed( &io->bandwidth, TR_UP );602 const double currentSpeed = tr_bandwidthGetPieceSpeed( &io->bandwidth, now, TR_UP ); 580 603 const double period = 20; /* arbitrary */ 581 604 const double numBlocks = 5.5; /* the 5 is arbitrary; the .5 is to leave room for messages */ … … 584 607 585 608 size_t 586 tr_peerIoGetWriteBufferSpace( const tr_peerIo * io )587 { 588 const size_t desiredLen = getDesiredOutputBufferSize( io );609 tr_peerIoGetWriteBufferSpace( const tr_peerIo * io, uint64_t now ) 610 { 611 const size_t desiredLen = getDesiredOutputBufferSize( io, now ); 589 612 const size_t currentLen = EVBUFFER_LENGTH( io->outbuf ); 590 613 size_t freeSpace = 0; -
trunk/libtransmission/peer-io.h
r7616 r7618 68 68 69 69 uint8_t encryptionMode; 70 70 71 tr_port port; 71 72 int socket; 73 74 ssize_t refCount; 72 75 73 76 uint8_t peerId[SHA_DIGEST_LENGTH]; … … 111 114 int socket ); 112 115 113 void tr_peerIoFree ( tr_peerIo * io ); 116 void tr_peerIoRef ( tr_peerIo * io ); 117 118 void tr_peerIoUnref ( tr_peerIo * io ); 114 119 115 120 tr_bool tr_isPeerIo ( const tr_peerIo * io ); … … 310 315 **/ 311 316 312 size_t tr_peerIoGetWriteBufferSpace( const tr_peerIo * io );317 size_t tr_peerIoGetWriteBufferSpace( const tr_peerIo * io, uint64_t now ); 313 318 314 319 static inline void tr_peerIoSetParent( tr_peerIo * io, … … 333 338 } 334 339 335 static inline double tr_peerIoGetPieceSpeed( const tr_peerIo * io, tr_direction dir )340 static inline double tr_peerIoGetPieceSpeed( const tr_peerIo * io, uint64_t now, tr_direction dir ) 336 341 { 337 342 assert( tr_isPeerIo( io ) ); 338 343 assert( tr_isDirection( dir ) ); 339 344 340 return tr_bandwidthGetPieceSpeed( &io->bandwidth, dir );345 return tr_bandwidthGetPieceSpeed( &io->bandwidth, now, dir ); 341 346 } 342 347 -
trunk/libtransmission/peer-mgr-private.h
r7580 r7618 77 77 78 78 double tr_peerGetPieceSpeed( const tr_peer * peer, 79 uint64_t now, 79 80 tr_direction direction ); 80 81 -
trunk/libtransmission/peer-mgr.c
r7614 r7618 145 145 tr_ptrArray torrents; /* Torrent */ 146 146 tr_ptrArray incomingHandshakes; /* tr_handshake */ 147 tr_ptrArray finishedHandshakes; /* tr_handshake */148 147 tr_timer * bandwidthTimer; 149 148 }; … … 357 356 } 358 357 359 tr_peerIo Free( peer->io );358 tr_peerIoUnref( peer->io ); 360 359 361 360 tr_bitfieldFree( peer->have ); … … 460 459 m->torrents = TR_PTR_ARRAY_INIT; 461 460 m->incomingHandshakes = TR_PTR_ARRAY_INIT; 462 m->finishedHandshakes = TR_PTR_ARRAY_INIT;463 461 m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC ); 464 462 return m; … … 468 466 tr_peerMgrFree( tr_peerMgr * manager ) 469 467 { 470 tr_handshake * handshake;471 472 468 managerLock( manager ); 473 469 … … 480 476 481 477 tr_ptrArrayDestruct( &manager->incomingHandshakes, NULL ); 482 483 while(( handshake = tr_ptrArrayPop( &manager->finishedHandshakes )))484 tr_handshakeFree( handshake );485 486 tr_ptrArrayDestruct( &manager->finishedHandshakes, NULL );487 478 488 479 /* free the torrents. */ … … 1277 1268 1278 1269 if( !success ) 1279 tr_ ptrArrayAppend( &manager->finishedHandshakes,handshake );1270 tr_handshakeFree( handshake ); 1280 1271 1281 1272 if( t ) … … 1794 1785 int webseedCount; 1795 1786 float * ret; 1787 uint64_t now; 1796 1788 1797 1789 assert( manager ); … … 1803 1795 assert( webseedCount == t->tor->info.webseedCount ); 1804 1796 ret = tr_new0( float, webseedCount ); 1797 now = tr_date( ); 1805 1798 1806 1799 for( i=0; i<webseedCount; ++i ) 1807 if( !tr_webseedGetSpeed( webseeds[i], &ret[i] ) )1800 if( !tr_webseedGetSpeed( webseeds[i], now, &ret[i] ) ) 1808 1801 ret[i] = -1.0; 1809 1802 … … 1813 1806 1814 1807 double 1815 tr_peerGetPieceSpeed( const tr_peer * peer, tr_direction direction )1816 { 1817 return peer->io ? tr_peerIoGetPieceSpeed( peer->io, direction ) : 0.0;1808 tr_peerGetPieceSpeed( const tr_peer * peer, uint64_t now, tr_direction direction ) 1809 { 1810 return peer->io ? tr_peerIoGetPieceSpeed( peer->io, now, direction ) : 0.0; 1818 1811 } 1819 1812 … … 1828 1821 const tr_peer ** peers; 1829 1822 tr_peer_stat * ret; 1823 uint64_t now; 1830 1824 1831 1825 assert( manager ); … … 1836 1830 peers = (const tr_peer**) tr_ptrArrayBase( &t->peers ); 1837 1831 ret = tr_new0( tr_peer_stat, size ); 1832 now = tr_date( ); 1838 1833 1839 1834 for( i = 0; i < size; ++i ) … … 1854 1849 stat->progress = peer->progress; 1855 1850 stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0; 1856 stat->rateToPeer = tr_peerGetPieceSpeed( peer, TR_CLIENT_TO_PEER );1857 stat->rateToClient = tr_peerGetPieceSpeed( peer, TR_PEER_TO_CLIENT );1851 stat->rateToPeer = tr_peerGetPieceSpeed( peer, now, TR_CLIENT_TO_PEER ); 1852 stat->rateToClient = tr_peerGetPieceSpeed( peer, now, TR_PEER_TO_CLIENT ); 1858 1853 stat->peerIsChoked = peer->peerIsChoked; 1859 1854 stat->peerIsInterested = peer->peerIsInterested; … … 1938 1933 struct ChokeData * choke = tr_new0( struct ChokeData, peerCount ); 1939 1934 const int chokeAll = !tr_torrentIsPieceTransferAllowed( t->tor, TR_CLIENT_TO_PEER ); 1935 const uint64_t now = tr_date( ); 1940 1936 1941 1937 assert( torrentIsLocked( t ) ); … … 1965 1961 n->isInterested = peer->peerIsInterested; 1966 1962 n->isChoked = peer->peerIsChoked; 1967 n->rate = tr_peerGetPieceSpeed( peer, TR_CLIENT_TO_PEER ) * 1024;1963 n->rate = tr_peerGetPieceSpeed( peer, now, TR_CLIENT_TO_PEER ) * 1024; 1968 1964 } 1969 1965 } … … 2374 2370 bandwidthPulse( void * vmgr ) 2375 2371 { 2376 tr_handshake * handshake;2377 2372 tr_peerMgr * mgr = vmgr; 2378 2373 managerLock( mgr ); … … 2385 2380 tr_bandwidthAllocate( mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC ); 2386 2381 2387 /* free all the finished handshakes */2388 while(( handshake = tr_ptrArrayPop( &mgr->finishedHandshakes )))2389 tr_handshakeFree( handshake );2390 2391 2382 managerUnlock( mgr ); 2392 2383 return TRUE; -
trunk/libtransmission/peer-msgs.c
r7611 r7618 1639 1639 1640 1640 static int 1641 ratePulse( void * vmsgs ) 1642 { 1643 tr_peermsgs * msgs = vmsgs; 1644 const double rateToClient = tr_peerGetPieceSpeed( msgs->peer, TR_PEER_TO_CLIENT ); 1641 ratePulse( tr_peermsgs * msgs, uint64_t now ) 1642 { 1643 const double rateToClient = tr_peerGetPieceSpeed( msgs->peer, now, TR_PEER_TO_CLIENT ); 1645 1644 const int seconds = 10; 1646 1645 const int floor = 8; … … 1688 1687 **/ 1689 1688 1690 if( ( tr_peerIoGetWriteBufferSpace( msgs->peer->io ) >= msgs->torrent->blockSize )1689 if( ( tr_peerIoGetWriteBufferSpace( msgs->peer->io, now ) >= msgs->torrent->blockSize ) 1691 1690 && popNextRequest( msgs, &req ) ) 1692 1691 { … … 1748 1747 const time_t now = time( NULL ); 1749 1748 1750 ratePulse( msgs );1749 ratePulse( msgs, now ); 1751 1750 1752 1751 pumpRequestQueue( msgs, now ); … … 2124 2123 2125 2124 tr_peerIoSetIOFuncs( m->peer->io, canRead, didWrite, gotError, m ); 2126 ratePulse( m );2125 ratePulse( m, tr_date() ); 2127 2126 2128 2127 return m; -
trunk/libtransmission/ratecontrol.c
r7584 r7618 33 33 static float 34 34 rateForInterval( const tr_ratecontrol * r, 35 int interval_msec ) 35 int interval_msec, 36 uint64_t now ) 36 37 { 37 38 uint64_t bytes = 0; 38 const uint64_t cutoff = tr_date () - interval_msec;39 const uint64_t cutoff = (now?now:tr_date()) - interval_msec; 39 40 int i = r->newest; 40 41 … … 58 59 59 60 float 60 tr_rcRate( const tr_ratecontrol * r )61 tr_rcRate( const tr_ratecontrol * r, uint64_t now ) 61 62 { 62 63 float ret = 0.0f; 63 64 64 65 if( r ) 65 ret = rateForInterval( r, TR_RC_HISTORY_MSEC );66 ret = rateForInterval( r, TR_RC_HISTORY_MSEC, now ); 66 67 67 68 return ret; -
trunk/libtransmission/ratecontrol.h
r7584 r7618 71 71 size_t byteCount ); 72 72 73 float tr_rcRate ( const tr_ratecontrol * ratecontrol ); 73 float tr_rcRate ( const tr_ratecontrol * ratecontrol, 74 uint64_t now ); 74 75 75 76 -
trunk/libtransmission/session.c
r7580 r7618 736 736 tr_sessionGetPieceSpeed( const tr_session * session, tr_direction dir ) 737 737 { 738 return session ? tr_bandwidthGetPieceSpeed( session->bandwidth, dir ) : 0.0;738 return session ? tr_bandwidthGetPieceSpeed( session->bandwidth, 0, dir ) : 0.0; 739 739 } 740 740 … … 742 742 tr_sessionGetRawSpeed( const tr_session * session, tr_direction dir ) 743 743 { 744 return session ? tr_bandwidthGetPieceSpeed( session->bandwidth, dir ) : 0.0;744 return session ? tr_bandwidthGetPieceSpeed( session->bandwidth, 0, dir ) : 0.0; 745 745 } 746 746 -
trunk/libtransmission/torrent.c
r7601 r7618 723 723 const tr_tracker_info * ti; 724 724 int usableSeeds = 0; 725 uint64_t now; 725 726 726 727 if( !tor ) … … 759 760 s->peersFrom ); 760 761 761 s->rawUploadSpeed = tr_bandwidthGetRawSpeed ( tor->bandwidth, TR_UP ); 762 s->rawDownloadSpeed = tr_bandwidthGetRawSpeed ( tor->bandwidth, TR_DOWN ); 763 s->pieceUploadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, TR_UP ); 764 s->pieceDownloadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, TR_DOWN ); 762 now = tr_date( ); 763 s->swarmSpeed = tr_rcRate( &tor->swarmSpeed, now ); 764 s->rawUploadSpeed = tr_bandwidthGetRawSpeed ( tor->bandwidth, now, TR_UP ); 765 s->rawDownloadSpeed = tr_bandwidthGetRawSpeed ( tor->bandwidth, now, TR_DOWN ); 766 s->pieceUploadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_UP ); 767 s->pieceDownloadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_DOWN ); 765 768 766 769 usableSeeds += tor->info.webseedCount; … … 778 781 : 0.0; 779 782 780 s->swarmSpeed = tr_rcRate( &tor->swarmSpeed );781 783 782 784 s->activityDate = tor->activityDate; -
trunk/libtransmission/webseed.c
r7584 r7618 253 253 254 254 int 255 tr_webseedGetSpeed( const tr_webseed * w, float * setme_KiBs )255 tr_webseedGetSpeed( const tr_webseed * w, uint64_t now, float * setme_KiBs ) 256 256 { 257 257 const int isActive = tr_webseedIsActive( w ); 258 258 259 *setme_KiBs = isActive ? tr_rcRate( &w->rateDown ) : 0.0f;259 *setme_KiBs = isActive ? tr_rcRate( &w->rateDown, now ) : 0.0f; 260 260 return isActive; 261 261 } -
trunk/libtransmission/webseed.h
r7404 r7618 37 37 /** @return true if a request is being processed, or false if idle */ 38 38 int tr_webseedGetSpeed( const tr_webseed * w, 39 uint64_t now, 39 40 float * setme_KiBs ); 40 41
Note: See TracChangeset
for help on using the changeset viewer.