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

don't announce stopped-event to websocket trackers. #5933

Merged
merged 1 commit into from
Feb 1, 2021
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
7 changes: 4 additions & 3 deletions src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5845,12 +5845,13 @@ namespace {
}

#if TORRENT_USE_RTC
void torrent::generate_rtc_offers(int count
, std::function<void(error_code const&, std::vector<aux::rtc_offer>)> handler)
void torrent::generate_rtc_offers(int const count
, std::function<void(error_code const&, std::vector<aux::rtc_offer>)> handler)
{
// rtc_signaling is created lazily
if(!m_rtc_signaling)
if (!m_rtc_signaling)
{
TORRENT_ASSERT(count > 0);
m_rtc_signaling = std::make_shared<aux::rtc_signaling>(m_ses.get_context()
, this
, std::bind(&torrent::on_rtc_stream, this, _1));
Expand Down
16 changes: 13 additions & 3 deletions src/tracker_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace libtorrent::aux {
if (m_abort && req.event != event_t::stopped) return;

#ifndef TORRENT_DISABLE_LOGGING
if(auto cb = c.lock())
if (auto cb = c.lock())
cb->debug_log("*** QUEUE_TRACKER_REQUEST [ listen_port: %d ]", req.listen_port);
#endif

Expand Down Expand Up @@ -305,16 +305,26 @@ namespace libtorrent::aux {
else if (protocol == "ws" || protocol == "wss")
{
std::shared_ptr<request_callback> cb = c.lock();
if(!cb) return;
if (!cb) return;

// TODO: introduce a setting for max_offers
const int max_offers = 10;
req.num_want = std::min(req.num_want, max_offers);
if (req.num_want == 0)
{
// when we're shutting down, we don't really want to
// re-establish the persistent websocket connection just to
// announce "stopped", and advertize 0 offers. It may hang
// shutdown.
post(ios, std::bind(&request_callback::tracker_request_error, cb, std::move(req)
, errors::torrent_aborted, operation_t::connect
, "", seconds32(0)));
}
cb->generate_rtc_offers(req.num_want
, [this, &ios, req = std::move(req), c](error_code const& ec
, std::vector<aux::rtc_offer> offers) mutable
{
if(!ec) req.offers = std::move(offers);
if (!ec) req.offers = std::move(offers);

auto it = m_websocket_conns.find(req.url);
if (it != m_websocket_conns.end() && it->second->is_started()) {
Expand Down