lt update which fixes cpu spikes in 0.5.8.2

This commit is contained in:
Marcos Pinto 2008-01-28 03:17:29 +00:00
parent 6dd304ee63
commit 67dfd74bdc
8 changed files with 27 additions and 20 deletions

View File

@ -173,7 +173,7 @@ struct bandwidth_manager
++i->priority;
++i;
}
m_queue.insert(i.base(), bw_queue_entry<PeerConnection>(peer, blk, priority));
m_queue.insert(i.base(), bw_queue_entry<PeerConnection, Torrent>(peer, blk, priority));
if (!m_queue.empty()) hand_out_bandwidth(l);
}
@ -292,7 +292,7 @@ private:
queue_t tmp;
while (!m_queue.empty() && amount > 0)
{
bw_queue_entry<PeerConnection> qe = m_queue.front();
bw_queue_entry<PeerConnection, Torrent> qe = m_queue.front();
TORRENT_ASSERT(qe.max_block_size > 0);
m_queue.pop_front();
@ -401,7 +401,7 @@ private:
int m_current_quota;
// these are the consumers that want bandwidth
typedef std::deque<bw_queue_entry<PeerConnection> > queue_t;
typedef std::deque<bw_queue_entry<PeerConnection, Torrent> > queue_t;
queue_t m_queue;
// these are the consumers that have received bandwidth

View File

@ -37,16 +37,15 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
template<class PeerConnection>
template<class PeerConnection, class Torrent>
struct bw_queue_entry
{
typedef typename PeerConnection::torrent_type torrent_type;
bw_queue_entry(boost::intrusive_ptr<PeerConnection> const& pe
, int blk, int prio)
: peer(pe), torrent(peer->associated_torrent())
, max_block_size(blk), priority(prio) {}
boost::intrusive_ptr<PeerConnection> peer;
boost::weak_ptr<torrent_type> torrent;
boost::weak_ptr<Torrent> torrent;
int max_block_size;
int priority; // 0 is low prio
};

View File

@ -214,8 +214,14 @@ namespace libtorrent
}
template<class InIt>
void bdecode_recursive(InIt& in, InIt end, entry& ret, bool& err)
void bdecode_recursive(InIt& in, InIt end, entry& ret, bool& err, int depth)
{
if (depth >= 100)
{
err = true;
return;
}
if (in == end)
{
err = true;
@ -247,7 +253,7 @@ namespace libtorrent
{
ret.list().push_back(entry());
entry& e = ret.list().back();
bdecode_recursive(in, end, e, err);
bdecode_recursive(in, end, e, err, depth + 1);
if (err) return;
if (in == end)
{
@ -268,10 +274,10 @@ namespace libtorrent
while (*in != 'e')
{
entry key;
bdecode_recursive(in, end, key, err);
bdecode_recursive(in, end, key, err, depth + 1);
if (err) return;
entry& e = ret[key.string()];
bdecode_recursive(in, end, e, err);
bdecode_recursive(in, end, e, err, depth + 1);
if (err) return;
if (in == end)
{
@ -317,7 +323,7 @@ namespace libtorrent
{
entry e;
bool err = false;
detail::bdecode_recursive(start, end, e, err);
detail::bdecode_recursive(start, end, e, err, 0);
if (err)
{
#ifdef BOOST_NO_EXCEPTIONS
@ -332,3 +338,4 @@ namespace libtorrent
}
#endif // TORRENT_BENCODE_HPP_INCLUDED

View File

@ -98,8 +98,6 @@ namespace libtorrent
friend class invariant_access;
public:
typedef torrent torrent_type;
enum channels
{
upload_channel,

View File

@ -688,7 +688,7 @@ namespace libtorrent
boost::scoped_ptr<piece_picker> m_picker;
// the queue of peer_connections that want more bandwidth
typedef std::deque<bw_queue_entry<peer_connection> > queue_t;
typedef std::deque<bw_queue_entry<peer_connection, torrent> > queue_t;
queue_t m_bandwidth_queue[2];
std::vector<announce_entry> m_trackers;

View File

@ -54,7 +54,7 @@ namespace libtorrent
{
s.instantiate<http_stream>(ios);
s.get<http_stream>().set_proxy(ps.hostname, ps.port);
if (ps.type == proxy_settings::socks5_pw)
if (ps.type == proxy_settings::http_pw)
s.get<http_stream>().set_username(ps.username, ps.password);
}
else if (ps.type == proxy_settings::socks5

View File

@ -2253,7 +2253,7 @@ namespace libtorrent
++i->priority;
++i;
}
m_bandwidth_queue[channel].insert(i.base(), bw_queue_entry<peer_connection>(
m_bandwidth_queue[channel].insert(i.base(), bw_queue_entry<peer_connection, torrent>(
p, block_size, priority));
}
}
@ -2267,7 +2267,7 @@ namespace libtorrent
queue_t tmp;
while (!m_bandwidth_queue[channel].empty())
{
bw_queue_entry<peer_connection> qe = m_bandwidth_queue[channel].front();
bw_queue_entry<peer_connection, torrent> qe = m_bandwidth_queue[channel].front();
if (m_bandwidth_limit[channel].max_assignable() == 0)
break;
m_bandwidth_queue[channel].pop_front();

View File

@ -503,7 +503,7 @@ namespace libtorrent
session_impl::mutex_t::scoped_lock l(m_ses->m_mutex);
mutex::scoped_lock l2(m_chk->m_mutex);
boost::shared_ptr<torrent> t = m_ses->find_torrent(m_info_hash).lock();
torrent* t = find_torrent(m_ses, m_chk, m_info_hash);
if (!t || !t->valid_metadata())
#ifdef BOOST_NO_EXCEPTIONS
return entry();
@ -599,11 +599,13 @@ namespace libtorrent
for (policy::iterator i = pol.begin_peer()
, end(pol.end_peer()); i != end; ++i)
{
asio::error_code ec;
if (i->second.banned)
{
tcp::endpoint ip = i->second.ip;
entry peer(entry::dictionary_t);
peer["ip"] = ip.address().to_string();
peer["ip"] = ip.address().to_string(ec);
if (ec) continue;
peer["port"] = ip.port();
banned_peer_list.push_back(peer);
continue;
@ -619,7 +621,8 @@ namespace libtorrent
tcp::endpoint ip = i->second.ip;
entry peer(entry::dictionary_t);
peer["ip"] = ip.address().to_string();
peer["ip"] = ip.address().to_string(ec);
if (ec) continue;
peer["port"] = ip.port();
peer_list.push_back(peer);
}