2007-09-20 16:32:01 +00:00
|
|
|
/*
|
2010-01-04 21:00:47 +00:00
|
|
|
* This file Copyright (C) 2007-2010 Mnemosyne LLC
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2007-09-20 16:32:01 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
|
|
|
#error only libtransmission should #include this header.
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#ifndef TR_PEER_MGR_H
|
|
|
|
#define TR_PEER_MGR_H
|
|
|
|
|
|
|
|
#include <inttypes.h> /* uint16_t */
|
2008-01-10 18:52:46 +00:00
|
|
|
|
2008-10-23 02:37:21 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <winsock2.h> /* struct in_addr */
|
|
|
|
#endif
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-06-15 00:11:06 +00:00
|
|
|
#include "bitfield.h"
|
2009-11-24 02:16:31 +00:00
|
|
|
#include "bitset.h"
|
2010-03-08 04:29:58 +00:00
|
|
|
#include "history.h"
|
2008-12-02 03:41:58 +00:00
|
|
|
#include "net.h"
|
2009-11-08 23:20:00 +00:00
|
|
|
#include "peer-common.h" /* struct peer_request */
|
2008-12-02 03:41:58 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup peers Peers
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
struct tr_peer_stat;
|
|
|
|
struct tr_torrent;
|
|
|
|
typedef struct tr_peerMgr tr_peerMgr;
|
|
|
|
|
2008-04-19 15:07:59 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* corresponds to ut_pex's added.f flags */
|
|
|
|
ADDED_F_ENCRYPTION_FLAG = 1,
|
|
|
|
|
|
|
|
/* corresponds to ut_pex's added.f flags */
|
|
|
|
ADDED_F_SEED_FLAG = 2,
|
|
|
|
};
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
typedef struct tr_pex
|
|
|
|
{
|
2008-12-02 03:41:58 +00:00
|
|
|
tr_address addr;
|
2009-12-16 00:45:18 +00:00
|
|
|
tr_port port; /* this field is in network byte order */
|
2008-12-02 03:41:58 +00:00
|
|
|
uint8_t flags;
|
2007-09-20 16:32:01 +00:00
|
|
|
}
|
|
|
|
tr_pex;
|
|
|
|
|
2009-01-13 16:32:43 +00:00
|
|
|
|
|
|
|
struct tr_bandwidth;
|
|
|
|
struct tr_peerIo;
|
|
|
|
struct tr_peermsgs;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ENCRYPTION_PREFERENCE_UNKNOWN,
|
|
|
|
ENCRYPTION_PREFERENCE_YES,
|
|
|
|
ENCRYPTION_PREFERENCE_NO
|
|
|
|
};
|
|
|
|
|
2009-10-22 19:08:45 +00:00
|
|
|
/* opaque forward declaration */
|
|
|
|
struct peer_atom;
|
|
|
|
|
2009-01-13 16:32:43 +00:00
|
|
|
/**
|
|
|
|
* State information about a connected peer.
|
|
|
|
*
|
|
|
|
* @see struct peer_atom
|
|
|
|
* @see tr_peermsgs
|
|
|
|
*/
|
|
|
|
typedef struct tr_peer
|
|
|
|
{
|
|
|
|
tr_bool peerIsChoked;
|
|
|
|
tr_bool peerIsInterested;
|
|
|
|
tr_bool clientIsChoked;
|
|
|
|
tr_bool clientIsInterested;
|
|
|
|
tr_bool doPurge;
|
|
|
|
|
|
|
|
/* number of bad pieces they've contributed to */
|
|
|
|
uint8_t strikes;
|
|
|
|
|
|
|
|
uint8_t encryption_preference;
|
2009-05-16 14:31:18 +00:00
|
|
|
tr_port dht_port;
|
2009-12-16 18:20:01 +00:00
|
|
|
|
|
|
|
/* how many requests the peer has made that we haven't responded to yet */
|
|
|
|
int pendingReqsToClient;
|
|
|
|
|
|
|
|
/* how many requests we've made and are currently awaiting a response for */
|
|
|
|
int pendingReqsToPeer;
|
|
|
|
|
2009-01-13 16:32:43 +00:00
|
|
|
struct tr_peerIo * io;
|
2009-05-09 06:08:21 +00:00
|
|
|
struct peer_atom * atom;
|
2009-01-13 16:32:43 +00:00
|
|
|
|
|
|
|
struct tr_bitfield * blame;
|
2009-11-24 02:16:31 +00:00
|
|
|
struct tr_bitset have;
|
2009-01-13 16:32:43 +00:00
|
|
|
|
|
|
|
/** how complete the peer's copy of the torrent is. [0.0...1.0] */
|
|
|
|
float progress;
|
|
|
|
|
|
|
|
/* the client name from the `v' string in LTEP's handshake dictionary */
|
|
|
|
char * client;
|
|
|
|
|
|
|
|
time_t chokeChangedAt;
|
|
|
|
|
2010-03-08 04:29:58 +00:00
|
|
|
tr_recentHistory * blocksSentToClient;
|
|
|
|
tr_recentHistory * blocksSentToPeer;
|
|
|
|
|
|
|
|
tr_recentHistory * cancelsSentToClient;
|
|
|
|
tr_recentHistory * cancelsSentToPeer;
|
|
|
|
|
2009-01-13 16:32:43 +00:00
|
|
|
struct tr_peermsgs * msgs;
|
|
|
|
}
|
|
|
|
tr_peer;
|
|
|
|
|
2009-10-29 16:10:03 +00:00
|
|
|
const tr_address * tr_peerAddress( const tr_peer * );
|
2009-01-13 16:32:43 +00:00
|
|
|
|
2008-10-20 03:47:48 +00:00
|
|
|
int tr_pexCompare( const void * a, const void * b );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-14 11:21:11 +00:00
|
|
|
tr_peerMgr* tr_peerMgrNew( tr_session * );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-10-20 03:47:48 +00:00
|
|
|
void tr_peerMgrFree( tr_peerMgr * manager );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor,
|
|
|
|
const tr_address * addr );
|
2008-04-17 03:48:56 +00:00
|
|
|
|
2009-11-08 23:20:00 +00:00
|
|
|
void tr_peerMgrGetNextRequests( tr_torrent * torrent,
|
|
|
|
tr_peer * peer,
|
|
|
|
int numwant,
|
|
|
|
tr_block_index_t * setme,
|
|
|
|
int * numgot );
|
|
|
|
|
|
|
|
tr_bool tr_peerMgrDidPeerRequest( const tr_torrent * torrent,
|
|
|
|
const tr_peer * peer,
|
|
|
|
tr_block_index_t block );
|
|
|
|
|
|
|
|
void tr_peerMgrRebuildRequests( tr_torrent * torrent );
|
|
|
|
|
2008-12-02 03:41:58 +00:00
|
|
|
void tr_peerMgrAddIncoming( tr_peerMgr * manager,
|
|
|
|
tr_address * addr,
|
|
|
|
tr_port port,
|
|
|
|
int socket );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-10-20 03:47:48 +00:00
|
|
|
tr_pex * tr_peerMgrCompactToPex( const void * compact,
|
|
|
|
size_t compactLen,
|
|
|
|
const uint8_t * added_f,
|
|
|
|
size_t added_f_len,
|
|
|
|
size_t * setme_pex_count );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-15 00:17:08 +00:00
|
|
|
tr_pex * tr_peerMgrCompact6ToPex( const void * compact,
|
|
|
|
size_t compactLen,
|
|
|
|
const uint8_t * added_f,
|
|
|
|
size_t added_f_len,
|
|
|
|
size_t * pexCount );
|
|
|
|
|
|
|
|
tr_pex * tr_peerMgrArrayToPex( const void * array,
|
|
|
|
size_t arrayLen,
|
|
|
|
size_t * setme_pex_count );
|
|
|
|
|
2010-04-20 21:54:03 +00:00
|
|
|
/**
|
|
|
|
* @param seedProbability [0..100] for likelihood that the peer is a seed; -1 for unknown
|
|
|
|
*/
|
2009-01-13 21:00:05 +00:00
|
|
|
void tr_peerMgrAddPex( tr_torrent * tor,
|
2008-10-20 03:47:48 +00:00
|
|
|
uint8_t from,
|
2010-04-20 21:54:03 +00:00
|
|
|
const tr_pex * pex,
|
|
|
|
int8_t seedProbability );
|
|
|
|
|
|
|
|
void tr_peerMgrMarkAllAsSeeds( tr_torrent * tor );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
void tr_peerMgrSetBlame( tr_torrent * tor,
|
2008-10-20 03:47:48 +00:00
|
|
|
tr_piece_index_t pieceIndex,
|
|
|
|
int success );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2010-01-05 23:47:50 +00:00
|
|
|
enum
|
2009-11-20 07:47:31 +00:00
|
|
|
{
|
|
|
|
TR_PEERS_CONNECTED,
|
|
|
|
TR_PEERS_ALL
|
|
|
|
};
|
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
int tr_peerMgrGetPeers( tr_torrent * tor,
|
2008-12-15 00:17:08 +00:00
|
|
|
tr_pex ** setme_pex,
|
2009-11-20 07:47:31 +00:00
|
|
|
uint8_t address_type,
|
|
|
|
uint8_t peer_list_mode,
|
|
|
|
int max_peer_count );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
void tr_peerMgrStartTorrent( tr_torrent * tor );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
void tr_peerMgrStopTorrent( tr_torrent * tor );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-10-20 03:47:48 +00:00
|
|
|
void tr_peerMgrAddTorrent( tr_peerMgr * manager,
|
|
|
|
struct tr_torrent * tor );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
void tr_peerMgrRemoveTorrent( tr_torrent * tor );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
void tr_peerMgrTorrentAvailability( const tr_torrent * tor,
|
2008-10-20 03:47:48 +00:00
|
|
|
int8_t * tab,
|
|
|
|
unsigned int tabCount );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor );
|
2007-09-27 03:03:38 +00:00
|
|
|
|
2010-06-14 12:01:50 +00:00
|
|
|
void tr_peerMgrOnBlocklistChanged( tr_peerMgr * manager );
|
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
void tr_peerMgrTorrentStats( tr_torrent * tor,
|
2008-10-20 03:47:48 +00:00
|
|
|
int * setmePeersKnown,
|
|
|
|
int * setmePeersConnected,
|
|
|
|
int * setmeSeedsConnected,
|
|
|
|
int * setmeWebseedsSendingToUs,
|
|
|
|
int * setmePeersSendingToUs,
|
|
|
|
int * setmePeersGettingFromUs,
|
|
|
|
int * setmePeersFrom ); /* TR_PEER_FROM__MAX */
|
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
|
|
|
|
int * setmeCount );
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2010-07-03 00:25:22 +00:00
|
|
|
int tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now );
|
2009-05-28 02:28:14 +00:00
|
|
|
|
2010-07-04 06:07:21 +00:00
|
|
|
double* tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor );
|
2008-10-20 03:47:48 +00:00
|
|
|
|
|
|
|
|
2010-07-03 00:25:22 +00:00
|
|
|
int tr_peerGetPieceSpeed_Bps( const tr_peer * peer,
|
|
|
|
uint64_t now,
|
|
|
|
tr_direction direction );
|
2009-01-13 16:32:43 +00:00
|
|
|
|
2010-09-25 00:34:15 +00:00
|
|
|
void tr_peerMgrClearInterest( tr_torrent * tor );
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/* @} */
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#endif
|