-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathwrappers.cc
More file actions
200 lines (155 loc) · 4 KB
/
wrappers.cc
File metadata and controls
200 lines (155 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "config.h"
#include "torrent/tracker/wrappers.h"
#include <utility>
#include "tracker/tracker_list.h"
#include "tracker/tracker_controller.h"
namespace torrent::tracker {
// Must be called from main thread.
bool
TrackerControllerWrapper::is_active() const {
return m_ptr->is_active();
}
bool
TrackerControllerWrapper::is_requesting() const {
return m_ptr->is_requesting();
}
bool
TrackerControllerWrapper::is_failure_mode() const {
return m_ptr->is_failure_mode();
}
bool
TrackerControllerWrapper::is_promiscuous_mode() const {
return m_ptr->is_promiscuous_mode();
}
bool
TrackerControllerWrapper::has_active_trackers() const {
return m_ptr->tracker_list()->has_active();
}
bool
TrackerControllerWrapper::has_active_trackers_not_scrape() const {
return m_ptr->tracker_list()->has_active_not_scrape();
}
bool
TrackerControllerWrapper::has_usable_trackers() const {
return m_ptr->tracker_list()->has_usable();
}
uint32_t
TrackerControllerWrapper::key() const {
return m_ptr->tracker_list()->key();
}
int32_t
TrackerControllerWrapper::numwant() const {
return m_ptr->tracker_list()->numwant();
}
void
TrackerControllerWrapper::set_numwant(int32_t n) {
m_ptr->tracker_list()->set_numwant(n);
}
uint32_t
TrackerControllerWrapper::size() const {
return m_ptr->tracker_list()->size();
}
Tracker
TrackerControllerWrapper::at(uint32_t index) const {
// TODO: This function should make it a hard exception if the index is out of range, and have a
// different function that can return invalid trackers.
return m_ptr->tracker_list()->at(index);
}
void
TrackerControllerWrapper::add_extra_tracker(uint32_t group, const std::string& url) {
m_ptr->tracker_list()->insert_url(group, url, true);
}
uint32_t
TrackerControllerWrapper::seconds_to_next_timeout() const {
return m_ptr->seconds_to_next_timeout();
}
uint32_t
TrackerControllerWrapper::seconds_to_next_scrape() const {
return m_ptr->seconds_to_next_scrape();
}
void
TrackerControllerWrapper::manual_request(bool request_now) {
m_ptr->manual_request(request_now);
}
void
TrackerControllerWrapper::scrape_request(uint32_t seconds_to_request) {
m_ptr->scrape_request(seconds_to_request);
}
void
TrackerControllerWrapper::cycle_group(uint32_t group) {
m_ptr->tracker_list()->cycle_group(group);
}
// Algorithms:
Tracker
TrackerControllerWrapper::find_if(const std::function<bool(Tracker&)>& f) {
for (auto& tracker : *m_ptr->tracker_list()) {
if (f(tracker))
return tracker;
}
return {};
}
void
TrackerControllerWrapper::for_each(const std::function<void(Tracker&)>& f) {
for (auto& tracker : *m_ptr->tracker_list())
f(tracker);
}
Tracker
TrackerControllerWrapper::c_find_if(const std::function<bool(const Tracker&)>& f) const {
for (auto& tracker : *m_ptr->tracker_list()) {
if (f(tracker))
return tracker;
}
return {};
}
void
TrackerControllerWrapper::c_for_each(const std::function<void(const Tracker&)>& f) const {
for (auto& tracker : *m_ptr->tracker_list())
f(tracker);
}
// Private:
void
TrackerControllerWrapper::enable() {
m_ptr->enable();
}
void
TrackerControllerWrapper::enable_dont_reset_stats() {
m_ptr->enable(TrackerController::enable_dont_reset_stats);
}
void
TrackerControllerWrapper::disable() {
m_ptr->disable();
}
void
TrackerControllerWrapper::close() {
m_ptr->close();
}
void
TrackerControllerWrapper::send_start_event() {
m_ptr->send_start_event();
}
void
TrackerControllerWrapper::send_stop_event() {
m_ptr->send_stop_event();
}
void
TrackerControllerWrapper::send_completed_event() {
m_ptr->send_completed_event();
}
void
TrackerControllerWrapper::send_update_event() {
m_ptr->send_update_event();
}
void
TrackerControllerWrapper::start_requesting() {
m_ptr->start_requesting();
}
void
TrackerControllerWrapper::stop_requesting() {
m_ptr->stop_requesting();
}
void
TrackerControllerWrapper::set_slots(slot_address_list success, slot_string failure) {
m_ptr->slot_success() = std::move(success);
m_ptr->slot_failure() = std::move(failure);
}
} // namespace torrent::tracker