minor cleanup and refactor (#1016)

minor cleanup and refactor
This commit is contained in:
Alden Torres 2016-08-20 19:46:55 -04:00 committed by Arvid Norberg
parent bd557ca2b2
commit 4d96939b7b
19 changed files with 37 additions and 85 deletions

View File

@ -35,28 +35,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#ifdef __OBJC__
#define Protocol Protocol_
#endif
#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
// asio assumes that the windows error codes are defined already
#include <winsock2.h>
#endif
#include <boost/asio/ip/address.hpp>
#if defined TORRENT_BUILD_SIMULATOR
#include "simulator/simulator.hpp"
#endif
#else
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/asio/ip/address.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#ifdef __OBJC__
#undef Protocol
#endif
#endif // SIMULATOR
namespace libtorrent
{

View File

@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_ALERT_HPP_INCLUDED
#define TORRENT_ALERT_HPP_INCLUDED
#include <deque>
#include <string>
// OVERVIEW

View File

@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_ANNOUNCE_ENTRY_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/time.hpp" // for time_point
#include "libtorrent/time.hpp"
#include "libtorrent/error_code.hpp"
#include <string>
@ -42,10 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
namespace aux {
struct session_settings;
}
// this class holds information about one bittorrent tracker, as it
// relates to a specific torrent.
struct TORRENT_EXPORT announce_entry
@ -161,7 +157,7 @@ namespace libtorrent
// updates the failure counter and time-outs for re-trying.
// This is called when the tracker announce fails.
void failed(aux::session_settings const& sett, int retry_interval = 0);
void failed(time_duration tracker_backoff, int retry_interval = 0);
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.0

View File

@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_PROXY_SETTINGS_HPP_INCLUDED
#define TORRENT_PROXY_SETTINGS_HPP_INCLUDED
#include "libtorrent/version.hpp"
#include "libtorrent/config.hpp"
#include <string>
@ -138,8 +137,6 @@ namespace aux {
};
}
}
}}
#endif

View File

@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_AUX_SESSION_SETTINGS_HPP_INCLUDED
#define TORRENT_AUX_SESSION_SETTINGS_HPP_INCLUDED
#include "libtorrent/version.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/assert.hpp"
@ -102,4 +101,3 @@ namespace libtorrent { namespace aux
} }
#endif

View File

@ -45,6 +45,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/dht_storage.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include <deque>
#endif
namespace libtorrent
{
struct plugin;

View File

@ -61,7 +61,8 @@ namespace libtorrent
TORRENT_EXTRA_EXPORT boost::shared_ptr<settings_pack> load_pack_from_dict(bdecode_node const& settings);
TORRENT_EXTRA_EXPORT void save_settings_to_dict(aux::session_settings const& s, entry::dictionary_type& sett);
TORRENT_EXTRA_EXPORT void apply_pack(settings_pack const* pack, aux::session_settings& sett, aux::session_impl* ses = 0);
TORRENT_EXTRA_EXPORT void apply_pack(settings_pack const* pack, aux::session_settings& sett
, aux::session_impl* ses = nullptr);
TORRENT_EXPORT int setting_by_name(std::string const& name);
TORRENT_EXPORT char const* name_for_setting(int s);

View File

@ -1223,7 +1223,7 @@ namespace libtorrent
// directory, if there is one. The source files will still be removed in
// that case.
//
// Files that have been renamed to have absolute pahts are not moved by
// Files that have been renamed to have absolute paths are not moved by
// this function. Keep in mind that files that don't belong to the
// torrent but are stored in the torrent's directory may be moved as
// well. This goes for files that have been renamed to absolute paths

View File

@ -41,10 +41,10 @@ namespace libtorrent
enum
{
// wait at least 5 seconds before retrying a failed tracker
tracker_retry_delay_min = 5
tracker_retry_delay_min = 5,
// when tracker_failed_max trackers
// has failed, wait 60 minutes instead
, tracker_retry_delay_max = 60 * 60
tracker_retry_delay_max = 60 * 60
};
announce_entry::announce_entry(std::string const& u)
@ -99,14 +99,15 @@ namespace libtorrent
min_announce = min_time();
}
void announce_entry::failed(aux::session_settings const& sett, int retry_interval)
void announce_entry::failed(time_duration const tracker_backoff, int const retry_interval)
{
++fails;
// the exponential back-off ends up being:
// 7, 15, 27, 45, 95, 127, 165, ... seconds
// with the default tracker_backoff of 250
int const tracker_backoff_seconds = total_seconds(tracker_backoff);
int delay = (std::min)(tracker_retry_delay_min + int(fails) * int(fails)
* tracker_retry_delay_min * sett.get_int(settings_pack::tracker_backoff) / 100
* tracker_retry_delay_min * tracker_backoff_seconds / 100
, int(tracker_retry_delay_max));
delay = (std::max)(delay, retry_interval);
next_announce = aux::time_now() + seconds(delay);

View File

@ -42,7 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/performance_counters.hpp" // for counters
#include "libtorrent/alert_manager.hpp"
#include <boost/next_prior.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
@ -55,9 +54,6 @@ using namespace std::placeholders;
namespace libtorrent
{
class alert;
namespace
{
inline bool default_pred(std::string const&) { return true; }
@ -740,6 +736,4 @@ namespace libtorrent
if (str == nullptr) m_created_by.clear();
else m_created_by = str;
}
}

View File

@ -36,18 +36,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/allocator.hpp"
#include "libtorrent/aux_/session_settings.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/disk_observer.hpp"
#include "libtorrent/platform_util.hpp" // for total_physical_ram
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <algorithm>
#include <functional>
#include <boost/system/error_code.hpp>
#include <boost/shared_ptr.hpp>
#if TORRENT_HAVE_MMAP
#include <sys/mman.h>
#endif

View File

@ -75,4 +75,3 @@ proxy_settings::proxy_settings(aux::session_settings const& sett)
} // namespace aux
} // namespace libtorrent

