27#include "librats/util/rats_export.h"
29#include "librats/bittorrent/client.h"
30#include "librats/dht/dht.h"
32#include <condition_variable>
48 bool use_node_dht =
true;
54 explicit Bittorrent(
const bittorrent::Client::Config& client_config);
68 bittorrent::Client*
client() noexcept {
return client_.get(); }
69 const bittorrent::Client*
client() const noexcept {
return client_.get(); }
71 bool is_running()
const {
return client_ && client_->is_running(); }
85#ifdef RATS_SEARCH_FEATURES
103 using MetadataCallback = std::function<void(
const bittorrent::TorrentInfo& info,
bool success,
104 const std::string& error)>;
113 const std::string& ip, uint16_t port,
118 DhtClient* active_dht()
const;
120 void fetch_metadata_impl(
const std::string& info_hash_hex,
const std::string& ip,
125 std::unique_ptr<bittorrent::Client> client_;
126 bool shared_dht_ =
false;
129 std::mutex meta_mutex_;
130 std::condition_variable meta_cv_;
131 std::condition_variable meta_drain_cv_;
132 bool meta_stopping_ =
false;
133 int meta_inflight_ = 0;
bool using_node_dht() const noexcept
True when start() borrowed the node's DHT rather than running DHT-less.
Bittorrent(Config config)
Bittorrent(const bittorrent::Client::Config &client_config)
Convenience: configure the underlying client directly, share the node DHT.
bool is_spider_mode() const
size_t spider_pool_size() const
std::function< void(const bittorrent::TorrentInfo &info, bool success, const std::string &error)> MetadataCallback
bittorrent::Client * client() noexcept
The underlying client — drive torrents through it (add_magnet, add_torrent_file, add_torrent_for_seed...
Bittorrent & operator=(const Bittorrent &)=delete
void set_spider_mode(bool enable)
void attach(NodeContext &ctx) override
size_t spider_visited_count() const
void set_spider_ignore(bool ignore)
bool is_spider_ignoring() const
void set_spider_announce_callback(SpiderAnnounceCallback callback)
void get_torrent_metadata_from_peer(const std::string &info_hash_hex, const std::string &ip, uint16_t port, MetadataCallback callback, int timeout_ms=60000)
Fetch metadata directly from a known peer (the fast path used when a spider announce told us exactly ...
void clear_spider_state()
Bittorrent(const Bittorrent &)=delete
void get_torrent_metadata(const std::string &info_hash_hex, MetadataCallback callback, int timeout_ms=60000)
Fetch metadata by searching the DHT/trackers for peers that have it.
const bittorrent::Client * client() const noexcept
A pluggable network subsystem.
The narrow contract a subsystem needs from the node — and nothing more.
bittorrent::Client::Config client
download path, listen port, …