(trunk gtk) #3519 "webseeds don't work" -- fix webseed peer counts and download speeds in the GTK+ client's main window

This commit is contained in:
Jordan Lee 2011-01-06 02:40:10 +00:00
parent cc428376e9
commit aea8d8d0b5
1 changed files with 47 additions and 49 deletions

View File

@ -44,11 +44,11 @@ enum
static char* static char*
getProgressString( const tr_torrent * tor, getProgressString( const tr_torrent * tor,
const tr_info * info, const tr_info * info,
const tr_stat * torStat ) const tr_stat * st )
{ {
const int isDone = torStat->leftUntilDone == 0; const int isDone = st->leftUntilDone == 0;
const uint64_t haveTotal = torStat->haveUnchecked + torStat->haveValid; const uint64_t haveTotal = st->haveUnchecked + st->haveValid;
const int isSeed = torStat->haveValid >= info->totalSize; const int isSeed = st->haveValid >= info->totalSize;
char buf1[32], buf2[32], buf3[32], buf4[32], buf5[32], buf6[32]; char buf1[32], buf2[32], buf3[32], buf4[32], buf5[32], buf6[32];
char * str; char * str;
double seedRatio; double seedRatio;
@ -62,8 +62,8 @@ getProgressString( const tr_torrent * tor,
%3$s%% is a percentage of the two */ %3$s%% is a percentage of the two */
_( "%1$s of %2$s (%3$s%%)" ), _( "%1$s of %2$s (%3$s%%)" ),
tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
tr_strlsize( buf2, torStat->sizeWhenDone, sizeof( buf2 ) ), tr_strlsize( buf2, st->sizeWhenDone, sizeof( buf2 ) ),
tr_strlpercent( buf3, torStat->percentDone * 100.0, sizeof( buf3 ) ) ); tr_strlpercent( buf3, st->percentDone * 100.0, sizeof( buf3 ) ) );
} }
else if( !isSeed ) /* partial seeds */ else if( !isSeed ) /* partial seeds */
{ {
@ -79,9 +79,9 @@ getProgressString( const tr_torrent * tor,
_( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s Goal: %6$s)" ), _( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s Goal: %6$s)" ),
tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ), tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ),
tr_strlpercent( buf3, torStat->percentComplete * 100.0, sizeof( buf3 ) ), tr_strlpercent( buf3, st->percentComplete * 100.0, sizeof( buf3 ) ),
tr_strlsize( buf4, torStat->uploadedEver, sizeof( buf4 ) ), tr_strlsize( buf4, st->uploadedEver, sizeof( buf4 ) ),
tr_strlratio( buf5, torStat->ratio, sizeof( buf5 ) ), tr_strlratio( buf5, st->ratio, sizeof( buf5 ) ),
tr_strlratio( buf6, seedRatio, sizeof( buf6 ) ) ); tr_strlratio( buf6, seedRatio, sizeof( buf6 ) ) );
} }
else else
@ -95,9 +95,9 @@ getProgressString( const tr_torrent * tor,
_( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s)" ), _( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s)" ),
tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ), tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ),
tr_strlpercent( buf3, torStat->percentComplete * 100.0, sizeof( buf3 ) ), tr_strlpercent( buf3, st->percentComplete * 100.0, sizeof( buf3 ) ),
tr_strlsize( buf4, torStat->uploadedEver, sizeof( buf4 ) ), tr_strlsize( buf4, st->uploadedEver, sizeof( buf4 ) ),
tr_strlratio( buf5, torStat->ratio, sizeof( buf5 ) ) ); tr_strlratio( buf5, st->ratio, sizeof( buf5 ) ) );
} }
} }
else /* seeding */ else /* seeding */
@ -111,8 +111,8 @@ getProgressString( const tr_torrent * tor,
%4$s is the ratio we want to reach before we stop uploading */ %4$s is the ratio we want to reach before we stop uploading */
_( "%1$s, uploaded %2$s (Ratio: %3$s Goal: %4$s)" ), _( "%1$s, uploaded %2$s (Ratio: %3$s Goal: %4$s)" ),
tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ), tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ),
tr_strlsize( buf2, torStat->uploadedEver, sizeof( buf2 ) ), tr_strlsize( buf2, st->uploadedEver, sizeof( buf2 ) ),
tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ), tr_strlratio( buf3, st->ratio, sizeof( buf3 ) ),
tr_strlratio( buf4, seedRatio, sizeof( buf4 ) ) ); tr_strlratio( buf4, seedRatio, sizeof( buf4 ) ) );
} }
else /* seeding w/o a ratio */ else /* seeding w/o a ratio */
@ -123,16 +123,16 @@ getProgressString( const tr_torrent * tor,
%3$s is our upload-to-download ratio */ %3$s is our upload-to-download ratio */
_( "%1$s, uploaded %2$s (Ratio: %3$s)" ), _( "%1$s, uploaded %2$s (Ratio: %3$s)" ),
tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ), tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ),
tr_strlsize( buf2, torStat->uploadedEver, sizeof( buf2 ) ), tr_strlsize( buf2, st->uploadedEver, sizeof( buf2 ) ),
tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) ); tr_strlratio( buf3, st->ratio, sizeof( buf3 ) ) );
} }
} }
/* add time when downloading */ /* add time when downloading */
if( ( torStat->activity == TR_STATUS_DOWNLOAD ) if( ( st->activity == TR_STATUS_DOWNLOAD )
|| ( hasSeedRatio && ( torStat->activity == TR_STATUS_SEED ) ) ) || ( hasSeedRatio && ( st->activity == TR_STATUS_SEED ) ) )
{ {
const int eta = torStat->eta; const int eta = st->eta;
GString * gstr = g_string_new( str ); GString * gstr = g_string_new( str );
g_string_append( gstr, " - " ); g_string_append( gstr, " - " );
if( eta < 0 ) if( eta < 0 )
@ -153,7 +153,7 @@ getProgressString( const tr_torrent * tor,
static char* static char*
getShortTransferString( const tr_torrent * tor, getShortTransferString( const tr_torrent * tor,
const tr_stat * torStat, const tr_stat * st,
double uploadSpeed_KBps, double uploadSpeed_KBps,
double downloadSpeed_KBps, double downloadSpeed_KBps,
char * buf, char * buf,
@ -161,8 +161,8 @@ getShortTransferString( const tr_torrent * tor,
{ {
char downStr[32], upStr[32]; char downStr[32], upStr[32];
const int haveMeta = tr_torrentHasMetadata( tor ); const int haveMeta = tr_torrentHasMetadata( tor );
const int haveDown = haveMeta && torStat->peersSendingToUs > 0; const int haveUp = haveMeta && st->peersGettingFromUs > 0;
const int haveUp = haveMeta && torStat->peersGettingFromUs > 0; const int haveDown = haveMeta && ( ( st->peersSendingToUs > 0 ) || ( st->webseedsSendingToUs > 0 ) );
if( haveDown ) if( haveDown )
tr_formatter_speed_KBps( downStr, downloadSpeed_KBps, sizeof( downStr ) ); tr_formatter_speed_KBps( downStr, downloadSpeed_KBps, sizeof( downStr ) );
@ -193,16 +193,16 @@ getShortTransferString( const tr_torrent * tor,
static char* static char*
getShortStatusString( const tr_torrent * tor, getShortStatusString( const tr_torrent * tor,
const tr_stat * torStat, const tr_stat * st,
double uploadSpeed_KBps, double uploadSpeed_KBps,
double downloadSpeed_KBps ) double downloadSpeed_KBps )
{ {
GString * gstr = g_string_new( NULL ); GString * gstr = g_string_new( NULL );
switch( torStat->activity ) switch( st->activity )
{ {
case TR_STATUS_STOPPED: case TR_STATUS_STOPPED:
if( torStat->finished ) if( st->finished )
g_string_assign( gstr, _( "Finished" ) ); g_string_assign( gstr, _( "Finished" ) );
else else
g_string_assign( gstr, _( "Paused" ) ); g_string_assign( gstr, _( "Paused" ) );
@ -215,20 +215,20 @@ getShortStatusString( const tr_torrent * tor,
case TR_STATUS_CHECK: case TR_STATUS_CHECK:
g_string_append_printf( gstr, g_string_append_printf( gstr,
_( "Verifying local data (%.1f%% tested)" ), _( "Verifying local data (%.1f%% tested)" ),
tr_truncd( torStat->recheckProgress * 100.0, 1 ) ); tr_truncd( st->recheckProgress * 100.0, 1 ) );
break; break;
case TR_STATUS_DOWNLOAD: case TR_STATUS_DOWNLOAD:
case TR_STATUS_SEED: case TR_STATUS_SEED:
{ {
char buf[512]; char buf[512];
if( torStat->activity != TR_STATUS_DOWNLOAD ) if( st->activity != TR_STATUS_DOWNLOAD )
{ {
tr_strlratio( buf, torStat->ratio, sizeof( buf ) ); tr_strlratio( buf, st->ratio, sizeof( buf ) );
g_string_append_printf( gstr, _( "Ratio %s" ), buf ); g_string_append_printf( gstr, _( "Ratio %s" ), buf );
g_string_append( gstr, ", " ); g_string_append( gstr, ", " );
} }
getShortTransferString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) ); getShortTransferString( tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) );
g_string_append( gstr, buf ); g_string_append( gstr, buf );
break; break;
} }
@ -242,30 +242,30 @@ getShortStatusString( const tr_torrent * tor,
static char* static char*
getStatusString( const tr_torrent * tor, getStatusString( const tr_torrent * tor,
const tr_stat * torStat, const tr_stat * st,
const double uploadSpeed_KBps, const double uploadSpeed_KBps,
const double downloadSpeed_KBps ) const double downloadSpeed_KBps )
{ {
const int isActive = torStat->activity != TR_STATUS_STOPPED; const int isActive = st->activity != TR_STATUS_STOPPED;
const int isChecking = torStat->activity == TR_STATUS_CHECK const int isChecking = st->activity == TR_STATUS_CHECK
|| torStat->activity == TR_STATUS_CHECK_WAIT; || st->activity == TR_STATUS_CHECK_WAIT;
GString * gstr = g_string_new( NULL ); GString * gstr = g_string_new( NULL );
if( torStat->error ) if( st->error )
{ {
const char * fmt[] = { NULL, N_( "Tracker gave a warning: \"%s\"" ), const char * fmt[] = { NULL, N_( "Tracker gave a warning: \"%s\"" ),
N_( "Tracker gave an error: \"%s\"" ), N_( "Tracker gave an error: \"%s\"" ),
N_( "Error: %s" ) }; N_( "Error: %s" ) };
g_string_append_printf( gstr, _( fmt[torStat->error] ), torStat->errorString ); g_string_append_printf( gstr, _( fmt[st->error] ), st->errorString );
} }
else switch( torStat->activity ) else switch( st->activity )
{ {
case TR_STATUS_STOPPED: case TR_STATUS_STOPPED:
case TR_STATUS_CHECK_WAIT: case TR_STATUS_CHECK_WAIT:
case TR_STATUS_CHECK: case TR_STATUS_CHECK:
{ {
char * pch = getShortStatusString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps ); char * pch = getShortStatusString( tor, st, uploadSpeed_KBps, downloadSpeed_KBps );
g_string_assign( gstr, pch ); g_string_assign( gstr, pch );
g_free( pch ); g_free( pch );
break; break;
@ -278,20 +278,18 @@ getStatusString( const tr_torrent * tor,
g_string_append_printf( gstr, g_string_append_printf( gstr,
gtr_ngettext( "Downloading from %1$'d of %2$'d connected peer", gtr_ngettext( "Downloading from %1$'d of %2$'d connected peer",
"Downloading from %1$'d of %2$'d connected peers", "Downloading from %1$'d of %2$'d connected peers",
torStat->peersConnected ), st->webseedsSendingToUs + st->peersSendingToUs ),
torStat->peersSendingToUs + st->webseedsSendingToUs + st->peersSendingToUs,
torStat->webseedsSendingToUs, st->webseedsSendingToUs + st->peersConnected );
torStat->peersConnected +
torStat->webseedsSendingToUs );
} }
else else
{ {
g_string_append_printf( gstr, g_string_append_printf( gstr,
gtr_ngettext( "Downloading metadata from %1$'d peer (%2$d%% done)", gtr_ngettext( "Downloading metadata from %1$'d peer (%2$d%% done)",
"Downloading metadata from %1$'d peers (%2$d%% done)", "Downloading metadata from %1$'d peers (%2$d%% done)",
torStat->peersConnected ), st->peersConnected + st->peersConnected ),
torStat->peersConnected + torStat->webseedsSendingToUs, st->peersConnected + st->webseedsSendingToUs,
(int)(100.0*torStat->metadataPercentComplete) ); (int)(100.0*st->metadataPercentComplete) );
} }
break; break;
} }
@ -300,16 +298,16 @@ getStatusString( const tr_torrent * tor,
g_string_append_printf( gstr, g_string_append_printf( gstr,
gtr_ngettext( "Seeding to %1$'d of %2$'d connected peer", gtr_ngettext( "Seeding to %1$'d of %2$'d connected peer",
"Seeding to %1$'d of %2$'d connected peers", "Seeding to %1$'d of %2$'d connected peers",
torStat->peersConnected ), st->peersConnected ),
torStat->peersGettingFromUs, st->peersGettingFromUs,
torStat->peersConnected ); st->peersConnected );
break; break;
} }
if( isActive && !isChecking ) if( isActive && !isChecking )
{ {
char buf[256]; char buf[256];
getShortTransferString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) ); getShortTransferString( tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) );
if( *buf ) if( *buf )
g_string_append_printf( gstr, " - %s", buf ); g_string_append_printf( gstr, " - %s", buf );
} }