Skip to content

Commit

Permalink
Improved backtrace error checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed May 1, 2021
1 parent abe26cd commit e22c77f
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 344 deletions.
36 changes: 0 additions & 36 deletions src/download/download_main.cc
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
// libTorrent - BitTorrent library
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY

#include "config.h"

#include <cstring>
Expand Down
36 changes: 0 additions & 36 deletions src/download/download_main.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
// libTorrent - BitTorrent library
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY

#ifndef LIBTORRENT_DOWNLOAD_MAIN_H
#define LIBTORRENT_DOWNLOAD_MAIN_H

Expand Down
43 changes: 4 additions & 39 deletions src/download/download_wrapper.cc
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
// libTorrent - BitTorrent library
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY

#include "config.h"

#include <iterator>
Expand Down Expand Up @@ -62,6 +26,8 @@

#include "download_wrapper.h"

#define LT_LOG_THIS(log_fmt, ...) \
lt_log_print_info(LOG_TORRENT_INFO, this->info(), "download", log_fmt, __VA_ARGS__);
#define LT_LOG_STORAGE_ERRORS(log_fmt, ...) \
lt_log_print_info(LOG_PROTOCOL_STORAGE_ERRORS, this->info(), "storage_errors", log_fmt, __VA_ARGS__);

