2007-09-20 16:32:01 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2012-12-05 17:29:46 +00:00
|
|
|
* 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
|
|
|
|
2011-03-24 22:45:04 +00:00
|
|
|
#include "net.h" /* tr_address */
|
2013-02-03 22:40:00 +00:00
|
|
|
#include "peer-common.h"
|
2012-12-22 20:35:19 +00:00
|
|
|
#include "quark.h"
|
2008-12-02 03:41:58 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup peers Peers
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-02-18 00:23:51 +00:00
|
|
|
struct UTPSocket;
|
2007-09-20 16:32:01 +00:00
|
|
|
struct tr_peer_stat;
|
|
|
|
struct tr_torrent;
|
|
|
|
typedef struct tr_peerMgr tr_peerMgr;
|
|
|
|
|
2010-12-14 18:33:48 +00:00
|
|
|
/* added_f's bitwise-or'ed flags */
|
2008-04-19 15:07:59 +00:00
|
|
|
enum
|
|
|
|
{
|
2013-02-02 20:17:52 +00:00
|
|
|
/* true if the peer supports encryption */
|
|
|
|
ADDED_F_ENCRYPTION_FLAG = 1,
|
2008-04-19 15:07:59 +00:00
|
|
|
|
2013-02-02 20:17:52 +00:00
|
|
|
/* true if the peer is a seed or partial seed */
|
|
|
|
ADDED_F_SEED_FLAG = 2,
|
2010-12-14 18:33:48 +00:00
|
|
|
|
2013-02-02 20:17:52 +00:00
|
|
|
/* true if the peer supports uTP */
|
|
|
|
ADDED_F_UTP_FLAGS = 4,
|
2010-12-14 18:33:48 +00:00
|
|
|
|
2013-02-02 20:17:52 +00:00
|
|
|
/* true if the peer has holepunch support */
|
|
|
|
ADDED_F_HOLEPUNCH = 8,
|
2010-12-14 18:33:48 +00:00
|
|
|
|
2013-02-02 20:17:52 +00:00
|
|
|
/* true if the peer telling us about this peer
|
|
|
|
* initiated the connection (implying that it is connectible) */
|
|
|
|
ADDED_F_CONNECTABLE = 16
|
2008-04-19 15:07:59 +00:00
|
|
|
};
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
typedef struct tr_pex
|
|
|
|
{
|
2013-02-02 20:17:52 +00:00
|
|
|
tr_address addr;
|
|
|
|
tr_port port; /* this field is in network byte order */
|
|
|
|
uint8_t flags;
|
2007-09-20 16:32:01 +00:00
|
|
|
}
|
|
|
|
tr_pex;
|
|
|
|
|
2009-10-22 19:08:45 +00:00
|
|
|
struct peer_atom;
|
2013-02-04 16:23:33 +00:00
|
|
|
struct tr_peerIo;
|
|
|
|
struct tr_peerMsgs;
|
|
|
|
struct tr_swarm;
|
2011-03-03 18:33:24 +00:00
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static inline bool
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_isPex (const tr_pex * pex)
|
2011-01-16 15:47:09 +00:00
|
|
|
{
|
2013-02-04 16:23:33 +00:00
|
|
|
return pex && tr_address_is_valid (&pex->addr);
|
2011-01-16 15:47:09 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_address * tr_peerAddress (const tr_peer *);
|
2009-01-13 16:32:43 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
int tr_pexCompare (const void * a, const void * b);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
tr_peerMgr * tr_peerMgrNew (tr_session * session);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrFree (tr_peerMgr * manager);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
bool tr_peerMgrPeerIsSeed (const tr_torrent * tor,
|
|
|
|
const tr_address * addr);
|
2008-04-17 03:48:56 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrSetUtpSupported (tr_torrent * tor,
|
|
|
|
const tr_address * addr);
|
2011-02-18 00:41:06 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrSetUtpFailed (tr_torrent * tor,
|
|
|
|
const tr_address * addr,
|
|
|
|
bool failed);
|
2011-02-18 00:43:31 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrGetNextRequests (tr_torrent * torrent,
|
|
|
|
tr_peer * peer,
|
|
|
|
int numwant,
|
|
|
|
tr_block_index_t * setme,
|
|
|
|
int * numgot,
|
|
|
|
bool get_intervals);
|
2009-11-08 23:20:00 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
bool tr_peerMgrDidPeerRequest (const tr_torrent * torrent,
|
|
|
|
const tr_peer * peer,
|
|
|
|
tr_block_index_t block);
|
2009-11-08 23:20:00 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrRebuildRequests (tr_torrent * torrent);
|
2009-11-08 23:20:00 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrAddIncoming (tr_peerMgr * manager,
|
|
|
|
tr_address * addr,
|
|
|
|
tr_port port,
|
|
|
|
int socket,
|
|
|
|
struct UTPSocket * utp_socket);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +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
|
|
|
|
2013-02-04 16:23:33 +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);
|
2008-12-15 00:17:08 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
tr_pex * tr_peerMgrArrayToPex (const void * array,
|
|
|
|
size_t arrayLen,
|
|
|
|
size_t * setme_pex_count);
|
2008-12-15 00:17:08 +00:00
|
|
|
|
2010-04-20 21:54:03 +00:00
|
|
|
/**
|
|
|
|
* @param seedProbability [0..100] for likelihood that the peer is a seed; -1 for unknown
|
|
|
|
*/
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrAddPex (tr_torrent * tor,
|
|
|
|
uint8_t from,
|
|
|
|
const tr_pex * pex,
|
|
|
|
int8_t seedProbability);
|
2010-04-20 21:54:03 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrMarkAllAsSeeds (tr_torrent * tor);
|
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
|
|
|
{
|
2013-02-04 16:23:33 +00:00
|
|
|
TR_PEERS_CONNECTED,
|
|
|
|
TR_PEERS_INTERESTING
|
2009-11-20 07:47:31 +00:00
|
|
|
};
|
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
int tr_peerMgrGetPeers (tr_torrent * tor,
|
|
|
|
tr_pex ** setme_pex,
|
|
|
|
uint8_t address_type,
|
|
|
|
uint8_t peer_list_mode,
|
|
|
|
int max_peer_count);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrStartTorrent (tr_torrent * tor);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrStopTorrent (tr_torrent * tor);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrAddTorrent (tr_peerMgr * manager,
|
|
|
|
struct tr_torrent * tor);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrRemoveTorrent (tr_torrent * tor);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrTorrentAvailability (const tr_torrent * tor,
|
|
|
|
int8_t * tab,
|
|
|
|
unsigned int tabCount);
|
2007-09-27 03:03:38 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
uint64_t tr_peerMgrGetDesiredAvailable (const tr_torrent * tor);
|
2011-02-24 14:35:45 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrOnTorrentGotMetainfo (tr_torrent * tor);
|
2010-06-14 12:01:50 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrOnBlocklistChanged (tr_peerMgr * manager);
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrTorrentStats (tr_torrent * tor,
|
|
|
|
int * setmePeersConnected,
|
|
|
|
int * setmeWebseedsSendingToUs,
|
|
|
|
int * setmePeersSendingToUs,
|
|
|
|
int * setmePeersGettingFromUs,
|
|
|
|
int * setmePeersFrom); /* TR_PEER_FROM__MAX */
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
struct tr_peer_stat * tr_peerMgrPeerStats (const tr_torrent * tor,
|
|
|
|
int * setmeCount);
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
double * tr_peerMgrWebSpeeds_KBps (const tr_torrent * tor);
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
unsigned int tr_peerGetPieceSpeed_Bps (const tr_peer * peer,
|
|
|
|
uint64_t now,
|
|
|
|
tr_direction direction);
|
2009-01-13 16:32:43 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrClearInterest (tr_torrent * tor);
|
2010-09-25 00:34:15 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrGotBadPiece (tr_torrent * tor,
|
|
|
|
tr_piece_index_t pieceIndex);
|
2013-01-26 23:08:51 +00:00
|
|
|
|
2013-02-04 16:23:33 +00:00
|
|
|
void tr_peerMgrPieceCompleted (tr_torrent * tor,
|
|
|
|
tr_piece_index_t pieceIndex);
|
2013-01-26 23:08:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/* @} */
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#endif
|