#include "transmission.h"
#include "bencode.h"
+#include "torrent.h"
#include "utils.h"
#include "ipcparse.h"
{ "lookup", 2, IPC_MSG_LOOKUP },
{ "noop", 2, IPC_MSG_NOOP },
{ "not-supported", 2, IPC_MSG_NOTSUP },
+ { "peer-max", 2, IPC_MSG_PEERMAX },
{ "pex", 2, IPC_MSG_PEX },
{ "port", 2, IPC_MSG_PORT },
{ "quit", 1, IPC_MSG_QUIT },
{ "id", IPC_ST_ID },
{ "peers-downloading", IPC_ST_PEERDOWN },
{ "peers-from", IPC_ST_PEERFROM },
+ { "peers-max", IPC_ST_PEERMAX },
{ "peers-total", IPC_ST_PEERTOTAL },
{ "peers-uploading", IPC_ST_PEERUP },
{ "running", IPC_ST_RUNNING },
* It specifies what to put in the dictionary.
*/
int
-ipc_addstat( tr_benc * list,
- int torrent_id,
- const tr_stat * st,
- int types )
+ipc_addstat( tr_benc * list,
+ int torrent_id,
+ tr_torrent * tor,
+ int types )
{
- tr_benc * dict;
- int ii, used;
+ const tr_stat * st = tr_torrentStatCached( tor );
+ tr_benc * dict;
+ int ii, used;
/* add the dictionary child */
tr_bencListReserve( list, 1 );
tr_bencInitInt( tr_bencDictAdd( item, "pex" ),
st->peersFrom[TR_PEER_FROM_PEX] );
break;
+ case IPC_ST_PEERMAX:
+ tr_bencInitInt( item, tor->maxConnectedPeers );
+ break;
case IPC_ST_PEERTOTAL:
tr_bencInitInt( item, st->peersConnected );
break;
IPC_MSG_LOOKUP,
IPC_MSG_NOOP,
IPC_MSG_NOTSUP,
+ IPC_MSG_PEERMAX,
IPC_MSG_PEX,
IPC_MSG_PORT,
IPC_MSG_QUIT,
#define IPC_ST_ID ( 1 << 7 )
#define IPC_ST_PEERDOWN ( 1 << 8 )
#define IPC_ST_PEERFROM ( 1 << 9 )
-#define IPC_ST_PEERTOTAL ( 1 << 10 )
-#define IPC_ST_PEERUP ( 1 << 11 )
-#define IPC_ST_RUNNING ( 1 << 12 )
-#define IPC_ST_TKDONE ( 1 << 13 )
-#define IPC_ST_TKLEECH ( 1 << 14 )
-#define IPC_ST_TKSEED ( 1 << 15 )
-#define IPC_ST_STATE ( 1 << 16 )
-#define IPC_ST_SWARM ( 1 << 17 )
-#define IPC_ST_TRACKER ( 1 << 18 )
-#define IPC_ST_UPSPEED ( 1 << 19 )
-#define IPC_ST_UPTOTAL ( 1 << 20 )
-#define IPC_ST__MAX ( 1 << 21 )
+#define IPC_ST_PEERMAX ( 1 << 10 )
+#define IPC_ST_PEERTOTAL ( 1 << 11 )
+#define IPC_ST_PEERUP ( 1 << 12 )
+#define IPC_ST_RUNNING ( 1 << 13 )
+#define IPC_ST_TKDONE ( 1 << 14 )
+#define IPC_ST_TKLEECH ( 1 << 15 )
+#define IPC_ST_TKSEED ( 1 << 16 )
+#define IPC_ST_STATE ( 1 << 17 )
+#define IPC_ST_SWARM ( 1 << 18 )
+#define IPC_ST_TRACKER ( 1 << 19 )
+#define IPC_ST_UPSPEED ( 1 << 20 )
+#define IPC_ST_UPTOTAL ( 1 << 21 )
+#define IPC_ST__MAX ( 1 << 22 )
struct ipc_funcs;
struct ipc_info;
int ipc_addinfo ( struct tr_benc *, int,
const struct tr_info *, int );
-int ipc_addstat ( struct tr_benc *, int,
- const struct tr_stat *, int );
+
+struct tr_torrent;
+
+int ipc_addstat ( struct tr_benc * appendme_list,
+ int torrent_id,
+ struct tr_torrent * tor,
+ int stat_types );
/* sets errno to EINVAL on parse error or
EPERM for unsupported protocol version */
int socket;
errno = 0;
socket = tr_netBindTCP( s->publicPort );
-fprintf( stderr, "opening socket on %d to listen\n", s->publicPort );
if( socket >= 0 ) {
tr_ninf( getKey(), _( "Opened port %d to listen for incoming peer connections" ), s->publicPort );
s->bindPort = s->publicPort;
const tr_info *
tr_torrentInfo( const tr_torrent * tor )
{
- return &tor->info;
+ return tor ? &tor->info : NULL;
}
const tr_stat *
{
const time_t now = time( NULL );
- return now == tor->lastStatTime ? &tor->stats
- : tr_torrentStat( tor );
+ return tor && ( now == tor->lastStatTime ) ? &tor->stats
+ : tr_torrentStat( tor );
}
tr_torrent_status
tr_stat * s;
struct tr_tracker * tc;
+ if( !tor )
+ return NULL;
+
tr_torrentLock( tor );
tor->lastStatTime = time( NULL );