(trunk libT) partial revert of r7825: back out the refillPulse() changes
This commit is contained in:
parent
c443159681
commit
509465a85b
|
@ -47,7 +47,8 @@ typedef enum
|
|||
TR_PEER_PEER_PROGRESS,
|
||||
TR_PEER_ERROR,
|
||||
TR_PEER_CANCEL,
|
||||
TR_PEER_UPLOAD_ONLY
|
||||
TR_PEER_UPLOAD_ONLY,
|
||||
TR_PEER_NEED_REQ
|
||||
}
|
||||
PeerEventType;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
|
||||
*
|
||||
|
@ -126,6 +127,7 @@ typedef struct tr_torrent_peers
|
|||
tr_ptrArray pool; /* struct peer_atom */
|
||||
tr_ptrArray peers; /* tr_peer */
|
||||
tr_ptrArray webseeds; /* tr_webseed */
|
||||
tr_timer * refillTimer;
|
||||
tr_torrent * tor;
|
||||
tr_peer * optimistic; /* the optimistic peer, or NULL if none */
|
||||
|
||||
|
@ -139,7 +141,6 @@ struct tr_peerMgr
|
|||
tr_ptrArray incomingHandshakes; /* tr_handshake */
|
||||
tr_timer * bandwidthTimer;
|
||||
tr_timer * rechokeTimer;
|
||||
tr_timer * refillTimer;
|
||||
tr_timer * reconnectTimer;
|
||||
};
|
||||
|
||||
|
@ -380,6 +381,8 @@ torrentDestructor( void * vt )
|
|||
|
||||
memcpy( hash, t->hash, SHA_DIGEST_LENGTH );
|
||||
|
||||
tr_timerFree( &t->refillTimer );
|
||||
|
||||
tr_ptrArrayDestruct( &t->webseeds, (PtrArrayForeachFunc)tr_webseedFree );
|
||||
tr_ptrArrayDestruct( &t->pool, (PtrArrayForeachFunc)tr_free );
|
||||
tr_ptrArrayDestruct( &t->outgoingHandshakes, NULL );
|
||||
|
@ -422,7 +425,6 @@ torrentConstructor( tr_peerMgr * manager,
|
|||
|
||||
static int bandwidthPulse ( void * vmgr );
|
||||
static int rechokePulse ( void * vmgr );
|
||||
static int refillPulse ( void * vmgr );
|
||||
static int reconnectPulse ( void * vmgr );
|
||||
|
||||
tr_peerMgr*
|
||||
|
@ -434,7 +436,6 @@ tr_peerMgrNew( tr_session * session )
|
|||
m->incomingHandshakes = TR_PTR_ARRAY_INIT;
|
||||
m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC );
|
||||
m->rechokeTimer = tr_timerNew( session, rechokePulse, m, RECHOKE_PERIOD_MSEC );
|
||||
m->refillTimer = tr_timerNew( session, refillPulse, m, REFILL_PERIOD_MSEC );
|
||||
m->reconnectTimer = tr_timerNew( session, reconnectPulse, m, RECONNECT_PERIOD_MSEC );
|
||||
|
||||
rechokePulse( m );
|
||||
|
@ -448,7 +449,6 @@ tr_peerMgrFree( tr_peerMgr * manager )
|
|||
managerLock( manager );
|
||||
|
||||
tr_timerFree( &manager->reconnectTimer );
|
||||
tr_timerFree( &manager->refillTimer );
|
||||
tr_timerFree( &manager->rechokeTimer );
|
||||
tr_timerFree( &manager->bandwidthTimer );
|
||||
|
||||
|
@ -734,8 +734,8 @@ getBlockOffsetInPiece( const tr_torrent * tor, uint64_t b )
|
|||
return (uint32_t)( blockPos - piecePos );
|
||||
}
|
||||
|
||||
static void
|
||||
refillTorrent( Torrent * t )
|
||||
static int
|
||||
refillPulse( void * vtorrent )
|
||||
{
|
||||
tr_block_index_t block;
|
||||
int peerCount;
|
||||
|
@ -743,13 +743,15 @@ refillTorrent( Torrent * t )
|
|||
tr_peer ** peers;
|
||||
tr_webseed ** webseeds;
|
||||
struct tr_blockIterator * blockIterator;
|
||||
Torrent * t = vtorrent;
|
||||
tr_torrent * tor = t->tor;
|
||||
|
||||
if( !t->isRunning )
|
||||
return;
|
||||
return TRUE;
|
||||
if( tr_torrentIsSeed( t->tor ) )
|
||||
return;
|
||||
return TRUE;
|
||||
|
||||
torrentLock( t );
|
||||
tordbg( t, "Refilling Request Buffers..." );
|
||||
|
||||
blockIterator = blockIteratorNew( t );
|
||||
|
@ -821,21 +823,10 @@ refillTorrent( Torrent * t )
|
|||
blockIteratorFree( blockIterator );
|
||||
tr_free( webseeds );
|
||||
tr_free( peers );
|
||||
}
|
||||
|
||||
static int
|
||||
refillPulse( void * vmgr )
|
||||
{
|
||||
tr_torrent * tor = NULL;
|
||||
tr_peerMgr * mgr = vmgr;
|
||||
managerLock( mgr );
|
||||
|
||||
while(( tor = tr_torrentNext( mgr->session, tor )))
|
||||
if( tor->isRunning && !tr_torrentIsSeed( tor ) )
|
||||
refillTorrent( tor->torrentPeers );
|
||||
|
||||
managerUnlock( mgr );
|
||||
return TRUE;
|
||||
t->refillTimer = NULL;
|
||||
torrentUnlock( t );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -884,6 +875,15 @@ gotBadPiece( Torrent * t,
|
|||
tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
|
||||
}
|
||||
|
||||
static void
|
||||
refillSoon( Torrent * t )
|
||||
{
|
||||
if( t->refillTimer == NULL )
|
||||
t->refillTimer = tr_timerNew( t->manager->session,
|
||||
refillPulse, t,
|
||||
REFILL_PERIOD_MSEC );
|
||||
}
|
||||
|
||||
static void
|
||||
peerSuggestedPiece( Torrent * t UNUSED,
|
||||
tr_peer * peer UNUSED,
|
||||
|
@ -951,6 +951,10 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
|
|||
}
|
||||
break;
|
||||
|
||||
case TR_PEER_NEED_REQ:
|
||||
refillSoon( t );
|
||||
break;
|
||||
|
||||
case TR_PEER_CANCEL:
|
||||
decrementPieceRequests( t, e->pieceIndex );
|
||||
break;
|
||||
|
@ -1512,7 +1516,21 @@ tr_peerMgrGetPeers( tr_torrent * tor,
|
|||
void
|
||||
tr_peerMgrStartTorrent( tr_torrent * tor )
|
||||
{
|
||||
tor->torrentPeers->isRunning = TRUE;
|
||||
Torrent * t = tor->torrentPeers;
|
||||
|
||||
managerLock( t->manager );
|
||||
|
||||
assert( t );
|
||||
|
||||
if( !t->isRunning )
|
||||
{
|
||||
t->isRunning = TRUE;
|
||||
|
||||
if( !tr_ptrArrayEmpty( &t->webseeds ) )
|
||||
refillSoon( t );
|
||||
}
|
||||
|
||||
managerUnlock( t->manager );
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -419,6 +419,14 @@ fireUploadOnly( tr_peermsgs * msgs, tr_bool uploadOnly )
|
|||
publish( msgs, &e );
|
||||
}
|
||||
|
||||
static void
|
||||
fireNeedReq( tr_peermsgs * msgs )
|
||||
{
|
||||
tr_peer_event e = blankEvent;
|
||||
e.eventType = TR_PEER_NEED_REQ;
|
||||
publish( msgs, &e );
|
||||
}
|
||||
|
||||
static void
|
||||
firePeerProgress( tr_peermsgs * msgs )
|
||||
{
|
||||
|
@ -645,6 +653,8 @@ updateInterest( tr_peermsgs * msgs )
|
|||
|
||||
if( i != msgs->peer->clientIsInterested )
|
||||
sendInterest( msgs, i );
|
||||
if( i )
|
||||
fireNeedReq( msgs );
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -809,6 +819,9 @@ pumpRequestQueue( tr_peermsgs * msgs, const time_t now )
|
|||
if( sent )
|
||||
dbgmsg( msgs, "pump sent %d requests, now have %d active and %d queued",
|
||||
sent, msgs->clientAskedFor.len, msgs->clientWillAskFor.len );
|
||||
|
||||
if( len < max )
|
||||
fireNeedReq( msgs );
|
||||
}
|
||||
|
||||
static TR_INLINE int
|
||||
|
@ -1353,6 +1366,7 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
|
|||
case BT_UNCHOKE:
|
||||
dbgmsg( msgs, "got Unchoke" );
|
||||
msgs->peer->clientIsChoked = 0;
|
||||
fireNeedReq( msgs );
|
||||
break;
|
||||
|
||||
case BT_INTERESTED:
|
||||
|
@ -1378,10 +1392,13 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
|
|||
break;
|
||||
|
||||
case BT_BITFIELD:
|
||||
{
|
||||
dbgmsg( msgs, "got a bitfield" );
|
||||
tr_peerIoReadBytes( msgs->peer->io, inbuf, msgs->peer->have->bits, msglen );
|
||||
updatePeerProgress( msgs );
|
||||
fireNeedReq( msgs );
|
||||
break;
|
||||
}
|
||||
|
||||
case BT_REQUEST:
|
||||
{
|
||||
|
|
|
@ -61,6 +61,14 @@ publish( tr_webseed * w,
|
|||
w->callback( NULL, e, w->callback_userdata );
|
||||
}
|
||||
|
||||
static void
|
||||
fireNeedReq( tr_webseed * w )
|
||||
{
|
||||
tr_peer_event e = blankEvent;
|
||||
e.eventType = TR_PEER_NEED_REQ;
|
||||
publish( w, &e );
|
||||
}
|
||||
|
||||
static void
|
||||
fireClientGotBlock( tr_webseed * w, uint32_t pieceIndex, uint32_t offset, uint32_t length )
|
||||
{
|
||||
|
@ -172,8 +180,10 @@ webResponseFunc( tr_session * session,
|
|||
w->busy = 0;
|
||||
if( w->dead )
|
||||
tr_webseedFree( w );
|
||||
else
|
||||
else {
|
||||
fireClientGotBlock( w, w->pieceIndex, w->pieceOffset, w->byteCount );
|
||||
fireNeedReq( w );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue