fix warnings

This commit is contained in:
Arvid Norberg 2015-05-19 03:13:49 +00:00
parent d18495eb39
commit 607e708bc4
19 changed files with 97 additions and 81 deletions

View File

@ -188,10 +188,6 @@ namespace libtorrent
void set_load_function(user_load_function_t fun) void set_load_function(user_load_function_t fun)
{ m_user_load_torrent = fun; } { m_user_load_torrent = fun; }
void queue_async_resume_data(boost::shared_ptr<torrent> const& t);
void done_async_resume();
void async_resume_dispatched(int num_popped_resume);
void init_peer_class_filter(bool unlimited_local); void init_peer_class_filter(bool unlimited_local);
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
@ -213,7 +209,7 @@ namespace libtorrent
void open_listen_port(); void open_listen_port();
void init_settings(); void init_settings();
torrent_peer_allocator_interface* get_peer_allocator() { return &m_peer_allocator; } torrent_peer_allocator_interface* get_peer_allocator() { return &m_peer_allocator; }
io_service& get_io_service() { return m_io_service; } io_service& get_io_service() { return m_io_service; }
@ -247,7 +243,7 @@ namespace libtorrent
, error_code const& e); , error_code const& e);
void incoming_connection(boost::shared_ptr<socket_type> const& s); void incoming_connection(boost::shared_ptr<socket_type> const& s);
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
feed_handle add_feed(feed_settings const& feed); feed_handle add_feed(feed_settings const& feed);
void remove_feed(feed_handle h); void remove_feed(feed_handle h);
@ -283,7 +279,7 @@ namespace libtorrent
void apply_settings_pack(settings_pack* pack); void apply_settings_pack(settings_pack* pack);
session_settings const& settings() const { return m_settings; } session_settings const& settings() const { return m_settings; }
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
dht::dht_tracker* dht() { return m_dht.get(); } dht::dht_tracker* dht() { return m_dht.get(); }
bool announce_dht() const { return !m_listen_sockets.empty(); } bool announce_dht() const { return !m_listen_sockets.empty(); }
@ -355,7 +351,7 @@ namespace libtorrent
void set_ip_filter(boost::shared_ptr<ip_filter> const& f); void set_ip_filter(boost::shared_ptr<ip_filter> const& f);
ip_filter const& get_ip_filter(); ip_filter const& get_ip_filter();
void set_port_filter(port_filter const& f); void set_port_filter(port_filter const& f);
port_filter const& get_port_filter() const TORRENT_OVERRIDE; port_filter const& get_port_filter() const TORRENT_OVERRIDE;
void ban_ip(address addr) TORRENT_OVERRIDE; void ban_ip(address addr) TORRENT_OVERRIDE;
@ -373,13 +369,13 @@ namespace libtorrent
int copy_pertinent_channels(peer_class_set const& set int copy_pertinent_channels(peer_class_set const& set
, int channel, bandwidth_channel** dst, int max); , int channel, bandwidth_channel** dst, int max);
int use_quota_overhead(peer_class_set& set, int amount_down, int amount_up); int use_quota_overhead(peer_class_set& set, int amount_down, int amount_up);
bool use_quota_overhead(bandwidth_channel* ch, int channel, int amount); bool use_quota_overhead(bandwidth_channel* ch, int amount);
int create_peer_class(char const* name); int create_peer_class(char const* name);
void delete_peer_class(int cid); void delete_peer_class(int cid);
void set_peer_class_filter(ip_filter const& f); void set_peer_class_filter(ip_filter const& f);
ip_filter const& get_peer_class_filter() const; ip_filter const& get_peer_class_filter() const;
void set_peer_class_type_filter(peer_class_type_filter f); void set_peer_class_type_filter(peer_class_type_filter f);
peer_class_type_filter get_peer_class_type_filter(); peer_class_type_filter get_peer_class_type_filter();
@ -411,7 +407,7 @@ namespace libtorrent
void post_dht_stats(); void post_dht_stats();
std::vector<torrent_handle> get_torrents() const; std::vector<torrent_handle> get_torrents() const;
void pop_alerts(std::vector<alert*>* alerts); void pop_alerts(std::vector<alert*>* alerts);
alert* wait_for_alert(time_duration max_wait); alert* wait_for_alert(time_duration max_wait);
@ -474,12 +470,12 @@ namespace libtorrent
address listen_address() const; address listen_address() const;
boost::uint16_t listen_port() const; boost::uint16_t listen_port() const;
boost::uint16_t ssl_listen_port() const; boost::uint16_t ssl_listen_port() const;
alert_manager& alerts() { return m_alerts; } alert_manager& alerts() { return m_alerts; }
disk_interface& disk_thread() { return m_disk_thread; } disk_interface& disk_thread() { return m_disk_thread; }
void abort(); void abort();
torrent_handle find_torrent_handle(sha1_hash const& info_hash); torrent_handle find_torrent_handle(sha1_hash const& info_hash);
void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false); void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false);
@ -556,7 +552,7 @@ namespace libtorrent
char* async_allocate_disk_buffer(char const* category char* async_allocate_disk_buffer(char const* category
, boost::function<void(char*)> const& handler); , boost::function<void(char*)> const& handler);
void reclaim_block(block_cache_reference ref); void reclaim_block(block_cache_reference ref);
bool exceeded_cache_use() const bool exceeded_cache_use() const
{ return m_disk_thread.exceeded_cache_use(); } { return m_disk_thread.exceeded_cache_use(); }
@ -643,7 +639,7 @@ namespace libtorrent
void update_peer_fingerprint(); void update_peer_fingerprint();
void on_trigger_auto_manage(); void on_trigger_auto_manage();
void update_socket_buffer_size(); void update_socket_buffer_size();
void update_dht_announce_interval(); void update_dht_announce_interval();
void update_anonymous_mode(); void update_anonymous_mode();
@ -756,7 +752,7 @@ namespace libtorrent
// shouldn't. Each torrent that's loaded is part of this // shouldn't. Each torrent that's loaded is part of this
// list. // list.
linked_list m_torrent_lru; linked_list m_torrent_lru;
std::map<std::string, boost::shared_ptr<torrent> > m_uuids; std::map<std::string, boost::shared_ptr<torrent> > m_uuids;
// when saving resume data for many torrents, torrents are // when saving resume data for many torrents, torrents are
@ -793,7 +789,7 @@ namespace libtorrent
// the session, all of these are disconnected, otherwise // the session, all of these are disconnected, otherwise
// they would linger and stall or hang session shutdown // they would linger and stall or hang session shutdown
std::set<boost::shared_ptr<socket_type> > m_incoming_sockets; std::set<boost::shared_ptr<socket_type> > m_incoming_sockets;
// maps IP ranges to bitfields representing peer class IDs // maps IP ranges to bitfields representing peer class IDs
// to assign peers matching a specific IP range based on its // to assign peers matching a specific IP range based on its
// remote endpoint // remote endpoint
@ -807,7 +803,7 @@ namespace libtorrent
// filters outgoing connections // filters outgoing connections
port_filter m_port_filter; port_filter m_port_filter;
// the peer id that is generated at the start of the session // the peer id that is generated at the start of the session
peer_id m_peer_id; peer_id m_peer_id;
@ -851,7 +847,7 @@ namespace libtorrent
// on this machine // on this machine
tcp::endpoint m_ipv6_interface; tcp::endpoint m_ipv6_interface;
tcp::endpoint m_ipv4_interface; tcp::endpoint m_ipv4_interface;
// since we might be listening on multiple interfaces // since we might be listening on multiple interfaces
// we might need more than one listen socket // we might need more than one listen socket
std::list<listen_socket_t> m_listen_sockets; std::list<listen_socket_t> m_listen_sockets;
@ -885,7 +881,7 @@ namespace libtorrent
listen_socket_t setup_listener(std::string const& device listen_socket_t setup_listener(std::string const& device
, bool ipv4, int port, int& retries, int flags, error_code& ec); , bool ipv4, int port, int& retries, int flags, error_code& ec);
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
entry m_dht_state; entry m_dht_state;
#endif #endif
@ -990,7 +986,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
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;
// 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
std::list<udp::endpoint> m_dht_router_nodes; std::list<udp::endpoint> m_dht_router_nodes;
@ -1131,6 +1127,12 @@ namespace libtorrent
private: private:
// TODO: 2 the throttling of saving resume data could probably be
// factored out into a separate class
void queue_async_resume_data(boost::shared_ptr<torrent> const& t);
void done_async_resume();
void async_resume_dispatched();
// state for keeping track of external IPs // state for keeping track of external IPs
external_ip m_external_ip; external_ip m_external_ip;
@ -1146,14 +1148,14 @@ 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;
// 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;
// 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,