Expand Down Expand Up @@ -325,8 +291,8 @@ DownloadWrapper::receive_tick(uint32_t ticks) {

void
DownloadWrapper::receive_update_priorities() {
if (m_main->chunk_selector()->empty())
return;
LT_LOG_THIS("update priorities: chunks_selected:%" PRIu32 " wanted_chunks:%" PRIu32,
m_main->chunk_selector()->size(), data()->wanted_chunks());

data()->mutable_high_priority()->clear();
data()->mutable_normal_priority()->clear();
Expand Down Expand Up @@ -359,7 +325,6 @@ DownloadWrapper::receive_update_priorities() {
}

bool was_partial = data()->wanted_chunks() != 0;

data()->update_wanted_chunks();

m_main->chunk_selector()->update_priorities();
Expand Down
36 changes: 0 additions & 36 deletions src/torrent/data/download_data.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
// libTorrent - BitTorrent library
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY

#ifndef LIBTORRENT_DATA_DOWNLOAD_DATA_H
#define LIBTORRENT_DATA_DOWNLOAD_DATA_H

Expand Down
50 changes: 12 additions & 38 deletions src/torrent/download/choke_queue.cc
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
// libTorrent - BitTorrent library
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY

#include "config.h"

#include <algorithm>
Expand All @@ -50,6 +14,10 @@

#include "choke_queue.h"

// TODO: Add a different logging category.
#define LT_LOG_THIS(log_fmt, ...) \
lt_log_print_subsystem(LOG_TORRENT_INFO, "choke_queue", log_fmt, __VA_ARGS__);

namespace torrent {

struct choke_manager_less {
Expand Down Expand Up @@ -193,6 +161,9 @@ choke_queue::rebuild_containers(container_type* queued, container_type* unchoked

void
choke_queue::balance() {
LT_LOG_THIS("balancing queue: heuristics:%i currently_unchoked:%" PRIu32 " max_unchoked:%" PRIu32,
m_heuristics, m_currently_unchoked, m_maxUnchoked)

// Return if no balancing is needed. Don't return if is_unlimited()
// as we might have just changed the value and have interested that
// can be unchoked.
Expand All @@ -216,6 +187,9 @@ choke_queue::balance() {

// If we have more unchoked than max global slots allow for,
// 'can_unchoke' will be negative.
//
// Throws std::bad_function_call if 'set_slot_can_unchoke' is not
// set.
int can_unchoke = m_slotCanUnchoke();
int max_unchoked = std::min(m_maxUnchoked, (uint32_t)(1 << 20));

Expand All @@ -240,8 +214,8 @@ choke_queue::balance() {
if (result != 0)
m_slotUnchoke(result);

lt_log_print(LOG_PEER_DEBUG, "Called balance; adjust:%i can_unchoke:%i queued:%u unchoked:%u result:%i.",
adjust, can_unchoke, (unsigned)queued.size(), (unsigned)unchoked.size(), result);
LT_LOG_THIS("balanced queue: adjust:%i can_unchoke:%i queued:%" PRIu32 " unchoked:%" PRIu32 " result:%i",
adjust, can_unchoke, queued.size(), unchoked.size(), result);
}

void
Expand Down
53 changes: 13 additions & 40 deletions src/torrent/download/resource_manager.cc
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
// libTorrent - BitTorrent library
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY

#include "config.h"

#include <algorithm>
Expand All @@ -51,6 +15,11 @@
#include "choke_queue.h"
#include "resource_manager.h"

#define LT_LOG_THIS(log_fmt, ...) \
lt_log_print_subsystem(LOG_TORRENT_INFO, "resource_manager", log_fmt, __VA_ARGS__);
#define LT_LOG_ITR(log_fmt, ...) \
lt_log_print_info(LOG_TORRENT_INFO, itr->download()->info(), "resource_manager", log_fmt, __VA_ARGS__);

namespace torrent {

const Rate* resource_manager_entry::up_rate() const { return m_download->info()->up_rate(); }
Expand Down Expand Up @@ -226,6 +195,8 @@ ResourceManager::group_index_of(const std::string& name) {

void
ResourceManager::set_priority(iterator itr, uint16_t pri) {
LT_LOG_ITR("set priority: %" PRIu16, 0)

itr->set_priority(pri);
}

Expand Down Expand Up @@ -283,7 +254,7 @@ ResourceManager::set_max_download_unchoked(unsigned int m) {
// possibly multiple calls of this function.
void
ResourceManager::receive_upload_unchoke(int num) {
lt_log_print(LOG_PEER_INFO, "Upload unchoked slots adjust; currently:%u adjust:%i", m_currentlyUploadUnchoked, num);
LT_LOG_THIS("adjusting upload unchoked slots; current:%u adjusted:%i", m_currentlyUploadUnchoked, num);

if ((int)m_currentlyUploadUnchoked + num < 0)
throw internal_error("ResourceManager::receive_upload_unchoke(...) received an invalid value.");
Expand All @@ -293,7 +264,7 @@ ResourceManager::receive_upload_unchoke(int num) {

void
ResourceManager::receive_download_unchoke(int num) {
lt_log_print(LOG_PEER_INFO, "Download unchoked slots adjust; currently:%u adjust:%i", m_currentlyDownloadUnchoked, num);
LT_LOG_THIS("adjusting download unchoked slots; current:%u adjusted:%i", m_currentlyDownloadUnchoked, num);

if ((int)m_currentlyDownloadUnchoked + num < 0)
throw internal_error("ResourceManager::receive_download_unchoke(...) received an invalid value.");
Expand Down Expand Up @@ -387,12 +358,14 @@ ResourceManager::balance_unchoked(unsigned int weight, unsigned int max_unchoked
std::sort(group_first, group_last, std::bind(std::less<uint32_t>(),
std::bind(&choke_group::up_requested, std::placeholders::_1),
std::bind(&choke_group::up_requested, std::placeholders::_2)));
lt_log_print(LOG_PEER_DEBUG, "Upload unchoked slots cycle; currently:%u adjusted:%i max_unchoked:%u", m_currentlyUploadUnchoked, change, max_unchoked);

LT_LOG_THIS("balancing upload unchoked slots; current_unchoked:%u change:%i max_unchoked:%u", m_currentlyUploadUnchoked, change, max_unchoked);
} else {
std::sort(group_first, group_last, std::bind(std::less<uint32_t>(),
std::bind(&choke_group::down_requested, std::placeholders::_1),
std::bind(&choke_group::down_requested, std::placeholders::_2)));
lt_log_print(LOG_PEER_DEBUG, "Download unchoked slots cycle; currently:%u adjusted:%i max_unchoked:%u", m_currentlyDownloadUnchoked, change, max_unchoked);

LT_LOG_THIS("balancing download unchoked slots; current_unchoked:%u change:%i max_unchoked:%u", m_currentlyDownloadUnchoked, change, max_unchoked);
}

while (group_first != group_last) {
Expand Down
Loading

0 comments on commit e22c77f

Please sign in to comment.