DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
transfer_interface_bittorrent.hpp
Go to the documentation of this file.
1
9#ifndef SNBMODULES_INCLUDE_SNBMODULES_INTERFACES_TRANSFER_INTERFACE_BITTORRENT_HPP_
10#define SNBMODULES_INCLUDE_SNBMODULES_INTERFACES_TRANSFER_INTERFACE_BITTORRENT_HPP_
11
14
15#include "libtorrent/create_torrent.hpp"
16#include "libtorrent/error_code.hpp"
17#include "libtorrent/torrent_handle.hpp"
18#include "libtorrent/torrent_status.hpp"
19
20#include "libtorrent/add_torrent_params.hpp"
21#include "libtorrent/alert_types.hpp"
22#include "libtorrent/announce_entry.hpp"
23#include "libtorrent/bdecode.hpp"
24#include "libtorrent/bencode.hpp"
25#include "libtorrent/config.hpp"
26#include "libtorrent/disabled_disk_io.hpp" // for disabled_disk_io_constructor
27#include "libtorrent/disk_interface.hpp" // for open_file_state
28#include "libtorrent/entry.hpp"
29#include "libtorrent/identify_client.hpp"
30#include "libtorrent/ip_filter.hpp"
31#include "libtorrent/load_torrent.hpp"
32#include "libtorrent/magnet_uri.hpp"
33#include "libtorrent/peer_info.hpp"
34#include "libtorrent/read_resume_data.hpp"
35#include "libtorrent/session.hpp"
36#include "libtorrent/session_params.hpp"
37#include "libtorrent/string_view.hpp"
38#include "libtorrent/time.hpp"
39#include "libtorrent/torrent_info.hpp"
40#include "libtorrent/write_resume_data.hpp"
41
42#include <csignal>
43#include <dirent.h>
44#include <filesystem>
45#include <sys/ioctl.h>
46#include <termios.h>
47#include <utility>
48
49#include <algorithm> // for min()/max()
50#include <cstdio> // for snprintf
51#include <cstdlib> // for atoi
52#include <cstring>
53#include <deque>
54#include <fstream>
55#include <regex>
56
57#include <map>
58#include <string>
59#include <vector>
60
61namespace dunedaq::snbmodules {
62using clk = std::chrono::steady_clock;
63using lt::seconds;
64using std::chrono::duration_cast;
65
67{
68 // torrent_view &view;
69 // session_view &ses_view;
70 std::deque<std::string> events;
71 std::vector<lt::peer_info> peers;
72 std::vector<std::int64_t> file_progress;
73 std::vector<lt::partial_piece_info> download_queue;
74 std::vector<lt::block_info> download_queue_block_info;
75 std::vector<int> piece_availability;
76 std::vector<lt::announce_entry> trackers;
77
78 void clear()
79 {
80 peers.clear();
81 file_progress.clear();
82 download_queue.clear();
84 piece_availability.clear();
85 trackers.clear();
86 }
87};
88
90{
91
92public:
94 bool is_client,
95 std::filesystem::path work_dir,
96 const IPFormat& listening_ip);
98
99 void generate_torrents_files(const std::filesystem::path& dest, const std::string& tracker);
100 std::filesystem::path get_work_dir() { return m_work_dir; }
101
102 bool upload_file(TransferMetadata& f_meta) override;
103 bool download_file(TransferMetadata& f_meta, std::filesystem::path dest) override;
104 bool pause_file(TransferMetadata& f_meta) override;
105 bool resume_file(TransferMetadata& f_meta) override;
106 bool hash_file(TransferMetadata& f_meta) override;
107 bool cancel_file(TransferMetadata& f_meta) override;
108
109private:
110 lt::session ses;
113 int m_peer_num = 0;
114 int m_paused = 0;
115 bool save_on_exit = true;
116 std::filesystem::path m_work_dir;
119 std::map<std::string, TransferMetadata*> m_filename_to_metadata;
120 int m_rate_limit = -1;
121
122 // bool print_ip = true;
123 // bool print_peaks = true;
124 // bool print_local_ip = true;
125 // bool print_timers = false;
126 // bool print_block = false;
127 // bool print_fails = false;
128 // bool print_send_bufs = true;
129 // bool print_connecting_peers = true;
130
131 // bool print_peers = true;
132 // bool print_peers_legend = true;
133
134 // return the name of a torrent status enum
135 char const* state(lt::torrent_status::state_t s);
136
137 bool add_magnet(lt::string_view uri, const std::filesystem::path& dest);
138 // return magnet url
139 std::string add_torrent(const std::string& torrent, const std::filesystem::path& dest);
140
141 void set_torrent_params(lt::add_torrent_params& p, const std::filesystem::path& dest);
142 lt::session_params set_settings(const IPFormat& listen_interface, const std::string& listen_port);
143
144 static std::vector<char> load_file(std::string const& filename);
145 static std::string branch_path(std::string const& f);
146 // int print_peer_info(std::string &out, std::vector<lt::peer_info> const &peers, int max_lines);
147 // int print_peer_legend(std::string &out, int max_lines);
148 // std::string print_endpoint(lt::tcp::endpoint const &ep);
149
150 // do not include files and folders whose
151 // name starts with a .
152 static bool file_filter(std::string const& f);
153
154 bool make_torrent(std::filesystem::path full_path,
155 int piece_size,
156 const std::string& tracker,
157 const std::string& outfile);
158
159 // Threading
161 void do_work(std::atomic<bool>&);
162};
163} // namespace dunedaq::snbmodules
164#endif // SNBMODULES_INCLUDE_SNBMODULES_INTERFACES_TRANSFER_INTERFACE_BITTORRENT_HPP_
Class that represents an IP address and a port TODO: should be replaced by something better ?
Definition ip_format.hpp:26
TransferInterfaceBittorrent(GroupMetadata &config, bool is_client, std::filesystem::path work_dir, const IPFormat &listening_ip)
void set_torrent_params(lt::add_torrent_params &p, const std::filesystem::path &dest)
static std::vector< char > load_file(std::string const &filename)
bool make_torrent(std::filesystem::path full_path, int piece_size, const std::string &tracker, const std::string &outfile)
bool download_file(TransferMetadata &f_meta, std::filesystem::path dest) override
bool add_magnet(lt::string_view uri, const std::filesystem::path &dest)
std::map< std::string, TransferMetadata * > m_filename_to_metadata
lt::session_params set_settings(const IPFormat &listen_interface, const std::string &listen_port)
void generate_torrents_files(const std::filesystem::path &dest, const std::string &tracker)
std::string add_torrent(const std::string &torrent, const std::filesystem::path &dest)
WorkerThread contains a thread which runs the do_work() function.
std::chrono::steady_clock clk
Unsupported std::string uri Execution of command std::string error Failed to create CommandFacility uri
Definition Issues.hpp:77
std::vector< lt::block_info > download_queue_block_info
std::vector< lt::partial_piece_info > download_queue