refactor in alert types to use more const fields and more clear API (#1222)

refactor in alert types to use more const fields and more clear API
This commit is contained in:
Alden Torres 2016-10-19 01:32:15 -04:00 committed by Arvid Norberg
parent 524f7b1c27
commit ded3ed6abf
15 changed files with 408 additions and 247 deletions

View File

@ -1,3 +1,4 @@
* refactor in alert types to use more const fields and more clear API
* changed session_stats_alert counters type to signed (std::int64_t)
* remove torrent eviction/ghost torrent feature
* include target in DHT lookups, when queried from the session

View File

@ -347,6 +347,7 @@ void bind_alert()
class_<read_piece_alert, bases<torrent_alert>, noncopyable>(
"read_piece_alert", nullptr, no_init)
.def_readonly("error", &read_piece_alert::error)
.add_property("buffer", get_buffer)
.def_readonly("piece", &read_piece_alert::piece)
.def_readonly("size", &read_piece_alert::size)
@ -354,8 +355,12 @@ void bind_alert()
class_<peer_alert, bases<torrent_alert>, noncopyable>(
"peer_alert", no_init)
#ifndef TORRENT_NO_DEPRECATE
.add_property("ip", make_getter(&peer_alert::ip
, return_value_policy<return_by_value>()))
#endif
.add_property("endpoint", make_getter(&peer_alert::endpoint
, return_value_policy<return_by_value>()))
.def_readonly("pid", &peer_alert::pid)
;
class_<tracker_error_alert, bases<tracker_alert>, noncopyable>(
@ -494,7 +499,10 @@ void bind_alert()
.def("listen_interface", &listen_failed_alert::listen_interface)
.def_readonly("error", &listen_failed_alert::error)
.def_readonly("operation", &listen_failed_alert::operation)
#ifndef TORRENT_NO_DEPRECATE
.def_readonly("sock_type", &listen_failed_alert::sock_type)
#endif
.def_readonly("socket_type", &listen_failed_alert::socket_type)
;
class_<listen_succeeded_alert, bases<alert>, noncopyable>(
@ -504,7 +512,10 @@ void bind_alert()
#endif
.def_readonly("address", &listen_succeeded_alert::address)
.def_readonly("port", &listen_succeeded_alert::port)
#ifndef TORRENT_NO_DEPRECATE
.def_readonly("sock_type", &listen_succeeded_alert::sock_type)
#endif
.def_readonly("socket_type", &listen_succeeded_alert::socket_type)
;
class_<portmap_error_alert, bases<alert>, noncopyable>(
@ -761,8 +772,12 @@ void bind_alert()
class_<incoming_connection_alert, bases<alert>, noncopyable>(
"incoming_connection_alert", no_init)
.def_readonly("socket_type", &incoming_connection_alert::socket_type)
#ifndef TORRENT_NO_DEPRECATE
.add_property("ip", make_getter(&incoming_connection_alert::ip
, return_value_policy<return_by_value>()))
#endif
.add_property("endpoint", make_getter(&incoming_connection_alert::endpoint
, return_value_policy<return_by_value>()))
;
class_<torrent_need_cert_alert, bases<torrent_alert>, noncopyable>(
"torrent_need_cert_alert", no_init)
@ -787,25 +802,36 @@ void bind_alert()
"dht_outgoing_get_peers_alert", no_init)
.def_readonly("info_hash", &dht_outgoing_get_peers_alert::info_hash)
.def_readonly("obfuscated_info_hash", &dht_outgoing_get_peers_alert::obfuscated_info_hash)
#ifndef TORRENT_NO_DEPRECATE
.add_property("ip", make_getter(&dht_outgoing_get_peers_alert::ip
, return_value_policy<return_by_value>()))
#endif
.add_property("endpoint", make_getter(&dht_outgoing_get_peers_alert::endpoint
, return_value_policy<return_by_value>()))
;
#ifndef TORRENT_DISABLE_LOGGING
class_<log_alert, bases<alert>, noncopyable>(
"log_alert", no_init)
#ifndef TORRENT_NO_DEPRECATE
.def("msg", &log_alert::msg)
#endif
.def("log_message", &log_alert::log_message)
;
class_<torrent_log_alert, bases<torrent_alert>, noncopyable>(
"torrent_log_alert", no_init)
#ifndef TORRENT_NO_DEPRECATE
.def("msg", &torrent_log_alert::msg)
#endif
.def("log_message", &torrent_log_alert::log_message)
;
class_<peer_log_alert, bases<peer_alert>, noncopyable>(
"peer_log_alert", no_init)
#ifndef TORRENT_NO_DEPRECATE
.def("msg", &peer_log_alert::msg)
#endif
.def("log_message", &peer_log_alert::log_message)
;
class_<picker_log_alert, bases<peer_alert>, noncopyable>(
@ -814,8 +840,6 @@ void bind_alert()
.def("blocks", &picker_log_alert::blocks)
;
#endif // TORRENT_DISABLE_LOGGING
class_<lsd_error_alert, bases<alert>, noncopyable>(
"lsd_error_alert", no_init)
.def_readonly("error", &lsd_error_alert::error)

View File

@ -862,7 +862,7 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
if (session_stats_alert* s = alert_cast<session_stats_alert>(a))
{
ses_view.update_counters(s->values, sizeof(s->values)/sizeof(s->values[0])
ses_view.update_counters(s->values.data(), int(s->values.size())
, duration_cast<microseconds>(s->timestamp().time_since_epoch()).count());
return true;
}

View File

@ -189,7 +189,7 @@ void session_view::render()
}
}
void session_view::update_counters(std::int64_t* stats_counters
void session_view::update_counters(std::int64_t const* stats_counters
, int num_cnt, std::uint64_t t)
{
// only update the previous counters if there's been enough

View File

@ -21,7 +21,7 @@ struct session_view
void print_utp_stats(bool p) { m_print_utp_stats = p; }
bool print_utp_stats() const { return m_print_utp_stats; }
void update_counters(std::int64_t* stats_counters, int num_cnt
void update_counters(std::int64_t const* stats_counters, int num_cnt
, std::uint64_t t);
private:

View File

@ -262,7 +262,7 @@ namespace libtorrent {
#endif // TORRENT_NO_DEPRECATE
private:
time_point m_timestamp;
time_point const m_timestamp;
};
// When you get an alert, you can use ``alert_cast<>`` to attempt to cast the

View File

@ -117,10 +117,15 @@ namespace libtorrent
virtual std::string message() const override;
// The peer's IP address and port.
tcp::endpoint const ip;
tcp::endpoint const endpoint;
// the peer ID, if known.
peer_id const pid;
#ifndef TORRENT_NO_DEPRECATE
// The peer's IP address and port.
tcp::endpoint const ip;
#endif
};
// This is a base class used for alerts that are associated with a
@ -145,7 +150,7 @@ namespace libtorrent
std::string url;
#endif
private:
int m_url_idx;
int const m_url_idx;
};
#define TORRENT_DEFINE_ALERT_IMPL(name, seq, prio) \
@ -197,7 +202,7 @@ namespace libtorrent
TORRENT_DEFINE_ALERT_PRIO(torrent_removed_alert, 4)
static const int static_category = alert::status_notification;
virtual std::string message() const override;
sha1_hash info_hash;
sha1_hash const info_hash;
};
// This alert is posted when the asynchronous read operation initiated by
@ -207,7 +212,7 @@ namespace libtorrent
// of the piece. ``piece`` is the piece index that was read. ``size`` is the
// number of bytes that was read.
//
// If the operation fails, ec will indicate what went wrong.
// If the operation fails, ``error`` will indicate what went wrong.
struct TORRENT_EXPORT read_piece_alert final : torrent_alert
{
// internal
@ -220,10 +225,14 @@ namespace libtorrent
static const int static_category = alert::storage_notification;
virtual std::string message() const override;
error_code const error;
boost::shared_array<char> const buffer;
int const piece;
int const size;
#ifndef TORRENT_NO_DEPRECATE
error_code ec;
boost::shared_array<char> buffer;
int piece;
int size;
#endif
};
// This is posted whenever an individual file completes its download. i.e.
@ -240,7 +249,7 @@ namespace libtorrent
virtual std::string message() const override;
// refers to the index of the file that completed.
int index;
int const index;
};
// This is posted as a response to a torrent_handle::rename_file() call, if the rename
@ -262,9 +271,9 @@ namespace libtorrent
char const* new_name() const;
// refers to the index of the file that was renamed,
int index;
int const index;
private:
int m_name_idx;
int const m_name_idx;
};
// This is posted as a response to a torrent_handle::rename_file() call, if the rename
@ -284,8 +293,8 @@ namespace libtorrent
// refers to the index of the file that was supposed to be renamed,
// ``error`` is the error code returned from the filesystem.
int index;
error_code error;
int const index;
error_code const error;
};
// This alert is generated when a limit is reached that might have a negative impact on
@ -383,7 +392,7 @@ namespace libtorrent
virtual std::string message() const override;
performance_warning_t warning_code;
performance_warning_t const warning_code;
};
// Generated whenever a torrent changes its state.
@ -401,10 +410,10 @@ namespace libtorrent
virtual std::string message() const override;
// the new state of the torrent.
torrent_status::state_t state;
torrent_status::state_t const state;
// the previous state.
torrent_status::state_t prev_state;
torrent_status::state_t const prev_state;
};
// This alert is generated on tracker time outs, premature disconnects,
@ -427,9 +436,9 @@ namespace libtorrent
static const int static_category = alert::tracker_notification | alert::error_notification;
virtual std::string message() const override;
int times_in_row;
int status_code;
error_code error;
int const times_in_row;
int const status_code;
error_code const error;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
#endif
@ -438,7 +447,7 @@ namespace libtorrent
char const* error_message() const;
private:
int m_msg_idx;
int const m_msg_idx;
};
// This alert is triggered if the tracker reply contains a warning field.
@ -464,7 +473,7 @@ namespace libtorrent
char const* warning_message() const;
private:
int m_msg_idx;
int const m_msg_idx;
};
// This alert is generated when a scrape request succeeds.
@ -480,8 +489,8 @@ namespace libtorrent
// the data returned in the scrape response. These numbers
// may be -1 if the response was malformed.
int incomplete;
int complete;
int const incomplete;
int const complete;
};
// If a scrape request fails, this alert is generated. This might be due
@ -508,14 +517,14 @@ namespace libtorrent
// the error itself. This may indicate that the tracker sent an error
// message (``error::tracker_failure``), in which case it can be
// retrieved by calling ``error_message()``.
error_code error;
error_code const error;
// if the error indicates there is an associated message, this returns
// that message. Otherwise and empty string.
char const* error_message() const;
private:
int m_msg_idx;
int const m_msg_idx;
};
// This alert is only for informational purpose. It is generated when a tracker announce
@ -534,7 +543,7 @@ namespace libtorrent
// tells how many peers the tracker returned in this response. This is
// not expected to be more thant the ``num_want`` settings. These are not necessarily
// all new peers, some of them may already be connected.
int num_peers;
int const num_peers;
};
// This alert is generated each time the DHT receives peers from a node. ``num_peers``
@ -552,7 +561,7 @@ namespace libtorrent
virtual std::string message() const override;
int num_peers;
int const num_peers;
};
// This alert is generated each time a tracker announce is sent (or attempted to be sent).
@ -575,7 +584,7 @@ namespace libtorrent
// 1. Completed
// 2. Started
// 3. Stopped
int event;
int const event;
};
// This alert is generated when a finished piece fails its hash check. You can get the handle
@ -591,7 +600,7 @@ namespace libtorrent
static const int static_category = alert::status_notification;
virtual std::string message() const override;
int piece_index;
int const piece_index;
};
// This alert is generated when a peer is banned because it has sent too many corrupt pieces
@ -649,10 +658,10 @@ namespace libtorrent
// a 0-terminated string of the low-level operation that failed, or nullptr if
// there was no low level disk operation.
int operation;
int const operation;
// tells you what error caused this alert.
error_code error;
error_code const error;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
@ -690,17 +699,17 @@ namespace libtorrent
virtual std::string message() const override;
// the kind of socket this peer was connected over
int socket_type;
int const socket_type;
// the operation or level where the error occurred. Specified as an
// value from the operation_t enum. Defined in operations.hpp.
operation_t operation;
operation_t const operation;
// tells you what error caused peer to disconnect.
error_code error;
error_code const error;
// the reason the peer disconnected (if specified)
close_reason_t reason;
close_reason_t const reason;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
@ -723,18 +732,18 @@ namespace libtorrent
virtual std::string message() const override;
// the request we received from the peer
peer_request request;
peer_request const request;
// true if we have this piece
bool we_have;
bool const we_have;
// true if the peer indicated that it was interested to download before
// sending the request
bool peer_interested;
bool const peer_interested;
// if this is true, the peer is not allowed to download this piece because
// of superseeding rules.
bool withheld;
bool const withheld;
};
// This alert is generated when a torrent switches from being a downloader to a seed.
@ -767,7 +776,7 @@ namespace libtorrent
virtual std::string message() const override;
// the index of the piece that finished
int piece_index;
int const piece_index;
};
// This alert is generated when a peer rejects or ignores a piece request.
@ -784,8 +793,8 @@ namespace libtorrent
| alert::peer_notification;
virtual std::string message() const override;
int block_index;
int piece_index;
int const block_index;
int const piece_index;
};
// This alert is generated when a block request times out.
@ -802,8 +811,8 @@ namespace libtorrent
| alert::peer_notification;
virtual std::string message() const override;
int block_index;
int piece_index;
int const block_index;
int const piece_index;
};
// This alert is generated when a block request receives a response.
@ -819,8 +828,8 @@ namespace libtorrent
static const int static_category = alert::progress_notification;
virtual std::string message() const override;
int block_index;
int piece_index;
int const block_index;
int const piece_index;
};
// This alert is generated when a block request is sent to a peer.
@ -839,8 +848,8 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
char const* peer_speedmsg;
#endif
int block_index;
int piece_index;
int const block_index;
int const piece_index;
};
// This alert is generated when a block is received that was not requested or
@ -856,8 +865,8 @@ namespace libtorrent
virtual std::string message() const override;
int block_index;
int piece_index;
int const block_index;
int const piece_index;
};
// The ``storage_moved_alert`` is generated when all the disk IO has completed and the
@ -883,7 +892,7 @@ namespace libtorrent
char const* storage_path() const;
private:
int m_path_idx;
int const m_path_idx;
};
// The ``storage_moved_failed_alert`` is generated when an attempt to move the storage,
@ -900,7 +909,7 @@ namespace libtorrent
static const int static_category = alert::storage_notification;
virtual std::string message() const override;
error_code error;
error_code const error;
#ifndef TORRENT_NO_DEPRECATE
// If the error happened for a specific file, ``file`` is its path.
@ -914,7 +923,7 @@ namespace libtorrent
// terminated string naming which one, otherwise it's nullptr.
char const* operation;
private:
int m_file_idx;
int const m_file_idx;
};
// This alert is generated when a request to delete the files of a torrent complete.
@ -937,8 +946,7 @@ namespace libtorrent
static const int static_category = alert::storage_notification;
virtual std::string message() const override;
sha1_hash info_hash;
sha1_hash const info_hash;
};
// This alert is generated when a request to delete the files of a torrent fails.
@ -956,10 +964,10 @@ namespace libtorrent
virtual std::string message() const override;
// tells you why it failed.
error_code error;
error_code const error;
// the info hash of the torrent whose files failed to be deleted
sha1_hash info_hash;
sha1_hash const info_hash;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
@ -981,7 +989,7 @@ namespace libtorrent
virtual std::string message() const override;
// points to the resume data.
std::shared_ptr<entry> resume_data;
std::shared_ptr<entry> const resume_data;
};
// This alert is generated instead of ``save_resume_data_alert`` if there was an error
@ -999,7 +1007,7 @@ namespace libtorrent
virtual std::string message() const override;
// the error code from the resume_data failure
error_code error;
error_code const error;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
@ -1070,7 +1078,7 @@ namespace libtorrent
// the error the web seed encountered. If this is not set, the server
// sent an error message, call ``error_message()``.
error_code error;
error_code const error;
// the URL the error is associated with
char const* server_url() const;
@ -1080,8 +1088,8 @@ namespace libtorrent
char const* error_message() const;
private:
int m_url_idx;
int m_msg_idx;
int const m_url_idx;
int const m_msg_idx;
};
// If the storage fails to read or write files that it needs access to, this alert is
@ -1105,7 +1113,7 @@ namespace libtorrent
#endif
// the error code describing the error.
error_code error;
error_code const error;
char const* operation;
// the file that experienced the error
@ -1115,7 +1123,7 @@ namespace libtorrent
std::string msg;
#endif
private:
int m_file_idx;
int const m_file_idx;
};
// This alert is generated when the metadata has been completely received and the info-hash
@ -1135,7 +1143,7 @@ namespace libtorrent
// indicates what failed when parsing the metadata. This error is
// what's returned from lazy_bdecode().
error_code error;
error_code const error;
};
// This alert is generated when the metadata has been completely received and the torrent
@ -1191,10 +1199,10 @@ namespace libtorrent
virtual std::string message() const override;
// the source address associated with the error (if any)
udp::endpoint endpoint;
udp::endpoint const endpoint;
// the error code describing the error
error_code error;
error_code const error;
};
// Whenever libtorrent learns about the machines external IP, this alert is
@ -1212,7 +1220,12 @@ namespace libtorrent
virtual std::string message() const override;
// the IP address that is believed to be our external IP
address external_address;
address const external_address;
};
enum class socket_type_t : std::uint8_t
{
tcp, tcp_ssl, udp, i2p, socks5, utp_ssl
};
// This alert is generated when none of the ports, given in the port range, to
@ -1232,23 +1245,25 @@ namespace libtorrent
// listen on it.
struct TORRENT_EXPORT listen_failed_alert final : alert
{
#ifndef TORRENT_NO_DEPRECATE
enum socket_type_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl };
#endif
// internal
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, libtorrent::address const& listen_addr, int listen_port
, int op, error_code const& ec, socket_type_t t);
, int op, error_code const& ec, libtorrent::socket_type_t t);
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, tcp::endpoint const& ep, int op, error_code const& ec
, socket_type_t t);
, libtorrent::socket_type_t t);
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, udp::endpoint const& ep, int op, error_code const& ec
, socket_type_t t);
, libtorrent::socket_type_t t);
listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, int op, error_code const& ec, socket_type_t t);
, int op, error_code const& ec, libtorrent::socket_type_t t);
TORRENT_DEFINE_ALERT_PRIO(listen_failed_alert, 48)
@ -1259,7 +1274,7 @@ namespace libtorrent
char const* listen_interface() const;
// the error the system returned
error_code error;
error_code const error;
enum op_t
{
@ -1267,27 +1282,30 @@ namespace libtorrent
};
// the specific low level operation that failed. See op_t.
int operation;
int const operation;
// the type of listen socket this alert refers to.
socket_type_t sock_type;
libtorrent::socket_type_t const socket_type;
// the address libtorrent attempted to listen on
// see alert's documentation for validity of this value
libtorrent::address address;
libtorrent::address const address;
// the port libtorrent attempted to listen on
// see alert's documentation for validity of this value
int port;
int const port;
#ifndef TORRENT_NO_DEPRECATE
// the address and port libtorrent attempted to listen on
tcp::endpoint endpoint;
// the type of listen socket this alert refers to.
socket_type_t sock_type;
#endif
private:
std::reference_wrapper<aux::stack_allocator const> m_alloc;
int m_interface_idx;
int const m_interface_idx;
};
// This alert is posted when the listen port succeeds to be opened on a
@ -1295,21 +1313,23 @@ namespace libtorrent
// successfully was opened for listening.
struct TORRENT_EXPORT listen_succeeded_alert final : alert
{
#ifndef TORRENT_NO_DEPRECATE
enum socket_type_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl };
#endif
// internal
listen_succeeded_alert(aux::stack_allocator& alloc
, libtorrent::address const& listen_addr
, int listen_port
, socket_type_t t);
, libtorrent::socket_type_t t);
listen_succeeded_alert(aux::stack_allocator& alloc
, tcp::endpoint const& ep
, socket_type_t t);
, libtorrent::socket_type_t t);
listen_succeeded_alert(aux::stack_allocator& alloc
, udp::endpoint const& ep
, socket_type_t t);
, libtorrent::socket_type_t t);
TORRENT_DEFINE_ALERT_PRIO(listen_succeeded_alert, 49)
@ -1318,19 +1338,22 @@ namespace libtorrent
// the address libtorrent ended up listening on. This address
// refers to the local interface.
libtorrent::address address;
libtorrent::address const address;
// the port libtorrent ended up listening on.
int port;
int const port;
// the type of listen socket this alert refers to.
libtorrent::socket_type_t const socket_type;
#ifndef TORRENT_NO_DEPRECATE
// the endpoint libtorrent ended up listening on. The address
// refers to the local interface and the port is the listen port.
tcp::endpoint endpoint;
#endif
// the type of listen socket this alert refers to.
socket_type_t sock_type;
#endif
};
// This alert is generated when a NAT router was successfully found but some
@ -1353,13 +1376,13 @@ namespace libtorrent
// refers to the mapping index of the port map that failed, i.e.
// the index returned from add_mapping().
int mapping;
int const mapping;
// is 0 for NAT-PMP and 1 for UPnP.
int map_type;
int const map_type;
// tells you what failed.
error_code error;
error_code const error;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
#endif
@ -1381,13 +1404,13 @@ namespace libtorrent
// refers to the mapping index of the port map that failed, i.e.
// the index returned from add_mapping().
int mapping;
int const mapping;
// the external port allocated for the mapping.
int external_port;
int const external_port;
// 0 for NAT-PMP and 1 for UPnP.
int map_type;
int const map_type;
enum protocol_t
{
@ -1396,7 +1419,7 @@ namespace libtorrent
};
// the protocol this mapping was for. one of protocol_t enums
int protocol;
int const protocol;
};
// This alert is generated to log informational events related to either
@ -1415,7 +1438,7 @@ namespace libtorrent
static const int static_category = alert::port_mapping_log_notification;
virtual std::string message() const override;
int map_type;
int const map_type;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
@ -1429,7 +1452,7 @@ namespace libtorrent
// TODO: 2 should the alert baseclass have this object instead?
std::reference_wrapper<aux::stack_allocator const> m_alloc;
int m_log_idx;
int const m_log_idx;
};
// This alert is generated when a fastresume file has been passed to
@ -1448,7 +1471,7 @@ namespace libtorrent
| alert::error_notification;
virtual std::string message() const override;
error_code error;
error_code const error;
#ifndef TORRENT_NO_DEPRECATE
// If the error happened to a specific file, ``file`` is the path to it.
@ -1466,7 +1489,7 @@ namespace libtorrent
std::string msg;
#endif
private:
int m_path_idx;
int const m_path_idx;
};
// This alert is posted when an incoming peer connection, or a peer that's about to be added
@ -1517,9 +1540,9 @@ namespace libtorrent
static const int static_category = alert::dht_notification;
virtual std::string message() const override;
address ip;
int port;
sha1_hash info_hash;
address const ip;
int const port;
sha1_hash const info_hash;
};
// This alert is generated when a DHT node sends a ``get_peers`` message to
@ -1534,7 +1557,7 @@ namespace libtorrent
static const int static_category = alert::dht_notification;
virtual std::string message() const override;
sha1_hash info_hash;
sha1_hash const info_hash;
};
// This alert is posted approximately once every second, and it contains
@ -1578,12 +1601,12 @@ namespace libtorrent
// an array of samples. The enum describes what each sample is a
// measurement of. All of these are raw, and not smoothing is performed.
int transferred[num_channels];
std::array<int, num_channels> const transferred;
// the number of milliseconds during which these stats were collected.
// This is typically just above 1000, but if CPU is limited, it may be
// higher than that.
int interval;
int const interval;
};
// This alert is posted when the disk cache has been flushed for a specific
@ -1625,9 +1648,9 @@ namespace libtorrent
tracker_not_anonymous = 0
};
// specifies what error this is, see kind_t.
int kind;
std::string str;
// specifies what error this is, see kind_t.
int const kind;
std::string const str;
};
// This alert is generated when we receive a local service discovery message
@ -1667,7 +1690,7 @@ namespace libtorrent
char const* tracker_id() const;
private:
int m_tracker_idx;
int const m_tracker_idx;
};
// This alert is posted when the initial DHT bootstrap is done.
@ -1695,7 +1718,7 @@ namespace libtorrent
virtual std::string message() const override;
// specifies which error the torrent encountered.
error_code error;
error_code const error;
#ifndef TORRENT_NO_DEPRECATE
// the filename (or object) the error occurred on.
@ -1706,7 +1729,7 @@ namespace libtorrent
char const* filename() const;
private:
int m_file_idx;
int const m_file_idx;
};
// This is always posted for SSL torrents. This is a reminder to the client that
@ -1724,7 +1747,7 @@ namespace libtorrent
static const int static_category = alert::status_notification;
virtual std::string message() const override;
error_code error;
error_code const error;
};
// The incoming connection alert is posted every time we successfully accept
@ -1760,8 +1783,13 @@ namespace libtorrent
//
int const socket_type;
// is the IP address and port the connection came from.
tcp::endpoint const endpoint;
#ifndef TORRENT_NO_DEPRECATE
// is the IP address and port the connection came from.
tcp::endpoint const ip;
#endif
};
// This alert is always posted when a torrent was attempted to be added
@ -1807,7 +1835,7 @@ namespace libtorrent
// to a specific torrent via its ``handle`` member. The receiving end is
// suggested to have all torrents sorted by the torrent_handle or hashed
// by it, for efficient updates.
std::vector<torrent_status> status;
std::vector<torrent_status> const status;
};
struct TORRENT_EXPORT mmap_cache_alert final : alert
@ -1819,7 +1847,7 @@ namespace libtorrent
static const int static_category = alert::error_notification;
virtual std::string message() const override;
error_code error;
error_code const error;
};
// The session_stats_alert is posted when the user requests session statistics by
@ -1843,7 +1871,7 @@ namespace libtorrent
// interpret these values throughout the process' runtime.
//
// For more information, see the session-statistics_ section.
std::int64_t values[counters::num_counters];
std::array<std::int64_t, counters::num_counters> const values;
};
#ifndef TORRENT_NO_DEPRECATE
@ -1885,7 +1913,7 @@ namespace libtorrent
virtual std::string message() const override;
// the error code
error_code error;
error_code const error;
enum op_t
{
@ -1894,7 +1922,7 @@ namespace libtorrent
};
// the operation that failed
op_t operation;
op_t const operation;
};
// this alert is posted as a response to a call to session::get_item(),
@ -1912,10 +1940,10 @@ namespace libtorrent
// the target hash of the immutable item. This must
// match the sha-1 hash of the bencoded form of ``item``.
sha1_hash target;
sha1_hash const target;
// the data for this item
entry item;
entry const item;
};
// this alert is posted as a response to a call to session::get_item(),
@ -1932,27 +1960,27 @@ namespace libtorrent
virtual std::string message() const override;
// the public key that was looked up
std::array<char, 32> key;
std::array<char, 32> const key;
// the signature of the data. This is not the signature of the
// plain encoded form of the item, but it includes the sequence number
// and possibly the hash as well. See the dht_store document for more
// information. This is primarily useful for echoing back in a store
// request.
std::array<char, 64> signature;
std::array<char, 64> const signature;
// the sequence number of this item
std::uint64_t seq;
std::uint64_t const seq;
// the salt, if any, used to lookup and store this item. If no
// salt was used, this is an empty string
std::string salt;
std::string const salt;
// the data for this item
entry item;
entry const item;
// the last response for mutable data is authoritative.
bool authoritative;
bool const authoritative;
};
// this is posted when a DHT put operation completes. This is useful if the
@ -1974,20 +2002,20 @@ namespace libtorrent
// the target hash the item was stored under if this was an *immutable*
// item.
sha1_hash target;
sha1_hash const target;
// if a mutable item was stored, these are the public key, signature,
// salt and sequence number the item was stored under.
std::array<char, 32> public_key;
std::array<char, 64> signature;
std::string salt;
std::uint64_t seq;
std::array<char, 32> const public_key;
std::array<char, 64> const signature;
std::string const salt;
std::uint64_t const seq;
// DHT put operation usually writes item to k nodes, maybe the node
// is stale so no response, or the node doesn't support 'put', or the
// token for write is out of date, etc. num_success is the number of
// successful responses we got from the puts.
int num_success;
int const num_success;
};
// this alert is used to report errors in the i2p SAM connection
@ -2001,7 +2029,7 @@ namespace libtorrent
virtual std::string message() const override;
// the error that occurred in the i2p SAM connection
error_code error;
error_code const error;
};
// This alert is generated when we send a get_peers request
@ -2019,14 +2047,19 @@ namespace libtorrent
virtual std::string message() const override;
// the info_hash of the torrent we're looking for peers for.
sha1_hash info_hash;
sha1_hash const info_hash;
// if this was an obfuscated lookup, this is the info-hash target
// actually sent to the node.
sha1_hash obfuscated_info_hash;
sha1_hash const obfuscated_info_hash;
// the endpoint we're sending this query to
udp::endpoint const endpoint;
#ifndef TORRENT_NO_DEPRECATE
// the endpoint we're sending this query to
udp::endpoint ip;
#endif
};
// This alert is posted by some session wide event. Its main purpose is
@ -2045,11 +2078,17 @@ namespace libtorrent
virtual std::string message() const override;
// returns the log message
char const* log_message() const;
#ifndef TORRENT_NO_DEPRECATE
// returns the log message
TORRENT_DEPRECATED
char const* msg() const;
#endif
private:
std::reference_wrapper<aux::stack_allocator const> m_alloc;
int m_str_idx;
int const m_str_idx;
};
// This alert is posted by torrent wide events. It's meant to be used for
@ -2068,10 +2107,16 @@ namespace libtorrent
virtual std::string message() const override;
// returns the log message
char const* log_message() const;
#ifndef TORRENT_NO_DEPRECATE
// returns the log message
TORRENT_DEPRECATED
char const* msg() const;
#endif
private:
int m_str_idx;
int const m_str_idx;
};
// This alert is posted by events specific to a peer. It's meant to be used
@ -2106,13 +2151,19 @@ namespace libtorrent
// message name.
char const* event_type;
direction_t direction;
direction_t const direction;
// returns the log message
char const* log_message() const;
#ifndef TORRENT_NO_DEPRECATE
// returns the log message
TORRENT_DEPRECATED
char const* msg() const;
#endif
private:
int m_str_idx;
int const m_str_idx;
};
// posted if the local service discovery socket fails to start properly.
@ -2128,7 +2179,7 @@ namespace libtorrent
virtual std::string message() const override;
// The error code
error_code error;
error_code const error;
};
// holds statistics about a current dht_lookup operation.
@ -2205,11 +2256,11 @@ namespace libtorrent
virtual std::string message() const override;
// a vector of the currently running DHT lookups.
std::vector<dht_lookup> active_requests;
std::vector<dht_lookup> const active_requests;
// contains information about every bucket in the DHT routing
// table.
std::vector<dht_routing_bucket> routing_table;
std::vector<dht_routing_bucket> const routing_table;
};
// posted every time an incoming request from a peer is accepted and queued
@ -2229,7 +2280,7 @@ namespace libtorrent
virtual std::string message() const override;
// the request this peer sent to us
peer_request req;
peer_request const req;
};
struct TORRENT_EXPORT dht_log_alert final : alert
@ -2255,11 +2306,11 @@ namespace libtorrent
char const* log_message() const;
// the module, or part, of the DHT that produced this log message.
dht_module_t module;
dht_module_t const module;
private:
std::reference_wrapper<aux::stack_allocator const> m_alloc;
int m_msg_idx;
int const m_msg_idx;
};
// This alert is posted every time a DHT message is sent or received. It is
@ -2285,12 +2336,16 @@ namespace libtorrent
span<char const> pkt_buf() const;
// whether this is an incoming or outgoing packet.
direction_t const dir;
direction_t const direction;
// the DHT node we received this packet from, or sent this packet to
// (depending on ``dir``).
// (depending on ``direction``).
udp::endpoint const node;
#ifndef TORRENT_NO_DEPRECATE
direction_t const dir;
#endif
private:
std::reference_wrapper<aux::stack_allocator> m_alloc;
int const m_msg_idx;
@ -2341,10 +2396,14 @@ namespace libtorrent
virtual std::string message() const override;
void const* userdata;
udp::endpoint const addr;
udp::endpoint const endpoint;
bdecode_node response() const;
#ifndef TORRENT_NO_DEPRECATE
udp::endpoint const addr;
#endif
private:
std::reference_wrapper<aux::stack_allocator> m_alloc;
int const m_response_idx;

