getSpeed_Bps( const struct bratecontrol * r, unsigned int interval_msec, uint64_t now )
{
uint64_t bytes = 0;
- const uint64_t cutoff = (now?now:tr_date()) - interval_msec;
+ const uint64_t cutoff = (now?now:tr_time_msec()) - interval_msec;
int i = r->newest;
for( ;; )
size_t byteCount,
tr_bool isPieceData )
{
- bandwidthUsedImpl( b, dir, byteCount, isPieceData, tr_date( ) );
+ bandwidthUsedImpl( b, dir, byteCount, isPieceData, tr_time_msec( ) );
}
if( !init )
{
- srand( tr_date( ) );
+ srand( tr_time_msec( ) );
init = TRUE;
}
if( ( match != NULL ) && ( !doWrite || match->isWritable ) )
{
- match->date = tr_date( );
+ match->date = tr_time_msec( );
return match->fd;
}
dbgmsg( "it's not already open. looking for an open slot or an old file." );
while( winner < 0 )
{
- uint64_t date = tr_date( ) + 1;
+ uint64_t date = tr_time_msec( ) + 1;
/* look for the file that's been open longest */
for( i=0; i<gFd->openFileLimit; ++i )
dbgmsg( "checking out '%s' in slot %d", filename, winner );
o->torrentId = torrentId;
o->fileNum = fileNum;
- o->date = tr_date( );
+ o->date = tr_time_msec( );
return o->fd;
}
tr_historyGet( const tr_recentHistory * h, uint64_t now, unsigned int msec )
{
unsigned int n = 0;
- const uint64_t cutoff = (now?now:tr_date()) - msec;
+ const uint64_t cutoff = (now?now:tr_time_msec()) - msec;
int i = h->newest;
for( ;; )
/**
* @brief add a counter to the recent history object.
- * @param when the current time in msec, such as from tr_date()
+ * @param when the current time in msec, such as from tr_time_msec()
* @param n how many items to add to the history's counter
*/
void tr_historyAdd( tr_recentHistory *, uint64_t when, unsigned int n );
/**
* @brief count how many events have occurred in the last N seconds.
- * @param when the current time in msec, such as from tr_date()
+ * @param when the current time in msec, such as from tr_time_msec()
* @param seconds how many seconds to count back through.
*/
unsigned int tr_historyGet( const tr_recentHistory *, uint64_t when, unsigned int seconds );
managerLock( mgr );
now = tr_time( );
- now_msec = tr_date( );
+ now_msec = tr_time_msec( );
too_old = now - REQUEST_TTL_SECS;
tor = NULL;
pieceListRemoveRequest( t, block );
if( peer != NULL )
- tr_historyAdd( peer->blocksSentToClient, tr_date( ), 1 );
+ tr_historyAdd( peer->blocksSentToClient, tr_time_msec( ), 1 );
if( tr_cpBlockIsComplete( &tor->completion, block ) )
{
webseedCount = tr_ptrArraySize( &t->webseeds );
assert( webseedCount == tor->info.webseedCount );
ret = tr_new0( double, webseedCount );
- now = tr_date( );
+ now = tr_time_msec( );
for( i=0; i<webseedCount; ++i ) {
int Bps;
size = tr_ptrArraySize( &t->peers );
peers = (const tr_peer**) tr_ptrArrayBase( &t->peers );
ret = tr_new0( tr_peer_stat, size );
- now = tr_date( );
+ now = tr_time_msec( );
for( i=0; i<size; ++i )
{
rechokeDownloads( Torrent * t )
{
int i;
- const uint64_t now = tr_date( );
+ const uint64_t now = tr_time_msec( );
const int msec = 60 * 1000;
const int MIN_INTERESTING_PEERS = 5;
const int peerCount = tr_ptrArraySize( &t->peers );
tr_peerMgr * mgr = vmgr;
managerLock( mgr );
- now = tr_date( );
+ now = tr_time_msec( );
while(( tor = tr_torrentNext( mgr->session, tor ))) {
if( tor->isRunning ) {
rechokeUploads( tor->torrentPeers, now );
if( shouldPeerBeClosed( t, peers[i], peerCount, now ) == closeType )
ret[outsize++] = peers[i];
- sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_date( ) );
+ sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_time_msec( ) );
*setmeSize = outsize;
return ret;
{
tr_torrent * tor;
tr_peerMgr * mgr = vmgr;
- const uint64_t now = tr_date( );
+ const uint64_t now = tr_time_msec( );
/**
*** enforce the per-session and per-torrent peer limits
struct peer_candidate * candidates;
struct peer_candidate * walk;
const time_t now = tr_time( );
- const uint64_t now_msec = tr_date( );
+ const uint64_t now_msec = tr_time_msec( );
/* leave 5% of connection slots for incoming connections -- ticket #2609 */
const int maxCandidates = tr_sessionGetPeerLimit( session ) * 0.95;
case BT_UNCHOKE:
dbgmsg( msgs, "got Unchoke" );
msgs->peer->clientIsChoked = 0;
- updateDesiredRequestCount( msgs, tr_date( ) );
+ updateDesiredRequestCount( msgs, tr_time_msec( ) );
break;
case BT_INTERESTED:
tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.index );
tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset );
tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length );
- tr_historyAdd( msgs->peer->cancelsSentToClient, tr_date( ), 1 );
+ tr_historyAdd( msgs->peer->cancelsSentToClient, tr_time_msec( ), 1 );
dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length );
for( i=0; i<msgs->peer->pendingReqsToClient; ++i ) {
tr_peerIoWriteBuf( io, out, TRUE );
bytesWritten += EVBUFFER_LENGTH( out );
msgs->clientSentAnythingAt = now;
- tr_historyAdd( msgs->peer->blocksSentToPeer, tr_date( ), 1 );
+ tr_historyAdd( msgs->peer->blocksSentToPeer, tr_time_msec( ), 1 );
}
evbuffer_free( out );
const time_t now = tr_time( );
if ( tr_isPeerIo( msgs->peer->io ) ) {
- updateDesiredRequestCount( msgs, tr_date( ) );
+ updateDesiredRequestCount( msgs, tr_time_msec( ) );
updateBlockRequests( msgs );
updateMetadataRequests( msgs, now );
}
}
tr_peerIoSetIOFuncs( m->peer->io, canRead, didWrite, gotError, m );
- updateDesiredRequestCount( m, tr_date( ) );
+ updateDesiredRequestCount( m, tr_time_msec( ) );
return m;
}
uint64_t now )
{
uint64_t bytes = 0;
- const uint64_t cutoff = (now?now:tr_date()) - interval_msec;
+ const uint64_t cutoff = (now?now:tr_time_msec()) - interval_msec;
int i = r->newest;
for( ; ; )
tr_rcTransferred( tr_ratecontrol * r,
size_t size )
{
- const uint64_t now = tr_date ( );
+ const uint64_t now = tr_time_msec ( );
if( r->transfers[r->newest].date + TR_RC_GRANULARITY_MSEC >= now )
r->transfers[r->newest].size += size;
&s->peersGettingFromUs,
s->peersFrom );
- now = tr_date( );
+ now = tr_time_msec( );
d = tr_peerMgrGetWebseedSpeed_Bps( tor, now );
s->rawUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_UP ) );
s->pieceUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_UP ) );
****/
uint64_t
-tr_date( void )
+tr_time_msec( void )
{
struct timeval tv;
/** @brief return the current date in milliseconds */
-uint64_t tr_date( void );
+uint64_t tr_time_msec( void );
/** @brief sleep the specified number of milliseconds */
void tr_wait_msec( long int delay_milliseconds );