mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-27 02:20:32 +00:00
lt sync - cpu spike fix
This commit is contained in:
parent
d1677a855f
commit
94f36c72a1
@ -173,7 +173,7 @@ struct bandwidth_manager
|
|||||||
++i->priority;
|
++i->priority;
|
||||||
++i;
|
++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);
|
if (!m_queue.empty()) hand_out_bandwidth(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ private:
|
|||||||
queue_t tmp;
|
queue_t tmp;
|
||||||
while (!m_queue.empty() && amount > 0)
|
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);
|
TORRENT_ASSERT(qe.max_block_size > 0);
|
||||||
m_queue.pop_front();
|
m_queue.pop_front();
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ private:
|
|||||||
int m_current_quota;
|
int m_current_quota;
|
||||||
|
|
||||||
// these are the consumers that want bandwidth
|
// 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;
|
queue_t m_queue;
|
||||||
|
|
||||||
// these are the consumers that have received bandwidth
|
// these are the consumers that have received bandwidth
|
||||||
|
@ -37,16 +37,15 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
namespace libtorrent {
|
namespace libtorrent {
|
||||||
|
|
||||||
template<class PeerConnection>
|
template<class PeerConnection, class Torrent>
|
||||||
struct bw_queue_entry
|
struct bw_queue_entry
|
||||||
{
|
{
|
||||||
typedef typename PeerConnection::torrent_type torrent_type;
|
|
||||||
bw_queue_entry(boost::intrusive_ptr<PeerConnection> const& pe
|
bw_queue_entry(boost::intrusive_ptr<PeerConnection> const& pe
|
||||||
, int blk, int prio)
|
, int blk, int prio)
|
||||||
: peer(pe), torrent(peer->associated_torrent())
|
: peer(pe), torrent(peer->associated_torrent())
|
||||||
, max_block_size(blk), priority(prio) {}
|
, max_block_size(blk), priority(prio) {}
|
||||||
boost::intrusive_ptr<PeerConnection> peer;
|
boost::intrusive_ptr<PeerConnection> peer;
|
||||||
boost::weak_ptr<torrent_type> torrent;
|
boost::weak_ptr<Torrent> torrent;
|
||||||
int max_block_size;
|
int max_block_size;
|
||||||
int priority; // 0 is low prio
|
int priority; // 0 is low prio
|
||||||
};
|
};
|
||||||
|
@ -214,8 +214,14 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class InIt>
|
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)
|
if (in == end)
|
||||||
{
|
{
|
||||||
err = true;
|
err = true;
|
||||||
@ -247,7 +253,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
ret.list().push_back(entry());
|
ret.list().push_back(entry());
|
||||||
entry& e = ret.list().back();
|
entry& e = ret.list().back();
|
||||||
bdecode_recursive(in, end, e, err);
|
bdecode_recursive(in, end, e, err, depth + 1);
|
||||||
if (err) return;
|
if (err) return;
|
||||||
if (in == end)
|
if (in == end)
|
||||||
{
|
{
|
||||||
@ -268,10 +274,10 @@ namespace libtorrent
|
|||||||
while (*in != 'e')
|
while (*in != 'e')
|
||||||
{
|
{
|
||||||
entry key;
|
entry key;
|
||||||
bdecode_recursive(in, end, key, err);
|
bdecode_recursive(in, end, key, err, depth + 1);
|
||||||
if (err) return;
|
if (err) return;
|
||||||
entry& e = ret[key.string()];
|
entry& e = ret[key.string()];
|
||||||
bdecode_recursive(in, end, e, err);
|
bdecode_recursive(in, end, e, err, depth + 1);
|
||||||
if (err) return;
|
if (err) return;
|
||||||
if (in == end)
|
if (in == end)
|
||||||
{
|
{
|
||||||
@ -317,7 +323,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
entry e;
|
entry e;
|
||||||
bool err = false;
|
bool err = false;
|
||||||
detail::bdecode_recursive(start, end, e, err);
|
detail::bdecode_recursive(start, end, e, err, 0);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_NO_EXCEPTIONS
|
#ifdef BOOST_NO_EXCEPTIONS
|
||||||
@ -332,3 +338,4 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // TORRENT_BENCODE_HPP_INCLUDED
|
#endif // TORRENT_BENCODE_HPP_INCLUDED
|
||||||
|
|
||||||
|
@ -98,8 +98,6 @@ namespace libtorrent
|
|||||||
friend class invariant_access;
|
friend class invariant_access;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef torrent torrent_type;
|
|
||||||
|
|
||||||
enum channels
|
enum channels
|
||||||
{
|
{
|
||||||
upload_channel,
|
upload_channel,
|
||||||
|
@ -688,7 +688,7 @@ namespace libtorrent
|
|||||||
boost::scoped_ptr<piece_picker> m_picker;
|
boost::scoped_ptr<piece_picker> m_picker;
|
||||||
|
|
||||||
// the queue of peer_connections that want more bandwidth
|
// 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];
|
queue_t m_bandwidth_queue[2];
|
||||||
|
|
||||||
std::vector<announce_entry> m_trackers;
|
std::vector<announce_entry> m_trackers;
|
||||||
|
@ -54,7 +54,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
s.instantiate<http_stream>(ios);
|
s.instantiate<http_stream>(ios);
|
||||||
s.get<http_stream>().set_proxy(ps.hostname, ps.port);
|
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);
|
s.get<http_stream>().set_username(ps.username, ps.password);
|
||||||
}
|
}
|
||||||
else if (ps.type == proxy_settings::socks5
|
else if (ps.type == proxy_settings::socks5
|
||||||
|
@ -2253,7 +2253,7 @@ namespace libtorrent
|
|||||||
++i->priority;
|
++i->priority;
|
||||||
++i;
|
++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));
|
p, block_size, priority));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2267,7 +2267,7 @@ namespace libtorrent
|
|||||||
queue_t tmp;
|
queue_t tmp;
|
||||||
while (!m_bandwidth_queue[channel].empty())
|
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)
|
if (m_bandwidth_limit[channel].max_assignable() == 0)
|
||||||
break;
|
break;
|
||||||
m_bandwidth_queue[channel].pop_front();
|
m_bandwidth_queue[channel].pop_front();
|
||||||
|
@ -503,7 +503,7 @@ namespace libtorrent
|
|||||||
session_impl::mutex_t::scoped_lock l(m_ses->m_mutex);
|
session_impl::mutex_t::scoped_lock l(m_ses->m_mutex);
|
||||||
mutex::scoped_lock l2(m_chk->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())
|
if (!t || !t->valid_metadata())
|
||||||
#ifdef BOOST_NO_EXCEPTIONS
|
#ifdef BOOST_NO_EXCEPTIONS
|
||||||
return entry();
|
return entry();
|
||||||
@ -599,11 +599,13 @@ namespace libtorrent
|
|||||||
for (policy::iterator i = pol.begin_peer()
|
for (policy::iterator i = pol.begin_peer()
|
||||||
, end(pol.end_peer()); i != end; ++i)
|
, end(pol.end_peer()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
asio::error_code ec;
|
||||||
if (i->second.banned)
|
if (i->second.banned)
|
||||||
{
|
{
|
||||||
tcp::endpoint ip = i->second.ip;
|
tcp::endpoint ip = i->second.ip;
|
||||||
entry peer(entry::dictionary_t);
|
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["port"] = ip.port();
|
||||||
banned_peer_list.push_back(peer);
|
banned_peer_list.push_back(peer);
|
||||||
continue;
|
continue;
|
||||||
@ -619,7 +621,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
tcp::endpoint ip = i->second.ip;
|
tcp::endpoint ip = i->second.ip;
|
||||||
entry peer(entry::dictionary_t);
|
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["port"] = ip.port();
|
||||||
peer_list.push_back(peer);
|
peer_list.push_back(peer);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user