mirror of
https://github.com/transmission/transmission
synced 2025-03-08 21:04:25 +00:00
Get peers separately from the rest of the stats. This should also get rid of a memory leak.
This commit is contained in:
parent
e392a84e36
commit
62d9f1ebb1
3 changed files with 49 additions and 20 deletions
|
@ -434,15 +434,9 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
|
|||
s->peersDownloading = 0;
|
||||
|
||||
tr_peer_t * peer;
|
||||
s->peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) );
|
||||
|
||||
for( i = 0; i < tor->peerCount; i++ )
|
||||
{
|
||||
peer = tor->peers[i];
|
||||
|
||||
s->peers[i].client = tr_clientForId(tr_peerId(peer));
|
||||
s->peers[i].isDownloading = tr_peerIsDownloading(peer);
|
||||
s->peers[i].isUploading = tr_peerIsUploading(peer);
|
||||
|
||||
if( tr_peerIsConnected( peer ) )
|
||||
{
|
||||
|
@ -490,6 +484,33 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
|
|||
return s;
|
||||
}
|
||||
|
||||
tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount )
|
||||
{
|
||||
*peerCount = tor->peerCount;
|
||||
|
||||
tr_peer_stat_t * peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) );
|
||||
if (peers != NULL)
|
||||
{
|
||||
tr_peer_t * peer;
|
||||
int i = 0;
|
||||
for( i = 0; i < tor->peerCount; i++ )
|
||||
{
|
||||
peer = tor->peers[i];
|
||||
|
||||
peers[i].client = tr_clientForId(tr_peerId(peer));
|
||||
peers[i].isDownloading = tr_peerIsDownloading(peer);
|
||||
peers[i].isUploading = tr_peerIsUploading(peer);
|
||||
}
|
||||
}
|
||||
|
||||
return peers;
|
||||
}
|
||||
|
||||
void tr_torrentPeersFree( tr_peer_stat_t * peers )
|
||||
{
|
||||
free( peers );
|
||||
}
|
||||
|
||||
void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size )
|
||||
{
|
||||
int i, j, piece;
|
||||
|
|
|
@ -210,6 +210,13 @@ int tr_getFinished( tr_torrent_t * );
|
|||
typedef struct tr_stat_s tr_stat_t;
|
||||
tr_stat_t * tr_torrentStat( tr_torrent_t * );
|
||||
|
||||
/***********************************************************************
|
||||
* tr_torrentPeers
|
||||
***********************************************************************/
|
||||
typedef struct tr_peer_stat_s tr_peer_stat_t;
|
||||
tr_peer_stat_t * tr_torrentPeers( tr_torrent_t *, int * peerCount );
|
||||
void tr_torrentPeersFree( tr_peer_stat_t * );
|
||||
|
||||
/***********************************************************************
|
||||
* tr_torrentAvailability
|
||||
***********************************************************************
|
||||
|
@ -279,14 +286,6 @@ struct tr_info_s
|
|||
/***********************************************************************
|
||||
* tr_stat_s
|
||||
**********************************************************************/
|
||||
typedef struct tr_peer_stat_s
|
||||
{
|
||||
char * client;
|
||||
|
||||
int isDownloading;
|
||||
int isUploading;
|
||||
}
|
||||
tr_peer_stat_t;
|
||||
struct tr_stat_s
|
||||
{
|
||||
#define TR_STATUS_CHECK 0x001 /* Checking files */
|
||||
|
@ -311,7 +310,6 @@ struct tr_stat_s
|
|||
float rateUpload;
|
||||
int eta;
|
||||
int peersTotal;
|
||||
tr_peer_stat_t * peers;
|
||||
int peersUploading;
|
||||
int peersDownloading;
|
||||
int seeders;
|
||||
|
@ -321,6 +319,14 @@ struct tr_stat_s
|
|||
uint64_t uploaded;
|
||||
};
|
||||
|
||||
struct tr_peer_stat_s
|
||||
{
|
||||
char * client;
|
||||
|
||||
int isDownloading;
|
||||
int isUploading;
|
||||
};
|
||||
|
||||
#ifdef __TRANSMISSION__
|
||||
# include "internal.h"
|
||||
#endif
|
||||
|
|
|
@ -517,22 +517,24 @@
|
|||
|
||||
- (NSArray *) peers
|
||||
{
|
||||
int totalPeers = [self totalPeers], i;
|
||||
int totalPeers, i;
|
||||
|
||||
tr_peer_stat_t * peers = tr_torrentPeers(fHandle, & totalPeers);
|
||||
tr_peer_stat_t peer;
|
||||
|
||||
NSMutableArray * peers = [NSMutableArray arrayWithCapacity: totalPeers];
|
||||
NSMutableArray * peerDics = [NSMutableArray arrayWithCapacity: totalPeers];
|
||||
for (i = 0; i < totalPeers; i++)
|
||||
{
|
||||
peer = fStat->peers[i];
|
||||
peer = peers[i];
|
||||
|
||||
[peers addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[peerDics addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSString stringWithCString: (char *) peer.client encoding: NSUTF8StringEncoding], @"Client",
|
||||
[NSNumber numberWithBool: peer.isDownloading], @"UL To",
|
||||
[NSNumber numberWithBool: peer.isUploading], @"DL From", nil]];
|
||||
}
|
||||
//NSLog(@"%d", tr_peerId(peer));
|
||||
|
||||
return peers;
|
||||
return peerDics;
|
||||
}
|
||||
|
||||
- (NSString *) progressString
|
||||
|
|
Loading…
Add table
Reference in a new issue