lt sync 2205

This commit is contained in:
Andrew Resch 2008-04-20 00:39:26 +00:00
parent e366b75714
commit 354b31dbbe
3 changed files with 67 additions and 9 deletions

View File

@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <utility>
#include <vector>
#include "libtorrent/assert.hpp"
#include <boost/cstdint.hpp>
#include "libtorrent/size_type.hpp"
#include <iosfwd>
namespace libtorrent
@ -71,7 +71,7 @@ namespace libtorrent
m_end = start + length + 1; // include 'e'
}
boost::int64_t int_value() const;
size_type int_value() const;
// string functions
// ================
@ -119,6 +119,12 @@ namespace libtorrent
lazy_entry* dict_find(char const* name);
lazy_entry const* dict_find(char const* name) const
{ return const_cast<lazy_entry*>(this)->dict_find(name); }
std::string dict_find_string_value(char const* name) const;
size_type dict_find_int_value(char const* name, size_type default_val = 0) const;
lazy_entry const* dict_find_dict(char const* name) const;
lazy_entry const* dict_find_list(char const* name) const;
std::pair<char const*, lazy_entry const*> dict_at(int i) const
{
TORRENT_ASSERT(m_type == dict_t);
@ -154,6 +160,9 @@ namespace libtorrent
lazy_entry const* list_at(int i) const
{ return const_cast<lazy_entry*>(this)->list_at(i); }
std::string list_string_value_at(int i) const;
size_type list_int_value_at(int i, size_type default_val = 0) const;
int list_size() const
{
TORRENT_ASSERT(m_type == list_t);

View File

@ -158,7 +158,7 @@ namespace libtorrent
return 0;
}
boost::int64_t lazy_entry::int_value() const
size_type lazy_entry::int_value() const
{
TORRENT_ASSERT(m_type == int_t);
boost::int64_t val = 0;
@ -241,6 +241,34 @@ namespace libtorrent
}
}
std::string lazy_entry::dict_find_string_value(char const* name) const
{
lazy_entry const* e = dict_find(name);
if (e == 0 || e->type() != lazy_entry::string_t) return std::string();
return e->string_value();
}
size_type lazy_entry::dict_find_int_value(char const* name, size_type default_val) const
{
lazy_entry const* e = dict_find(name);
if (e == 0 || e->type() != lazy_entry::int_t) return default_val;
return e->int_value();
}
lazy_entry const* lazy_entry::dict_find_dict(char const* name) const
{
lazy_entry const* e = dict_find(name);
if (e == 0 || e->type() != lazy_entry::dict_t) return 0;
return e;
}
lazy_entry const* lazy_entry::dict_find_list(char const* name) const
{
lazy_entry const* e = dict_find(name);
if (e == 0 || e->type() != lazy_entry::list_t) return 0;
return e;
}
lazy_entry* lazy_entry::dict_find(char const* name)
{
TORRENT_ASSERT(m_type == dict_t);
@ -279,6 +307,20 @@ namespace libtorrent
return m_data.list + (m_size++);
}
std::string lazy_entry::list_string_value_at(int i) const
{
lazy_entry const* e = list_at(i);
if (e == 0 || e->type() != lazy_entry::string_t) return std::string();
return e->string_value();
}
size_type lazy_entry::list_int_value_at(int i, size_type default_val) const
{
lazy_entry const* e = list_at(i);
if (e == 0 || e->type() != lazy_entry::int_t) return default_val;
return e->int_value();
}
void lazy_entry::clear()
{
switch (m_type)

View File

@ -450,8 +450,7 @@ namespace libtorrent
policy::iterator policy::find_connect_candidate()
{
// too expensive
// INVARIANT_CHECK;
INVARIANT_CHECK;
ptime now = time_now();
ptime min_connect_time(now);
@ -834,8 +833,15 @@ namespace libtorrent
{
TORRENT_ASSERT(m_peers.count(p->ip.address()) == 1);
}
bool was_conn_cand = is_connect_candidate(*p, m_torrent->is_finished());
p->ip.port(port);
p->source |= src;
if (was_conn_cand != is_connect_candidate(*p, m_torrent->is_finished()))
{
m_num_connect_candidates += was_conn_cand ? -1 : 1;
if (m_num_connect_candidates < 0) m_num_connect_candidates = 0;
}
return true;
}
@ -853,8 +859,7 @@ namespace libtorrent
policy::peer* policy::peer_from_tracker(tcp::endpoint const& remote, peer_id const& pid
, int src, char flags)
{
// too expensive
// INVARIANT_CHECK;
INVARIANT_CHECK;
// just ignore the obviously invalid entries
if (remote.address() == address() || remote.port() == 0)
@ -963,8 +968,10 @@ namespace libtorrent
#endif
if (was_conn_cand != is_connect_candidate(i->second, m_torrent->is_finished()))
if (was_conn_cand) --m_num_connect_candidates;
else ++m_num_connect_candidates;
{
m_num_connect_candidates += was_conn_cand ? -1 : 1;
if (m_num_connect_candidates < 0) m_num_connect_candidates = 0;
}
}
return &i->second;