2007-09-20 16:32:01 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#include <inttypes.h> /* uint16_t */
|
2008-01-10 18:52:46 +00:00
|
|
|
|
2014-07-04 00:00:07 +00:00
|
|
|
#ifdef _WIN32
|
2017-04-19 12:04:45 +00:00
|
|
|
#include <winsock2.h> /* struct in_addr */
|
2008-10-23 02:37:21 +00:00
|
|
|
#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"
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "peer-socket.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
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
class tr_peerIo;
|
2021-10-07 13:33:55 +00:00
|
|
|
class tr_peerMsgs;
|
2021-10-10 00:13:40 +00:00
|
|
|
class tr_swarm;
|
2011-02-18 00:23:51 +00:00
|
|
|
struct UTPSocket;
|
2021-10-06 22:24:04 +00:00
|
|
|
struct peer_atom;
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_peerMgr;
|
2007-09-20 16:32:01 +00:00
|
|
|
struct tr_peer_stat;
|
|
|
|
struct tr_torrent;
|
|
|
|
|
2010-12-14 18:33:48 +00:00
|
|
|
/* added_f's bitwise-or'ed flags */
|
2008-04-19 15:07:59 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* true if the peer supports encryption */
|
|
|
|
ADDED_F_ENCRYPTION_FLAG = 1,
|
|
|
|
/* true if the peer is a seed or partial seed */
|
|
|
|
ADDED_F_SEED_FLAG = 2,
|
|
|
|
/* true if the peer supports uTP */
|
|
|
|
ADDED_F_UTP_FLAGS = 4,
|
|
|
|
/* true if the peer has holepunch support */
|
|
|
|
ADDED_F_HOLEPUNCH = 8,
|
|
|
|
/* 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
|
|
|
};
|
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_pex
|
2007-09-20 16:32:01 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_address addr;
|
|
|
|
tr_port port; /* this field is in network byte order */
|
|
|
|
uint8_t flags;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_isPex(tr_pex const* pex)
|
2011-01-16 15:47:09 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return pex && tr_address_is_valid(&pex->addr);
|
2011-01-16 15:47:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_address const* tr_peerAddress(tr_peer const*);
|
2009-01-13 16:32:43 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int tr_pexCompare(void const* a, void const* b);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_peerMgr* tr_peerMgrNew(tr_session* session);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrFree(tr_peerMgr* manager);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_peerMgrPeerIsSeed(tr_torrent const* tor, tr_address const* addr);
|
2008-04-17 03:48:56 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_peerMgrSetUtpSupported(tr_torrent* tor, tr_address const* addr);
|
2011-02-18 00:41:06 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_peerMgrSetUtpFailed(tr_torrent* tor, tr_address const* addr, bool failed);
|
2011-02-18 00:43:31 +00:00
|
|
|
|
2021-12-01 23:11:57 +00:00
|
|
|
std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_peer const* peer, size_t numwant);
|
2009-11-08 23:20:00 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_peerMgrDidPeerRequest(tr_torrent const* torrent, tr_peer const* peer, tr_block_index_t block);
|
2009-11-08 23:20:00 +00:00
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
void tr_peerMgrClientSentRequests(tr_torrent* torrent, tr_peer* peer, tr_block_span_t span);
|
2021-11-19 18:37:38 +00:00
|
|
|
|
|
|
|
size_t tr_peerMgrCountActiveRequestsToPeer(tr_torrent const* torrent, tr_peer const* peer);
|
2009-11-08 23:20:00 +00:00
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_address* addr, tr_port port, struct tr_peer_socket const socket);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_pex* tr_peerMgrCompactToPex(
|
|
|
|
void const* compact,
|
|
|
|
size_t compactLen,
|
|
|
|
uint8_t const* added_f,
|
|
|
|
size_t added_f_len,
|
2017-04-19 12:04:45 +00:00
|
|
|
size_t* setme_pex_count);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_pex* tr_peerMgrCompact6ToPex(
|
|
|
|
void const* compact,
|
|
|
|
size_t compactLen,
|
|
|
|
uint8_t const* added_f,
|
|
|
|
size_t added_f_len,
|
2017-04-19 12:04:45 +00:00
|
|
|
size_t* pexCount);
|
2008-12-15 00:17:08 +00:00
|
|
|
|
2021-09-09 20:25:30 +00:00
|
|
|
size_t tr_peerMgrAddPex(tr_torrent* tor, uint8_t from, tr_pex const* pex, size_t n_pex);
|
|
|
|
|
|
|
|
void tr_peerMgrSetSwarmIsAllSeeds(tr_torrent* tor);
|
2010-04-20 21:54:03 +00:00
|
|
|
|
2010-01-05 23:47:50 +00:00
|
|
|
enum
|
2009-11-20 07:47:31 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TR_PEERS_CONNECTED,
|
|
|
|
TR_PEERS_INTERESTING
|
2009-11-20 07:47:31 +00:00
|
|
|
};
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int tr_peerMgrGetPeers(
|
|
|
|
tr_torrent const* tor,
|
|
|
|
tr_pex** setme_pex,
|
|
|
|
uint8_t address_type,
|
|
|
|
uint8_t peer_list_mode,
|
2020-11-05 22:46:21 +00:00
|
|
|
int max_peer_count);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrStartTorrent(tr_torrent* tor);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrStopTorrent(tr_torrent* tor);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrAddTorrent(tr_peerMgr* manager, struct tr_torrent* tor);
|
2007-09-27 03:03:38 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrRemoveTorrent(tr_torrent* tor);
|
2011-02-24 14:35:45 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned int tabCount);
|
2010-06-14 12:01:50 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor);
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrOnTorrentGotMetainfo(tr_torrent* tor);
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrOnBlocklistChanged(tr_peerMgr* manager);
|
2008-10-20 03:47:48 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
struct tr_peer_stat* tr_peerMgrPeerStats(tr_torrent const* tor, int* setmeCount);
|
2009-01-13 16:32:43 +00:00
|
|
|
|
2021-12-07 18:11:28 +00:00
|
|
|
tr_webseed_view tr_peerMgrWebseed(tr_torrent const* tor, size_t i);
|
2010-09-25 00:34:15 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
unsigned int tr_peerGetPieceSpeed_Bps(tr_peer const* peer, uint64_t now, tr_direction direction);
|
2013-01-26 23:08:51 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrClearInterest(tr_torrent* tor);
|
2015-01-02 11:15:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerMgrGotBadPiece(tr_torrent* tor, tr_piece_index_t pieceIndex);
|
2013-01-26 23:08:51 +00:00
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
/* @} */
|