View File

@ -44,6 +44,7 @@ namespace libtorrent
{
struct TORRENT_EXTRA_EXPORT counters
{
// TODO: move this out of counters
enum stats_counter_t
{
// the number of peers that were disconnected this

View File

@ -122,7 +122,7 @@ TORRENT_TEST(allow_fast)
{
if (strcmp(l->event_type, "ALLOWED_FAST") != 0) return;
int const piece = atoi(l->msg());
int const piece = atoi(l->log_message());
// make sure we don't get the same allowed piece more than once
TEST_EQUAL(local_allowed_fast.count(piece), 0);
@ -184,7 +184,7 @@ TORRENT_TEST(allow_fast_stress)
{
if (strcmp(l->event_type, "ALLOWED_FAST") != 0) return;
int const piece = atoi(l->msg());
int const piece = atoi(l->log_message());
// make sure we don't get the same allowed piece more than once
TEST_EQUAL(allowed_fast.count(piece), 0);

View File

@ -155,7 +155,7 @@ TORRENT_TEST(socks4_tcp_accept)
if (auto* a = lt::alert_cast<lt::incoming_connection_alert>(alert))
{
TEST_EQUAL(a->socket_type, 2);
TEST_EQUAL(a->ip.address(), addr("60.0.0.0"))
TEST_EQUAL(a->endpoint.address(), addr("60.0.0.0"))
incoming_connection = true;
}
},
@ -190,7 +190,7 @@ TORRENT_TEST(socks4_tcp_listen_alert)
[&](lt::session&, lt::alert const* alert) {
if (auto* a = lt::alert_cast<lt::listen_succeeded_alert>(alert))
{
if (a->sock_type == listen_succeeded_alert::socks5)
if (a->socket_type == socket_type_t::socks5)
{
TEST_EQUAL(a->address, addr("50.50.50.50"));
TEST_EQUAL(a->port, 6881);
@ -220,7 +220,7 @@ TORRENT_TEST(socks5_tcp_listen_alert)
[&](lt::session&, lt::alert const* alert) {
if (auto* a = lt::alert_cast<lt::listen_succeeded_alert>(alert))
{
if (a->sock_type == listen_succeeded_alert::socks5)
if (a->socket_type == socket_type_t::socks5)
{
TEST_EQUAL(a->address, addr("50.50.50.50"));
TEST_EQUAL(a->port, 6881);
@ -257,7 +257,7 @@ TORRENT_TEST(socks5_tcp_announce)
[&alert_port](lt::session&, lt::alert const* alert) {
if (auto* a = lt::alert_cast<lt::listen_succeeded_alert>(alert))
{
if (a->sock_type == listen_succeeded_alert::socks5)
if (a->socket_type == socket_type_t::socks5)
{
alert_port = a->port;
}

View File

@ -103,13 +103,16 @@ namespace libtorrent {
, tcp::endpoint const& i
, peer_id const& pi)
: torrent_alert(alloc, h)
, ip(i)
, endpoint(i)
, pid(pi)
#ifndef TORRENT_NO_DEPRECATE
, ip(i)
#endif
{}
std::string peer_alert::message() const
{
return torrent_alert::message() + " peer (" + print_endpoint(ip)
return torrent_alert::message() + " peer (" + print_endpoint(endpoint)
+ ", " + identify_client(pid) + ")";
}
@ -148,19 +151,22 @@ namespace libtorrent {
read_piece_alert::read_piece_alert(aux::stack_allocator& alloc
, torrent_handle h, int p, error_code e)
: torrent_alert(alloc, h)
, ec(e)
, error(e)
, piece(p)
, size(0)
#ifndef TORRENT_NO_DEPRECATE
, ec(e)
#endif
{}
std::string read_piece_alert::message() const
{
char msg[200];
if (ec)
if (error)
{
std::snprintf(msg, sizeof(msg), "%s: read_piece %u failed: %s"
, torrent_alert::message().c_str() , piece
, convert_from_native(ec.message()).c_str());
, convert_from_native(error.message()).c_str());
}
else
{
@ -774,10 +780,21 @@ namespace libtorrent {
namespace
{
static char const* const sock_type_str[] =
int sock_type_idx(socket_type_t type)
{
"TCP", "TCP/SSL", "UDP", "I2P", "Socks5", "uTP/SSL"
};
int idx =
static_cast<std::underlying_type<socket_type_t>::type>(type);
TORRENT_ASSERT(0 <= idx && idx < 6);
return idx;
}
char const* sock_type_str(socket_type_t type)
{
static char const* type_str[] =
{ "TCP", "TCP/SSL", "UDP", "I2P", "Socks5", "uTP/SSL" };
return type_str[sock_type_idx(type)];
}
static char const* const nat_type_str[] = {"NAT-PMP", "UPnP"};
@ -804,14 +821,15 @@ namespace libtorrent {
, int listen_port
, int op
, error_code const& ec
, socket_type_t t)
, libtorrent::socket_type_t t)
: error(ec)
, operation(op)
, sock_type(t)
, socket_type(t)
, address(listen_addr)
, port(listen_port)
#ifndef TORRENT_NO_DEPRECATE
, endpoint(listen_addr, listen_port)
, sock_type(static_cast<socket_type_t>(sock_type_idx(t)))
#endif
, m_alloc(alloc)
, m_interface_idx(alloc.copy_string(iface))
@ -823,7 +841,7 @@ namespace libtorrent {
, tcp::endpoint const& ep
, int op
, error_code const& ec
, socket_type_t t)
, libtorrent::socket_type_t t)
: listen_failed_alert(alloc
, iface
, ep.address()
@ -839,7 +857,7 @@ namespace libtorrent {
, udp::endpoint const& ep
, int op
, error_code const& ec
, socket_type_t t)
, libtorrent::socket_type_t t)
: listen_failed_alert(alloc
, iface
, ep.address()
@ -854,7 +872,7 @@ namespace libtorrent {
, string_view iface
, int op
, error_code const& ec
, socket_type_t t)
, libtorrent::socket_type_t t)
: listen_failed_alert(alloc
, iface
, libtorrent::address()
@ -887,7 +905,7 @@ namespace libtorrent {
, print_endpoint(address, port).c_str()
, listen_interface()
, op_str[operation]
, sock_type_str[sock_type]
, sock_type_str(socket_type)
, convert_from_native(error.message()).c_str());
return ret;
}
@ -941,18 +959,19 @@ namespace libtorrent {
listen_succeeded_alert::listen_succeeded_alert(aux::stack_allocator&
, libtorrent::address const& listen_addr
, int listen_port
, socket_type_t t)
, libtorrent::socket_type_t t)
: address(listen_addr)
, port(listen_port)
, socket_type(t)
#ifndef TORRENT_NO_DEPRECATE
, endpoint(listen_addr, listen_port)
, sock_type(static_cast<socket_type_t>(sock_type_idx(t)))
#endif
, sock_type(t)
{}
listen_succeeded_alert::listen_succeeded_alert(aux::stack_allocator& alloc
, tcp::endpoint const& ep
, socket_type_t t)
, libtorrent::socket_type_t t)
: listen_succeeded_alert(alloc
, ep.address()
, ep.port()
@ -961,7 +980,7 @@ namespace libtorrent {
listen_succeeded_alert::listen_succeeded_alert(aux::stack_allocator& alloc
, udp::endpoint const& ep
, socket_type_t t)
, libtorrent::socket_type_t t)
: listen_succeeded_alert(alloc
, ep.address()
, ep.port()
@ -970,10 +989,9 @@ namespace libtorrent {
std::string listen_succeeded_alert::message() const
{
char const* type_str[] = { "TCP", "SSL/TCP", "UDP", "i2p", "socks5", "SSL/uTP" };
char ret[200];
std::snprintf(ret, sizeof(ret), "successfully listening on [%s] %s"
, type_str[sock_type], print_endpoint(address, port).c_str());
, sock_type_str(socket_type), print_endpoint(address, port).c_str());
return ret;
}
@ -1124,30 +1142,40 @@ namespace libtorrent {
return msg;
}
namespace
{
std::array<int, stats_alert::num_channels> stat_to_array(stat const& s)
{
std::array<int, stats_alert::num_channels> arr;
arr[stats_alert::upload_payload] = s[stat::upload_payload].counter();
arr[stats_alert::upload_protocol] = s[stat::upload_protocol].counter();
arr[stats_alert::download_payload] = s[stat::download_payload].counter();
arr[stats_alert::download_protocol] = s[stat::download_protocol].counter();
arr[stats_alert::upload_ip_protocol] = s[stat::upload_ip_protocol].counter();
arr[stats_alert::download_ip_protocol] = s[stat::download_ip_protocol].counter();
#ifndef TORRENT_NO_DEPRECATE
arr[stats_alert::upload_dht_protocol] = 0;
arr[stats_alert::upload_tracker_protocol] = 0;
arr[stats_alert::download_dht_protocol] = 0;
arr[stats_alert::download_tracker_protocol] = 0;
#else
arr[stats_alert::deprecated1] = 0;
arr[stats_alert::deprecated2] = 0;
arr[stats_alert::deprecated3] = 0;
arr[stats_alert::deprecated4] = 0;
#endif
return arr;
}
}
stats_alert::stats_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int in, stat const& s)
: torrent_alert(alloc, h)
, transferred(stat_to_array(s))
, interval(in)
{
transferred[upload_payload] = s[stat::upload_payload].counter();
transferred[upload_protocol] = s[stat::upload_protocol].counter();
transferred[download_payload] = s[stat::download_payload].counter();
transferred[download_protocol] = s[stat::download_protocol].counter();
transferred[upload_ip_protocol] = s[stat::upload_ip_protocol].counter();
transferred[download_ip_protocol] = s[stat::download_ip_protocol].counter();
#ifndef TORRENT_NO_DEPRECATE
transferred[upload_dht_protocol] = 0;
transferred[upload_tracker_protocol] = 0;
transferred[download_dht_protocol] = 0;
transferred[download_tracker_protocol] = 0;
#else
transferred[deprecated1] = 0;
transferred[deprecated2] = 0;
transferred[deprecated3] = 0;
transferred[deprecated4] = 0;
#endif
}
{}
std::string stats_alert::message() const
{
@ -1311,14 +1339,17 @@ namespace libtorrent {
incoming_connection_alert::incoming_connection_alert(aux::stack_allocator&, int t
, tcp::endpoint const& i)
: socket_type(t)
, endpoint(i)
#ifndef TORRENT_NO_DEPRECATE
, ip(i)
#endif
{}
std::string incoming_connection_alert::message() const
{
char msg[600];
std::snprintf(msg, sizeof(msg), "incoming connection from %s (%s)"
, print_endpoint(ip).c_str(), socket_type_str[socket_type]);
, print_endpoint(endpoint).c_str(), socket_type_str[socket_type]);
return msg;
}
@ -1552,6 +1583,9 @@ namespace libtorrent {
dht_put_alert::dht_put_alert(aux::stack_allocator&, sha1_hash const& t, int n)
: target(t)
, public_key()
, signature()
, salt()
, seq(0)
, num_success(n)
{}
@ -1607,7 +1641,10 @@ namespace libtorrent {
, udp::endpoint ep)
: info_hash(ih)
, obfuscated_info_hash(obfih)
, ip(std::move(ep))
, endpoint(std::move(ep))
#ifndef TORRENT_NO_DEPRECATE
, ip(endpoint)
#endif
{}
std::string dht_outgoing_get_peers_alert::message() const
@ -1623,7 +1660,7 @@ namespace libtorrent {
std::snprintf(msg, sizeof(msg), "outgoing dht get_peers : %s%s -> %s"
, aux::to_hex(info_hash).c_str()
, obf
, print_endpoint(ip).c_str());
, print_endpoint(endpoint).c_str());
return msg;
}
@ -1636,14 +1673,21 @@ namespace libtorrent {
, m_str_idx(alloc.format_string(fmt, v))
{}
char const* log_alert::msg() const
char const* log_alert::log_message() const
{
return m_alloc.get().ptr(m_str_idx);
}
#ifndef TORRENT_NO_DEPRECATE
char const* log_alert::msg() const
{
return log_message();
}
#endif
std::string log_alert::message() const
{
return msg();
return log_message();
}
torrent_log_alert::torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
@ -1652,14 +1696,21 @@ namespace libtorrent {
, m_str_idx(alloc.format_string(fmt, v))
{}
char const* torrent_log_alert::msg() const
char const* torrent_log_alert::log_message() const
{
return m_alloc.get().ptr(m_str_idx);
}
#ifndef TORRENT_NO_DEPRECATE
char const* torrent_log_alert::msg() const
{
return log_message();
}
#endif
std::string torrent_log_alert::message() const
{
return torrent_alert::message() + ": " + msg();
return torrent_alert::message() + ": " + log_message();
}
peer_log_alert::peer_log_alert(aux::stack_allocator& alloc
@ -1673,17 +1724,24 @@ namespace libtorrent {
, m_str_idx(alloc.format_string(fmt, v))
{}
char const* peer_log_alert::msg() const
char const* peer_log_alert::log_message() const
{
return m_alloc.get().ptr(m_str_idx);
}
#ifndef TORRENT_NO_DEPRECATE
char const* peer_log_alert::msg() const
{
return log_message();
}
#endif
std::string peer_log_alert::message() const
{
static char const* mode[] =
{ "<==", "==>", "<<<", ">>>", "***" };
return torrent_alert::message() + " [" + print_endpoint(ip) + "] "
+ mode[direction] + " " + event_type + " [ " + msg() + " ]";
return torrent_alert::message() + " [" + print_endpoint(endpoint) + "] "
+ mode[direction] + " " + event_type + " [ " + log_message() + " ]";
}
lsd_error_alert::lsd_error_alert(aux::stack_allocator&, error_code const& ec)
@ -1696,12 +1754,23 @@ namespace libtorrent {
return "Local Service Discovery error: " + convert_from_native(error.message());
}
session_stats_alert::session_stats_alert(aux::stack_allocator&, counters const& cnt)
namespace
{
for (int i = 0; i < counters::num_counters; ++i)
values[i] = cnt[i];
std::array<std::int64_t, counters::num_counters> counters_to_array(counters const& cnt)
{
std::array<std::int64_t, counters::num_counters> arr;
for (int i = 0; i < counters::num_counters; ++i)
arr[i] = cnt[i];
return arr;
}
}
session_stats_alert::session_stats_alert(aux::stack_allocator&, counters const& cnt)
: values(counters_to_array(cnt))
{}
std::string session_stats_alert::message() const
{
// this specific output is parsed by tools/parse_session_stats.py
@ -1856,8 +1925,11 @@ namespace libtorrent {
dht_pkt_alert::dht_pkt_alert(aux::stack_allocator& alloc
, span<char const> buf, dht_pkt_alert::direction_t d
, udp::endpoint const& ep)
: dir(d)
: direction(d)
, node(std::move(ep))
#ifndef TORRENT_NO_DEPRECATE
, dir(d)
#endif
, m_alloc(alloc)
, m_msg_idx(alloc.copy_buffer(buf))
, m_size(int(buf.size()))
@ -1882,7 +1954,7 @@ namespace libtorrent {
char const* prefix[2] = { "<==", "==>"};
char buf[1024];
std::snprintf(buf, sizeof(buf), "%s [%s] %s", prefix[dir]
std::snprintf(buf, sizeof(buf), "%s [%s] %s", prefix[direction]
, print_endpoint(node).c_str(), msg.c_str());
return buf;
@ -1950,7 +2022,11 @@ namespace libtorrent {
dht_direct_response_alert::dht_direct_response_alert(
aux::stack_allocator& alloc, void* userdata_
, udp::endpoint const& addr_, bdecode_node const& response)
: userdata(userdata_), addr(addr_), m_alloc(alloc)
: userdata(userdata_), endpoint(addr_)
#ifndef TORRENT_NO_DEPRECATE
, addr(addr_)
#endif
, m_alloc(alloc)
, m_response_idx(alloc.copy_buffer(response.data_section()))
, m_response_size(int(response.data_section().size()))
{}
@ -1959,7 +2035,11 @@ namespace libtorrent {
aux::stack_allocator& alloc
, void* userdata_
, udp::endpoint const& addr_)
: userdata(userdata_), addr(addr_), m_alloc(alloc)
: userdata(userdata_), endpoint(addr_)
#ifndef TORRENT_NO_DEPRECATE
, addr(addr_)
#endif
, m_alloc(alloc)
, m_response_idx(-1), m_response_size(0)
{}
@ -1967,7 +2047,7 @@ namespace libtorrent {
{
char msg[1050];
std::snprintf(msg, sizeof(msg), "DHT direct response (address=%s) [ %s ]"
, addr.address().to_string().c_str()
, endpoint.address().to_string().c_str()
, m_response_size ? std::string(m_alloc.get().ptr(m_response_idx), m_response_size).c_str() : "");
return msg;
}
@ -2077,4 +2157,3 @@ namespace libtorrent {
}
} // namespace libtorrent

View File

@ -1383,10 +1383,10 @@ namespace aux {
listen_socket_t ret;
ret.ssl = (flags & open_ssl_socket) != 0;
int last_op = 0;
listen_failed_alert::socket_type_t const sock_type
socket_type_t const sock_type
= (flags & open_ssl_socket)
? listen_failed_alert::tcp_ssl
: listen_failed_alert::tcp;
? socket_type_t::tcp_ssl
: socket_type_t::tcp;
// if we're in force-proxy mode, don't open TCP listen sockets. We cannot
// accept connections on our local machine in this case.
@ -1633,10 +1633,10 @@ namespace aux {
}
#endif
listen_failed_alert::socket_type_t const udp_sock_type
socket_type_t const udp_sock_type
= (flags & open_ssl_socket)
? listen_failed_alert::utp_ssl
: listen_failed_alert::udp;
? socket_type_t::utp_ssl
: socket_type_t::udp;
if (m_alerts.should_post<listen_failed_alert>())
m_alerts.emplace_alert<listen_failed_alert>(device
@ -1742,7 +1742,7 @@ namespace aux {
m_alerts.emplace_alert<listen_failed_alert>(device
, listen_failed_alert::open
, boost::asio::error::operation_not_supported
, listen_failed_alert::tcp_ssl);
, socket_type_t::tcp_ssl);
}
continue;
}
@ -1786,7 +1786,7 @@ namespace aux {
{
m_alerts.emplace_alert<listen_failed_alert>(device
, listen_failed_alert::enum_if, ec
, listen_failed_alert::tcp);
, socket_type_t::tcp);
}
continue;
}
@ -1830,10 +1830,10 @@ namespace aux {
tcp::endpoint const tcp_ep = l.sock->local_endpoint(err);
if (!err)
{
listen_succeeded_alert::socket_type_t const socket_type
socket_type_t const socket_type
= l.ssl
? listen_succeeded_alert::tcp_ssl
: listen_succeeded_alert::tcp;
? socket_type_t::tcp_ssl
: socket_type_t::tcp;
m_alerts.emplace_alert<listen_succeeded_alert>(
tcp_ep, socket_type);
@ -1845,10 +1845,10 @@ namespace aux {
udp::endpoint const udp_ep = l.udp_sock->local_endpoint(err);
if (!err && l.udp_sock->is_open())
{
listen_succeeded_alert::socket_type_t const socket_type
socket_type_t const socket_type
= l.ssl
? listen_succeeded_alert::utp_ssl
: listen_succeeded_alert::udp;
? socket_type_t::utp_ssl
: socket_type_t::udp;
m_alerts.emplace_alert<listen_succeeded_alert>(
udp_ep, socket_type);
@ -1952,7 +1952,7 @@ namespace aux {
if (m_alerts.should_post<listen_failed_alert>())
m_alerts.emplace_alert<listen_failed_alert>("socks5"
, listen_failed_alert::accept, e
, listen_failed_alert::socks5);
, socket_type_t::socks5);
return;
}
@ -1965,7 +1965,7 @@ namespace aux {
if (m_alerts.should_post<listen_succeeded_alert>())
m_alerts.emplace_alert<listen_succeeded_alert>(
ep, listen_succeeded_alert::socks5);
ep, socket_type_t::socks5);
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("session_impl::on_socks_accept");
@ -1987,7 +1987,7 @@ namespace aux {
if (m_alerts.should_post<listen_failed_alert>())
m_alerts.emplace_alert<listen_failed_alert>("socks5"
, listen_failed_alert::accept, e
, listen_failed_alert::socks5);
, socket_type_t::socks5);
return;
}
if (m_abort) return;
@ -2078,7 +2078,7 @@ namespace aux {
{
m_alerts.emplace_alert<listen_failed_alert>("i2p"
, listen_failed_alert::accept
, e, listen_failed_alert::i2p);
, e, socket_type_t::i2p);
}
#ifndef TORRENT_DISABLE_LOGGING
if (should_log())
@ -2437,7 +2437,7 @@ namespace aux {
error_code err;
m_alerts.emplace_alert<listen_failed_alert>(ep.address().to_string(err)
, ep, listen_failed_alert::accept, e
, ssl ? listen_failed_alert::tcp_ssl : listen_failed_alert::tcp);
, ssl ? socket_type_t::tcp_ssl : socket_type_t::tcp);
}
return;
}

View File

@ -303,7 +303,8 @@ bool print_alerts(lt::session& ses, char const* name
if (predicate && predicate(a)) ret = true;
if (peer_disconnected_alert const* p = alert_cast<peer_disconnected_alert>(a))
{
std::printf("%s: %s: [%s] (%s): %s\n", time_now_string(), name, (a)->what(), print_endpoint(p->ip).c_str(), p->message().c_str());
std::printf("%s: %s: [%s] (%s): %s\n", time_now_string(), name, (a)->what()
, print_endpoint(p->endpoint).c_str(), p->message().c_str());
}
else if (should_print(a)
&& !no_output)

View File

@ -116,8 +116,8 @@ TORRENT_TEST(direct_dht_request)
if (ra)
{
bdecode_node response = ra->response();
TEST_EQUAL(ra->addr.address(), address::from_string("127.0.0.1"));
TEST_EQUAL(ra->addr.port(), responder.listen_port());
TEST_EQUAL(ra->endpoint.address(), address::from_string("127.0.0.1"));
TEST_EQUAL(ra->endpoint.port(), responder.listen_port());
TEST_EQUAL(response.type(), bdecode_node::dict_t);
TEST_EQUAL(response.dict_find_dict("r").dict_find_int_value("good"), 1);
TEST_EQUAL(ra->userdata, (void*)12345);
@ -132,8 +132,8 @@ TORRENT_TEST(direct_dht_request)
TEST_CHECK(ra);
if (ra)
{
TEST_EQUAL(ra->addr.address(), address::from_string("127.0.0.1"));
TEST_EQUAL(ra->addr.port(), 53545);
TEST_EQUAL(ra->endpoint.address(), address::from_string("127.0.0.1"));
TEST_EQUAL(ra->endpoint.port(), 53545);
TEST_EQUAL(ra->response().type(), bdecode_node::none_t);
TEST_EQUAL(ra->userdata, (void*)123456);
}

View File

@ -308,11 +308,9 @@ int main(int argc, char* argv[])
alert* a = wait_for_alert(s, dht_immutable_item_alert::alert_type);
dht_immutable_item_alert* item = alert_cast<dht_immutable_item_alert>(a);
entry data;
if (item)
data.swap(item->item);
std::printf("%s", data.to_string().c_str());
std::string str = item->item.to_string();
std::printf("%s", str.c_str());
}
else if (strcmp(argv[0], "put") == 0)
{
@ -399,12 +397,10 @@ int main(int argc, char* argv[])
alert* a = wait_for_alert(s, dht_mutable_item_alert::alert_type);
dht_mutable_item_alert* item = alert_cast<dht_mutable_item_alert>(a);
entry data;
if (item)
data.swap(item->item);
authoritative = item->authoritative;
std::printf("%s: %s", authoritative ? "auth" : "non-auth", data.to_string().c_str());
std::string str = item->item.to_string();
std::printf("%s: %s", authoritative ? "auth" : "non-auth", str.c_str());
}
}
else