forked from premiere/premiere-libtorrent
add some const and enum class (#1055)
This commit is contained in:
parent
585a760588
commit
19dd9d323a
|
@ -91,6 +91,13 @@ namespace libtorrent
|
|||
class bt_peer_connection;
|
||||
struct listen_socket_t;
|
||||
|
||||
enum class waste_reason
|
||||
{
|
||||
piece_timed_out, piece_cancelled, piece_unknown, piece_seed
|
||||
, piece_end_game, piece_closing
|
||||
, max
|
||||
};
|
||||
|
||||
struct time_critical_piece
|
||||
{
|
||||
// when this piece was first requested
|
||||
|
@ -660,12 +667,14 @@ namespace libtorrent
|
|||
|
||||
void update_scrape_state();
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// if no password and username is set
|
||||
// this will return an empty string, otherwise
|
||||
// it will concatenate the login and password
|
||||
// ready to be sent over http (but without
|
||||
// base64 encoding).
|
||||
std::string tracker_login() const;
|
||||
#endif
|
||||
|
||||
// generate the tracker key for this torrent.
|
||||
// The key is passed to http trackers as ``&key=``.
|
||||
|
@ -870,13 +879,7 @@ namespace libtorrent
|
|||
// this is the handler for write failure piece synchronization
|
||||
void on_piece_fail_sync(disk_io_job const* j, piece_block b);
|
||||
|
||||
enum wasted_reason_t
|
||||
{
|
||||
piece_timed_out, piece_cancelled, piece_unknown, piece_seed
|
||||
, piece_end_game, piece_closing
|
||||
, waste_reason_max
|
||||
};
|
||||
void add_redundant_bytes(int b, wasted_reason_t reason);
|
||||
void add_redundant_bytes(int b, waste_reason reason);
|
||||
void add_failed_bytes(int b);
|
||||
|
||||
// this is true if we have all the pieces, but not necessarily flushed them to disk
|
||||
|
|
|
@ -2629,7 +2629,7 @@ namespace libtorrent
|
|||
if (m_download_queue.empty())
|
||||
m_counters.inc_stats_counter(counters::num_peers_down_requests, -1);
|
||||
}
|
||||
t->add_redundant_bytes(p.length, torrent::piece_seed);
|
||||
t->add_redundant_bytes(p.length, waste_reason::piece_seed);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2663,7 +2663,7 @@ namespace libtorrent
|
|||
TORRENT_ASSERT_VAL(m_received_in_piece == p.length, m_received_in_piece);
|
||||
m_received_in_piece = 0;
|
||||
#endif
|
||||
t->add_redundant_bytes(p.length, torrent::piece_unknown);
|
||||
t->add_redundant_bytes(p.length, waste_reason::piece_unknown);
|
||||
|
||||
// the bytes of the piece we just completed have been deducted from
|
||||
// m_outstanding_bytes as we received it, in incoming_piece_fragment.
|
||||
|
@ -2684,11 +2684,11 @@ namespace libtorrent
|
|||
// if the block we got is already finished, then ignore it
|
||||
if (picker.is_downloaded(block_finished))
|
||||
{
|
||||
torrent::wasted_reason_t reason;
|
||||
if (b->timed_out) reason = torrent::piece_timed_out;
|
||||
else if (b->not_wanted) reason = torrent::piece_cancelled;
|
||||
else if (b->busy) reason = torrent::piece_end_game;
|
||||
else reason = torrent::piece_unknown;
|
||||
waste_reason reason;
|
||||
if (b->timed_out) reason = waste_reason::piece_timed_out;
|
||||
else if (b->not_wanted) reason = waste_reason::piece_cancelled;
|
||||
else if (b->busy) reason = waste_reason::piece_end_game;
|
||||
else reason = waste_reason::piece_unknown;
|
||||
|
||||
t->add_redundant_bytes(p.length, reason);
|
||||
|
||||
|
@ -2745,7 +2745,7 @@ namespace libtorrent
|
|||
|
||||
if (!t->need_loaded())
|
||||
{
|
||||
t->add_redundant_bytes(p.length, torrent::piece_unknown);
|
||||
t->add_redundant_bytes(p.length, waste_reason::piece_unknown);
|
||||
return;
|
||||
}
|
||||
t->inc_refcount("async_write");
|
||||
|
@ -4168,7 +4168,7 @@ namespace libtorrent
|
|||
&& pbp->bytes_downloaded > 0
|
||||
&& pbp->bytes_downloaded < pbp->full_block_bytes)
|
||||
{
|
||||
t->add_redundant_bytes(pbp->bytes_downloaded, torrent::piece_closing);
|
||||
t->add_redundant_bytes(pbp->bytes_downloaded, waste_reason::piece_closing);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4714,9 +4714,9 @@ namespace libtorrent
|
|||
|
||||
std::uint32_t torrent::tracker_key() const
|
||||
{
|
||||
uintptr_t self = reinterpret_cast<uintptr_t>(this);
|
||||
uintptr_t ses = reinterpret_cast<uintptr_t>(&m_ses);
|
||||
uintptr_t storage = reinterpret_cast<uintptr_t>(m_storage.get());
|
||||
uintptr_t const self = reinterpret_cast<uintptr_t>(this);
|
||||
uintptr_t const ses = reinterpret_cast<uintptr_t>(&m_ses);
|
||||
uintptr_t const storage = reinterpret_cast<uintptr_t>(m_storage.get());
|
||||
sha1_hash const h = hasher(reinterpret_cast<char const*>(&self), sizeof(self))
|
||||
.update(reinterpret_cast<char const*>(&storage), sizeof(storage))
|
||||
.update(reinterpret_cast<char const*>(&ses), sizeof(ses))
|
||||
|
@ -5433,8 +5433,8 @@ namespace libtorrent
|
|||
if (!bitmask[i])
|
||||
{
|
||||
// mark all pieces of the file as downloadable
|
||||
int start_piece = int(start / piece_length);
|
||||
int last_piece = int(position / piece_length);
|
||||
int const start_piece = int(start / piece_length);
|
||||
int const last_piece = int(position / piece_length);
|
||||
// if one piece spans several files, we might
|
||||
// come here several times with the same start_piece, end_piece
|
||||
std::fill(piece_filter.begin() + start_piece, piece_filter.begin()
|
||||
|
@ -8647,7 +8647,7 @@ namespace libtorrent
|
|||
// if we haven't yet met the seed limits, set the seed_ratio_not_met
|
||||
// flag. That will make this seed prioritized
|
||||
// downloaded may be 0 if the torrent is 0-sized
|
||||
std::int64_t downloaded = (std::max)(m_total_downloaded, m_torrent_file->total_size());
|
||||
std::int64_t const downloaded = (std::max)(m_total_downloaded, m_torrent_file->total_size());
|
||||
if (fin_time < s.get_int(settings_pack::seed_time_limit)
|
||||
&& (download_time > 1
|
||||
&& fin_time * 100 / download_time < s.get_int(settings_pack::seed_time_ratio_limit))
|
||||
|
@ -11139,17 +11139,17 @@ namespace libtorrent
|
|||
st->last_seen_complete = m_swarm_last_seen_complete;
|
||||
}
|
||||
|
||||
void torrent::add_redundant_bytes(int b, torrent::wasted_reason_t reason)
|
||||
void torrent::add_redundant_bytes(int b, waste_reason reason)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
TORRENT_ASSERT(b > 0);
|
||||
m_total_redundant_bytes += b;
|
||||
|
||||
TORRENT_ASSERT(b > 0);
|
||||
TORRENT_ASSERT(reason >= 0);
|
||||
TORRENT_ASSERT(reason < waste_reason_max);
|
||||
TORRENT_ASSERT(static_cast<int>(reason) >= 0);
|
||||
TORRENT_ASSERT(static_cast<int>(reason) < static_cast<int>(waste_reason::max));
|
||||
m_stats_counters.inc_stats_counter(counters::recv_redundant_bytes, b);
|
||||
m_stats_counters.inc_stats_counter(counters::waste_piece_timed_out + reason, b);
|
||||
m_stats_counters.inc_stats_counter(counters::waste_piece_timed_out + static_cast<int>(reason), b);
|
||||
}
|
||||
|
||||
void torrent::add_failed_bytes(int b)
|
||||
|
|
|
@ -544,7 +544,7 @@ namespace libtorrent { namespace
|
|||
source.m_pc.peer_log(peer_log_alert::info, "UT_METADATA"
|
||||
, "already have metadata");
|
||||
#endif
|
||||
m_torrent.add_redundant_bytes(size, torrent::piece_unknown);
|
||||
m_torrent.add_redundant_bytes(size, waste_reason::piece_unknown);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ void web_peer_connection::disconnect(error_code const& ec
|
|||
// we're about to replace a different restart piece
|
||||
// buffer. So it was wasted download
|
||||
if (t) t->add_redundant_bytes(int(m_web->restart_piece.size())
|
||||
, torrent::piece_closing);
|
||||
, waste_reason::piece_closing);
|
||||
}
|
||||
m_web->restart_piece.swap(m_piece);
|
||||
|
||||
|
|
Loading…
Reference in New Issue