1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

Adds progress in tr_peer_stat_t

This commit is contained in:
Eric Petit 2006-11-10 04:21:46 +00:00
parent 7b375e9736
commit 3f129d8829
5 changed files with 32 additions and 0 deletions

View file

@ -63,6 +63,8 @@ struct tr_peer_s
/* The pieces that the peer has */
uint8_t * bitfield;
int pieceCount;
float progress;
int goodPcs;
int badPcs;
@ -534,6 +536,16 @@ int tr_peerIsDownloading( tr_peer_t * peer )
return peer->outBlockSending;
}
/***********************************************************************
* tr_peerIsDownloading
***********************************************************************
*
**********************************************************************/
float tr_peerProgress( tr_peer_t * peer )
{
return peer->progress;
}
/***********************************************************************
* tr_peerBitfield
***********************************************************************

View file

@ -43,6 +43,7 @@ int tr_peerIsConnected ( tr_peer_t * );
int tr_peerIsIncoming ( tr_peer_t * );
int tr_peerIsUploading ( tr_peer_t * );
int tr_peerIsDownloading ( tr_peer_t * );
float tr_peerProgress ( tr_peer_t * );
uint8_t * tr_peerBitfield ( tr_peer_t * );
float tr_peerDownloadRate ( tr_peer_t * );
int tr_peerIsUnchoked ( tr_peer_t * );

View file

@ -106,6 +106,11 @@ static inline int parseHave( tr_torrent_t * tor, tr_peer_t * peer,
{
peer->bitfield = calloc( ( tor->info.pieceCount + 7 ) / 8, 1 );
}
if( !tr_bitfieldHas( peer->bitfield, piece ) )
{
peer->pieceCount++;
peer->progress = (float) peer->pieceCount / tor->info.pieceCount;
}
tr_bitfieldAdd( peer->bitfield, piece );
updateInterest( tor, peer );
@ -119,6 +124,7 @@ static inline int parseBitfield( tr_torrent_t * tor, tr_peer_t * peer,
{
tr_info_t * inf = &tor->info;
int bitfieldSize;
int i;
bitfieldSize = ( inf->pieceCount + 7 ) / 8;
@ -151,6 +157,17 @@ static inline int parseBitfield( tr_torrent_t * tor, tr_peer_t * peer,
peer->bitfield = malloc( bitfieldSize );
}
memcpy( peer->bitfield, p, bitfieldSize );
peer->pieceCount = 0;
for( i = 0; i < inf->pieceCount; i++ )
{
if( tr_bitfieldHas( peer->bitfield, i ) )
{
peer->pieceCount++;
}
}
peer->progress = (float) peer->pieceCount / inf->pieceCount;
updateInterest( tor, peer );
return 0;

View file

@ -591,6 +591,7 @@ tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount )
peers[i].isIncoming = tr_peerIsIncoming(peer);
peers[i].isDownloading = tr_peerIsDownloading(peer);
peers[i].isUploading = tr_peerIsUploading(peer);
peers[i].progress = tr_peerProgress(peer);
}
}

View file

@ -378,6 +378,7 @@ struct tr_peer_stat_s
int isIncoming;
int isDownloading;
int isUploading;
float progress;
};
struct tr_msg_list_s