View File

@ -276,7 +276,7 @@ namespace libtorrent { namespace aux
virtual void trancieve_ip_packet(int bytes, bool ipv6) = 0; virtual void trancieve_ip_packet(int bytes, bool ipv6) = 0;
virtual void sent_syn(bool ipv6) = 0; virtual void sent_syn(bool ipv6) = 0;
virtual void received_synack(bool ipv6) = 0; virtual void received_synack(bool ipv6) = 0;
virtual int peak_up_rate() const = 0; virtual int peak_up_rate() const = 0;
enum torrent_list_index enum torrent_list_index
@ -316,7 +316,7 @@ namespace libtorrent { namespace aux
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
virtual boost::asio::ssl::context* ssl_ctx() = 0 ; virtual boost::asio::ssl::context* ssl_ctx() = 0 ;
#endif #endif
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
virtual torrent const* find_encrypted_torrent( virtual torrent const* find_encrypted_torrent(
sha1_hash const& info_hash, sha1_hash const& xor_mask) = 0; sha1_hash const& info_hash, sha1_hash const& xor_mask) = 0;

View File

@ -223,7 +223,7 @@ namespace libtorrent
// the number of dirty blocks in this piece // the number of dirty blocks in this piece
boost::uint64_t num_dirty:14; boost::uint64_t num_dirty:14;
// the number of blocks in the cache for this piece // the number of blocks in the cache for this piece
boost::uint64_t num_blocks:14; boost::uint64_t num_blocks:14;
@ -430,7 +430,7 @@ namespace libtorrent
// associates the job with it. When the block is // associates the job with it. When the block is
// flushed, the callback is posted // flushed, the callback is posted
cached_piece_entry* add_dirty_block(disk_io_job* j); cached_piece_entry* add_dirty_block(disk_io_job* j);
enum { blocks_inc_refcount = 1 }; enum { blocks_inc_refcount = 1 };
void insert_blocks(cached_piece_entry* pe, int block, file::iovec_t *iov void insert_blocks(cached_piece_entry* pe, int block, file::iovec_t *iov
, int iov_len, disk_io_job* j, int flags = 0); , int iov_len, disk_io_job* j, int flags = 0);
@ -438,7 +438,7 @@ namespace libtorrent
#if TORRENT_USE_INVARIANT_CHECKS #if TORRENT_USE_INVARIANT_CHECKS
void check_invariant() const; void check_invariant() const;
#endif #endif
// try to remove num number of read cache blocks from the cache // try to remove num number of read cache blocks from the cache
// pick the least recently used ones first // pick the least recently used ones first
// return the number of blocks that was requested to be evicted // return the number of blocks that was requested to be evicted

View File

@ -133,9 +133,8 @@ namespace libtorrent {
TORRENT_ASSERT(m_size > 1); TORRENT_ASSERT(m_size > 1);
uintptr_t* ptr = m_storage; uintptr_t* ptr = m_storage;
header_t* hdr = reinterpret_cast<header_t*>(ptr); TORRENT_ASSERT(reinterpret_cast<header_t*>(ptr)->len <= m_size);
ptr += header_size; ptr += header_size;
TORRENT_ASSERT(hdr->len <= m_size);
return reinterpret_cast<T*>(ptr); return reinterpret_cast<T*>(ptr);
} }

View File

@ -59,6 +59,7 @@ namespace libtorrent
list_node* m_current; list_node* m_current;
}; };
// TOOD: 3 move the code into a .cpp file and add a unit test for linked_list
struct linked_list struct linked_list
{ {
linked_list(): m_first(0), m_last(0), m_size(0) {} linked_list(): m_first(0), m_last(0), m_size(0) {}
@ -68,7 +69,7 @@ namespace libtorrent
void erase(list_node* e) void erase(list_node* e)
{ {
#ifdef TORRENT_DEBUG #if TORRENT_USE_ASSERTS
list_node* tmp = m_first; list_node* tmp = m_first;
bool found = false; bool found = false;
while (tmp) while (tmp)

View File

@ -62,7 +62,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/asio/read.hpp> #include <boost/asio/read.hpp>
#endif #endif
#ifdef __OBJC__ #ifdef __OBJC__
#undef Protocol #undef Protocol
#endif #endif
@ -110,7 +110,7 @@ namespace libtorrent
}; };
#endif #endif
#endif #endif
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
#ifndef IPV6_PROTECTION_LEVEL #ifndef IPV6_PROTECTION_LEVEL

View File

@ -71,7 +71,7 @@ POSSIBILITY OF SUCH DAMAGE.
accessor, the piece is promoted into LRU2. which holds pieces that are accessor, the piece is promoted into LRU2. which holds pieces that are
more frequently used, and more important to keep around as this LRU list more frequently used, and more important to keep around as this LRU list
takes churn. takes churn.
read_lru1_ghost read_lru1_ghost
This is a list of pieces that were least recently evicted from read_lru1. This is a list of pieces that were least recently evicted from read_lru1.
These pieces don't hold any actual blocks in the cache, they are just These pieces don't hold any actual blocks in the cache, they are just
@ -1240,6 +1240,7 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, file::iovec_t
if (flags & blocks_inc_refcount) if (flags & blocks_inc_refcount)
{ {
bool ret = inc_block_refcount(pe, block, ref_reading); bool ret = inc_block_refcount(pe, block, ref_reading);
TORRENT_UNUSED(ret); // suppress warning
TORRENT_ASSERT(ret); TORRENT_ASSERT(ret);
} }
else else
@ -1710,7 +1711,7 @@ int block_cache::copy_from_piece(cached_piece_entry* pe, disk_io_job* j
TORRENT_PIECE_ASSERT(size <= block_size(), pe); TORRENT_PIECE_ASSERT(size <= block_size(), pe);
const int start_block = block; const int start_block = block;
#ifdef TORRENT_DEBUG #if TORRENT_USE_ASSERTS
int piece_size = j->storage->files()->piece_size(j->piece); int piece_size = j->storage->files()->piece_size(j->piece);
int blocks_in_piece = (piece_size + block_size() - 1) / block_size(); int blocks_in_piece = (piece_size + block_size() - 1) / block_size();
TORRENT_PIECE_ASSERT(start_block < blocks_in_piece, pe); TORRENT_PIECE_ASSERT(start_block < blocks_in_piece, pe);
@ -1810,6 +1811,7 @@ bool block_cache::maybe_free_piece(cached_piece_entry* pe)
tailqueue jobs; tailqueue jobs;
bool removed = evict_piece(pe, jobs); bool removed = evict_piece(pe, jobs);
TORRENT_UNUSED(removed); // suppress warning
TORRENT_PIECE_ASSERT(removed, pe); TORRENT_PIECE_ASSERT(removed, pe);
TORRENT_PIECE_ASSERT(jobs.empty(), pe); TORRENT_PIECE_ASSERT(jobs.empty(), pe);

View File

@ -586,10 +586,13 @@ namespace libtorrent
#endif #endif
} }
void bt_peer_connection::write_pe_vc_cryptofield(char* write_buf, int len void bt_peer_connection::write_pe_vc_cryptofield(char* write_buf, int len
, int crypto_field, int pad_size) , int crypto_field, int pad_size)
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
#if !TORRENT_USE_ASSERTS
TORRENT_UNUSED(len);
#endif
TORRENT_ASSERT(crypto_field <= 0x03 && crypto_field > 0); TORRENT_ASSERT(crypto_field <= 0x03 && crypto_field > 0);
// vc,crypto_field,len(pad),pad, (len(ia)) // vc,crypto_field,len(pad),pad, (len(ia))
@ -599,7 +602,7 @@ namespace libtorrent
// encrypt(vc, crypto_provide/select, len(Pad), len(IA)) // encrypt(vc, crypto_provide/select, len(Pad), len(IA))
// len(pad) is zero for now, len(IA) only for outgoing connections // len(pad) is zero for now, len(IA) only for outgoing connections
// vc // vc
memset(write_buf, 0, 8); memset(write_buf, 0, 8);
write_buf += 8; write_buf += 8;
@ -614,14 +617,14 @@ namespace libtorrent
// append len(ia) if we are initiating // append len(ia) if we are initiating
if (is_outgoing()) if (is_outgoing())
detail::write_uint16(handshake_len, write_buf); // len(IA) detail::write_uint16(handshake_len, write_buf); // len(IA)
} }
void bt_peer_connection::init_pe_rc4_handler(char const* secret, sha1_hash const& stream_key) void bt_peer_connection::init_pe_rc4_handler(char const* secret, sha1_hash const& stream_key)
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
TORRENT_ASSERT(secret); TORRENT_ASSERT(secret);
hasher h; hasher h;
static const char keyA[] = "keyA"; static const char keyA[] = "keyA";
static const char keyB[] = "keyB"; static const char keyB[] = "keyB";
@ -629,7 +632,7 @@ namespace libtorrent
// encryption rc4 longkeys // encryption rc4 longkeys
// outgoing connection : hash ('keyA',S,SKEY) // outgoing connection : hash ('keyA',S,SKEY)
// incoming connection : hash ('keyB',S,SKEY) // incoming connection : hash ('keyB',S,SKEY)
if (is_outgoing()) h.update(keyA, 4); else h.update(keyB, 4); if (is_outgoing()) h.update(keyA, 4); else h.update(keyB, 4);
h.update(secret, dh_key_len); h.update(secret, dh_key_len);
h.update((char const*)stream_key.begin(), 20); h.update((char const*)stream_key.begin(), 20);
@ -640,12 +643,12 @@ namespace libtorrent
// decryption rc4 longkeys // decryption rc4 longkeys
// outgoing connection : hash ('keyB',S,SKEY) // outgoing connection : hash ('keyB',S,SKEY)
// incoming connection : hash ('keyA',S,SKEY) // incoming connection : hash ('keyA',S,SKEY)
if (is_outgoing()) h.update(keyB, 4); else h.update(keyA, 4); if (is_outgoing()) h.update(keyB, 4); else h.update(keyA, 4);
h.update(secret, dh_key_len); h.update(secret, dh_key_len);
h.update((char const*)stream_key.begin(), 20); h.update((char const*)stream_key.begin(), 20);
const sha1_hash remote_key = h.final(); const sha1_hash remote_key = h.final();
TORRENT_ASSERT(!m_rc4.get()); TORRENT_ASSERT(!m_rc4.get());
m_rc4 = boost::make_shared<rc4_handler>(); m_rc4 = boost::make_shared<rc4_handler>();
@ -1953,14 +1956,15 @@ namespace libtorrent
TORRENT_ASSERT(m_message_handler[packet_type] != 0); TORRENT_ASSERT(m_message_handler[packet_type] != 0);
#ifdef TORRENT_DEBUG #if TORRENT_USE_ASSERTS
boost::int64_t cur_payload_dl = statistics().last_payload_downloaded(); boost::int64_t cur_payload_dl = statistics().last_payload_downloaded();
boost::int64_t cur_protocol_dl = statistics().last_protocol_downloaded(); boost::int64_t cur_protocol_dl = statistics().last_protocol_downloaded();
#endif #endif
// call the correct handler for this packet type // call the correct handler for this packet type
(this->*m_message_handler[packet_type])(received); (this->*m_message_handler[packet_type])(received);
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
TORRENT_ASSERT(statistics().last_payload_downloaded() - cur_payload_dl >= 0); TORRENT_ASSERT(statistics().last_payload_downloaded() - cur_payload_dl >= 0);
TORRENT_ASSERT(statistics().last_protocol_downloaded() - cur_protocol_dl >= 0); TORRENT_ASSERT(statistics().last_protocol_downloaded() - cur_protocol_dl >= 0);
boost::int64_t stats_diff = statistics().last_payload_downloaded() - cur_payload_dl + boost::int64_t stats_diff = statistics().last_payload_downloaded() - cur_payload_dl +
@ -1993,7 +1997,7 @@ namespace libtorrent
void bt_peer_connection::write_upload_only() void bt_peer_connection::write_upload_only()
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
boost::shared_ptr<torrent> t = associated_torrent().lock(); boost::shared_ptr<torrent> t = associated_torrent().lock();
if (m_upload_only_id == 0) return; if (m_upload_only_id == 0) return;
if (t->share_mode()) return; if (t->share_mode()) return;
@ -3521,7 +3525,7 @@ namespace libtorrent
disconnect(errors::torrent_removed, op_bittorrent, 1); disconnect(errors::torrent_removed, op_bittorrent, 1);
return; return;
} }
#ifdef TORRENT_DEBUG #if TORRENT_USE_ASSERTS
boost::int64_t cur_payload_dl = statistics().last_payload_downloaded(); boost::int64_t cur_payload_dl = statistics().last_payload_downloaded();
boost::int64_t cur_protocol_dl = statistics().last_protocol_downloaded(); boost::int64_t cur_protocol_dl = statistics().last_protocol_downloaded();
#endif #endif
@ -3530,14 +3534,15 @@ namespace libtorrent
m_state = read_packet_size; m_state = read_packet_size;
m_recv_buffer.reset(5); m_recv_buffer.reset(5);
} }
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
TORRENT_ASSERT(statistics().last_payload_downloaded() - cur_payload_dl >= 0); TORRENT_ASSERT(statistics().last_payload_downloaded() - cur_payload_dl >= 0);
TORRENT_ASSERT(statistics().last_protocol_downloaded() - cur_protocol_dl >= 0); TORRENT_ASSERT(statistics().last_protocol_downloaded() - cur_protocol_dl >= 0);
boost::int64_t stats_diff = statistics().last_payload_downloaded() - cur_payload_dl + boost::int64_t stats_diff = statistics().last_payload_downloaded() - cur_payload_dl +
statistics().last_protocol_downloaded() - cur_protocol_dl; statistics().last_protocol_downloaded() - cur_protocol_dl;
TORRENT_ASSERT(stats_diff == boost::int64_t(bytes_transferred)); TORRENT_ASSERT(stats_diff == boost::int64_t(bytes_transferred));
#endif
TORRENT_ASSERT(!m_recv_buffer.packet_finished()); TORRENT_ASSERT(!m_recv_buffer.packet_finished());
#endif
return; return;
} }

