*** empty log message ***

This commit is contained in:
Magnus Jonsson 2004-01-25 04:18:08 +00:00
parent bb36fa8e24
commit 0634e778e9
8 changed files with 63 additions and 36 deletions

View File

@ -123,7 +123,7 @@ namespace libtorrent
struct checker_impl: boost::noncopyable struct checker_impl: boost::noncopyable
{ {
checker_impl(session_impl* s): m_ses(s), m_abort(false) {} checker_impl(session_impl* s): m_ses(s), m_abort(false) { assert(s); }
void operator()(); void operator()();
piece_checker_data* find_torrent(const sha1_hash& info_hash); piece_checker_data* find_torrent(const sha1_hash& info_hash);
@ -208,7 +208,7 @@ namespace libtorrent
void purge_connections(); void purge_connections();
#ifndef NDEBUG #ifndef NDEBUG
void assert_invariant(int marker = -1); void assert_invariant(const char *place);
boost::shared_ptr<logger> create_log(std::string name); boost::shared_ptr<logger> create_log(std::string name);
boost::shared_ptr<logger> m_logger; boost::shared_ptr<logger> m_logger;
#endif #endif

View File

@ -80,9 +80,9 @@ namespace libtorrent
bool operator<(const address& a) const bool operator<(const address& a) const
{ if (ip() == a.ip()) return port() < a.port(); else return ip() < a.ip(); } { if (ip() == a.ip()) return port() < a.port(); else return ip() < a.ip(); }
bool operator!=(const address& a) const bool operator!=(const address& a) const
{ return (ip() != a.ip()) || port() != a.port(); } { return ip() != a.ip() || port() != a.port(); }
bool operator==(const address& a) const bool operator==(const address& a) const
{ return (ip() == a.ip()) && port() == a.port(); } { return ip() == a.ip() && port() == a.port(); }
private: private:

View File

@ -104,17 +104,17 @@ namespace libtorrent
void second_tick(); void second_tick();
// only counts the payload data! // only counts the payload data!
float upload_rate() const { return m_mean_upload_per_second; } float upload_rate() const { assert(m_mean_upload_per_second>=0.0f); return m_mean_upload_per_second; }
float download_rate() const { return m_mean_download_per_second; } float download_rate() const { assert(m_mean_download_per_second>=0.0f); return m_mean_download_per_second; }
float down_peak() const { return m_peak_downloaded_per_second; } float down_peak() const { return m_peak_downloaded_per_second; }
float up_peak() const { return m_peak_uploaded_per_second; } float up_peak() const { return m_peak_uploaded_per_second; }
size_type total_payload_upload() const { return m_total_upload_payload; } size_type total_payload_upload() const { assert(m_total_upload_payload>=0); return m_total_upload_payload; }
size_type total_payload_download() const { return m_total_download_payload; } size_type total_payload_download() const { assert(m_total_download_payload>=0); return m_total_download_payload; }
size_type total_protocol_upload() const { return m_total_upload_protocol; } size_type total_protocol_upload() const { assert(m_total_upload_protocol>=0); return m_total_upload_protocol; }
size_type total_protocol_download() const { return m_total_download_protocol; } size_type total_protocol_download() const { assert(m_total_download_protocol>=0); return m_total_download_protocol; }
private: private:

View File

@ -119,15 +119,15 @@ namespace libtorrent
const torrent_info& torrent_file() const const torrent_info& torrent_file() const
{ return m_torrent_file; } { return m_torrent_file; }
policy& get_policy() { return *m_policy; } policy& get_policy() { assert(m_policy); return *m_policy; }
piece_manager& filesystem() { return m_storage; } piece_manager& filesystem() { return m_storage; }
void set_ratio(float ratio) void set_ratio(float ratio)
{ m_ratio = ratio; } { assert(ratio>=0.0f); m_ratio = ratio; }
float ratio() const float ratio() const
{ return m_ratio; } { assert(m_ratio>=0.0f); return m_ratio; }
// -------------------------------------------- // --------------------------------------------
// PEER MANAGEMENT // PEER MANAGEMENT
@ -187,8 +187,9 @@ namespace libtorrent
// PIECE MANAGEMENT // PIECE MANAGEMENT
// returns true if we have downloaded the given piece // returns true if we have downloaded the given piece
bool have_piece(unsigned int index) const bool have_piece(int index) const
{ return m_have_pieces[index]; } { assert(index>=0 && (unsigned)index<m_have_pieces.size());
return m_have_pieces[index]; }
const std::vector<bool>& pieces() const const std::vector<bool>& pieces() const
{ return m_have_pieces; } { return m_have_pieces; }
@ -196,13 +197,14 @@ namespace libtorrent
// when we get a have- or bitfield- messages, this is called for every // when we get a have- or bitfield- messages, this is called for every
// piece a peer has gained. // piece a peer has gained.
void peer_has(int index) void peer_has(int index)
{ m_picker.inc_refcount(index); } { assert(index>=0 && (unsigned)index<m_have_pieces.size());
m_picker.inc_refcount(index); }
// when peer disconnects, this is called for every piece it had // when peer disconnects, this is called for every piece it had
void peer_lost(int index) void peer_lost(int index)
{ m_picker.dec_refcount(index); } { m_picker.dec_refcount(index); }
int block_size() const { return m_block_size; } int block_size() const { assert(m_block_size>0); return m_block_size; }
// this will tell all peers that we just got his piece // this will tell all peers that we just got his piece
// and also let the piece picker know that we have this piece // and also let the piece picker know that we have this piece
@ -231,7 +233,7 @@ namespace libtorrent
void set_priority(float p) void set_priority(float p)
{ {
assert(p >= 0.f && p <= 0.f); assert(p >= 0.f && p <= 1.f);
m_priority = p; m_priority = p;
} }

View File

@ -116,9 +116,10 @@ namespace
{ {
using namespace libtorrent; using namespace libtorrent;
assert(upload_limit > 0 || upload_limit==-1);
if (connections.empty()) return; if (connections.empty()) return;
assert(upload_limit != 0);
if (upload_limit == -1) if (upload_limit == -1)
{ {
@ -169,7 +170,7 @@ namespace
// Sum all peer_connections' quota limit to get the total quota limit. // Sum all peer_connections' quota limit to get the total quota limit.
int sum_total_of_quota_limits=0; int sum_total_of_quota_limits=0;
for(int i=0;i<peer_info.size();i++) for(int i=0;(unsigned)i<peer_info.size();i++)
{ {
int quota_limit=peer_info[i].quota_limit; int quota_limit=peer_info[i].quota_limit;
if(quota_limit==-1) if(quota_limit==-1)
@ -197,7 +198,7 @@ namespace
{ {
assert(quota_left_to_distribute>0); assert(quota_left_to_distribute>0);
for(int i=0;i<peer_info.size();i++) for(int i=0;(unsigned)i<peer_info.size();i++)
{ {
// Traverse the peer list from slowest connection to fastest. // Traverse the peer list from slowest connection to fastest.
@ -223,7 +224,7 @@ namespace
// Finally, inform the peers of how much quota they get. // Finally, inform the peers of how much quota they get.
for(int i=0;i<peer_info.size();i++) for(int i=0;(unsigned)i<peer_info.size();i++)
peer_info[i].p->set_send_quota(peer_info[i].allocated_quota); peer_info[i].p->set_send_quota(peer_info[i].allocated_quota);
} }
@ -349,6 +350,7 @@ namespace libtorrent
, m_upload_rate(-1) , m_upload_rate(-1)
, m_incoming_connection(false) , m_incoming_connection(false)
{ {
assert(listen_port>0);
// ---- generate a peer id ---- // ---- generate a peer id ----
@ -431,7 +433,7 @@ namespace libtorrent
{ {
#ifndef NDEBUG #ifndef NDEBUG
assert_invariant(0); assert_invariant("loops_per_second++");
loops_per_second++; loops_per_second++;
#endif #endif
@ -472,7 +474,7 @@ namespace libtorrent
} }
#ifndef NDEBUG #ifndef NDEBUG
assert_invariant(); assert_invariant("before SEND SOCKETS");
#endif #endif
// ************************ // ************************
@ -520,7 +522,7 @@ namespace libtorrent
purge_connections(); purge_connections();
#ifndef NDEBUG #ifndef NDEBUG
assert_invariant(); assert_invariant("after SEND SOCKETS");
#endif #endif
// ************************ // ************************
// RECEIVE SOCKETS // RECEIVE SOCKETS
@ -584,7 +586,7 @@ namespace libtorrent
} }
purge_connections(); purge_connections();
#ifndef NDEBUG #ifndef NDEBUG
assert_invariant(); assert_invariant("after RECEIVE SOCKETS");
#endif #endif
// ************************ // ************************
@ -616,7 +618,7 @@ namespace libtorrent
} }
#ifndef NDEBUG #ifndef NDEBUG
assert_invariant(); assert_invariant("after ERROR SOCKETS");
#endif #endif
boost::posix_time::time_duration d = boost::posix_time::second_clock::local_time() - timer; boost::posix_time::time_duration d = boost::posix_time::second_clock::local_time() - timer;
@ -744,10 +746,10 @@ namespace libtorrent
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
void session_impl::assert_invariant(int marker) void session_impl::assert_invariant(const char *place)
{ {
static int place = 0; assert(place);
if (marker != -1) place = 0;
for (connection_map::iterator i = m_connections.begin(); for (connection_map::iterator i = m_connections.begin();
i != m_connections.end(); i != m_connections.end();
++i) ++i)
@ -772,7 +774,6 @@ namespace libtorrent
->get_policy().has_connection(boost::get_pointer(i->second))); ->get_policy().has_connection(boost::get_pointer(i->second)));
} }
} }
place++;
} }
#endif #endif
@ -985,7 +986,7 @@ namespace libtorrent
// read piece map // read piece map
const entry::list_type& slots = rd.dict()["slots"].list(); const entry::list_type& slots = rd.dict()["slots"].list();
if (slots.size() > info.num_pieces()) if ((int)slots.size() > info.num_pieces())
return; return;
std::vector<int> tmp_pieces; std::vector<int> tmp_pieces;

View File

@ -67,7 +67,10 @@ namespace {
lazy_hash(const char* data_, std::size_t size_) lazy_hash(const char* data_, std::size_t size_)
: data(data_) : data(data_)
, size(size_) , size(size_)
{} {
assert(data_);
assert(size_>0);
}
const libtorrent::sha1_hash& get() const const libtorrent::sha1_hash& get() const
{ {
@ -156,7 +159,7 @@ namespace libtorrent
{ {
thread_safe_storage(std::size_t n) thread_safe_storage(std::size_t n)
: slots(n, false) : slots(n, false)
{} { assert(n>=0); }
boost::mutex mutex; boost::mutex mutex;
boost::condition condition; boost::condition condition;
@ -169,6 +172,7 @@ namespace libtorrent
: storage_(s) : storage_(s)
, slot(slot_) , slot(slot_)
{ {
assert(slot_>=0 && (unsigned)slot_ < s.slots.size());
boost::mutex::scoped_lock lock(storage_.mutex); boost::mutex::scoped_lock lock(storage_.mutex);
while (storage_.slots[slot]) while (storage_.slots[slot])
@ -221,6 +225,8 @@ namespace libtorrent
, size_type offset , size_type offset
, size_type size) , size_type size)
{ {
assert(buf);
assert(slot >= 0 && slot < m_pimpl->info.num_pieces());
assert(offset >= 0); assert(offset >= 0);
assert(offset < m_pimpl->info.piece_size(slot)); assert(offset < m_pimpl->info.piece_size(slot));
assert(size > 0); assert(size > 0);
@ -310,6 +316,9 @@ namespace libtorrent
void storage::write(const char* buf, int slot, size_type offset, size_type size) void storage::write(const char* buf, int slot, size_type offset, size_type size)
{ {
assert(buf);
assert(slot >= 0 && slot < m_pimpl->info.num_pieces());
assert(offset >= 0);
assert(size > 0); assert(size > 0);
slot_lock lock(*m_pimpl, slot); slot_lock lock(*m_pimpl, slot);
@ -600,6 +609,9 @@ namespace libtorrent
, int block_size , int block_size
, const std::bitset<256>& bitmask) , const std::bitset<256>& bitmask)
{ {
assert(slot_index >= 0 && slot_index < m_info.num_pieces());
assert(block_size>0);
adler32_crc crc; adler32_crc crc;
std::vector<char> buf(block_size); std::vector<char> buf(block_size);
int num_blocks = m_info.piece_size(slot_index) / block_size; int num_blocks = m_info.piece_size(slot_index) / block_size;

View File

@ -97,7 +97,7 @@ namespace
/* /*
struct find_peer_by_id struct find_peer_by_id
{ {
find_peer_by_id(const peer_id& i, const torrent* t): id(i), tor(t) {} find_peer_by_id(const peer_id& i, const torrent* t): id(i), tor(t) { assert(t); }
bool operator()(const detail::session_impl::connection_map::value_type& c) const bool operator()(const detail::session_impl::connection_map::value_type& c) const
{ {
@ -115,7 +115,7 @@ namespace
*/ */
struct find_peer_by_ip struct find_peer_by_ip
{ {
find_peer_by_ip(const address& a, const torrent* t): ip(a), tor(t) {} find_peer_by_ip(const address& a, const torrent* t): ip(a), tor(t) { assert(t); }
bool operator()(const detail::session_impl::connection_map::value_type& c) const bool operator()(const detail::session_impl::connection_map::value_type& c) const
{ {
@ -192,6 +192,8 @@ namespace libtorrent
std::string escape_string(const char* str, int len) std::string escape_string(const char* str, int len)
{ {
assert(str);
assert(len>=0);
// http://www.ietf.org/rfc/rfc2396.txt // http://www.ietf.org/rfc/rfc2396.txt
// section 2.3 // section 2.3
static const char unreserved_chars[] = "-_.!~*'()"; static const char unreserved_chars[] = "-_.!~*'()";
@ -255,6 +257,7 @@ namespace libtorrent
std::vector<peer_entry>& peer_list std::vector<peer_entry>& peer_list
, int interval) , int interval)
{ {
assert(interval>0);
m_last_working_tracker m_last_working_tracker
= m_torrent_file.prioritize_tracker(m_currently_trying_tracker); = m_torrent_file.prioritize_tracker(m_currently_trying_tracker);
m_next_request = boost::posix_time::second_clock::local_time() m_next_request = boost::posix_time::second_clock::local_time()
@ -391,6 +394,7 @@ namespace libtorrent
void torrent::piece_failed(int index) void torrent::piece_failed(int index)
{ {
assert(index >= 0 && index < m_torrent_file.num_pieces());
if (m_ses.m_alerts.should_post(alert::info)) if (m_ses.m_alerts.should_post(alert::info))
{ {
std::stringstream s; std::stringstream s;
@ -436,6 +440,7 @@ namespace libtorrent
void torrent::announce_piece(int index) void torrent::announce_piece(int index)
{ {
assert(index >= 0 && index < m_torrent_file.num_pieces());
std::vector<address> downloaders; std::vector<address> downloaders;
m_picker.get_downloaders(downloaders, index); m_picker.get_downloaders(downloaders, index);
@ -457,6 +462,8 @@ namespace libtorrent
tracker_request torrent::generate_tracker_request(int port) tracker_request torrent::generate_tracker_request(int port)
{ {
assert(port>0);
assert((unsigned short)port == port);
m_duration = 1800; m_duration = 1800;
m_next_request = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(m_duration); m_next_request = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(m_duration);
@ -474,6 +481,7 @@ namespace libtorrent
void torrent::remove_peer(peer_connection* p) void torrent::remove_peer(peer_connection* p)
{ {
assert(p);
peer_iterator i = m_connections.find(p->get_socket()->sender()); peer_iterator i = m_connections.find(p->get_socket()->sender());
assert(i != m_connections.end()); assert(i != m_connections.end());
@ -544,6 +552,7 @@ namespace libtorrent
void torrent::attach_peer(peer_connection* p) void torrent::attach_peer(peer_connection* p)
{ {
assert(p);
assert(m_connections.find(p->get_socket()->sender()) == m_connections.end()); assert(m_connections.find(p->get_socket()->sender()) == m_connections.end());
assert(!p->is_local()); assert(!p->is_local());
@ -670,6 +679,7 @@ namespace libtorrent
bool torrent::verify_piece(int piece_index) bool torrent::verify_piece(int piece_index)
{ {
assert(piece_index >= 0 && piece_index < m_torrent_file.num_pieces());
size_type size = m_torrent_file.piece_size(piece_index); size_type size = m_torrent_file.piece_size(piece_index);
std::vector<char> buffer(size); std::vector<char> buffer(size);
assert(size > 0); assert(size > 0);

View File

@ -65,6 +65,7 @@ namespace libtorrent
void torrent_handle::set_max_uploads(int max_uploads) void torrent_handle::set_max_uploads(int max_uploads)
{ {
assert(max_uploads>=2 || max_uploads==-1);
if (m_ses == 0) throw invalid_handle(); if (m_ses == 0) throw invalid_handle();
{ {
@ -94,6 +95,7 @@ namespace libtorrent
void torrent_handle::set_max_connections(int max_connections) void torrent_handle::set_max_connections(int max_connections)
{ {
assert(max_connections>=2 || max_connections==-1);
if (m_ses == 0) throw invalid_handle(); if (m_ses == 0) throw invalid_handle();
{ {