simplify some constructors with in-class initializers (#1038)

simplify peer_connection, torrent and session_impl's contstructors by moving simple parts to their header files
This commit is contained in:
Arvid Norberg 2016-08-29 20:29:27 -04:00 committed by GitHub
parent 32f5f8f257
commit 9ac7475a90
9 changed files with 167 additions and 288 deletions

7
.gitignore vendored
View File

@ -34,6 +34,9 @@
*.deps *.deps
*.cache *.cache
*.dirstamp *.dirstamp
*.swp
*.orig
*.rej
bin bin
config* config*
@ -41,6 +44,10 @@ Makefile
build-aux build-aux
test_tmp_* test_tmp_*
libtool libtool
docs/reference*
docs/*.html
docs/*.png
docs/*-ref.rst
.DS_Store .DS_Store
.idea .idea

View File

@ -240,7 +240,7 @@ namespace libtorrent
bool is_posting_torrent_updates() const override { return m_posting_torrent_updates; } bool is_posting_torrent_updates() const override { return m_posting_torrent_updates; }
// this is set while the session is building the // this is set while the session is building the
// torrent status update message // torrent status update message
bool m_posting_torrent_updates; bool m_posting_torrent_updates = false;
#endif #endif
void reopen_listen_sockets(); void reopen_listen_sockets();
@ -744,7 +744,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR #ifndef TORRENT_DISABLE_POOL_ALLOCATOR
// this pool is used to allocate and recycle send // this pool is used to allocate and recycle send
// buffers from. // buffers from.
boost::pool<> m_send_buffers; boost::pool<> m_send_buffers{send_buffer_size_impl};
#endif #endif
io_service& m_io_service; io_service& m_io_service;
@ -766,7 +766,7 @@ namespace libtorrent
// the client. This is the offset into m_alert_pointers where the next // the client. This is the offset into m_alert_pointers where the next
// alert is. If this is greater than or equal to m_alert_pointers.size() // alert is. If this is greater than or equal to m_alert_pointers.size()
// it means we need to request new alerts from the main thread. // it means we need to request new alerts from the main thread.
mutable int m_alert_pointer_pos; mutable int m_alert_pointer_pos = 0;
#endif #endif
// handles disk io requests asynchronously // handles disk io requests asynchronously
@ -787,7 +787,7 @@ namespace libtorrent
bandwidth_manager m_upload_rate; bandwidth_manager m_upload_rate;
// the peer class that all peers belong to by default // the peer class that all peers belong to by default
peer_class_t m_global_class; peer_class_t m_global_class = 0;
// the peer class all TCP peers belong to by default // the peer class all TCP peers belong to by default
// all tcp peer connections are subject to these // all tcp peer connections are subject to these
@ -796,10 +796,10 @@ namespace libtorrent
// throttle TCP that passes over the internet // throttle TCP that passes over the internet
// bottleneck (i.e. modem) to avoid starving out // bottleneck (i.e. modem) to avoid starving out
// uTP connections. // uTP connections.
peer_class_t m_tcp_peer_class; peer_class_t m_tcp_peer_class = 0;
// peer class for local peers // peer class for local peers
peer_class_t m_local_peer_class; peer_class_t m_local_peer_class = 0;
tracker_manager m_tracker_manager; tracker_manager m_tracker_manager;
torrent_map m_torrents; torrent_map m_torrents;
@ -865,12 +865,12 @@ namespace libtorrent
// in this session. queue positions are packed (i.e. there // in this session. queue positions are packed (i.e. there
// are no gaps). If there are no torrents with queue positions // are no gaps). If there are no torrents with queue positions
// this is -1. // this is -1.
int m_max_queue_pos; int m_max_queue_pos = -1;
// the key is an id that is used to identify the // the key is an id that is used to identify the
// client with the tracker only. It is randomized // client with the tracker only. It is randomized
// at startup // at startup
int m_key; int m_key = 0;
// the addresses or device names of the interfaces we are supposed to // the addresses or device names of the interfaces we are supposed to
// listen on. if empty, it means that we should let the os decide // listen on. if empty, it means that we should let the os decide
@ -904,10 +904,10 @@ namespace libtorrent
// when as a socks proxy is used for peers, also // when as a socks proxy is used for peers, also
// listen for incoming connections on a socks connection // listen for incoming connections on a socks connection
boost::shared_ptr<socket_type> m_socks_listen_socket; boost::shared_ptr<socket_type> m_socks_listen_socket;
std::uint16_t m_socks_listen_port; std::uint16_t m_socks_listen_port = 0;
// round-robin index into m_outgoing_interfaces // round-robin index into m_outgoing_interfaces
mutable std::uint8_t m_interface_index; mutable std::uint8_t m_interface_index = 0;
void open_new_incoming_socks_connection(); void open_new_incoming_socks_connection();
@ -929,30 +929,30 @@ namespace libtorrent
// unchoke_interval and the unchoke set is // unchoke_interval and the unchoke set is
// recomputed. // recomputed.
// TODO: replace this by a proper asio timer // TODO: replace this by a proper asio timer
int m_unchoke_time_scaler; int m_unchoke_time_scaler = 0;
// this is used to decide when to recalculate which // this is used to decide when to recalculate which
// torrents to keep queued and which to activate // torrents to keep queued and which to activate
// TODO: replace this by a proper asio timer // TODO: replace this by a proper asio timer
int m_auto_manage_time_scaler; int m_auto_manage_time_scaler = 0;
// works like unchoke_time_scaler but it // works like unchoke_time_scaler but it
// is only decreased when the unchoke set // is only decreased when the unchoke set
// is recomputed, and when it reaches zero, // is recomputed, and when it reaches zero,
// the optimistic unchoke is moved to another peer. // the optimistic unchoke is moved to another peer.
// TODO: replace this by a proper asio timer // TODO: replace this by a proper asio timer
int m_optimistic_unchoke_time_scaler; int m_optimistic_unchoke_time_scaler = 0;
// works like unchoke_time_scaler. Each time // works like unchoke_time_scaler. Each time
// it reaches 0, and all the connections are // it reaches 0, and all the connections are
// used, the worst connection will be disconnected // used, the worst connection will be disconnected
// from the torrent with the most peers // from the torrent with the most peers
int m_disconnect_time_scaler; int m_disconnect_time_scaler = 90;
// when this scaler reaches zero, it will // when this scaler reaches zero, it will
// scrape one of the auto managed, paused, // scrape one of the auto managed, paused,
// torrents. // torrents.
int m_auto_scrape_time_scaler; int m_auto_scrape_time_scaler = 180;
// statistics gathered from all torrents. // statistics gathered from all torrents.
stat m_stat; stat m_stat;
@ -964,8 +964,8 @@ namespace libtorrent
virtual void sent_syn(bool ipv6) override; virtual void sent_syn(bool ipv6) override;
virtual void received_synack(bool ipv6) override; virtual void received_synack(bool ipv6) override;
int m_peak_up_rate; int m_peak_up_rate = 0;
int m_peak_down_rate; int m_peak_down_rate = 0;
void on_tick(error_code const& e); void on_tick(error_code const& e);
@ -1005,13 +1005,14 @@ namespace libtorrent
// when outgoing_ports is configured, this is the // when outgoing_ports is configured, this is the
// port we'll bind the next outgoing socket to // port we'll bind the next outgoing socket to
mutable int m_next_port; mutable int m_next_port = 0;
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
std::unique_ptr<dht::dht_storage_interface> m_dht_storage; std::unique_ptr<dht::dht_storage_interface> m_dht_storage;
boost::shared_ptr<dht::dht_tracker> m_dht; boost::shared_ptr<dht::dht_tracker> m_dht;
dht_settings m_dht_settings; dht_settings m_dht_settings;
dht::dht_storage_constructor_type m_dht_storage_constructor; dht::dht_storage_constructor_type m_dht_storage_constructor
= dht::dht_default_storage_constructor;
// these are used when starting the DHT // these are used when starting the DHT
// (and bootstrapping it), and then erased // (and bootstrapping it), and then erased
@ -1031,11 +1032,11 @@ namespace libtorrent
// compared to this number, the DHT announce interval // compared to this number, the DHT announce interval
// is updated again. This especially matters for // is updated again. This especially matters for
// small numbers. // small numbers.
int m_dht_interval_update_torrents; int m_dht_interval_update_torrents = 0;
// the number of DHT router lookups there are currently outstanding. As // the number of DHT router lookups there are currently outstanding. As
// long as this is > 0, we'll postpone starting the DHT // long as this is > 0, we'll postpone starting the DHT
int m_outstanding_router_lookups; int m_outstanding_router_lookups = 0;
#endif #endif
void send_udp_packet_hostname(char const* hostname void send_udp_packet_hostname(char const* hostname
@ -1065,7 +1066,7 @@ namespace libtorrent
// the number of torrent connection boosts // the number of torrent connection boosts
// connections that have been made this second // connections that have been made this second
// this is deducted from the connect speed // this is deducted from the connect speed
int m_boost_connections; int m_boost_connections = 0;
boost::shared_ptr<natpmp> m_natpmp; boost::shared_ptr<natpmp> m_natpmp;
boost::shared_ptr<upnp> m_upnp; boost::shared_ptr<upnp> m_upnp;
@ -1133,18 +1134,18 @@ namespace libtorrent
// m_torrent_lists[torrent_want_peers_downloading] // m_torrent_lists[torrent_want_peers_downloading]
// (which is a list of torrent pointers with all // (which is a list of torrent pointers with all
// torrents that want peers and are downloading) // torrents that want peers and are downloading)
int m_next_downloading_connect_torrent; int m_next_downloading_connect_torrent = 0;
int m_next_finished_connect_torrent; int m_next_finished_connect_torrent = 0;
// this is the number of attempts of connecting to // this is the number of attempts of connecting to
// peers we have given to downloading torrents. // peers we have given to downloading torrents.
// when this gets high enough, we try to connect // when this gets high enough, we try to connect
// a peer from a finished torrent // a peer from a finished torrent
int m_download_connect_attempts; int m_download_connect_attempts = 0;
// index into m_torrent_lists[torrent_want_scrape] referring // index into m_torrent_lists[torrent_want_scrape] referring
// to the next torrent to auto-scrape // to the next torrent to auto-scrape
int m_next_scrape_torrent; int m_next_scrape_torrent = 0;
#if TORRENT_USE_INVARIANT_CHECKS #if TORRENT_USE_INVARIANT_CHECKS
void check_invariant() const; void check_invariant() const;
@ -1163,7 +1164,7 @@ namespace libtorrent
// this keeps the timers more accurate over time // this keeps the timers more accurate over time
// as a kind of "leap second" to adjust for the // as a kind of "leap second" to adjust for the
// accumulated error // accumulated error
std::uint16_t m_tick_residual; std::uint16_t m_tick_residual = 0;
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
virtual void session_log(char const* fmt, ...) const override TORRENT_FORMAT(2,3); virtual void session_log(char const* fmt, ...) const override TORRENT_FORMAT(2,3);
@ -1189,29 +1190,29 @@ namespace libtorrent
// this is true whenever we have posted a deferred-disk job // this is true whenever we have posted a deferred-disk job
// it means we don't need to post another one // it means we don't need to post another one
bool m_deferred_submit_disk_jobs; bool m_deferred_submit_disk_jobs = false;
// this is set to true when a torrent auto-manage // this is set to true when a torrent auto-manage
// event is triggered, and reset whenever the message // event is triggered, and reset whenever the message
// is delivered and the auto-manage is executed. // is delivered and the auto-manage is executed.
// there should never be more than a single pending auto-manage // there should never be more than a single pending auto-manage
// message in-flight at any given time. // message in-flight at any given time.
bool m_pending_auto_manage; bool m_pending_auto_manage = false;
// this is also set to true when triggering an auto-manage // this is also set to true when triggering an auto-manage
// of the torrents. However, if the normal auto-manage // of the torrents. However, if the normal auto-manage
// timer comes along and executes the auto-management, // timer comes along and executes the auto-management,
// this is set to false, which means the triggered event // this is set to false, which means the triggered event
// no longer needs to execute the auto-management. // no longer needs to execute the auto-management.
bool m_need_auto_manage; bool m_need_auto_manage = false;
// set to true when the session object // set to true when the session object
// is being destructed and the thread // is being destructed and the thread
// should exit // should exit
bool m_abort; bool m_abort = false;
// is true if the session is paused // is true if the session is paused
bool m_paused; bool m_paused = false;
// this is a list of peer connections who have been // this is a list of peer connections who have been
// corked (i.e. their network socket) and needs to be // corked (i.e. their network socket) and needs to be

View File

@ -327,7 +327,7 @@ public:
private: private:
enum state_t enum class state_t : std::uint8_t
{ {
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
read_pe_dhkey = 0, read_pe_dhkey = 0,
@ -351,7 +351,7 @@ private:
}; };
// state of on_receive. one of the enums in state_t // state of on_receive. one of the enums in state_t
std::uint8_t m_state; state_t m_state = state_t::read_protocol_identifier;
// this is set to true if the handshake from // this is set to true if the handshake from
// the peer indicated that it supports the // the peer indicated that it supports the
@ -440,23 +440,23 @@ private:
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// used to disconnect peer if sync points are not found within // used to disconnect peer if sync points are not found within
// the maximum number of bytes // the maximum number of bytes
int m_sync_bytes_read; int m_sync_bytes_read = 0;
#endif #endif
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
// the message ID for upload only message // the message ID for upload only message
// 0 if not supported // 0 if not supported
std::uint8_t m_upload_only_id; std::uint8_t m_upload_only_id = 0;
// the message ID for holepunch messages // the message ID for holepunch messages
std::uint8_t m_holepunch_id; std::uint8_t m_holepunch_id = 0;
// the message ID for don't-have message // the message ID for don't-have message
std::uint8_t m_dont_have_id; std::uint8_t m_dont_have_id = 0;
// the message ID for share mode message // the message ID for share mode message
// 0 if not supported // 0 if not supported
std::uint8_t m_share_mode_id; std::uint8_t m_share_mode_id = 0;
std::weak_ptr<ut_pex_peer_store> m_ut_pex; std::weak_ptr<ut_pex_peer_store> m_ut_pex;
@ -464,7 +464,7 @@ private:
#endif #endif
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
bool m_in_constructor; bool m_in_constructor = true;
#endif #endif
}; };

View File

@ -60,6 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io_service_fwd.hpp" #include "libtorrent/io_service_fwd.hpp"
#include "libtorrent/receive_buffer.hpp" #include "libtorrent/receive_buffer.hpp"
#include "libtorrent/aux_/allocating_handler.hpp" #include "libtorrent/aux_/allocating_handler.hpp"
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/debug.hpp" #include "libtorrent/debug.hpp"
#include "libtorrent/span.hpp" #include "libtorrent/span.hpp"
@ -888,33 +889,33 @@ namespace libtorrent
// the time when we last got a part of a // the time when we last got a part of a
// piece packet from this peer // piece packet from this peer
time_point m_last_piece; time_point m_last_piece = aux::time_now();
// the time we sent a request to // the time we sent a request to
// this peer the last time // this peer the last time
time_point m_last_request; time_point m_last_request = aux::time_now();
// the time we received the last // the time we received the last
// piece request from the peer // piece request from the peer
time_point m_last_incoming_request; time_point m_last_incoming_request = min_time();
// the time when we unchoked this peer // the time when we unchoked this peer
time_point m_last_unchoke; time_point m_last_unchoke = aux::time_now();
// if we're unchoked by this peer, this // if we're unchoked by this peer, this
// was the time // was the time
time_point m_last_unchoked; time_point m_last_unchoked = aux::time_now();
// the time we last choked this peer. min_time() in // the time we last choked this peer. min_time() in
// case we never unchoked it // case we never unchoked it
time_point m_last_choke; time_point m_last_choke = min_time();
// timeouts // timeouts
time_point m_last_receive; time_point m_last_receive = aux::time_now();
time_point m_last_sent; time_point m_last_sent = aux::time_now();
// the last time we filled our send buffer with payload // the last time we filled our send buffer with payload
// this is used for timeouts // this is used for timeouts
time_point m_last_sent_payload; time_point m_last_sent_payload = aux::time_now();
// the time when the first entry in the request queue was requested. Used // the time when the first entry in the request queue was requested. Used
// for request timeout. it doesn't necessarily represent the time when a // for request timeout. it doesn't necessarily represent the time when a
@ -923,31 +924,31 @@ namespace libtorrent
// Once we get that response, we set it to the current time. // Once we get that response, we set it to the current time.
// for more information, see the blog post at: // for more information, see the blog post at:
// http://blog.libtorrent.org/2011/11/block-request-time-outs/ // http://blog.libtorrent.org/2011/11/block-request-time-outs/
time_point m_requested; time_point m_requested = aux::time_now();
// a timestamp when the remote download rate // a timestamp when the remote download rate
// was last updated // was last updated
time_point m_remote_dl_update; time_point m_remote_dl_update = aux::time_now();
// the time when async_connect was called // the time when async_connect was called
// or when the incoming connection was established // or when the incoming connection was established
time_point m_connect; time_point m_connect = aux::time_now();
// the time when this peer sent us a not_interested message // the time when this peer sent us a not_interested message
// the last time. // the last time.
time_point m_became_uninterested; time_point m_became_uninterested = aux::time_now();
// the time when we sent a not_interested message to // the time when we sent a not_interested message to
// this peer the last time. // this peer the last time.
time_point m_became_uninteresting; time_point m_became_uninteresting = aux::time_now();
// the total payload download bytes // the total payload download bytes
// at the last unchoke round. This is used to // at the last unchoke round. This is used to
// measure the number of bytes transferred during // measure the number of bytes transferred during
// an unchoke cycle, to unchoke peers the more bytes // an unchoke cycle, to unchoke peers the more bytes
// they sent us // they sent us
std::int64_t m_downloaded_at_last_round; std::int64_t m_downloaded_at_last_round = 0;
std::int64_t m_uploaded_at_last_round; std::int64_t m_uploaded_at_last_round = 0;
// this is the number of bytes we had uploaded the // this is the number of bytes we had uploaded the
// last time this peer was unchoked. This does not // last time this peer was unchoked. This does not
@ -955,19 +956,19 @@ namespace libtorrent
// track upload across rounds, for the full duration of // track upload across rounds, for the full duration of
// the peer being unchoked. Specifically, it's used // the peer being unchoked. Specifically, it's used
// for the round-robin unchoke algorithm. // for the round-robin unchoke algorithm.
std::int64_t m_uploaded_at_last_unchoke; std::int64_t m_uploaded_at_last_unchoke = 0;
// the number of payload bytes downloaded last second tick // the number of payload bytes downloaded last second tick
std::int32_t m_downloaded_last_second; std::int32_t m_downloaded_last_second = 0;
// the number of payload bytes uploaded last second tick // the number of payload bytes uploaded last second tick
std::int32_t m_uploaded_last_second; std::int32_t m_uploaded_last_second = 0;
// the number of bytes that the other // the number of bytes that the other
// end has to send us in order to respond // end has to send us in order to respond
// to all outstanding piece requests we // to all outstanding piece requests we
// have sent to it // have sent to it
int m_outstanding_bytes; int m_outstanding_bytes = 0;
aux::handler_storage<TORRENT_READ_HANDLER_MAX_SIZE> m_read_handler_storage; aux::handler_storage<TORRENT_READ_HANDLER_MAX_SIZE> m_read_handler_storage;
aux::handler_storage<TORRENT_WRITE_HANDLER_MAX_SIZE> m_write_handler_storage; aux::handler_storage<TORRENT_WRITE_HANDLER_MAX_SIZE> m_write_handler_storage;
@ -998,11 +999,11 @@ namespace libtorrent
// the time when this peer last saw a complete copy // the time when this peer last saw a complete copy
// of this torrent // of this torrent
time_t m_last_seen_complete; time_t m_last_seen_complete = 0;
// the block we're currently receiving. Or // the block we're currently receiving. Or
// (-1, -1) if we're not receiving one // (-1, -1) if we're not receiving one
piece_block m_receiving_block; piece_block m_receiving_block = piece_block::invalid;
// the local endpoint for this peer, i.e. our address // the local endpoint for this peer, i.e. our address
// and our port. If this is set for outgoing connections // and our port. If this is set for outgoing connections
@ -1029,7 +1030,7 @@ namespace libtorrent
// the number of outstanding bytes expected // the number of outstanding bytes expected
// to be received by extensions // to be received by extensions
int m_extension_outstanding_bytes; int m_extension_outstanding_bytes = 0;
// the number of time critical requests // the number of time critical requests
// queued up in the m_request_queue that // queued up in the m_request_queue that
@ -1039,18 +1040,18 @@ namespace libtorrent
// requests and take the previous requests // requests and take the previous requests
// into account without submitting it all // into account without submitting it all
// immediately // immediately
int m_queued_time_critical; int m_queued_time_critical = 0;
// the number of bytes we are currently reading // the number of bytes we are currently reading
// from disk, that will be added to the send // from disk, that will be added to the send
// buffer as soon as they complete // buffer as soon as they complete
int m_reading_bytes; int m_reading_bytes = 0;
// options used for the piece picker. These flags will // options used for the piece picker. These flags will
// be augmented with flags controlled by other settings // be augmented with flags controlled by other settings
// like sequential download etc. These are here to // like sequential download etc. These are here to
// let plugins control flags that should always be set // let plugins control flags that should always be set
int m_picker_options; int m_picker_options = 0;
// the number of invalid piece-requests // the number of invalid piece-requests
// we have got from this peer. If the request // we have got from this peer. If the request
@ -1059,30 +1060,30 @@ namespace libtorrent
// peer is waiting for those pieces. // peer is waiting for those pieces.
// we can then clear its download queue // we can then clear its download queue
// by sending choke, unchoke. // by sending choke, unchoke.
int m_num_invalid_requests; int m_num_invalid_requests = 0;
// if [0] is -1, superseeding is not active. If it is >= 0 // if [0] is -1, superseeding is not active. If it is >= 0
// this is the piece that is available to this peer. Only // this is the piece that is available to this peer. Only
// these two pieces can be downloaded from us by this peer. // these two pieces can be downloaded from us by this peer.
// This will remain the current piece for this peer until // This will remain the current piece for this peer until
// another peer sends us a have message for this piece // another peer sends us a have message for this piece
int m_superseed_piece[2]; int m_superseed_piece[2] = {-1, -1};
// pieces downloaded since last second // pieces downloaded since last second
// timer timeout; used for determining // timer timeout; used for determining
// approx download rate // approx download rate
int m_remote_pieces_dled; int m_remote_pieces_dled = 0;
// approximate peer download rate // approximate peer download rate
int m_remote_dl_rate; int m_remote_dl_rate = 0;
// the number of bytes send to the disk-io // the number of bytes send to the disk-io
// thread that hasn't yet been completely written. // thread that hasn't yet been completely written.
int m_outstanding_writing_bytes; int m_outstanding_writing_bytes = 0;
// max transfer rates seen on this peer // max transfer rates seen on this peer
int m_download_rate_peak; int m_download_rate_peak = 0;
int m_upload_rate_peak; int m_upload_rate_peak = 0;
// when using the BitTyrant choker, this is our // when using the BitTyrant choker, this is our
// estimated reciprocation rate. i.e. the rate // estimated reciprocation rate. i.e. the rate
@ -1091,12 +1092,12 @@ namespace libtorrent
int m_est_reciprocation_rate; int m_est_reciprocation_rate;
// stop sending data after this many bytes, INT_MAX = inf // stop sending data after this many bytes, INT_MAX = inf
int m_send_barrier; int m_send_barrier = INT_MAX;
// the number of request we should queue up // the number of request we should queue up
// at the remote end. // at the remote end.
// TODO: 2 rename this target queue size // TODO: 2 rename this target queue size
std::uint16_t m_desired_queue_size; std::uint16_t m_desired_queue_size = 4;
// if set to non-zero, this peer will always prefer // if set to non-zero, this peer will always prefer
// to request entire n pieces, rather than blocks. // to request entire n pieces, rather than blocks.
@ -1104,14 +1105,14 @@ namespace libtorrent
// if it is 0, the download rate limit setting // if it is 0, the download rate limit setting
// will be used to determine if whole pieces // will be used to determine if whole pieces
// are preferred. // are preferred.
std::uint8_t m_prefer_contiguous_blocks; std::uint8_t m_prefer_contiguous_blocks = 0;
// this is the number of times this peer has had // this is the number of times this peer has had
// a request rejected because of a disk I/O failure. // a request rejected because of a disk I/O failure.
// once this reaches a certain threshold, the // once this reaches a certain threshold, the
// peer is disconnected in order to avoid infinite // peer is disconnected in order to avoid infinite
// loops of consistent failures // loops of consistent failures
std::uint8_t m_disk_read_failures; std::uint8_t m_disk_read_failures = 0;
// this is used in seed mode whenever we trigger a hash check // this is used in seed mode whenever we trigger a hash check
// for a piece, before we read it. It's used to throttle // for a piece, before we read it. It's used to throttle
@ -1229,15 +1230,15 @@ namespace libtorrent
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
public: public:
bool m_in_constructor; bool m_in_constructor = true;
bool m_disconnect_started; bool m_disconnect_started = false;
bool m_initialized; bool m_initialized = false;
int m_in_use; int m_in_use = 1337;
int m_received_in_piece; int m_received_in_piece = 0;
bool m_destructed; bool m_destructed = false;
// this is true while there is an outstanding // this is true while there is an outstanding
// async write job on the socket // async write job on the socket
bool m_socket_is_writing; bool m_socket_is_writing = false;
bool is_single_thread() const; bool is_single_thread() const;
#endif #endif
}; };

View File

@ -1147,8 +1147,8 @@ namespace libtorrent
// all time totals of uploaded and downloaded payload // all time totals of uploaded and downloaded payload
// stored in resume data // stored in resume data
std::int64_t m_total_uploaded; std::int64_t m_total_uploaded = 0;
std::int64_t m_total_downloaded; std::int64_t m_total_downloaded = 0;
// if this pointer is 0, the torrent is in // if this pointer is 0, the torrent is in
// a state where the metadata hasn't been // a state where the metadata hasn't been
@ -1289,14 +1289,14 @@ namespace libtorrent
// it was completed. If the torrent isn't yet // it was completed. If the torrent isn't yet
// completed, m_completed_time is 0 // completed, m_completed_time is 0
time_t m_added_time; time_t m_added_time;
time_t m_completed_time; time_t m_completed_time = 0;
// this was the last time _we_ saw a seed in this swarm // this was the last time _we_ saw a seed in this swarm
time_t m_last_seen_complete; time_t m_last_seen_complete = 0;
// this is the time last any of our peers saw a seed // this is the time last any of our peers saw a seed
// in this swarm // in this swarm
time_t m_swarm_last_seen_complete; time_t m_swarm_last_seen_complete = 0;
// keep a copy if the info-hash here, so it can be accessed from multiple // keep a copy if the info-hash here, so it can be accessed from multiple
// threads, and be cheap to access from the client // threads, and be cheap to access from the client
@ -1317,7 +1317,7 @@ namespace libtorrent
private: private:
// m_num_verified = m_verified.count() // m_num_verified = m_verified.count()
std::uint32_t m_num_verified; std::uint32_t m_num_verified = 0;
// this timestamp is kept in session-time, to // this timestamp is kept in session-time, to
// make it fit in 16 bits // make it fit in 16 bits
@ -1335,23 +1335,23 @@ namespace libtorrent
// if we're a seed, this is the session time // if we're a seed, this is the session time
// timestamp of when we became one // timestamp of when we became one
std::uint16_t m_became_seed; std::uint16_t m_became_seed = 0;
// if we're finished, this is the session time // if we're finished, this is the session time
// timestamp of when we finished // timestamp of when we finished
std::uint16_t m_became_finished; std::uint16_t m_became_finished = 0;
// when checking, this is the first piece we have not // when checking, this is the first piece we have not
// issued a hash job for // issued a hash job for
int m_checking_piece; int m_checking_piece = 0;
// the number of pieces we completed the check of // the number of pieces we completed the check of
int m_num_checked_pieces; int m_num_checked_pieces = 0;
// the number of async. operations that need this torrent // the number of async. operations that need this torrent
// loaded in RAM. having a refcount > 0 prevents it from // loaded in RAM. having a refcount > 0 prevents it from
// being unloaded. // being unloaded.
int m_refcount; int m_refcount = 0;
// if the error ocurred on a file, this is the index of that file // if the error ocurred on a file, this is the index of that file
// there are a few special cases, when this is negative. See // there are a few special cases, when this is negative. See
@ -1359,15 +1359,15 @@ namespace libtorrent
int m_error_file; int m_error_file;
// the average time it takes to download one time critical piece // the average time it takes to download one time critical piece
std::uint32_t m_average_piece_time; std::uint32_t m_average_piece_time = 0;
// the average piece download time deviation // the average piece download time deviation
std::uint32_t m_piece_time_deviation; std::uint32_t m_piece_time_deviation = 0;
// the number of bytes that has been // the number of bytes that has been
// downloaded that failed the hash-test // downloaded that failed the hash-test
std::uint32_t m_total_failed_bytes; std::uint32_t m_total_failed_bytes = 0;
std::uint32_t m_total_redundant_bytes; std::uint32_t m_total_redundant_bytes = 0;
// the sequence number for this torrent, this is a // the sequence number for this torrent, this is a
// monotonically increasing number for each added torrent // monotonically increasing number for each added torrent
@ -1375,14 +1375,14 @@ namespace libtorrent
// for torrents who have a bandwidth limit, this is != 0 // for torrents who have a bandwidth limit, this is != 0
// and refers to a peer_class in the session. // and refers to a peer_class in the session.
std::uint16_t m_peer_class; std::uint16_t m_peer_class = 0;
// of all peers in m_connections, this is the number // of all peers in m_connections, this is the number
// of peers that are outgoing and still waiting to // of peers that are outgoing and still waiting to
// complete the connection. This is used to possibly // complete the connection. This is used to possibly
// kick out these connections when we get incoming // kick out these connections when we get incoming
// connections (if we've reached the connection limit) // connections (if we've reached the connection limit)
std::uint16_t m_num_connecting; std::uint16_t m_num_connecting = 0;
// ============================== // ==============================
// The following members are specifically // The following members are specifically
@ -1393,7 +1393,7 @@ namespace libtorrent
// the session time timestamp of when we entered upload mode // the session time timestamp of when we entered upload mode
// if we're currently in upload-mode // if we're currently in upload-mode
std::uint16_t m_upload_mode_time; std::uint16_t m_upload_mode_time = 0;
// true when this torrent should announce to // true when this torrent should announce to
// trackers // trackers
@ -1434,7 +1434,7 @@ namespace libtorrent
unsigned int m_active_time:24; unsigned int m_active_time:24;
// the index to the last tracker that worked // the index to the last tracker that worked
std::int8_t m_last_working_tracker; std::int8_t m_last_working_tracker = -1;
// ---- // ----
@ -1586,16 +1586,16 @@ namespace libtorrent
// the timestamp of the last piece passed for this torrent specified in // the timestamp of the last piece passed for this torrent specified in
// session_time. This is signed because it must be able to represent time // session_time. This is signed because it must be able to represent time
// before the session started // before the session started
std::int16_t m_last_download; std::int16_t m_last_download = (std::numeric_limits<std::int16_t>::min)();
// the number of peer connections to seeds. This should be the same as // the number of peer connections to seeds. This should be the same as
// counting the peer connections that say true for is_seed() // counting the peer connections that say true for is_seed()
std::uint16_t m_num_seeds; std::uint16_t m_num_seeds = 0;
// the timestamp of the last byte uploaded from this torrent specified in // the timestamp of the last byte uploaded from this torrent specified in
// session_time. This is signed because it must be able to represent time // session_time. This is signed because it must be able to represent time
// before the session started. // before the session started.
std::int16_t m_last_upload; std::int16_t m_last_upload = (std::numeric_limits<std::int16_t>::min)();
// ---- // ----
@ -1627,7 +1627,7 @@ namespace libtorrent
// the timestamp of the last scrape request to one of the trackers in // the timestamp of the last scrape request to one of the trackers in
// this torrent specified in session_time. This is signed because it must // this torrent specified in session_time. This is signed because it must
// be able to represent time before the session started // be able to represent time before the session started
std::int16_t m_last_scrape; std::int16_t m_last_scrape = (std::numeric_limits<std::int16_t>::min)();
// ---- // ----
@ -1637,8 +1637,8 @@ namespace libtorrent
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
// set to true when torrent is start()ed. It may only be started once // set to true when torrent is start()ed. It may only be started once
bool m_was_started; bool m_was_started = false;
bool m_outstanding_check_files; bool m_outstanding_check_files = false;
#endif #endif
}; };

View File

@ -156,7 +156,6 @@ namespace libtorrent
bt_peer_connection::bt_peer_connection(peer_connection_args const& pack bt_peer_connection::bt_peer_connection(peer_connection_args const& pack
, peer_id const& pid) , peer_id const& pid)
: peer_connection(pack) : peer_connection(pack)
, m_state(read_protocol_identifier)
, m_supports_extensions(false) , m_supports_extensions(false)
, m_supports_dht_port(false) , m_supports_dht_port(false)
, m_supports_fast(false) , m_supports_fast(false)
@ -169,20 +168,6 @@ namespace libtorrent
, m_recv_buffer(peer_connection::m_recv_buffer) , m_recv_buffer(peer_connection::m_recv_buffer)
#endif #endif
, m_our_peer_id(pid) , m_our_peer_id(pid)
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
, m_sync_bytes_read(0)
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
, m_upload_only_id(0)
, m_holepunch_id(0)
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
, m_dont_have_id(0)
, m_share_mode_id(0)
#endif
#if TORRENT_USE_ASSERTS
, m_in_constructor(true)
#endif
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "CONSTRUCT", "bt_peer_connection"); peer_log(peer_log_alert::info, "CONSTRUCT", "bt_peer_connection");
@ -262,7 +247,7 @@ namespace libtorrent
write_pe1_2_dhkey(); write_pe1_2_dhkey();
if (is_disconnecting()) return; if (is_disconnecting()) return;
m_state = read_pe_dhkey; m_state = state_t::read_pe_dhkey;
m_recv_buffer.reset(dh_key_len); m_recv_buffer.reset(dh_key_len);
setup_receive(); setup_receive();
} }
@ -284,7 +269,7 @@ namespace libtorrent
write_pe1_2_dhkey(); write_pe1_2_dhkey();
if (is_disconnecting()) return; if (is_disconnecting()) return;
m_state = read_pe_dhkey; m_state = state_t::read_pe_dhkey;
m_recv_buffer.reset(dh_key_len); m_recv_buffer.reset(dh_key_len);
setup_receive(); setup_receive();
} }
@ -324,7 +309,11 @@ namespace libtorrent
// we're still waiting to fully handshake with this peer. At the end of // we're still waiting to fully handshake with this peer. At the end of
// the handshake we'll send the bitfield and dht port anyway. It's too // the handshake we'll send the bitfield and dht port anyway. It's too
// early to do now // early to do now
if (m_state < read_packet_size) return; if (static_cast<int>(m_state)
< static_cast<int>(state_t::read_packet_size))
{
return;
}
// connections that are still in the handshake // connections that are still in the handshake
// will send their bitfield when the handshake // will send their bitfield when the handshake
@ -859,7 +848,7 @@ namespace libtorrent
span<char const> recv_buffer = m_recv_buffer.get(); span<char const> recv_buffer = m_recv_buffer.get();
// are we currently receiving a 'piece' message? // are we currently receiving a 'piece' message?
if (m_state != read_packet if (m_state != state_t::read_packet
|| int(recv_buffer.size()) <= 9 || int(recv_buffer.size()) <= 9
|| recv_buffer[0] != msg_piece) || recv_buffer[0] != msg_piece)
return boost::optional<piece_block_progress>(); return boost::optional<piece_block_progress>();
@ -2074,7 +2063,7 @@ namespace libtorrent
// if we have not received the other peer's extension bits yet, how do we // if we have not received the other peer's extension bits yet, how do we
// know whether to send a have-all or have-none? // know whether to send a have-all or have-none?
TORRENT_ASSERT(m_state >= read_peer_id); TORRENT_ASSERT(m_state >= state_t::read_peer_id);
boost::shared_ptr<torrent> t = associated_torrent().lock(); boost::shared_ptr<torrent> t = associated_torrent().lock();
TORRENT_ASSERT(t); TORRENT_ASSERT(t);
@ -2575,7 +2564,7 @@ namespace libtorrent
// m_state is set to read_pe_dhkey in initial state // m_state is set to read_pe_dhkey in initial state
// (read_protocol_identifier) for incoming, or in constructor // (read_protocol_identifier) for incoming, or in constructor
// for outgoing // for outgoing
if (m_state == read_pe_dhkey) if (m_state == state_t::read_pe_dhkey)
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
@ -2609,7 +2598,7 @@ namespace libtorrent
if (is_outgoing()) if (is_outgoing())
{ {
m_state = read_pe_syncvc; m_state = state_t::read_pe_syncvc;
write_pe3_sync(); write_pe3_sync();
// initial payload is the standard handshake, this is // initial payload is the standard handshake, this is
@ -2626,7 +2615,7 @@ namespace libtorrent
else else
{ {
// already written dh key // already written dh key
m_state = read_pe_synchash; m_state = state_t::read_pe_synchash;
// synchash,skeyhash,vc,crypto_provide,len(pad),pad,encrypt(handshake) // synchash,skeyhash,vc,crypto_provide,len(pad),pad,encrypt(handshake)
m_recv_buffer.reset(20+20+8+4+2+0+handshake_len); m_recv_buffer.reset(20+20+8+4+2+0+handshake_len);
} }
@ -2635,7 +2624,7 @@ namespace libtorrent
} }
// cannot fall through into // cannot fall through into
if (m_state == read_pe_synchash) if (m_state == state_t::read_pe_synchash)
{ {
TORRENT_ASSERT(!m_encrypted); TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted); TORRENT_ASSERT(!m_rc4_encrypted);
@ -2702,7 +2691,7 @@ namespace libtorrent
, "sync point (hash) found at offset %d" , "sync point (hash) found at offset %d"
, int(m_sync_bytes_read + bytes_processed - 20)); , int(m_sync_bytes_read + bytes_processed - 20));
#endif #endif
m_state = read_pe_skey_vc; m_state = state_t::read_pe_skey_vc;
// skey,vc - 28 bytes // skey,vc - 28 bytes
m_sync_hash.reset(); m_sync_hash.reset();
int transferred_used = int(bytes_processed - int(recv_buffer.size()) + bytes_transferred); int transferred_used = int(bytes_processed - int(recv_buffer.size()) + bytes_transferred);
@ -2713,7 +2702,7 @@ namespace libtorrent
} }
} }
if (m_state == read_pe_skey_vc) if (m_state == state_t::read_pe_skey_vc)
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
bytes_transferred = 0; bytes_transferred = 0;
@ -2773,12 +2762,12 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "ENCRYPTION", "verification constant found"); peer_log(peer_log_alert::info, "ENCRYPTION", "verification constant found");
#endif #endif
m_state = read_pe_cryptofield; m_state = state_t::read_pe_cryptofield;
m_recv_buffer.reset(4 + 2); m_recv_buffer.reset(4 + 2);
} }
// cannot fall through into // cannot fall through into
if (m_state == read_pe_syncvc) if (m_state == state_t::read_pe_syncvc)
{ {
TORRENT_ASSERT(is_outgoing()); TORRENT_ASSERT(is_outgoing());
TORRENT_ASSERT(!m_encrypted); TORRENT_ASSERT(!m_encrypted);
@ -2849,12 +2838,12 @@ namespace libtorrent
// delete verification constant // delete verification constant
m_sync_vc.reset(); m_sync_vc.reset();
m_state = read_pe_cryptofield; m_state = state_t::read_pe_cryptofield;
// fall through // fall through
} }
} }
if (m_state == read_pe_cryptofield) // local/remote if (m_state == state_t::read_pe_cryptofield) // local/remote
{ {
TORRENT_ASSERT(!m_encrypted); TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted); TORRENT_ASSERT(!m_rc4_encrypted);
@ -2942,7 +2931,7 @@ namespace libtorrent
return; return;
} }
m_state = read_pe_pad; m_state = state_t::read_pe_pad;
if (!is_outgoing()) if (!is_outgoing())
m_recv_buffer.reset(len_pad + 2); // len(IA) at the end of pad m_recv_buffer.reset(len_pad + 2); // len(IA) at the end of pad
else else
@ -2955,14 +2944,14 @@ namespace libtorrent
switch_send_crypto(m_rc4); switch_send_crypto(m_rc4);
switch_recv_crypto(m_rc4); switch_recv_crypto(m_rc4);
} }
m_state = init_bt_handshake; m_state = state_t::init_bt_handshake;
} }
else else
m_recv_buffer.reset(len_pad); m_recv_buffer.reset(len_pad);
} }
} }
if (m_state == read_pe_pad) if (m_state == state_t::read_pe_pad)
{ {
TORRENT_ASSERT(!m_encrypted); TORRENT_ASSERT(!m_encrypted);
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
@ -3001,11 +2990,11 @@ namespace libtorrent
switch_send_crypto(m_rc4); switch_send_crypto(m_rc4);
switch_recv_crypto(m_rc4); switch_recv_crypto(m_rc4);
} }
m_state = init_bt_handshake; m_state = state_t::init_bt_handshake;
} }
else else
{ {
m_state = read_pe_ia; m_state = state_t::read_pe_ia;
m_recv_buffer.reset(len_ia); m_recv_buffer.reset(len_ia);
} }
} }
@ -3018,11 +3007,11 @@ namespace libtorrent
switch_send_crypto(m_rc4); switch_send_crypto(m_rc4);
switch_recv_crypto(m_rc4); switch_recv_crypto(m_rc4);
} }
m_state = init_bt_handshake; m_state = state_t::init_bt_handshake;
} }
} }
if (m_state == read_pe_ia) if (m_state == state_t::read_pe_ia)
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
bytes_transferred = 0; bytes_transferred = 0;
@ -3051,11 +3040,11 @@ namespace libtorrent
} }
m_rc4.reset(); m_rc4.reset();
m_state = read_protocol_identifier; m_state = state_t::read_protocol_identifier;
m_recv_buffer.cut(0, 20); m_recv_buffer.cut(0, 20);
} }
if (m_state == init_bt_handshake) if (m_state == state_t::init_bt_handshake)
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
bytes_transferred = 0; bytes_transferred = 0;
@ -3076,7 +3065,7 @@ namespace libtorrent
m_rc4.reset(); m_rc4.reset();
// payload stream, start with 20 handshake bytes // payload stream, start with 20 handshake bytes
m_state = read_protocol_identifier; m_state = state_t::read_protocol_identifier;
m_recv_buffer.reset(20); m_recv_buffer.reset(20);
// encrypted portion of handshake completed, toggle // encrypted portion of handshake completed, toggle
@ -3094,7 +3083,7 @@ namespace libtorrent
#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
if (m_state == read_protocol_identifier) if (m_state == state_t::read_protocol_identifier)
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
bytes_transferred = 0; bytes_transferred = 0;
@ -3148,7 +3137,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "ENCRYPTION", "attempting encrypted connection"); peer_log(peer_log_alert::info, "ENCRYPTION", "attempting encrypted connection");
#endif #endif
m_state = read_pe_dhkey; m_state = state_t::read_pe_dhkey;
m_recv_buffer.cut(0, dh_key_len); m_recv_buffer.cut(0, dh_key_len);
TORRENT_ASSERT(!m_recv_buffer.packet_finished()); TORRENT_ASSERT(!m_recv_buffer.packet_finished());
return; return;
@ -3160,7 +3149,7 @@ namespace libtorrent
else else
{ {
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
TORRENT_ASSERT(m_state != read_pe_dhkey); TORRENT_ASSERT(m_state != state_t::read_pe_dhkey);
if (!is_outgoing() if (!is_outgoing()
&& m_settings.get_int(settings_pack::in_enc_policy) && m_settings.get_int(settings_pack::in_enc_policy)
@ -3178,12 +3167,12 @@ namespace libtorrent
#endif #endif
} }
m_state = read_info_hash; m_state = state_t::read_info_hash;
m_recv_buffer.reset(28); m_recv_buffer.reset(28);
} }
// fall through // fall through
if (m_state == read_info_hash) if (m_state == state_t::read_info_hash)
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
bytes_transferred = 0; bytes_transferred = 0;
@ -3264,12 +3253,12 @@ namespace libtorrent
if (is_disconnecting()) return; if (is_disconnecting()) return;
m_state = read_peer_id; m_state = state_t::read_peer_id;
m_recv_buffer.reset(20); m_recv_buffer.reset(20);
} }
// fall through // fall through
if (m_state == read_peer_id) if (m_state == state_t::read_peer_id)
{ {
TORRENT_ASSERT(m_sent_handshake); TORRENT_ASSERT(m_sent_handshake);
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
@ -3410,7 +3399,7 @@ namespace libtorrent
} }
} }
m_state = read_packet_size; m_state = state_t::read_packet_size;
m_recv_buffer.reset(5); m_recv_buffer.reset(5);
TORRENT_ASSERT(!m_recv_buffer.packet_finished()); TORRENT_ASSERT(!m_recv_buffer.packet_finished());
@ -3418,7 +3407,7 @@ namespace libtorrent
} }
// cannot fall through into // cannot fall through into
if (m_state == read_packet_size) if (m_state == state_t::read_packet_size)
{ {
// Make sure this is not fallen though into // Make sure this is not fallen though into
TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin()); TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin());
@ -3457,20 +3446,20 @@ namespace libtorrent
incoming_keepalive(); incoming_keepalive();
if (is_disconnecting()) return; if (is_disconnecting()) return;
// keepalive message // keepalive message
m_state = read_packet_size; m_state = state_t::read_packet_size;
m_recv_buffer.cut(4, 5); m_recv_buffer.cut(4, 5);
return; return;
} }
if (int(recv_buffer.size()) < 5) return; if (int(recv_buffer.size()) < 5) return;
m_state = read_packet; m_state = state_t::read_packet;
m_recv_buffer.cut(4, packet_size); m_recv_buffer.cut(4, packet_size);
recv_buffer = m_recv_buffer.get(); recv_buffer = m_recv_buffer.get();
TORRENT_ASSERT(int(recv_buffer.size()) == 1); TORRENT_ASSERT(int(recv_buffer.size()) == 1);
TORRENT_ASSERT(bytes_transferred == 1); TORRENT_ASSERT(bytes_transferred == 1);
} }
if (m_state == read_packet) if (m_state == state_t::read_packet)
{ {
TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin()); TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin());
TORRENT_ASSERT(recv_buffer.size() == m_recv_buffer.get().size()); TORRENT_ASSERT(recv_buffer.size() == m_recv_buffer.get().size());
@ -3486,7 +3475,7 @@ namespace libtorrent
#endif #endif
if (dispatch_message(int(bytes_transferred))) if (dispatch_message(int(bytes_transferred)))
{ {
m_state = read_packet_size; m_state = state_t::read_packet_size;
m_recv_buffer.reset(5); m_recv_buffer.reset(5);
} }
@ -3587,7 +3576,7 @@ namespace libtorrent
boost::shared_ptr<torrent> t = associated_torrent().lock(); boost::shared_ptr<torrent> t = associated_torrent().lock();
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
TORRENT_ASSERT( (bool(m_state != read_pe_dhkey) || m_dh_key_exchange.get()) TORRENT_ASSERT( (bool(m_state != state_t::read_pe_dhkey) || m_dh_key_exchange.get())
|| !is_outgoing()); || !is_outgoing());
TORRENT_ASSERT(!m_rc4_encrypted || (!m_encrypted && m_rc4) TORRENT_ASSERT(!m_rc4_encrypted || (!m_encrypted && m_rc4)

View File

@ -110,7 +110,6 @@ namespace libtorrent
} }
#endif #endif
// outbound connection
peer_connection::peer_connection(peer_connection_args const& pack) peer_connection::peer_connection(peer_connection_args const& pack)
: peer_connection_hot_members(pack.tor, *pack.ses, *pack.sett) : peer_connection_hot_members(pack.tor, *pack.ses, *pack.sett)
, m_socket(pack.s) , m_socket(pack.s)
@ -123,42 +122,6 @@ namespace libtorrent
, m_allocator(*pack.allocator) , m_allocator(*pack.allocator)
, m_ios(*pack.ios) , m_ios(*pack.ios)
, m_work(m_ios) , m_work(m_ios)
, m_last_piece(aux::time_now())
, m_last_request(aux::time_now())
, m_last_incoming_request(min_time())
, m_last_unchoke(aux::time_now())
, m_last_unchoked(aux::time_now())
, m_last_choke(min_time())
, m_last_receive(aux::time_now())
, m_last_sent(aux::time_now())
, m_last_sent_payload(aux::time_now())
, m_requested(min_time())
, m_remote_dl_update(aux::time_now())
, m_connect(aux::time_now())
, m_became_uninterested(aux::time_now())
, m_became_uninteresting(aux::time_now())
, m_downloaded_at_last_round(0)
, m_uploaded_at_last_round(0)
, m_uploaded_at_last_unchoke(0)
, m_downloaded_last_second(0)
, m_uploaded_last_second(0)
, m_outstanding_bytes(0)
, m_last_seen_complete(0)
, m_receiving_block(piece_block::invalid)
, m_extension_outstanding_bytes(0)
, m_queued_time_critical(0)
, m_reading_bytes(0)
, m_picker_options(0)
, m_num_invalid_requests(0)
, m_remote_pieces_dled(0)
, m_remote_dl_rate(0)
, m_outstanding_writing_bytes(0)
, m_download_rate_peak(0)
, m_upload_rate_peak(0)
, m_send_barrier(INT_MAX)
, m_desired_queue_size(4)
, m_prefer_contiguous_blocks(0)
, m_disk_read_failures(0)
, m_outstanding_piece_verification(0) , m_outstanding_piece_verification(0)
, m_outgoing(!pack.tor.expired()) , m_outgoing(!pack.tor.expired())
, m_received_listen_port(false) , m_received_listen_port(false)
@ -178,15 +141,6 @@ namespace libtorrent
, m_has_metadata(true) , m_has_metadata(true)
, m_exceeded_limit(false) , m_exceeded_limit(false)
, m_slow_start(true) , m_slow_start(true)
#if TORRENT_USE_ASSERTS
, m_in_constructor(true)
, m_disconnect_started(false)
, m_initialized(false)
, m_in_use(1337)
, m_received_in_piece(0)
, m_destructed(false)
, m_socket_is_writing(false)
#endif
{ {
m_counters.inc_stats_counter(counters::num_tcp_peers + m_socket->type() - 1); m_counters.inc_stats_counter(counters::num_tcp_peers + m_socket->type() - 1);
@ -195,8 +149,6 @@ namespace libtorrent
else if (m_connecting) else if (m_connecting)
m_counters.inc_stats_counter(counters::num_peers_half_open); m_counters.inc_stats_counter(counters::num_peers_half_open);
m_superseed_piece[0] = -1;
m_superseed_piece[1] = -1;
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
// if t is nullptr, we better not be connecting, since // if t is nullptr, we better not be connecting, since
// we can't decrement the connecting counter // we can't decrement the connecting counter
@ -5866,12 +5818,13 @@ namespace libtorrent
disconnect(ec, op_sock_read); disconnect(ec, op_sock_read);
return; return;
} }
else
{
account_received_bytes(bytes); account_received_bytes(bytes);
bytes_transferred += bytes; bytes_transferred += bytes;
} }
} }
}
// feed bytes in receive buffer to upper layer by calling on_receive() // feed bytes in receive buffer to upper layer by calling on_receive()

View File

@ -305,26 +305,15 @@ namespace aux {
#endif #endif
session_impl::session_impl(io_service& ios) session_impl::session_impl(io_service& ios)
: : m_io_service(ios)
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
m_send_buffers(send_buffer_size())
,
#endif
m_io_service(ios)
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
, m_ssl_ctx(m_io_service, boost::asio::ssl::context::sslv23) , m_ssl_ctx(m_io_service, boost::asio::ssl::context::sslv23)
#endif #endif
, m_alerts(m_settings.get_int(settings_pack::alert_queue_size), alert::all_categories) , m_alerts(m_settings.get_int(settings_pack::alert_queue_size), alert::all_categories)
#ifndef TORRENT_NO_DEPRECATE
, m_alert_pointer_pos(0)
#endif
, m_disk_thread(m_io_service, m_stats_counters , m_disk_thread(m_io_service, m_stats_counters
, static_cast<uncork_interface*>(this)) , static_cast<uncork_interface*>(this))
, m_download_rate(peer_connection::download_channel) , m_download_rate(peer_connection::download_channel)
, m_upload_rate(peer_connection::upload_channel) , m_upload_rate(peer_connection::upload_channel)
, m_global_class(0)
, m_tcp_peer_class(0)
, m_local_peer_class(0)
, m_tracker_manager( , m_tracker_manager(
std::bind(&session_impl::send_udp_packet, this, false, _1, _2, _3, _4) std::bind(&session_impl::send_udp_packet, this, false, _1, _2, _3, _4)
, std::bind(&session_impl::send_udp_packet_hostname, this, _1, _2, _3, _4, _5) , std::bind(&session_impl::send_udp_packet_hostname, this, _1, _2, _3, _4, _5)
@ -336,31 +325,16 @@ namespace aux {
#endif #endif
) )
, m_work(io_service::work(m_io_service)) , m_work(io_service::work(m_io_service))
, m_max_queue_pos(-1)
, m_key(0)
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
, m_i2p_conn(m_io_service) , m_i2p_conn(m_io_service)
#endif #endif
, m_socks_listen_port(0)
, m_interface_index(0)
, m_unchoke_time_scaler(0)
, m_auto_manage_time_scaler(0)
, m_optimistic_unchoke_time_scaler(0)
, m_disconnect_time_scaler(90)
, m_auto_scrape_time_scaler(180)
, m_peak_up_rate(0)
, m_peak_down_rate(0)
, m_created(clock_type::now()) , m_created(clock_type::now())
, m_last_tick(m_created) , m_last_tick(m_created)
, m_last_second_tick(m_created - milliseconds(900)) , m_last_second_tick(m_created - milliseconds(900))
, m_last_choke(m_created) , m_last_choke(m_created)
, m_last_auto_manage(m_created) , m_last_auto_manage(m_created)
, m_next_port(0)
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
, m_dht_storage_constructor(dht::dht_default_storage_constructor)
, m_dht_announce_timer(m_io_service) , m_dht_announce_timer(m_io_service)
, m_dht_interval_update_torrents(0)
, m_outstanding_router_lookups(0)
#endif #endif
, m_utp_socket_manager( , m_utp_socket_manager(
std::bind(&session_impl::send_udp_packet, this, false, _1, _2, _3, _4) std::bind(&session_impl::send_udp_packet, this, false, _1, _2, _3, _4)
@ -375,25 +349,10 @@ namespace aux {
, m_settings, m_stats_counters , m_settings, m_stats_counters
, &m_ssl_ctx) , &m_ssl_ctx)
#endif #endif
, m_boost_connections(0)
, m_timer(m_io_service) , m_timer(m_io_service)
, m_lsd_announce_timer(m_io_service) , m_lsd_announce_timer(m_io_service)
, m_host_resolver(m_io_service) , m_host_resolver(m_io_service)
, m_next_downloading_connect_torrent(0)
, m_next_finished_connect_torrent(0)
, m_download_connect_attempts(0)
, m_next_scrape_torrent(0)
, m_tick_residual(0)
, m_deferred_submit_disk_jobs(false)
, m_pending_auto_manage(false)
, m_need_auto_manage(false)
, m_abort(false)
, m_paused(false)
{ {
#if TORRENT_USE_ASSERTS
m_posting_torrent_updates = false;
#endif
update_time_now(); update_time_now();
} }
@ -447,9 +406,6 @@ namespace aux {
m_peer_class_type_filter.add(peer_class_type_filter::ssl_tcp_socket, m_tcp_peer_class); m_peer_class_type_filter.add(peer_class_type_filter::ssl_tcp_socket, m_tcp_peer_class);
m_peer_class_type_filter.add(peer_class_type_filter::i2p_socket, m_tcp_peer_class); m_peer_class_type_filter.add(peer_class_type_filter::i2p_socket, m_tcp_peer_class);
// TODO: there's no rule here to make uTP connections not have the global or
// local rate limits apply to it. This used to be the default.
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
session_log("config: %s version: %s revision: %s" session_log("config: %s version: %s revision: %s"
@ -471,7 +427,6 @@ namespace aux {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
session_log(" max connections: %d", m_settings.get_int(settings_pack::connections_limit)); session_log(" max connections: %d", m_settings.get_int(settings_pack::connections_limit));
session_log(" max files: %d", max_files); session_log(" max files: %d", max_files);
session_log(" generated peer ID: %s", m_peer_id.to_string().c_str()); session_log(" generated peer ID: %s", m_peer_id.to_string().c_str());
#endif #endif

View File

@ -183,8 +183,6 @@ namespace libtorrent
, add_torrent_params const& p , add_torrent_params const& p
, sha1_hash const& info_hash) , sha1_hash const& info_hash)
: torrent_hot_members(ses, p, block_size, session_paused) : torrent_hot_members(ses, p, block_size, session_paused)
, m_total_uploaded(0)
, m_total_downloaded(0)
, m_tracker_timer(ses.get_io_service()) , m_tracker_timer(ses.get_io_service())
, m_inactivity_timer(ses.get_io_service()) , m_inactivity_timer(ses.get_io_service())
, m_trackerid(p.trackerid) , m_trackerid(p.trackerid)
@ -197,27 +195,11 @@ namespace libtorrent
, m_stats_counters(ses.stats_counters()) , m_stats_counters(ses.stats_counters())
, m_storage_constructor(p.storage) , m_storage_constructor(p.storage)
, m_added_time(time(nullptr)) , m_added_time(time(nullptr))
, m_completed_time(0)
, m_last_seen_complete(0)
, m_swarm_last_seen_complete(0)
, m_info_hash(info_hash) , m_info_hash(info_hash)
, m_num_verified(0)
, m_last_saved_resume(ses.session_time()) , m_last_saved_resume(ses.session_time())
, m_started(ses.session_time()) , m_started(ses.session_time())
, m_became_seed(0)
, m_became_finished(0)
, m_checking_piece(0)
, m_num_checked_pieces(0)
, m_refcount(0)
, m_error_file(torrent_status::error_file_none) , m_error_file(torrent_status::error_file_none)
, m_average_piece_time(0)
, m_piece_time_deviation(0)
, m_total_failed_bytes(0)
, m_total_redundant_bytes(0)
, m_sequence_number(seq) , m_sequence_number(seq)
, m_peer_class(0)
, m_num_connecting(0)
, m_upload_mode_time(0)
, m_announce_to_trackers((p.flags & add_torrent_params::flag_paused) == 0) , m_announce_to_trackers((p.flags & add_torrent_params::flag_paused) == 0)
, m_announce_to_lsd((p.flags & add_torrent_params::flag_paused) == 0) , m_announce_to_lsd((p.flags & add_torrent_params::flag_paused) == 0)
, m_has_incoming(false) , m_has_incoming(false)
@ -226,7 +208,6 @@ namespace libtorrent
, m_announcing(false) , m_announcing(false)
, m_waiting_tracker(false) , m_waiting_tracker(false)
, m_active_time(0) , m_active_time(0)
, m_last_working_tracker(-1)
, m_finished_time(0) , m_finished_time(0)
, m_sequential_download(false) , m_sequential_download(false)
, m_auto_sequential(false) , m_auto_sequential(false)
@ -254,20 +235,12 @@ namespace libtorrent
, m_deleted(false) , m_deleted(false)
, m_pinned((p.flags & add_torrent_params::flag_pinned) != 0) , m_pinned((p.flags & add_torrent_params::flag_pinned) != 0)
, m_should_be_loaded(true) , m_should_be_loaded(true)
, m_last_download((std::numeric_limits<std::int16_t>::min)())
, m_num_seeds(0)
, m_last_upload((std::numeric_limits<std::int16_t>::min)())
, m_auto_managed((p.flags & add_torrent_params::flag_auto_managed) != 0) , m_auto_managed((p.flags & add_torrent_params::flag_auto_managed) != 0)
, m_current_gauge_state(no_gauge_state) , m_current_gauge_state(no_gauge_state)
, m_moving_storage(false) , m_moving_storage(false)
, m_inactive(false) , m_inactive(false)
, m_downloaded(0xffffff) , m_downloaded(0xffffff)
, m_last_scrape((std::numeric_limits<std::int16_t>::min)())
, m_progress_ppm(0) , m_progress_ppm(0)
#if TORRENT_USE_ASSERTS
, m_was_started(false)
, m_outstanding_check_files(false)
#endif
{ {
// we cannot log in the constructor, because it relies on shared_from_this // we cannot log in the constructor, because it relies on shared_from_this
// being initialized, which happens after the constructor returns. // being initialized, which happens after the constructor returns.