minor refactor, consts and cleanup in alerts (#1210)
minor refactor, consts and cleanup in alerts
This commit is contained in:
parent
c4119158a4
commit
0f20af3710
|
@ -1,3 +1,4 @@
|
||||||
|
* changed session_stats_alert counters type to signed (std::int64_t)
|
||||||
* remove torrent eviction/ghost torrent feature
|
* remove torrent eviction/ghost torrent feature
|
||||||
* include target in DHT lookups, when queried from the session
|
* include target in DHT lookups, when queried from the session
|
||||||
* improve support for HTTP redirects for web seeds
|
* improve support for HTTP redirects for web seeds
|
||||||
|
|
|
@ -108,9 +108,9 @@ void session_view::render()
|
||||||
, color(to_string(int(m_cnt[0][m_queued_reads_idx]), 3), col_red).c_str()
|
, color(to_string(int(m_cnt[0][m_queued_reads_idx]), 3), col_red).c_str()
|
||||||
, color(to_string(int(m_cnt[0][m_queued_writes_idx]), 3), col_green).c_str()
|
, color(to_string(int(m_cnt[0][m_queued_writes_idx]), 3), col_green).c_str()
|
||||||
, int((m_cnt[0][m_blocks_written_idx] - m_cnt[0][m_write_ops_idx]) * 100
|
, int((m_cnt[0][m_blocks_written_idx] - m_cnt[0][m_write_ops_idx]) * 100
|
||||||
/ (std::max)(std::uint64_t(1), m_cnt[0][m_blocks_written_idx]))
|
/ (std::max)(std::int64_t(1), m_cnt[0][m_blocks_written_idx]))
|
||||||
, int(m_cnt[0][m_cache_hit_idx] * 100
|
, int(m_cnt[0][m_cache_hit_idx] * 100
|
||||||
/ (std::max)(std::uint64_t(1), m_cnt[0][m_num_blocks_read_idx]))
|
/ (std::max)(std::int64_t(1), m_cnt[0][m_num_blocks_read_idx]))
|
||||||
, add_suffix(m_cnt[0][m_writes_cache_idx] * 16 * 1024).c_str()
|
, add_suffix(m_cnt[0][m_writes_cache_idx] * 16 * 1024).c_str()
|
||||||
, add_suffix(m_cnt[0][m_reads_cache_idx] * 16 * 1024).c_str()
|
, add_suffix(m_cnt[0][m_reads_cache_idx] * 16 * 1024).c_str()
|
||||||
, add_suffix(m_cnt[0][m_blocks_in_use_idx] * 16 * 1024).c_str()
|
, add_suffix(m_cnt[0][m_blocks_in_use_idx] * 16 * 1024).c_str()
|
||||||
|
@ -189,7 +189,7 @@ void session_view::render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_view::update_counters(std::uint64_t* stats_counters
|
void session_view::update_counters(std::int64_t* stats_counters
|
||||||
, int num_cnt, std::uint64_t t)
|
, int num_cnt, std::uint64_t t)
|
||||||
{
|
{
|
||||||
// only update the previous counters if there's been enough
|
// only update the previous counters if there's been enough
|
||||||
|
|
|
@ -21,7 +21,7 @@ struct session_view
|
||||||
void print_utp_stats(bool p) { m_print_utp_stats = p; }
|
void print_utp_stats(bool p) { m_print_utp_stats = p; }
|
||||||
bool print_utp_stats() const { return m_print_utp_stats; }
|
bool print_utp_stats() const { return m_print_utp_stats; }
|
||||||
|
|
||||||
void update_counters(std::uint64_t* stats_counters, int num_cnt
|
void update_counters(std::int64_t* stats_counters, int num_cnt
|
||||||
, std::uint64_t t);
|
, std::uint64_t t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -31,7 +31,7 @@ private:
|
||||||
|
|
||||||
// there are two sets of counters. the current one and the last one. This
|
// there are two sets of counters. the current one and the last one. This
|
||||||
// is used to calculate rates
|
// is used to calculate rates
|
||||||
std::vector<std::uint64_t> m_cnt[2];
|
std::vector<std::int64_t> m_cnt[2];
|
||||||
|
|
||||||
// the timestamps of the counters in m_cnt[0] and m_cnt[1]
|
// the timestamps of the counters in m_cnt[0] and m_cnt[1]
|
||||||
// respectively. The timestamps are microseconds since session start
|
// respectively. The timestamps are microseconds since session start
|
||||||
|
|
|
@ -117,10 +117,10 @@ namespace libtorrent
|
||||||
virtual std::string message() const override;
|
virtual std::string message() const override;
|
||||||
|
|
||||||
// The peer's IP address and port.
|
// The peer's IP address and port.
|
||||||
tcp::endpoint ip;
|
tcp::endpoint const ip;
|
||||||
|
|
||||||
// the peer ID, if known.
|
// the peer ID, if known.
|
||||||
peer_id pid;
|
peer_id const pid;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is a base class used for alerts that are associated with a
|
// This is a base class used for alerts that are associated with a
|
||||||
|
@ -671,7 +671,7 @@ namespace libtorrent
|
||||||
static const int static_category = alert::debug_notification;
|
static const int static_category = alert::debug_notification;
|
||||||
virtual std::string message() const override;
|
virtual std::string message() const override;
|
||||||
|
|
||||||
int socket_type;
|
int const socket_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This alert is generated when a peer is disconnected for any reason (other than the ones
|
// This alert is generated when a peer is disconnected for any reason (other than the ones
|
||||||
|
@ -1501,7 +1501,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// the reason for the peer being blocked. Is one of the values from the
|
// the reason for the peer being blocked. Is one of the values from the
|
||||||
// reason_t enum.
|
// reason_t enum.
|
||||||
int reason;
|
int const reason;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This alert is generated when a DHT node announces to an info-hash on our
|
// This alert is generated when a DHT node announces to an info-hash on our
|
||||||
|
@ -1758,10 +1758,10 @@ namespace libtorrent
|
||||||
// 8. HTTPS (SSL/HTTP)
|
// 8. HTTPS (SSL/HTTP)
|
||||||
// 9. SSL/uTP
|
// 9. SSL/uTP
|
||||||
//
|
//
|
||||||
int socket_type;
|
int const socket_type;
|
||||||
|
|
||||||
// is the IP address and port the connection came from.
|
// is the IP address and port the connection came from.
|
||||||
tcp::endpoint ip;
|
tcp::endpoint const ip;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This alert is always posted when a torrent was attempted to be added
|
// This alert is always posted when a torrent was attempted to be added
|
||||||
|
@ -1781,10 +1781,10 @@ namespace libtorrent
|
||||||
|
|
||||||
// a copy of the parameters used when adding the torrent, it can be used
|
// a copy of the parameters used when adding the torrent, it can be used
|
||||||
// to identify which invocation to ``async_add_torrent()`` caused this alert.
|
// to identify which invocation to ``async_add_torrent()`` caused this alert.
|
||||||
add_torrent_params params;
|
add_torrent_params const params;
|
||||||
|
|
||||||
// set to the error, if one occurred while adding the torrent.
|
// set to the error, if one occurred while adding the torrent.
|
||||||
error_code error;
|
error_code const error;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This alert is only posted when requested by the user, by calling
|
// This alert is only posted when requested by the user, by calling
|
||||||
|
@ -1843,7 +1843,7 @@ namespace libtorrent
|
||||||
// interpret these values throughout the process' runtime.
|
// interpret these values throughout the process' runtime.
|
||||||
//
|
//
|
||||||
// For more information, see the session-statistics_ section.
|
// For more information, see the session-statistics_ section.
|
||||||
std::uint64_t values[counters::num_counters];
|
std::int64_t values[counters::num_counters];
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
@ -2308,7 +2308,7 @@ namespace libtorrent
|
||||||
|
|
||||||
virtual std::string message() const override;
|
virtual std::string message() const override;
|
||||||
|
|
||||||
sha1_hash info_hash;
|
sha1_hash const info_hash;
|
||||||
|
|
||||||
int num_peers() const;
|
int num_peers() const;
|
||||||
|
|
||||||
|
@ -2413,7 +2413,7 @@ namespace libtorrent
|
||||||
std::string message() const override;
|
std::string message() const override;
|
||||||
|
|
||||||
// The error code, if one is associated with this error
|
// The error code, if one is associated with this error
|
||||||
error_code error;
|
error_code const error;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::reference_wrapper<aux::stack_allocator> m_alloc;
|
std::reference_wrapper<aux::stack_allocator> m_alloc;
|
||||||
|
|
|
@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/alert.hpp"
|
#include "libtorrent/alert.hpp"
|
||||||
#include "libtorrent/alert_types.hpp"
|
#include "libtorrent/alert_types.hpp"
|
||||||
#include "libtorrent/socket_io.hpp"
|
#include "libtorrent/socket_io.hpp"
|
||||||
#include "libtorrent/time.hpp"
|
|
||||||
#include "libtorrent/error_code.hpp"
|
#include "libtorrent/error_code.hpp"
|
||||||
#include "libtorrent/torrent.hpp"
|
#include "libtorrent/torrent.hpp"
|
||||||
#include "libtorrent/performance_counters.hpp"
|
#include "libtorrent/performance_counters.hpp"
|
||||||
|
@ -110,7 +109,6 @@ namespace libtorrent {
|
||||||
|
|
||||||
std::string peer_alert::message() const
|
std::string peer_alert::message() const
|
||||||
{
|
{
|
||||||
error_code ec;
|
|
||||||
return torrent_alert::message() + " peer (" + print_endpoint(ip)
|
return torrent_alert::message() + " peer (" + print_endpoint(ip)
|
||||||
+ ", " + identify_client(pid) + ")";
|
+ ", " + identify_client(pid) + ")";
|
||||||
}
|
}
|
||||||
|
@ -1076,7 +1074,6 @@ namespace libtorrent {
|
||||||
|
|
||||||
std::string peer_blocked_alert::message() const
|
std::string peer_blocked_alert::message() const
|
||||||
{
|
{
|
||||||
error_code ec;
|
|
||||||
char ret[600];
|
char ret[600];
|
||||||
static char const* reason_str[] =
|
static char const* reason_str[] =
|
||||||
{
|
{
|
||||||
|
@ -1320,7 +1317,6 @@ namespace libtorrent {
|
||||||
std::string incoming_connection_alert::message() const
|
std::string incoming_connection_alert::message() const
|
||||||
{
|
{
|
||||||
char msg[600];
|
char msg[600];
|
||||||
error_code ec;
|
|
||||||
std::snprintf(msg, sizeof(msg), "incoming connection from %s (%s)"
|
std::snprintf(msg, sizeof(msg), "incoming connection from %s (%s)"
|
||||||
, print_endpoint(ip).c_str(), socket_type_str[socket_type]);
|
, print_endpoint(ip).c_str(), socket_type_str[socket_type]);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -1335,7 +1331,6 @@ namespace libtorrent {
|
||||||
std::string peer_connect_alert::message() const
|
std::string peer_connect_alert::message() const
|
||||||
{
|
{
|
||||||
char msg[600];
|
char msg[600];
|
||||||
error_code ec;
|
|
||||||
std::snprintf(msg, sizeof(msg), "%s connecting to peer (%s)"
|
std::snprintf(msg, sizeof(msg), "%s connecting to peer (%s)"
|
||||||
, peer_alert::message().c_str(), socket_type_str[socket_type]);
|
, peer_alert::message().c_str(), socket_type_str[socket_type]);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -1900,7 +1895,7 @@ namespace libtorrent {
|
||||||
, m_alloc(alloc)
|
, m_alloc(alloc)
|
||||||
, m_num_peers(int(peers.size()))
|
, m_num_peers(int(peers.size()))
|
||||||
{
|
{
|
||||||
std::size_t total_size = m_num_peers; // num bytes for sizes
|
std::size_t total_size = 0; // num bytes for sizes
|
||||||
for (int i = 0; i < m_num_peers; i++) {
|
for (int i = 0; i < m_num_peers; i++) {
|
||||||
total_size += peers[i].size();
|
total_size += peers[i].size();
|
||||||
}
|
}
|
||||||
|
@ -1909,7 +1904,7 @@ namespace libtorrent {
|
||||||
|
|
||||||
char *ptr = alloc.ptr(m_peers_idx);
|
char *ptr = alloc.ptr(m_peers_idx);
|
||||||
for (int i = 0; i < m_num_peers; i++) {
|
for (int i = 0; i < m_num_peers; i++) {
|
||||||
tcp::endpoint endp = peers[i];
|
tcp::endpoint const& endp = peers[i];
|
||||||
std::size_t size = endp.size();
|
std::size_t size = endp.size();
|
||||||
TORRENT_ASSERT(size < 0x100);
|
TORRENT_ASSERT(size < 0x100);
|
||||||
detail::write_uint8(uint8_t(size), ptr);
|
detail::write_uint8(uint8_t(size), ptr);
|
||||||
|
@ -2003,8 +1998,7 @@ namespace libtorrent {
|
||||||
{
|
{
|
||||||
// we need to copy this array to make sure the structures are properly
|
// we need to copy this array to make sure the structures are properly
|
||||||
// aligned, not just to have a nice API
|
// aligned, not just to have a nice API
|
||||||
std::vector<piece_block> ret;
|
std::vector<piece_block> ret(m_num_blocks);
|
||||||
ret.resize(m_num_blocks);
|
|
||||||
|
|
||||||
char const* start = m_alloc.get().ptr(m_array_idx);
|
char const* start = m_alloc.get().ptr(m_array_idx);
|
||||||
std::memcpy(&ret[0], start, m_num_blocks * sizeof(piece_block));
|
std::memcpy(&ret[0], start, m_num_blocks * sizeof(piece_block));
|
||||||
|
|
Loading…
Reference in New Issue