View File

@ -32,13 +32,6 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <vector>
#include <map>
#include <utility>
@ -91,10 +84,10 @@ namespace
// CRCs from the time it failed and ban the peers that
// sent bad blocks
std::map<piece_block, block_entry>::iterator i = m_block_hashes.lower_bound(piece_block(p, 0));
if (i == m_block_hashes.end() || int(i->first.piece_index) != p) return;
if (i == m_block_hashes.end() || i->first.piece_index != p) return;
int size = m_torrent.torrent_file().piece_size(p);
peer_request r = {p, 0, (std::min)(16*1024, size)};
peer_request r = {p, 0, (std::min)(16 * 1024, size)};
piece_block pb(p, 0);
while (size > 0)
{
@ -114,9 +107,9 @@ namespace
if (i == m_block_hashes.end() || int(i->first.piece_index) != p)
break;
r.start += 16*1024;
size -= 16*1024;
r.length = (std::min)(16*1024, size);
r.start += 16 * 1024;
size -= 16 * 1024;
r.length = (std::min)(16 * 1024, size);
++pb.block_index;
}

View File

@ -610,7 +610,6 @@ namespace libtorrent
{
m_stat_cache.reserve(files().num_files());
std::string file_path;
for (int i = 0; i < files().num_files(); ++i)
{
std::int64_t sz = m_stat_cache.get_filesize(
@ -1541,7 +1540,7 @@ namespace libtorrent
// check if the fastresume data is up to date
// if it is, use it and return true. If it
// isn't return false and the full check
// will be run. If the links pointer is non-nullptr, it has the same number
// will be run. If the links pointer is non-empty, it has the same number
// of elements as there are files. Each element is either empty or contains
// the absolute path to a file identical to the corresponding file in this
// torrent. The storage must create hard links (or copy) those files. If

View File

@ -11256,7 +11256,8 @@ namespace libtorrent
announce_entry* ae = find_tracker(r);
if (ae)
{
ae->failed(settings(), retry_interval);
ae->failed(seconds(settings().get_int(settings_pack::tracker_backoff))
, retry_interval);
ae->last_error = ec;
ae->message = msg;
int tracker_index = ae - &m_trackers[0];
@ -11272,7 +11273,7 @@ namespace libtorrent
|| r.triggered_manually)
{
m_ses.alerts().emplace_alert<tracker_error_alert>(get_handle()
, ae?ae->fails:0, response_code, r.url, ec, msg);
, ae ? ae->fails : 0, response_code, r.url, ec, msg);
}
}
else

View File

@ -80,7 +80,7 @@ namespace libtorrent
} // anonymous namespace
// fixes invalid UTF-8 sequences
TORRENT_EXTRA_EXPORT bool verify_encoding(std::string& target)
bool verify_encoding(std::string& target)
{
if (target.empty()) return true;

View File

@ -107,13 +107,13 @@ namespace libtorrent
if (e1 > e2) swap(e1, e2);
address_v6::bytes_type b1 = e1.address().to_v6().to_bytes();
address_v6::bytes_type b2 = e2.address().to_v6().to_bytes();
int mask = memcmp(&b1[0], &b2[0], 4) ? 0
: memcmp(&b1[0], &b2[0], 6) ? 1 : 2;
apply_mask(&b1[0], v6mask[mask], 8);
apply_mask(&b2[0], v6mask[mask], 8);
int const mask = std::memcmp(b1.data(), b2.data(), 4) ? 0
: std::memcmp(b1.data(), b2.data(), 6) ? 1 : 2;
apply_mask(b1.data(), v6mask[mask], 8);
apply_mask(b2.data(), v6mask[mask], 8);
std::uint64_t addrbuf[4];
memcpy(&addrbuf[0], &b1[0], 16);
memcpy(&addrbuf[2], &b2[0], 16);
memcpy(&addrbuf[0], b1.data(), 16);
memcpy(&addrbuf[2], b2.data(), 16);
ret = crc32c(addrbuf, 4);
}
#endif
@ -313,4 +313,3 @@ namespace libtorrent
}
}

View File

@ -32,18 +32,12 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include <functional>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdio>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/peer_connection_handle.hpp"

View File

@ -71,11 +71,10 @@ TORRENT_TEST(primitives)
// on failing announces
announce_entry ae("dummy");
int last = 0;
aux::session_settings sett;
sett.set_int(settings_pack::tracker_backoff, 250);
auto const tracker_backoff = seconds(250);
for (int i = 0; i < 10; ++i)
{
ae.failed(sett, 5);
ae.failed(tracker_backoff, 5);
int delay = ae.next_announce_in();
TEST_CHECK(delay > last);
last = delay;