mirror of
https://github.com/transmission/transmission
synced 2025-03-09 13:50:00 +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;
|
s->peersDownloading = 0;
|
||||||
|
|
||||||
tr_peer_t * peer;
|
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++ )
|
for( i = 0; i < tor->peerCount; i++ )
|
||||||
{
|
{
|
||||||
peer = tor->peers[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 ) )
|
if( tr_peerIsConnected( peer ) )
|
||||||
{
|
{
|
||||||
|
@ -490,6 +484,33 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
|
||||||
return s;
|
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 )
|
void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size )
|
||||||
{
|
{
|
||||||
int i, j, piece;
|
int i, j, piece;
|
||||||
|
|
|
@ -210,6 +210,13 @@ int tr_getFinished( tr_torrent_t * );
|
||||||
typedef struct tr_stat_s tr_stat_t;
|
typedef struct tr_stat_s tr_stat_t;
|
||||||
tr_stat_t * tr_torrentStat( tr_torrent_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
|
* tr_torrentAvailability
|
||||||
***********************************************************************
|
***********************************************************************
|
||||||
|
@ -279,14 +286,6 @@ struct tr_info_s
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* tr_stat_s
|
* tr_stat_s
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
typedef struct tr_peer_stat_s
|
|
||||||
{
|
|
||||||
char * client;
|
|
||||||
|
|
||||||
int isDownloading;
|
|
||||||
int isUploading;
|
|
||||||
}
|
|
||||||
tr_peer_stat_t;
|
|
||||||
struct tr_stat_s
|
struct tr_stat_s
|
||||||
{
|
{
|
||||||
#define TR_STATUS_CHECK 0x001 /* Checking files */
|
#define TR_STATUS_CHECK 0x001 /* Checking files */
|
||||||
|
@ -311,7 +310,6 @@ struct tr_stat_s
|
||||||
float rateUpload;
|
float rateUpload;
|
||||||
int eta;
|
int eta;
|
||||||
int peersTotal;
|
int peersTotal;
|
||||||
tr_peer_stat_t * peers;
|
|
||||||
int peersUploading;
|
int peersUploading;
|
||||||
int peersDownloading;
|
int peersDownloading;
|
||||||
int seeders;
|
int seeders;
|
||||||
|
@ -321,6 +319,14 @@ struct tr_stat_s
|
||||||
uint64_t uploaded;
|
uint64_t uploaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct tr_peer_stat_s
|
||||||
|
{
|
||||||
|
char * client;
|
||||||
|
|
||||||
|
int isDownloading;
|
||||||
|
int isUploading;
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __TRANSMISSION__
|
#ifdef __TRANSMISSION__
|
||||||
# include "internal.h"
|
# include "internal.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -517,22 +517,24 @@
|
||||||
|
|
||||||
- (NSArray *) peers
|
- (NSArray *) peers
|
||||||
{
|
{
|
||||||
int totalPeers = [self totalPeers], i;
|
int totalPeers, i;
|
||||||
|
|
||||||
|
tr_peer_stat_t * peers = tr_torrentPeers(fHandle, & totalPeers);
|
||||||
tr_peer_stat_t peer;
|
tr_peer_stat_t peer;
|
||||||
|
|
||||||
NSMutableArray * peers = [NSMutableArray arrayWithCapacity: totalPeers];
|
NSMutableArray * peerDics = [NSMutableArray arrayWithCapacity: totalPeers];
|
||||||
for (i = 0; i < totalPeers; i++)
|
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",
|
[NSString stringWithCString: (char *) peer.client encoding: NSUTF8StringEncoding], @"Client",
|
||||||
[NSNumber numberWithBool: peer.isDownloading], @"UL To",
|
[NSNumber numberWithBool: peer.isDownloading], @"UL To",
|
||||||
[NSNumber numberWithBool: peer.isUploading], @"DL From", nil]];
|
[NSNumber numberWithBool: peer.isUploading], @"DL From", nil]];
|
||||||
}
|
}
|
||||||
//NSLog(@"%d", tr_peerId(peer));
|
//NSLog(@"%d", tr_peerId(peer));
|
||||||
|
|
||||||
return peers;
|
return peerDics;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) progressString
|
- (NSString *) progressString
|
||||||
|
|
Loading…
Add table
Reference in a new issue