*** empty log message ***
This commit is contained in:
parent
0634e778e9
commit
718f01155f
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ 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; }
|
||||
|
||||
|
@ -127,7 +127,7 @@ namespace libtorrent
|
|||
{ 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
|
||||
|
|
|
@ -170,7 +170,7 @@ 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)
|
||||
|
@ -198,25 +198,30 @@ namespace
|
|||
{
|
||||
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 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);
|
||||
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;
|
||||
}
|
||||
|
@ -224,7 +229,7 @@ namespace
|
|||
|
||||
// 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;
|
||||
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace {
|
|||
: data(data_)
|
||||
, size(size_)
|
||||
{
|
||||
assert(data_);
|
||||
assert(data_ != 0);
|
||||
assert(size_ > 0);
|
||||
}
|
||||
|
||||
|
@ -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,7 +609,8 @@ namespace libtorrent
|
|||
, int block_size
|
||||
, const std::bitset<256>& bitmask)
|
||||
{
|
||||
assert(slot_index >= 0 && slot_index < m_info.num_pieces());
|
||||
assert(slot_index >= 0);
|
||||
assert(slot_index < m_info.num_pieces());
|
||||
assert(block_size > 0);
|
||||
|
||||
adler32_crc crc;
|
||||
|
@ -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());
|
||||
|
@ -954,16 +952,21 @@ 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_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_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);
|
||||
|
@ -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,14 +1220,14 @@ 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];
|
||||
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());
|
||||
|
@ -1231,13 +1237,19 @@ namespace libtorrent
|
|||
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)
|
||||
|
@ -1257,7 +1269,7 @@ namespace libtorrent
|
|||
|
||||
if (m_slot_to_piece[i]>=0)
|
||||
{
|
||||
assert((unsigned)m_slot_to_piece[i]<m_piece_to_slot.size());
|
||||
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(
|
||||
|
|
|
@ -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,7 +176,7 @@ namespace libtorrent
|
|||
|
||||
std::string escape_string(const char* str, int len)
|
||||
{
|
||||
assert(str);
|
||||
assert(str != 0);
|
||||
assert(len >= 0);
|
||||
// http://www.ietf.org/rfc/rfc2396.txt
|
||||
// section 2.3
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -66,6 +66,7 @@ namespace libtorrent
|
|||
void torrent_handle::set_max_uploads(int max_uploads)
|
||||
{
|
||||
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();
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue