Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtorrent: Move resolver callback to connection manager #40

Merged
merged 5 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libtorrent/src/torrent/connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ ConnectionManager::start_udp_announce(uint64_t idx, const sockaddr* sa, int err)
}
}

void
ConnectionManager::add_resolver_callback(uint64_t idx) {
resolver_callback c = std::bind(&ConnectionManager::start_udp_announce, this, idx, std::placeholders::_1, std::placeholders::_2);
m_resolver_callback_list.push_back(c);
}

#define ASYNC_RESOLVER_IMPL UdnsAsyncResolver
#else
class StubAsyncResolver : public AsyncResolver {
Expand Down
4 changes: 4 additions & 0 deletions libtorrent/src/torrent/connection_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class LIBTORRENT_EXPORT ConnectionManager {
void null_udp_tracker(uint64_t idx) { m_tracker_udp_list[idx] = NULL; }
void add_udp_tracker(TrackerUdp* tracker) { m_tracker_udp_list.push_back(tracker); }
uint64_t get_udp_tracker_count() { return m_tracker_udp_list.size(); }

void add_resolver_callback(uint64_t idx);
resolver_callback* get_resolver_callback(uint64_t idx) { return &m_resolver_callback_list[idx]; }
#endif

// Legacy synchronous resolver interface.
Expand Down Expand Up @@ -232,6 +235,7 @@ class LIBTORRENT_EXPORT ConnectionManager {

#ifdef USE_UDNS
std::vector<TrackerUdp*> m_tracker_udp_list;
std::vector<resolver_callback> m_resolver_callback_list;
#endif

std::unique_ptr<AsyncResolver> m_async_resolver;
Expand Down
6 changes: 5 additions & 1 deletion libtorrent/src/tracker/tracker_udp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ TrackerUdp::TrackerUdp(TrackerList* parent, rak::udp_tracker_info& info, int fla
#ifdef USE_UDNS
manager->connection_manager()->add_udp_tracker(this);
m_vec_idx = manager->connection_manager()->get_udp_tracker_count() - 1;
m_resolver_callback = std::bind(&ConnectionManager::start_udp_announce, manager->connection_manager(), m_vec_idx, std::placeholders::_1, std::placeholders::_2);
manager->connection_manager()->add_resolver_callback(m_vec_idx);
#else
m_resolver_callback = std::bind(&TrackerUdp::start_announce, this, std::placeholders::_1, std::placeholders::_2);
#endif
Expand Down Expand Up @@ -111,7 +111,11 @@ TrackerUdp::send_state(int state) {
m_resolver_query = manager->connection_manager()->async_resolver().enqueue(
m_hostname.c_str(),
AF_UNSPEC,
#ifdef USE_UDNS
manager->connection_manager()->get_resolver_callback(m_vec_idx)
#else
&m_resolver_callback
#endif
);
manager->connection_manager()->async_resolver().flush();
}
Expand Down
Loading