View File

@ -580,6 +580,8 @@ namespace libtorrent
// it should always suceed, since it's a dirty block, and // it should always suceed, since it's a dirty block, and
// should never have been marked as volatile // should never have been marked as volatile
TORRENT_ASSERT(locked); TORRENT_ASSERT(locked);
TORRENT_ASSERT(pe->cache_state != cached_piece_entry::volatile_read_lru);
TORRENT_UNUSED(locked);
flushing[num_flushing++] = i + block_base_index; flushing[num_flushing++] = i + block_base_index;
iov[iov_len].iov_base = pe->blocks[i].buf; iov[iov_len].iov_base = pe->blocks[i].buf;
@ -1315,7 +1317,11 @@ namespace libtorrent
TORRENT_ASSERT(pe->blocks[block].buf); TORRENT_ASSERT(pe->blocks[block].buf);
int tmp = m_disk_cache.try_read(j, true); int tmp = m_disk_cache.try_read(j, true);
// This should always succeed because we just checked to see there is a
// buffer for this block
TORRENT_ASSERT(tmp >= 0); TORRENT_ASSERT(tmp >= 0);
TORRENT_UNUSED(tmp);
maybe_issue_queued_read_jobs(pe, completed_jobs); maybe_issue_queued_read_jobs(pe, completed_jobs);
@ -1679,9 +1685,7 @@ namespace libtorrent
if (m_settings.get_int(settings_pack::cache_size) > 0 if (m_settings.get_int(settings_pack::cache_size) > 0
&& m_settings.get_bool(settings_pack::use_write_cache)) && m_settings.get_bool(settings_pack::use_write_cache))
{ {
int block_size = m_disk_cache.block_size(); TORRENT_ASSERT((r.start % m_disk_cache.block_size()) == 0);
TORRENT_ASSERT((r.start % block_size) == 0);
if (storage->is_blocked(j)) if (storage->is_blocked(j))
{ {
@ -2103,6 +2107,7 @@ namespace libtorrent
tailqueue jobs; tailqueue jobs;
bool ok = m_disk_cache.evict_piece(pe, jobs); bool ok = m_disk_cache.evict_piece(pe, jobs);
TORRENT_PIECE_ASSERT(ok, pe); TORRENT_PIECE_ASSERT(ok, pe);
TORRENT_UNUSED(ok);
fail_jobs(storage_error(boost::asio::error::operation_aborted), jobs); fail_jobs(storage_error(boost::asio::error::operation_aborted), jobs);
} }

View File

@ -46,6 +46,10 @@ namespace libtorrent
, utp_socket_manager* sm , utp_socket_manager* sm
, bool peer_connection) , bool peer_connection)
{ {
#ifndef TORRENT_USE_OPENSSL
TORRENT_UNUSED(ssl_context);
#endif
if (sm) if (sm)
{ {
utp_stream* str; utp_stream* str;

View File

@ -81,14 +81,14 @@ namespace libtorrent { namespace
int size = (offset.first + offset.second) * 256 / total_size - start; int size = (offset.first + offset.second) * 256 / total_size - start;
std::pair<int, int> ret(start, size); std::pair<int, int> ret(start, size);
TORRENT_ASSERT(start >= 0); TORRENT_ASSERT(start >= 0);
TORRENT_ASSERT(size > 0); TORRENT_ASSERT(size > 0);
TORRENT_ASSERT(start <= 256); TORRENT_ASSERT(start <= 256);
TORRENT_ASSERT(start + size <= 256); TORRENT_ASSERT(start + size <= 256);
// assert the identity of this function // assert the identity of this function
#ifndef NDEBUG #if TORRENT_USE_ASSERTS
std::pair<int, int> identity = req_to_offset(ret, total_size); std::pair<int, int> identity = req_to_offset(ret, total_size);
TORRENT_ASSERT(offset == identity); TORRENT_ASSERT(offset == identity);
#endif #endif

View File

@ -5789,6 +5789,10 @@ namespace libtorrent
if (free_space > 0) if (free_space > 0)
{ {
char* dst = m_send_buffer.append(buf, free_space); char* dst = m_send_buffer.append(buf, free_space);
// this should always succeed, because we checked how much space
// there was up-front
TORRENT_UNUSED(dst);
TORRENT_ASSERT(dst != 0); TORRENT_ASSERT(dst != 0);
size -= free_space; size -= free_space;
buf += free_space; buf += free_space;

View File

@ -834,7 +834,7 @@ namespace libtorrent
erase_peer(i, state); erase_peer(i, state);
} }
} }
#ifdef TORRENT_DEBUG #if TORRENT_USE_ASSERTS
else else
{ {
#if TORRENT_USE_I2P #if TORRENT_USE_I2P

View File

@ -2354,7 +2354,7 @@ get_out:
= TORRENT_ALLOCA(downloading_piece const*, partials_size); = TORRENT_ALLOCA(downloading_piece const*, partials_size);
int c = 0; int c = 0;
#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS #if TORRENT_USE_ASSERTS && !defined TORRENT_DISABLE_INVARIANT_CHECKS
// if we get here, we're about to pick a busy block. First, make sure // if we get here, we're about to pick a busy block. First, make sure
// we really exhausted the available blocks // we really exhausted the available blocks
for (std::vector<downloading_piece>::const_iterator i for (std::vector<downloading_piece>::const_iterator i
@ -2402,7 +2402,7 @@ get_out:
i != end; ++i) i != end; ++i)
{ {
if (c == partials_size) break; if (c == partials_size) break;
downloading_piece const& dp = *i; downloading_piece const& dp = *i;
TORRENT_ASSERT(dp.requested > 0); TORRENT_ASSERT(dp.requested > 0);
// this peer doesn't have this piece, try again // this peer doesn't have this piece, try again
@ -2895,7 +2895,7 @@ get_out:
if (int(i->finished) + int(i->writing) < max_blocks) return false; if (int(i->finished) + int(i->writing) < max_blocks) return false;
TORRENT_ASSERT(int(i->finished) + int(i->writing) == max_blocks); TORRENT_ASSERT(int(i->finished) + int(i->writing) == max_blocks);
#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS #if TORRENT_USE_ASSERTS && !defined TORRENT_DISABLE_INVARIANT_CHECKS
block_info const* info = blocks_for_piece(*i); block_info const* info = blocks_for_piece(*i);
for (int k = 0; k < max_blocks; ++k) for (int k = 0; k < max_blocks; ++k)
{ {

View File

@ -622,7 +622,7 @@ namespace aux {
// this is called when one or all save resume alerts are // this is called when one or all save resume alerts are
// popped off the alert queue // popped off the alert queue
void session_impl::async_resume_dispatched(int num_popped_resume) void session_impl::async_resume_dispatched()
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
@ -1495,7 +1495,7 @@ namespace aux {
return num_copied; return num_copied;
} }
bool session_impl::use_quota_overhead(bandwidth_channel* ch, int channel, int amount) bool session_impl::use_quota_overhead(bandwidth_channel* ch, int amount)
{ {
ch->use_quota(amount); ch->use_quota(amount);
return (ch->throttle() > 0 && ch->throttle() < amount); return (ch->throttle() > 0 && ch->throttle() < amount);
@ -1509,11 +1509,12 @@ namespace aux {
{ {
peer_class* p = m_classes.at(set.class_at(i)); peer_class* p = m_classes.at(set.class_at(i));
if (p == 0) continue; if (p == 0) continue;
bandwidth_channel* ch = &p->channel[peer_connection::download_channel]; bandwidth_channel* ch = &p->channel[peer_connection::download_channel];
if (use_quota_overhead(ch, peer_connection::download_channel, amount_down)) if (use_quota_overhead(ch, amount_down))
ret |= 1 << peer_connection::download_channel; ret |= 1 << peer_connection::download_channel;
ch = &p->channel[peer_connection::upload_channel]; ch = &p->channel[peer_connection::upload_channel];
if (use_quota_overhead(ch, peer_connection::upload_channel, amount_up)) if (use_quota_overhead(ch, amount_up))
ret |= 1 << peer_connection::upload_channel; ret |= 1 << peer_connection::upload_channel;
} }
return ret; return ret;
@ -6177,7 +6178,7 @@ retry:
// we can only issue more resume data jobs from // we can only issue more resume data jobs from
// the network thread // the network thread
m_io_service.post(boost::bind(&session_impl::async_resume_dispatched m_io_service.post(boost::bind(&session_impl::async_resume_dispatched
, this, num_resume)); , this));
} }
} }

View File

@ -7304,13 +7304,14 @@ namespace libtorrent
pi.piece_index = i->index; pi.piece_index = i->index;
queue->push_back(pi); queue->push_back(pi);
} }
} }
bool torrent::connect_to_peer(torrent_peer* peerinfo, bool ignore_limit) bool torrent::connect_to_peer(torrent_peer* peerinfo, bool ignore_limit)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
TORRENT_UNUSED(ignore_limit);
TORRENT_ASSERT(peerinfo); TORRENT_ASSERT(peerinfo);
TORRENT_ASSERT(peerinfo->connection == 0); TORRENT_ASSERT(peerinfo->connection == 0);
@ -7318,7 +7319,7 @@ namespace libtorrent
if (m_abort) return false; if (m_abort) return false;
peerinfo->last_connected = m_ses.session_time(); peerinfo->last_connected = m_ses.session_time();
#ifdef TORRENT_DEBUG #if TORRENT_USE_ASSERTS
if (!settings().get_bool(settings_pack::allow_multiple_connections_per_ip)) if (!settings().get_bool(settings_pack::allow_multiple_connections_per_ip))
{ {
// this asserts that we don't have duplicates in the peer_list's peer list // this asserts that we don't have duplicates in the peer_list's peer list
@ -7333,7 +7334,7 @@ namespace libtorrent
|| (*i_)->type() != peer_connection::bittorrent_connection); || (*i_)->type() != peer_connection::bittorrent_connection);
#endif #endif
} }
#endif #endif // TORRENT_USE_ASSERTS
TORRENT_ASSERT(want_peers() || ignore_limit); TORRENT_ASSERT(want_peers() || ignore_limit);
TORRENT_ASSERT(m_ses.num_connections() TORRENT_ASSERT(m_ses.num_connections()

View File

@ -501,6 +501,7 @@ namespace libtorrent { namespace
int ret = bdecode(&pex_msg[0], &pex_msg[0] + pex_msg.size(), m, ec); int ret = bdecode(&pex_msg[0], &pex_msg[0] + pex_msg.size(), m, ec);
TORRENT_ASSERT(ret == 0); TORRENT_ASSERT(ret == 0);
TORRENT_ASSERT(!ec); TORRENT_ASSERT(!ec);
TORRENT_UNUSED(ret);
int num_dropped = 0; int num_dropped = 0;
int num_added = 0; int num_added = 0;
bdecode_node e = m.dict_find_string("added"); bdecode_node e = m.dict_find_string("added");

View File

@ -511,7 +511,7 @@ void web_peer_connection::on_receive(error_code const& error
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
#ifdef TORRENT_DEBUG #if TORRENT_USE_ASSERTS
TORRENT_ASSERT(statistics().last_payload_downloaded() TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + bytes_transferred < size_t(INT_MAX)); + statistics().last_protocol_downloaded() + bytes_transferred < size_t(INT_MAX));
int dl_target = statistics().last_payload_downloaded() int dl_target = statistics().last_payload_downloaded()
@ -525,11 +525,9 @@ void web_peer_connection::on_receive(error_code const& error
peer_log(peer_log_alert::info, "ERROR" peer_log(peer_log_alert::info, "ERROR"
, "web_peer_connection error: %s", error.message().c_str()); , "web_peer_connection error: %s", error.message().c_str());
#endif #endif
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded() TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + statistics().last_protocol_downloaded()
== dl_target); == dl_target);
#endif
return; return;
} }
@ -538,11 +536,9 @@ void web_peer_connection::on_receive(error_code const& error
for (;;) for (;;)
{ {
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded() TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + int(bytes_transferred) + statistics().last_protocol_downloaded() + int(bytes_transferred)
== dl_target); == dl_target);
#endif
buffer::const_interval recv_buffer = m_recv_buffer.get(); buffer::const_interval recv_buffer = m_recv_buffer.get();
@ -565,28 +561,24 @@ void web_peer_connection::on_receive(error_code const& error
, "%s", std::string(recv_buffer.begin, recv_buffer.end).c_str()); , "%s", std::string(recv_buffer.begin, recv_buffer.end).c_str());
#endif #endif
disconnect(errors::http_parse_error, op_bittorrent, 2); disconnect(errors::http_parse_error, op_bittorrent, 2);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded() TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + statistics().last_protocol_downloaded()
== dl_target); == dl_target);
#endif
return; return;
} }
TORRENT_ASSERT(recv_buffer.left() == 0 || *recv_buffer.begin == 'H'); TORRENT_ASSERT(recv_buffer.left() == 0 || *recv_buffer.begin == 'H');
TORRENT_ASSERT(recv_buffer.left() <= m_recv_buffer.packet_size()); TORRENT_ASSERT(recv_buffer.left() <= m_recv_buffer.packet_size());
// this means the entire status line hasn't been received yet // this means the entire status line hasn't been received yet
if (m_parser.status_code() == -1) if (m_parser.status_code() == -1)
{ {
TORRENT_ASSERT(payload == 0); TORRENT_ASSERT(payload == 0);
TORRENT_ASSERT(bytes_transferred == 0); TORRENT_ASSERT(bytes_transferred == 0);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded() TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + int(bytes_transferred) + statistics().last_protocol_downloaded() + int(bytes_transferred)
== dl_target); == dl_target);
#endif
break; break;
} }
@ -594,11 +586,9 @@ void web_peer_connection::on_receive(error_code const& error
{ {
TORRENT_ASSERT(payload == 0); TORRENT_ASSERT(payload == 0);
TORRENT_ASSERT(bytes_transferred == 0); TORRENT_ASSERT(bytes_transferred == 0);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded() TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + int(bytes_transferred) + statistics().last_protocol_downloaded() + int(bytes_transferred)
== dl_target); == dl_target);
#endif
break; break;
} }

