*** empty log message ***

This commit is contained in:
Arvid Norberg 2004-01-25 12:37:15 +00:00
parent 0634e778e9
commit 718f01155f
7 changed files with 183 additions and 147 deletions

View File

@ -123,13 +123,13 @@ namespace libtorrent
struct checker_impl: boost::noncopyable
{
checker_impl(session_impl* s): m_ses(s), m_abort(false) { assert(s); }
checker_impl(session_impl& s): m_ses(s), m_abort(false) {}
void operator()();
piece_checker_data* find_torrent(const sha1_hash& info_hash);
// when the files has been checked
// the torrent is added to the session
session_impl* m_ses;
session_impl& m_ses;
boost::mutex m_mutex;
boost::condition m_cond;

View File

@ -80,8 +80,8 @@ namespace libtorrent
void received_bytes(int bytes_payload, int bytes_protocol)
{
assert(bytes_payload>=0);
assert(bytes_protocol>=0);
assert(bytes_payload >= 0);
assert(bytes_protocol >= 0);
m_downloaded_payload += bytes_payload;
m_total_download_payload += bytes_payload;
@ -91,8 +91,8 @@ namespace libtorrent
void sent_bytes(int bytes_payload, int bytes_protocol)
{
assert(bytes_payload>=0);
assert(bytes_protocol>=0);
assert(bytes_payload >= 0);
assert(bytes_protocol >= 0);
m_uploaded_payload += bytes_payload;
m_total_upload_payload += bytes_payload;
@ -104,37 +104,49 @@ namespace libtorrent
void second_tick();
// only counts the payload data!
float upload_rate() const { assert(m_mean_upload_per_second>=0.0f); return m_mean_upload_per_second; }
float download_rate() const { assert(m_mean_download_per_second>=0.0f); return m_mean_download_per_second; }
float upload_rate() const { return m_mean_upload_per_second; }
float download_rate() const { return m_mean_download_per_second; }
float down_peak() const { return m_peak_downloaded_per_second; }
float up_peak() const { return m_peak_uploaded_per_second; }
size_type total_payload_upload() const { assert(m_total_upload_payload>=0); return m_total_upload_payload; }
size_type total_payload_download() const { assert(m_total_download_payload>=0); return m_total_download_payload; }
size_type total_payload_upload() const { return m_total_upload_payload; }
size_type total_payload_download() const { return m_total_download_payload; }
size_type total_protocol_upload() const { assert(m_total_upload_protocol>=0); return m_total_upload_protocol; }
size_type total_protocol_download() const { assert(m_total_download_protocol>=0); return m_total_download_protocol; }
size_type total_protocol_upload() const { return m_total_upload_protocol; }
size_type total_protocol_download() const { return m_total_download_protocol; }
private:
#ifndef NDEBUG
void check_invariant()
{
assert(m_mean_upload_per_second >= 0);
assert(m_mean_download_per_second >= 0);
assert(m_peak_uploaded_per_second >= 0);
assert(m_peak_downloaded_per_second >= 0);
assert(m_total_upload_payload >= 0);
assert(m_total_download_payload >= 0);
assert(m_total_upload_protocol >= 0);
assert(m_total_download_protocol >= 0);
}
#endif
// history of download/upload speeds a few seconds back
unsigned int m_download_per_second_history[history];
unsigned int m_upload_per_second_history[history];
int m_download_per_second_history[history];
int m_upload_per_second_history[history];
// the accumulators we are adding the downloads/upploads
// to this second. This only counts the actual payload
// and ignores the bytes sent as protocol chatter.
unsigned int m_downloaded_payload;
unsigned int m_uploaded_payload;
int m_downloaded_payload;
int m_uploaded_payload;
// the accumulators we are adding the downloads/upploads
// to this second. This only counts the protocol
// chatter and ignores the actual payload
unsigned int m_downloaded_protocol;
unsigned int m_uploaded_protocol;
int m_downloaded_protocol;
int m_uploaded_protocol;
// total download/upload counters
// only counting payload data
@ -147,12 +159,12 @@ namespace libtorrent
size_type m_total_upload_protocol;
// peak mean download/upload rates
unsigned int m_peak_downloaded_per_second;
unsigned int m_peak_uploaded_per_second;
int m_peak_downloaded_per_second;
int m_peak_uploaded_per_second;
// current mean download/upload rates
unsigned int m_mean_download_per_second;
unsigned int m_mean_upload_per_second;
int m_mean_download_per_second;
int m_mean_upload_per_second;
};
}

View File

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

View File

@ -116,7 +116,7 @@ namespace
{
using namespace libtorrent;
assert(upload_limit > 0 || upload_limit==-1);
assert(upload_limit > 0 || upload_limit == -1);
if (connections.empty()) return;
@ -153,9 +153,9 @@ namespace
peer_connection& p = *i->second;
connection_info pi;
pi.p=&p;
pi.allocated_quota=0; // we haven't given it any bandwith yet
pi.quota_limit=p.send_quota_limit();
pi.p = &p;
pi.allocated_quota = 0; // we haven't given it any bandwith yet
pi.quota_limit = p.send_quota_limit();
pi.estimated_upload_capacity=
p.has_data() ? std::max(10,(int)ceil(p.statistics().upload_rate()*1.1f))
@ -170,21 +170,21 @@ namespace
// Sum all peer_connections' quota limit to get the total quota limit.
int sum_total_of_quota_limits=0;
for(int i=0;(unsigned)i<peer_info.size();i++)
for (int i = 0; i < (int)peer_info.size(); ++i)
{
int quota_limit=peer_info[i].quota_limit;
if(quota_limit==-1)
int quota_limit = peer_info[i].quota_limit;
if (quota_limit == -1)
{
// quota_limit=-1 means infinite, so
// sum_total_of_quota_limits will be infinite too...
sum_total_of_quota_limits=std::numeric_limits<int>::max();
sum_total_of_quota_limits = std::numeric_limits<int>::max();
break;
}
sum_total_of_quota_limits+=quota_limit;
sum_total_of_quota_limits += quota_limit;
}
// This is how much total bandwidth that can be distributed.
int quota_left_to_distribute=std::min(upload_limit,sum_total_of_quota_limits);
int quota_left_to_distribute = std::min(upload_limit,sum_total_of_quota_limits);
// Sort w.r.t. channel capacitiy, lowest channel capacity first.
@ -194,37 +194,42 @@ namespace
// Distribute quota until there's nothing more to distribute
while(quota_left_to_distribute!=0)
while (quota_left_to_distribute != 0)
{
assert(quota_left_to_distribute>0);
assert(quota_left_to_distribute > 0);
for(int i=0;(unsigned)i<peer_info.size();i++)
for (int i = 0; i < (int)peer_info.size(); ++i)
{
// Traverse the peer list from slowest connection to fastest.
// In each step, share bandwidth equally between this peer_connection
// and the following faster peer_connections.
//
// Rounds upwards to avoid trying to give 0 bandwidth to someone (may get caught in an endless loop otherwise)
// Rounds upwards to avoid trying to give 0 bandwidth to someone
// (may get caught in an endless loop otherwise)
int num_peers_left_to_share_quota=peer_info.size()-i;
int try_to_give_to_this_peer=(quota_left_to_distribute+num_peers_left_to_share_quota-1)/num_peers_left_to_share_quota;
int num_peers_left_to_share_quota = peer_info.size() - i;
int try_to_give_to_this_peer
= (quota_left_to_distribute + num_peers_left_to_share_quota - 1)
/ num_peers_left_to_share_quota;
// But do not allocate more than the estimated upload capacity.
try_to_give_to_this_peer=std::min(
peer_info[i].estimated_upload_capacity,
try_to_give_to_this_peer);
try_to_give_to_this_peer = std::min(
peer_info[i].estimated_upload_capacity
, try_to_give_to_this_peer);
// Also, when the peer is given quota, it will not accept more than it's quota_limit.
int quota_actually_given_to_peer=peer_info[i].give(try_to_give_to_this_peer);
// Also, when the peer is given quota, it will
// not accept more than it's quota_limit.
int quota_actually_given_to_peer
= peer_info[i].give(try_to_give_to_this_peer);
quota_left_to_distribute-=quota_actually_given_to_peer;
quota_left_to_distribute -= quota_actually_given_to_peer;
}
}
// Finally, inform the peers of how much quota they get.
for(int i=0;(unsigned)i<peer_info.size();i++)
for(int i = 0; i < (int)peer_info.size(); ++i)
peer_info[i].p->set_send_quota(peer_info[i].allocated_quota);
}
@ -295,9 +300,9 @@ namespace libtorrent
boost::mutex::scoped_lock l(m_mutex);
if (!t->abort)
{
boost::mutex::scoped_lock l(m_ses->m_mutex);
boost::mutex::scoped_lock l(m_ses.m_mutex);
m_ses->m_torrents.insert(
m_ses.m_torrents.insert(
std::make_pair(t->info_hash, t->torrent_ptr)).first;
peer_id id;
@ -350,7 +355,7 @@ namespace libtorrent
, m_upload_rate(-1)
, m_incoming_connection(false)
{
assert(listen_port>0);
assert(listen_port > 0);
// ---- generate a peer id ----
@ -779,9 +784,10 @@ namespace libtorrent
}
// TODO: take a port range instead!
session::session(int listen_port, const fingerprint& id)
: m_impl(listen_port, id)
, m_checker_impl(&m_impl)
, m_checker_impl(m_impl)
, m_thread(boost::ref(m_impl))
, m_checker_thread(boost::ref(m_checker_impl))
{
@ -796,7 +802,7 @@ namespace libtorrent
session::session(int listen_port)
: m_impl(listen_port, fingerprint("LT",0,0,1,0))
, m_checker_impl(&m_impl)
, m_checker_impl(m_impl)
, m_thread(boost::ref(m_impl))
, m_checker_thread(boost::ref(m_checker_impl))
{

View File

@ -68,8 +68,8 @@ namespace {
: data(data_)
, size(size_)
{
assert(data_);
assert(size_>0);
assert(data_ != 0);
assert(size_ > 0);
}
const libtorrent::sha1_hash& get() const
@ -159,7 +159,7 @@ namespace libtorrent
{
thread_safe_storage(std::size_t n)
: slots(n, false)
{ assert(n>=0); }
{}
boost::mutex mutex;
boost::condition condition;
@ -172,7 +172,7 @@ namespace libtorrent
: storage_(s)
, slot(slot_)
{
assert(slot_>=0 && (unsigned)slot_ < s.slots.size());
assert(slot_>=0 && slot_ < (int)s.slots.size());
boost::mutex::scoped_lock lock(storage_.mutex);
while (storage_.slots[slot])
@ -316,7 +316,7 @@ namespace libtorrent
void storage::write(const char* buf, int slot, size_type offset, size_type size)
{
assert(buf);
assert(buf != 0);
assert(slot >= 0 && slot < m_pimpl->info.num_pieces());
assert(offset >= 0);
assert(size > 0);
@ -563,7 +563,7 @@ namespace libtorrent
#ifndef NDEBUG
check_invariant();
#endif
assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size());
assert(piece_index >= 0 && piece_index < (int)m_piece_to_slot.size());
assert(m_piece_to_slot[piece_index] >= 0);
int slot_index = m_piece_to_slot[piece_index];
@ -609,8 +609,9 @@ namespace libtorrent
, int block_size
, const std::bitset<256>& bitmask)
{
assert(slot_index >= 0 && slot_index < m_info.num_pieces());
assert(block_size>0);
assert(slot_index >= 0);
assert(slot_index < m_info.num_pieces());
assert(block_size > 0);
adler32_crc crc;
std::vector<char> buf(block_size);
@ -649,10 +650,10 @@ namespace libtorrent
assert(buf);
assert(offset >= 0);
assert(size > 0);
assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size());
assert(m_piece_to_slot[piece_index] >= 0 && (unsigned)m_piece_to_slot[piece_index] < m_slot_to_piece.size());
assert(piece_index >= 0 && piece_index < (int)m_piece_to_slot.size());
assert(m_piece_to_slot[piece_index] >= 0 && m_piece_to_slot[piece_index] < (int)m_slot_to_piece.size());
int slot = m_piece_to_slot[piece_index];
assert(slot >= 0 && (unsigned)slot < m_slot_to_piece.size());
assert(slot >= 0 && slot < (int)m_slot_to_piece.size());
return m_storage.read(buf, slot, offset, size);
}
@ -674,9 +675,9 @@ namespace libtorrent
assert(buf);
assert(offset >= 0);
assert(size > 0);
assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size());
assert(piece_index >= 0 && piece_index < (int)m_piece_to_slot.size());
int slot = allocate_slot_for_piece(piece_index);
assert(slot >= 0 && (unsigned)slot < m_slot_to_piece.size());
assert(slot >= 0 && slot < (int)m_slot_to_piece.size());
m_storage.write(buf, slot, offset, size);
}
@ -689,8 +690,6 @@ namespace libtorrent
m_pimpl->write(buf, piece_index, offset, size);
}
// TODO: must handle the case where some hashes are identical
// correctly
void piece_manager::impl::check_pieces(
boost::mutex& mutex
, detail::piece_checker_data& data
@ -707,8 +706,8 @@ namespace libtorrent
m_allocating = false;
m_piece_to_slot.resize(m_info.num_pieces(), has_no_slot);
m_slot_to_piece.resize(m_info.num_pieces(), unallocated);
m_free_slots.resize(0);
m_unallocated_slots.resize(0);
m_free_slots.clear();
m_unallocated_slots.clear();
const std::size_t piece_size = m_info.piece_length();
const std::size_t last_piece_size = m_info.piece_size(
@ -721,7 +720,7 @@ namespace libtorrent
if (!data.piece_map.empty()
&& data.piece_map.size() <= m_slot_to_piece.size())
{
for (int i = 0; (unsigned)i < data.piece_map.size(); ++i)
for (int i = 0; i < (int)data.piece_map.size(); ++i)
{
m_slot_to_piece[i] = data.piece_map[i];
if (data.piece_map[i] >= 0)
@ -751,7 +750,7 @@ namespace libtorrent
}
}
for (int i = data.piece_map.size(); (unsigned)i < pieces.size(); ++i)
for (int i = data.piece_map.size(); i < (int)pieces.size(); ++i)
{
m_unallocated_slots.push_back(i);
}
@ -766,7 +765,6 @@ namespace libtorrent
// do the real check (we didn't have valid resume data)
bool changed_file = true;
// fs::ifstream in;
file in;
std::vector<char> piece_data(m_info.piece_length());
@ -878,11 +876,11 @@ namespace libtorrent
}
assert(current_slot < m_info.num_pieces());
assert(m_slot_to_piece[current_slot]==unallocated);
assert(m_piece_to_slot[current_slot]==has_no_slot ||
(m_piece_to_slot[current_slot]>=0 &&
m_piece_to_slot[current_slot]<current_slot &&
m_slot_to_piece[m_piece_to_slot[current_slot]]==current_slot));
assert(m_slot_to_piece[current_slot] == unallocated);
assert(m_piece_to_slot[current_slot] == has_no_slot ||
(m_piece_to_slot[current_slot] >= 0 &&
m_piece_to_slot[current_slot] < current_slot &&
m_slot_to_piece[m_piece_to_slot[current_slot]] == current_slot));
// we need to take special actions if this is
// the last piece, since that piece might actually
@ -924,28 +922,28 @@ namespace libtorrent
assert(m_piece_to_slot[found_piece] == current_slot);
m_slot_to_piece[m_piece_to_slot[found_piece]] = unassigned;
m_free_slots.push_back(m_piece_to_slot[found_piece]);
m_piece_to_slot[found_piece]=has_no_slot;
m_piece_to_slot[found_piece] = has_no_slot;
}
assert(m_piece_to_slot[found_piece]==has_no_slot);
assert(m_piece_to_slot[found_piece] == has_no_slot);
m_piece_to_slot[found_piece] = current_slot;
m_slot_to_piece[current_slot] = found_piece;
pieces[found_piece] = true;
}
else
{
assert(found_piece==-1);
assert(found_piece == -1);
m_slot_to_piece[current_slot] = unassigned;
m_free_slots.push_back(current_slot);
}
assert(m_slot_to_piece[current_slot]!=unallocated);
assert(m_slot_to_piece[current_slot] != unallocated);
// done with piece, move on to next
piece_offset = 0;
++current_slot;
if(current_slot==m_info.num_pieces())
if (current_slot == m_info.num_pieces())
{
assert(file_iter == end_iter-1);
break;
@ -954,23 +952,28 @@ namespace libtorrent
}
// dirty "fix" for a bug when file is corrupt
for(int i=0;(unsigned)i<m_info.num_pieces();i++)
for(int i = 0; i < (int)m_info.num_pieces(); ++i)
{
if(m_piece_to_slot[i]!=has_no_slot && m_piece_to_slot[i]!=i && m_slot_to_piece[i]!=unallocated)
if(m_piece_to_slot[i] != has_no_slot
&& m_piece_to_slot[i] != i
&& m_slot_to_piece[i] != unallocated)
{
assert(m_piece_to_slot[i]>=0 && (unsigned)m_piece_to_slot[i]<m_slot_to_piece.size());
assert(m_slot_to_piece[m_piece_to_slot[i]]==i);
assert(m_piece_to_slot[i] >= 0);
assert(m_piece_to_slot[i] < (int)m_slot_to_piece.size());
assert(m_slot_to_piece[m_piece_to_slot[i]] == i);
if(m_slot_to_piece[i]!=unassigned)
{
assert(m_slot_to_piece[i]>=0 && (unsigned)m_slot_to_piece[i]<m_piece_to_slot.size());
assert(m_piece_to_slot[m_slot_to_piece[i]]==i);
m_piece_to_slot[m_slot_to_piece[i]]=has_no_slot;
m_slot_to_piece[i]=unassigned;
assert(m_slot_to_piece[i] >= 0);
assert(m_slot_to_piece[i] < (int)m_piece_to_slot.size());
assert(m_piece_to_slot[m_slot_to_piece[i]] == i);
m_piece_to_slot[m_slot_to_piece[i]] = has_no_slot;
m_slot_to_piece[i] = unassigned;
m_free_slots.push_back(i);
}
m_slot_to_piece[m_piece_to_slot[i]]=unassigned;
m_slot_to_piece[m_piece_to_slot[i]] = unassigned;
m_free_slots.push_back(m_piece_to_slot[i]);
m_piece_to_slot[i]=has_no_slot;
m_piece_to_slot[i] = has_no_slot;
}
}
@ -1016,14 +1019,16 @@ namespace libtorrent
check_invariant();
#endif
assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size());
assert(piece_index >= 0);
assert(piece_index < (int)m_piece_to_slot.size());
assert(m_piece_to_slot.size() == m_slot_to_piece.size());
int slot_index = m_piece_to_slot[piece_index];
if (slot_index != has_no_slot)
{
assert(slot_index >= 0 && (unsigned)slot_index < m_slot_to_piece.size());
assert(slot_index >= 0);
assert(slot_index < (int)m_slot_to_piece.size());
#ifndef NDEBUG
check_invariant();
@ -1117,7 +1122,8 @@ namespace libtorrent
#endif
}
assert(slot_index>=0 && (unsigned)slot_index < m_slot_to_piece.size());
assert(slot_index >= 0);
assert(slot_index < (int)m_slot_to_piece.size());
#ifndef NDEBUG
check_invariant();
@ -1214,33 +1220,39 @@ namespace libtorrent
assert(m_piece_to_slot.size() == m_info.num_pieces());
assert(m_slot_to_piece.size() == m_info.num_pieces());
for(int i=0;(unsigned)i<m_free_slots.size();++i)
for (int i = 0; i < (int)m_free_slots.size(); ++i)
{
unsigned slot=m_free_slots[i];
unsigned slot = m_free_slots[i];
assert(slot<m_slot_to_piece.size());
assert(m_slot_to_piece[slot] == unassigned);
}
for(int i=0;(unsigned)i<m_unallocated_slots.size();++i)
for (int i = 0; i < (int)m_unallocated_slots.size(); ++i)
{
unsigned slot=m_unallocated_slots[i];
assert(slot<m_slot_to_piece.size());
unsigned slot = m_unallocated_slots[i];
assert(slot < m_slot_to_piece.size());
assert(m_slot_to_piece[slot] == unallocated);
}
for (int i = 0; i < m_info.num_pieces(); ++i)
{
// Check domain of piece_to_slot's elements
assert(m_piece_to_slot[i]==has_no_slot
||(m_piece_to_slot[i]>=0 && (unsigned)m_piece_to_slot[i]<m_slot_to_piece.size()));
if (m_piece_to_slot[i] != has_no_slot)
{
assert(m_piece_to_slot[i] >= 0);
assert(m_piece_to_slot[i] < (int)m_slot_to_piece.size());
}
// Check domain of slot_to_piece's elements
assert(m_slot_to_piece[i]==unallocated
|| m_slot_to_piece[i]==unassigned
||(m_slot_to_piece[i]>=0 && (unsigned)m_slot_to_piece[i]<m_piece_to_slot.size()));
if (m_slot_to_piece[i] != unallocated
&& m_slot_to_piece[i] != unassigned)
{
assert(m_slot_to_piece[i] >= 0);
assert(m_slot_to_piece[i] < (int)m_piece_to_slot.size());
}
// do more detailed checks on piece_to_slot
if (m_piece_to_slot[i]>=0)
if (m_piece_to_slot[i] >= 0)
{
assert(m_slot_to_piece[m_piece_to_slot[i]]==i);
if (m_piece_to_slot[i] != i)
@ -1257,8 +1269,8 @@ namespace libtorrent
if (m_slot_to_piece[i]>=0)
{
assert((unsigned)m_slot_to_piece[i]<m_piece_to_slot.size());
assert(m_piece_to_slot[m_slot_to_piece[i]]==i);
assert(m_slot_to_piece[i] < (int)m_piece_to_slot.size());
assert(m_piece_to_slot[m_slot_to_piece[i]] == i);
#ifdef TORRENT_STORAGE_DEBUG
assert(
std::find(

View File

@ -94,28 +94,12 @@ namespace
return default_block_size;
}
/*
struct find_peer_by_id
{
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
{
if (c.second->get_peer_id() != id) return false;
if (tor != c.second->associated_torrent()) return false;
// have a special case for all zeros. We can have any number
// of peers with that id, since it's used to indicate no id.
if (std::count(id.begin(), id.end(), 0) == 20) return false;
return true;
}
const peer_id& id;
const torrent* tor;
};
*/
struct find_peer_by_ip
{
find_peer_by_ip(const address& a, const torrent* t): ip(a), tor(t) { assert(t); }
find_peer_by_ip(const address& a, const torrent* t)
: ip(a)
, tor(t)
{ assert(t != 0); }
bool operator()(const detail::session_impl::connection_map::value_type& c) const
{
@ -192,8 +176,8 @@ namespace libtorrent
std::string escape_string(const char* str, int len)
{
assert(str);
assert(len>=0);
assert(str != 0);
assert(len >= 0);
// http://www.ietf.org/rfc/rfc2396.txt
// section 2.3
static const char unreserved_chars[] = "-_.!~*'()";
@ -257,7 +241,10 @@ namespace libtorrent
std::vector<peer_entry>& peer_list
, int interval)
{
assert(interval>0);
// less than 60 seconds announce intervals
// are insane.
if (interval < 60) interval = 60;
m_last_working_tracker
= m_torrent_file.prioritize_tracker(m_currently_trying_tracker);
m_next_request = boost::posix_time::second_clock::local_time()
@ -394,7 +381,9 @@ namespace libtorrent
void torrent::piece_failed(int index)
{
assert(index >= 0 && index < m_torrent_file.num_pieces());
assert(index >= 0);
assert(index < m_torrent_file.num_pieces());
if (m_ses.m_alerts.should_post(alert::info))
{
std::stringstream s;
@ -440,7 +429,9 @@ namespace libtorrent
void torrent::announce_piece(int index)
{
assert(index >= 0 && index < m_torrent_file.num_pieces());
assert(index >= 0);
assert(index < m_torrent_file.num_pieces());
std::vector<address> downloaders;
m_picker.get_downloaders(downloaders, index);
@ -462,7 +453,7 @@ namespace libtorrent
tracker_request torrent::generate_tracker_request(int port)
{
assert(port>0);
assert(port > 0);
assert((unsigned short)port == port);
m_duration = 1800;
m_next_request = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(m_duration);
@ -481,7 +472,8 @@ namespace libtorrent
void torrent::remove_peer(peer_connection* p)
{
assert(p);
assert(p != 0);
peer_iterator i = m_connections.find(p->get_socket()->sender());
assert(i != m_connections.end());
@ -552,7 +544,7 @@ namespace libtorrent
void torrent::attach_peer(peer_connection* p)
{
assert(p);
assert(p != 0);
assert(m_connections.find(p->get_socket()->sender()) == m_connections.end());
assert(!p->is_local());
@ -652,6 +644,9 @@ namespace libtorrent
{
assert(m_num_pieces
== std::count(m_have_pieces.begin(), m_have_pieces.end(), true));
assert(m_priority >= 0.f && m_priority < 1.f);
assert(m_block_size > 0);
assert((m_torrent_file.piece_length() % m_block_size) == 0);
}
#endif
@ -679,7 +674,9 @@ namespace libtorrent
bool torrent::verify_piece(int piece_index)
{
assert(piece_index >= 0 && piece_index < m_torrent_file.num_pieces());
assert(piece_index >= 0);
assert(piece_index < m_torrent_file.num_pieces());
size_type size = m_torrent_file.piece_size(piece_index);
std::vector<char> buffer(size);
assert(size > 0);

View File

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