From 095cc3e05fa08f5d552eceb54f1132daeb12f9a9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 6 Mar 2010 14:56:15 +0000 Subject: [PATCH] (trunk libT) "don't cancel requests for blocks that we're downloading from slow peers" -- fixed in trunk for 1.92 --- libtransmission/handshake.c | 4 ++-- libtransmission/peer-mgr.c | 27 +++++++++++---------------- libtransmission/peer-msgs.c | 26 ++++++++++++++++++++------ libtransmission/peer-msgs.h | 5 +++-- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 075eeb20c..93739a185 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -1143,9 +1143,9 @@ tr_handshakeAbort( tr_handshake * handshake ) static void gotError( tr_peerIo * io UNUSED, short what, - void * arg ) + void * vhandshake ) { - tr_handshake * handshake = (tr_handshake *) arg; + tr_handshake * handshake = vhandshake; /* if the error happened while we were sending a public key, we might * have encountered a peer that doesn't do encryption... reconnect and diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 0665c7e83..d880c99c0 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -83,7 +83,7 @@ enum MINIMUM_RECONNECT_INTERVAL_SECS = 5, /** how long we'll let requests we've made linger before we cancel them */ - REQUEST_TTL_SECS = 45 + REQUEST_TTL_SECS = 60 }; @@ -980,6 +980,8 @@ tr_peerMgrGetNextRequests( tr_torrent * tor, /* sanity clause */ assert( tr_isTorrent( tor ) ); + assert( peer->clientIsInterested ); + assert( !peer->clientIsChoked ); assert( numwant > 0 ); /* walk through the pieces and find blocks that should be requested */ @@ -1103,7 +1105,7 @@ refillUpkeep( int foo UNUSED, short bar UNUSED, void * vmgr ) for( it=t->requests, end=it+n; it!=end; ++it ) { - if( it->sentAt <= too_old ) + if( ( it->sentAt <= too_old ) && !tr_peerMsgsIsReadingBlock( it->peer->msgs, it->block ) ) cancel[cancelCount++] = *it; else { @@ -2283,22 +2285,13 @@ compareChoke( const void * va, return 0; } +/* is this a new connection? */ static int isNew( const tr_peer * peer ) { return peer && peer->io && tr_peerIoGetAge( peer->io ) < 45; } -static int -isSame( const tr_peer * peer ) -{ - return peer && peer->client && strstr( peer->client, "Transmission" ); -} - -/** -*** -**/ - static void rechokeTorrent( Torrent * t, const uint64_t now ) { @@ -2375,7 +2368,6 @@ rechokeTorrent( Torrent * t, const uint64_t now ) const tr_peer * peer = choke[i].peer; int x = 1, y; if( isNew( peer ) ) x *= 3; - if( isSame( peer ) ) x *= 3; for( y=0; ysession, tor ))) - if( tor->isRunning ) + while(( tor = tr_torrentNext( mgr->session, tor ))) { + if( tor->isRunning ) { rechokeTorrent( tor->torrentPeers, now ); + } + } tr_timerAddMsec( mgr->rechokeTimer, RECHOKE_PERIOD_MSEC ); managerUnlock( mgr ); @@ -3074,7 +3068,7 @@ pumpAllPeers( tr_peerMgr * mgr ) static void bandwidthPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) { - tr_torrent * tor = NULL; + tr_torrent * tor; tr_peerMgr * mgr = vmgr; managerLock( mgr ); @@ -3086,6 +3080,7 @@ bandwidthPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) tr_bandwidthAllocate( mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC ); /* possibly stop torrents that have seeded enough */ + tor = NULL; while(( tor = tr_torrentNext( mgr->session, tor ))) { if( tor->needsSeedRatioCheck ) { tor->needsSeedRatioCheck = FALSE; diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 5b5f48173..d58fbebea 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -711,18 +711,17 @@ isPeerInteresting( const tr_peermsgs * msgs ) } static void -sendInterest( tr_peermsgs * msgs, - int weAreInterested ) +sendInterest( tr_peermsgs * msgs, tr_bool clientIsInterested ) { struct evbuffer * out = msgs->outMessages; assert( msgs ); - assert( weAreInterested == 0 || weAreInterested == 1 ); + assert( tr_isBool( clientIsInterested ) ); - msgs->peer->clientIsInterested = weAreInterested; - dbgmsg( msgs, "Sending %s", weAreInterested ? "Interested" : "Not Interested" ); + msgs->peer->clientIsInterested = clientIsInterested; + dbgmsg( msgs, "Sending %s", clientIsInterested ? "Interested" : "Not Interested" ); tr_peerIoWriteUint32( msgs->peer->io, out, sizeof( uint8_t ) ); - tr_peerIoWriteUint8 ( msgs->peer->io, out, weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED ); + tr_peerIoWriteUint8 ( msgs->peer->io, out, clientIsInterested ? BT_INTERESTED : BT_NOT_INTERESTED ); pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS ); dbgOutMessageLen( msgs ); @@ -1679,6 +1678,17 @@ canRead( tr_peerIo * io, void * vmsgs, size_t * piece ) return ret; } +int +tr_peerMsgsIsReadingBlock( const tr_peermsgs * msgs, tr_block_index_t block ) +{ + if( msgs->state != AWAITING_BT_PIECE ) + return FALSE; + + return block == _tr_block( msgs->torrent, + msgs->incoming.blockReq.index, + msgs->incoming.blockReq.offset ); +} + /** *** **/ @@ -1696,6 +1706,10 @@ updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now ) { msgs->desiredRequestCount = 0; } + else if( !msgs->peer->clientIsInterested ) + { + msgs->desiredRequestCount = 0; + } else { int irate; diff --git a/libtransmission/peer-msgs.h b/libtransmission/peer-msgs.h index 2d8214b80..77ce77db9 100644 --- a/libtransmission/peer-msgs.h +++ b/libtransmission/peer-msgs.h @@ -39,8 +39,9 @@ tr_peermsgs* tr_peerMsgsNew( struct tr_torrent * torrent, tr_publisher_tag * setme ); -void tr_peerMsgsSetChoke( tr_peermsgs *, - int doChoke ); +void tr_peerMsgsSetChoke( tr_peermsgs *, int doChoke ); + +int tr_peerMsgsIsReadingBlock( const tr_peermsgs * msgs, tr_block_index_t block ); void tr_peerMsgsHave( tr_peermsgs * msgs, uint32_t pieceIndex );