View File

@ -314,6 +314,7 @@ int test_main()
// test identify_client // test identify_client
// TODO: 3 move testing of identify_client out to its own test
TEST_EQUAL(identify_client(peer_id("-AZ123B-............")), "Azureus 1.2.3.11"); TEST_EQUAL(identify_client(peer_id("-AZ123B-............")), "Azureus 1.2.3.11");
TEST_EQUAL(identify_client(peer_id("-AZ1230-............")), "Azureus 1.2.3"); TEST_EQUAL(identify_client(peer_id("-AZ1230-............")), "Azureus 1.2.3");
TEST_EQUAL(identify_client(peer_id("S123--..............")), "Shadow 1.2.3"); TEST_EQUAL(identify_client(peer_id("S123--..............")), "Shadow 1.2.3");
@ -337,7 +338,7 @@ int test_main()
#endif #endif
TEST_CHECK(is_any(address_v4::any())); TEST_CHECK(is_any(address_v4::any()));
TEST_CHECK(!is_any(address::from_string("31.53.21.64", ec))); TEST_CHECK(!is_any(address::from_string("31.53.21.64", ec)));
TEST_CHECK(match_addr_mask( TEST_CHECK(match_addr_mask(
address::from_string("10.0.1.176", ec), address::from_string("10.0.1.176", ec),
address::from_string("10.0.1.176", ec), address::from_string("10.0.1.176", ec),