2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2010-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2009-09-25 21:05:59 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2009-09-25 21:05:59 +00:00
|
|
|
#endif
|
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
#include <cstddef> // size_t
|
2022-04-08 01:50:26 +00:00
|
|
|
#include <cstdint> // uint32_t
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <string_view>
|
2022-01-23 05:41:01 +00:00
|
|
|
#include <vector>
|
2021-12-15 21:25:42 +00:00
|
|
|
|
2009-09-25 21:05:59 +00:00
|
|
|
#include "transmission.h"
|
2021-12-15 21:25:42 +00:00
|
|
|
|
2022-01-09 16:55:09 +00:00
|
|
|
#include "interned-string.h"
|
2022-10-21 18:15:14 +00:00
|
|
|
#include "net.h"
|
2009-09-25 21:05:59 +00:00
|
|
|
|
|
|
|
struct tr_announcer;
|
2022-01-23 05:41:01 +00:00
|
|
|
struct tr_torrent_announcer;
|
2009-09-25 21:05:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* *** Tracker Publish / Subscribe
|
|
|
|
* **/
|
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
enum TrackerEventType
|
2009-09-25 21:05:59 +00:00
|
|
|
{
|
|
|
|
TR_TRACKER_WARNING,
|
|
|
|
TR_TRACKER_ERROR,
|
|
|
|
TR_TRACKER_ERROR_CLEAR,
|
2021-09-09 20:25:30 +00:00
|
|
|
TR_TRACKER_PEERS,
|
|
|
|
TR_TRACKER_COUNTS,
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2011-01-22 17:45:54 +00:00
|
|
|
struct tr_pex;
|
|
|
|
|
2022-04-21 14:28:38 +00:00
|
|
|
/** @brief Notification object to tell listeners about announce or scrape occurrences */
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_tracker_event
|
2009-09-25 21:05:59 +00:00
|
|
|
{
|
|
|
|
/* what type of event this is */
|
2017-04-19 12:04:45 +00:00
|
|
|
TrackerEventType messageType;
|
2009-09-25 21:05:59 +00:00
|
|
|
|
|
|
|
/* for TR_TRACKER_WARNING and TR_TRACKER_ERROR */
|
2021-12-23 17:16:05 +00:00
|
|
|
std::string_view text;
|
|
|
|
tr_interned_string announce_url;
|
2009-09-25 21:05:59 +00:00
|
|
|
|
|
|
|
/* for TR_TRACKER_PEERS */
|
2022-01-23 05:41:01 +00:00
|
|
|
std::vector<tr_pex> pex;
|
2010-04-20 21:54:03 +00:00
|
|
|
|
2021-09-09 20:25:30 +00:00
|
|
|
/* for TR_TRACKER_PEERS and TR_TRACKER_COUNTS */
|
|
|
|
int leechers;
|
|
|
|
int seeders;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
using tr_tracker_callback = void (*)(tr_torrent* tor, tr_tracker_event const* event, void* client_data);
|
2010-06-19 14:33:10 +00:00
|
|
|
|
2009-09-25 21:05:59 +00:00
|
|
|
/**
|
|
|
|
*** Session ctor/dtor
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_announcerInit(tr_session*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_announcerClose(tr_session*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** For torrent customers
|
|
|
|
**/
|
|
|
|
|
2022-08-03 06:15:37 +00:00
|
|
|
struct tr_torrent_announcer* tr_announcerAddTorrent(tr_torrent* torrent, tr_tracker_callback callback, void* callback_data);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_announcerResetTorrent(struct tr_announcer*, tr_torrent*);
|
2009-10-02 04:54:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_announcerRemoveTorrent(struct tr_announcer*, tr_torrent*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_announcerChangeMyPort(tr_torrent*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_announcerCanManualAnnounce(tr_torrent const*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_announcerManualAnnounce(tr_torrent*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_announcerTorrentStarted(tr_torrent*);
|
|
|
|
void tr_announcerTorrentStopped(tr_torrent*);
|
|
|
|
void tr_announcerTorrentCompleted(tr_torrent*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TR_ANN_UP,
|
|
|
|
TR_ANN_DOWN,
|
|
|
|
TR_ANN_CORRUPT
|
|
|
|
};
|
|
|
|
|
2022-09-07 16:04:28 +00:00
|
|
|
void tr_announcerAddBytes(tr_torrent*, int type, uint32_t n_bytes);
|
2010-02-08 16:47:30 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
time_t tr_announcerNextManualAnnounce(tr_torrent const*);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2022-08-03 06:15:37 +00:00
|
|
|
tr_tracker_view tr_announcerTracker(tr_torrent const* torrent, size_t nth);
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2021-12-10 02:03:26 +00:00
|
|
|
size_t tr_announcerTrackerCount(tr_torrent const* tor);
|
|
|
|
|
2022-10-21 18:15:14 +00:00
|
|
|
/// ANNOUNCE
|
|
|
|
|
|
|
|
enum tr_announce_event
|
|
|
|
{
|
|
|
|
/* Note: the ordering of this enum's values is important to
|
|
|
|
* announcer.c's tr_tier.announce_event_priority. If changing
|
|
|
|
* the enum, ensure announcer.c is compatible with the change. */
|
|
|
|
TR_ANNOUNCE_EVENT_NONE,
|
|
|
|
TR_ANNOUNCE_EVENT_STARTED,
|
|
|
|
TR_ANNOUNCE_EVENT_COMPLETED,
|
|
|
|
TR_ANNOUNCE_EVENT_STOPPED,
|
|
|
|
};
|
|
|
|
|
2022-11-18 02:23:54 +00:00
|
|
|
struct tr_announce_request;
|
|
|
|
struct tr_announce_response;
|
2022-10-21 18:15:14 +00:00
|
|
|
using tr_announce_response_func = void (*)(tr_announce_response const* response, void* userdata);
|
|
|
|
|
2022-11-18 02:23:54 +00:00
|
|
|
struct tr_scrape_request;
|
|
|
|
struct tr_scrape_response;
|
2022-10-21 18:15:14 +00:00
|
|
|
using tr_scrape_response_func = void (*)(tr_scrape_response const* response, void* user_data);
|
|
|
|
|
|
|
|
/// UDP ANNOUNCER
|
|
|
|
|
|
|
|
class tr_announcer_udp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Mediator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Mediator() noexcept = default;
|
|
|
|
virtual void sendto(void const* buf, size_t buflen, sockaddr const* addr, socklen_t addrlen) = 0;
|
|
|
|
[[nodiscard]] virtual std::optional<tr_address> announceIP() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~tr_announcer_udp() noexcept = default;
|
|
|
|
|
|
|
|
[[nodiscard]] static std::unique_ptr<tr_announcer_udp> create(Mediator&);
|
|
|
|
|
|
|
|
[[nodiscard]] virtual bool isIdle() const noexcept = 0;
|
|
|
|
|
|
|
|
virtual void announce(tr_announce_request const& request, tr_announce_response_func response_func, void* user_data) = 0;
|
|
|
|
|
|
|
|
virtual void scrape(tr_scrape_request const& request, tr_scrape_response_func response_func, void* user_data) = 0;
|
|
|
|
|
|
|
|
virtual void upkeep() = 0;
|
|
|
|
|
|
|
|
virtual void startShutdown() = 0;
|
|
|
|
|
|
|
|
// @brief process an incoming udp message if it's a tracker response.
|
|
|
|
// @return true if msg was a tracker response; false otherwise
|
|
|
|
virtual bool handleMessage(uint8_t const* msg, size_t msglen) = 0;
|
|
|
|
};
|