forked from premiere/premiere-libtorrent
removed set_ratio feature
This commit is contained in:
parent
42ac467777
commit
474e77039f
|
@ -1,3 +1,4 @@
|
|||
* remove set_ratio() feature
|
||||
* improve piece_deadline/streaming
|
||||
* honor pieces with priority 7 in sequential download mode
|
||||
* simplified building python bindings
|
||||
|
|
|
@ -399,18 +399,12 @@ namespace libtorrent
|
|||
// It will reset the used bandwidth to 0.
|
||||
void reset_upload_quota();
|
||||
|
||||
// free upload.
|
||||
size_type total_free_upload() const;
|
||||
void add_free_upload(size_type free_upload);
|
||||
|
||||
// trust management.
|
||||
virtual void received_valid_data(int index);
|
||||
// returns false if the peer should not be
|
||||
// disconnected
|
||||
virtual bool received_invalid_data(int index, bool single_peer);
|
||||
|
||||
size_type share_diff() const;
|
||||
|
||||
// a connection is local if it was initiated by us.
|
||||
// if it was an incoming connection, it is remote
|
||||
bool is_outgoing() const { return m_outgoing; }
|
||||
|
@ -909,14 +903,6 @@ namespace libtorrent
|
|||
// this peer the last time.
|
||||
ptime m_became_uninteresting;
|
||||
|
||||
// the amount of data this peer has been given
|
||||
// as free upload. This is distributed from
|
||||
// peers from which we get free download
|
||||
// this will be negative on a peer from which
|
||||
// we get free download, and positive on peers
|
||||
// that we give the free upload, to keep the balance.
|
||||
size_type m_free_upload;
|
||||
|
||||
// the total payload download bytes
|
||||
// at the last unchoke round. This is used to
|
||||
// measure the number of bytes transferred during
|
||||
|
|
|
@ -298,13 +298,6 @@ namespace libtorrent
|
|||
// the AS number the peer is located in.
|
||||
int inet_as;
|
||||
|
||||
// a measurement of the balancing of free download (that we get) and free
|
||||
// upload that we give. Every peer gets a certain amount of free upload,
|
||||
// but this member says how much *extra* free upload this peer has got.
|
||||
// If it is a negative number it means that this was a peer from which we
|
||||
// have got this amount of free download.
|
||||
size_type load_balancing;
|
||||
|
||||
// this is the number of requests
|
||||
// we have sent to this peer
|
||||
// that we haven't got a response
|
||||
|
|
|
@ -96,10 +96,6 @@ namespace libtorrent
|
|||
{
|
||||
// the limits of the download queue size
|
||||
min_request_queue = 2,
|
||||
|
||||
// the amount of free upload allowed before
|
||||
// the peer is choked
|
||||
free_upload_amount = 4 * 16 * 1024
|
||||
};
|
||||
|
||||
// calculate the priority of a peer based on its address. One of the
|
||||
|
|
|
@ -361,12 +361,6 @@ namespace libtorrent
|
|||
void connect_to_url_seed(std::list<web_seed_entry>::iterator url);
|
||||
bool connect_to_peer(policy::peer* peerinfo, bool ignore_limit = false);
|
||||
|
||||
void set_ratio(float r)
|
||||
{ TORRENT_ASSERT(r >= 0.0f); m_ratio = r; }
|
||||
|
||||
float ratio() const
|
||||
{ return m_ratio; }
|
||||
|
||||
int priority() const { return m_priority; }
|
||||
void set_priority(int prio)
|
||||
{
|
||||
|
@ -799,15 +793,6 @@ namespace libtorrent
|
|||
// --------------------------------------------
|
||||
// RESOURCE MANAGEMENT
|
||||
|
||||
void add_free_upload(size_type diff)
|
||||
{
|
||||
TORRENT_ASSERT(diff >= 0);
|
||||
if (UINT_MAX - m_available_free_upload > diff)
|
||||
m_available_free_upload += boost::uint32_t(diff);
|
||||
else
|
||||
m_available_free_upload = UINT_MAX;
|
||||
}
|
||||
|
||||
int get_peer_upload_limit(tcp::endpoint ip) const;
|
||||
int get_peer_download_limit(tcp::endpoint ip) const;
|
||||
void set_peer_upload_limit(tcp::endpoint ip, int limit);
|
||||
|
@ -1117,15 +1102,6 @@ namespace libtorrent
|
|||
sha1_hash m_obfuscated_hash;
|
||||
#endif
|
||||
|
||||
// the upload/download ratio that each peer
|
||||
// tries to maintain.
|
||||
// 0 is infinite
|
||||
float m_ratio;
|
||||
|
||||
// free download we have got that hasn't
|
||||
// been distributed yet.
|
||||
boost::uint32_t m_available_free_upload;
|
||||
|
||||
// the average time it takes to download one time critical piece
|
||||
boost::uint32_t m_average_piece_time;
|
||||
// the average piece download time deviation
|
||||
|
|
|
@ -147,7 +147,6 @@ namespace libtorrent
|
|||
, m_connect(time_now())
|
||||
, m_became_uninterested(time_now())
|
||||
, m_became_uninteresting(time_now())
|
||||
, m_free_upload(0)
|
||||
, m_downloaded_at_last_round(0)
|
||||
, m_uploaded_at_last_round(0)
|
||||
, m_uploaded_at_last_unchoke(0)
|
||||
|
@ -1051,18 +1050,6 @@ namespace libtorrent
|
|||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
size_type peer_connection::total_free_upload() const
|
||||
{
|
||||
return m_free_upload;
|
||||
}
|
||||
|
||||
void peer_connection::add_free_upload(size_type free_upload)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
m_free_upload += free_upload;
|
||||
}
|
||||
|
||||
// verifies a piece to see if it is valid (is within a valid range)
|
||||
// and if it can correspond to a request generated by libtorrent.
|
||||
|
@ -1517,10 +1504,7 @@ namespace libtorrent
|
|||
send_unchoke();
|
||||
}
|
||||
else if ((m_ses.num_uploads() < m_ses.settings().unchoke_slots_limit
|
||||
|| m_ses.settings().unchoke_slots_limit < 0)
|
||||
&& (t->ratio() == 0
|
||||
|| share_diff() >= size_type(-free_upload_amount)
|
||||
|| t->is_finished()))
|
||||
|| m_ses.settings().unchoke_slots_limit < 0))
|
||||
{
|
||||
// if the peer is choked and we have upload slots left,
|
||||
// then unchoke it. Another condition that has to be met
|
||||
|
@ -1537,20 +1521,9 @@ namespace libtorrent
|
|||
#if defined TORRENT_VERBOSE_LOGGING
|
||||
else
|
||||
{
|
||||
std::string reason;
|
||||
if (m_ses.num_uploads() >= m_ses.settings().unchoke_slots_limit
|
||||
&& m_ses.settings().unchoke_slots_limit >= 0)
|
||||
{
|
||||
peer_log("DID NOT UNCHOKE [ the number of uploads (%d)"
|
||||
"is more than or equal to the limit (%d) ]"
|
||||
, m_ses.num_uploads(), m_ses.settings().unchoke_slots_limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
peer_log("DID NOT UNCHOKE [ the share ratio (%d) is <= "
|
||||
"free_upload_amount (%d) and we are not seeding and the ratio (%d) is non-zero"
|
||||
, share_diff(), int(free_upload_amount), t->ratio());
|
||||
}
|
||||
peer_log("DID NOT UNCHOKE [ the number of uploads (%d)"
|
||||
"is more than or equal to the limit (%d) ]"
|
||||
, m_ses.num_uploads(), m_ses.settings().unchoke_slots_limit);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1607,20 +1580,6 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
if (t->ratio() != 0.f)
|
||||
{
|
||||
TORRENT_ASSERT(share_diff() < (std::numeric_limits<size_type>::max)());
|
||||
size_type diff = share_diff();
|
||||
if (diff > 0 && is_seed())
|
||||
{
|
||||
// the peer is a seed and has sent
|
||||
// us more than we have sent it back.
|
||||
// consider the download as free download
|
||||
t->add_free_upload(diff);
|
||||
add_free_upload(-diff);
|
||||
}
|
||||
}
|
||||
|
||||
if (t->super_seeding())
|
||||
{
|
||||
// maybe we need to try another piece, to see if the peer
|
||||
|
@ -3778,25 +3737,6 @@ namespace libtorrent
|
|||
m_bandwidth_channel[download_channel].throttle(m_download_limit);
|
||||
}
|
||||
|
||||
size_type peer_connection::share_diff() const
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||
TORRENT_ASSERT(t);
|
||||
|
||||
float ratio = t->ratio();
|
||||
|
||||
// if we have an infinite ratio, just say we have downloaded
|
||||
// much more than we have uploaded. And we'll keep uploading.
|
||||
if (ratio == 0.f)
|
||||
return (std::numeric_limits<size_type>::max)();
|
||||
|
||||
return m_free_upload
|
||||
+ static_cast<size_type>(m_statistics.total_payload_download() * ratio)
|
||||
- m_statistics.total_payload_upload();
|
||||
}
|
||||
|
||||
bool peer_connection::ignore_unchoke_slots() const
|
||||
{
|
||||
return m_ignore_unchoke_slots
|
||||
|
@ -3864,8 +3804,6 @@ namespace libtorrent
|
|||
else
|
||||
p.download_limit = m_bandwidth_channel[download_channel].throttle();
|
||||
|
||||
p.load_balancing = total_free_upload();
|
||||
|
||||
p.download_queue_length = int(download_queue().size() + m_request_queue.size());
|
||||
p.requests_in_buffer = int(m_requests_in_buffer.size() + m_request_queue.size());
|
||||
p.target_dl_queue_length = int(desired_queue_size());
|
||||
|
@ -4387,48 +4325,6 @@ namespace libtorrent
|
|||
snub_peer();
|
||||
}
|
||||
|
||||
// If the client sends more data
|
||||
// we send it data faster, otherwise, slower.
|
||||
// It will also depend on how much data the
|
||||
// client has sent us. This is the mean to
|
||||
// maintain the share ratio given by m_ratio
|
||||
// with all peers.
|
||||
|
||||
if (t->is_upload_only() || is_choked() || t->ratio() == 0.0f)
|
||||
{
|
||||
// if we have downloaded more than one piece more
|
||||
// than we have uploaded OR if we are a seed
|
||||
// have an unlimited upload rate
|
||||
m_bandwidth_channel[upload_channel].throttle(m_upload_limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_type bias = 0x10000 + 2 * t->block_size() + m_free_upload;
|
||||
|
||||
const int break_even_time = 15; // seconds.
|
||||
size_type have_uploaded = m_statistics.total_payload_upload();
|
||||
size_type have_downloaded = m_statistics.total_payload_download();
|
||||
int download_speed = m_statistics.download_rate();
|
||||
|
||||
size_type soon_downloaded =
|
||||
have_downloaded + (size_type)(download_speed * (break_even_time + break_even_time / 2));
|
||||
|
||||
if (t->ratio() != 1.f)
|
||||
soon_downloaded = size_type(soon_downloaded * t->ratio());
|
||||
|
||||
TORRENT_ASSERT((soon_downloaded - have_uploaded + bias) / break_even_time < INT_MAX);
|
||||
int upload_speed_limit = int((soon_downloaded - have_uploaded
|
||||
+ bias) / break_even_time);
|
||||
|
||||
if (m_upload_limit > 0 && m_upload_limit < upload_speed_limit)
|
||||
upload_speed_limit = m_upload_limit;
|
||||
|
||||
upload_speed_limit = (std::min)(upload_speed_limit, (std::numeric_limits<int>::max)());
|
||||
|
||||
m_bandwidth_channel[upload_channel].throttle(
|
||||
(std::min)((std::max)(upload_speed_limit, 10), m_upload_limit));
|
||||
}
|
||||
|
||||
// update once every minute
|
||||
if (now - m_remote_dl_update >= seconds(60))
|
||||
{
|
||||
|
|
|
@ -4604,9 +4604,7 @@ retry:
|
|||
|
||||
if (!p->is_peer_interested()
|
||||
|| p->is_disconnecting()
|
||||
|| p->is_connecting()
|
||||
|| (p->share_diff() < -free_upload_amount
|
||||
&& !t->is_seed()))
|
||||
|| p->is_connecting())
|
||||
{
|
||||
// this peer is not unchokable. So, if it's unchoked
|
||||
// already, make sure to choke it.
|
||||
|
@ -4616,6 +4614,8 @@ retry:
|
|||
pi->optimistically_unchoked = false;
|
||||
// force a new optimistic unchoke
|
||||
m_optimistic_unchoke_time_scaler = 0;
|
||||
// TODO: post a message to have this happen
|
||||
// immediately instead of waiting for the next tick
|
||||
}
|
||||
t->choke_peer(*p);
|
||||
continue;
|
||||
|
|
105
src/torrent.cpp
105
src/torrent.cpp
|
@ -96,73 +96,6 @@ using libtorrent::aux::session_impl;
|
|||
|
||||
namespace
|
||||
{
|
||||
size_type collect_free_download(
|
||||
torrent::peer_iterator start
|
||||
, torrent::peer_iterator end)
|
||||
{
|
||||
size_type accumulator = 0;
|
||||
for (torrent::peer_iterator i = start; i != end; ++i)
|
||||
{
|
||||
// if the peer is interested in us, it means it may
|
||||
// want to trade it's surplus uploads for downloads itself
|
||||
// (and we should not consider it free). If the share diff is
|
||||
// negative, there's no free download to get from this peer.
|
||||
size_type diff = (*i)->share_diff();
|
||||
TORRENT_ASSERT(diff < (std::numeric_limits<size_type>::max)());
|
||||
if ((*i)->is_peer_interested() || diff <= 0)
|
||||
continue;
|
||||
|
||||
TORRENT_ASSERT(diff > 0);
|
||||
(*i)->add_free_upload(-diff);
|
||||
accumulator += diff;
|
||||
TORRENT_ASSERT(accumulator > 0);
|
||||
}
|
||||
TORRENT_ASSERT(accumulator >= 0);
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
// returns the amount of free upload left after
|
||||
// it has been distributed to the peers
|
||||
boost::uint32_t distribute_free_upload(
|
||||
torrent::peer_iterator start
|
||||
, torrent::peer_iterator end
|
||||
, size_type free_upload)
|
||||
{
|
||||
TORRENT_ASSERT(free_upload >= 0);
|
||||
if (free_upload <= 0) return 0;
|
||||
int num_peers = 0;
|
||||
size_type total_diff = 0;
|
||||
for (torrent::peer_iterator i = start; i != end; ++i)
|
||||
{
|
||||
size_type d = (*i)->share_diff();
|
||||
TORRENT_ASSERT(d < (std::numeric_limits<size_type>::max)());
|
||||
total_diff += d;
|
||||
if (!(*i)->is_peer_interested() || (*i)->share_diff() >= 0) continue;
|
||||
++num_peers;
|
||||
}
|
||||
|
||||
if (num_peers == 0) return boost::uint32_t(free_upload);
|
||||
size_type upload_share;
|
||||
if (total_diff >= 0)
|
||||
{
|
||||
upload_share = (std::min)(free_upload, total_diff) / num_peers;
|
||||
}
|
||||
else
|
||||
{
|
||||
upload_share = (free_upload + total_diff) / num_peers;
|
||||
}
|
||||
if (upload_share < 0) return boost::uint32_t(free_upload);
|
||||
|
||||
for (torrent::peer_iterator i = start; i != end; ++i)
|
||||
{
|
||||
peer_connection* p = *i;
|
||||
if (!p->is_peer_interested() || p->share_diff() >= 0) continue;
|
||||
p->add_free_upload(upload_share);
|
||||
free_upload -= upload_share;
|
||||
}
|
||||
return (std::min)(free_upload, size_type(UINT_MAX));
|
||||
}
|
||||
|
||||
struct find_peer_by_ip
|
||||
{
|
||||
find_peer_by_ip(tcp::endpoint const& a, const torrent* t)
|
||||
|
@ -249,8 +182,6 @@ namespace libtorrent
|
|||
, m_last_seen_complete(0)
|
||||
, m_swarm_last_seen_complete(0)
|
||||
, m_num_verified(0)
|
||||
, m_ratio(0.f)
|
||||
, m_available_free_upload(0)
|
||||
, m_average_piece_time(0)
|
||||
, m_piece_time_deviation(0)
|
||||
, m_total_failed_bytes(0)
|
||||
|
@ -4514,15 +4445,6 @@ namespace libtorrent
|
|||
if (pp->optimistically_unchoked)
|
||||
m_ses.m_optimistic_unchoke_time_scaler = 0;
|
||||
|
||||
// if the share ratio is 0 (infinite), the
|
||||
// m_available_free_upload isn't used,
|
||||
// because it isn't necessary.
|
||||
if (ratio() != 0.f)
|
||||
{
|
||||
TORRENT_ASSERT(p->associated_torrent().lock().get() == this);
|
||||
TORRENT_ASSERT(p->share_diff() < (std::numeric_limits<size_type>::max)());
|
||||
add_free_upload(p->share_diff());
|
||||
}
|
||||
TORRENT_ASSERT(pp->prev_amount_upload == 0);
|
||||
TORRENT_ASSERT(pp->prev_amount_download == 0);
|
||||
pp->prev_amount_download += p->statistics().total_payload_download() >> 10;
|
||||
|
@ -7779,33 +7701,6 @@ namespace libtorrent
|
|||
for (int i = start; i < end; ++i)
|
||||
update_sparse_piece_prio(i, start, end);
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// upload shift
|
||||
// ------------------------
|
||||
|
||||
// this part will shift downloads
|
||||
// from peers that are seeds and peers
|
||||
// that don't want to download from us
|
||||
// to peers that cannot upload anything
|
||||
// to us. The shifting will make sure
|
||||
// that the torrent's share ratio
|
||||
// will be maintained
|
||||
|
||||
// if the share ratio is 0 (infinite)
|
||||
// m_available_free_upload isn't used
|
||||
// because it isn't necessary
|
||||
if (ratio() != 0.f)
|
||||
{
|
||||
// accumulate all the free download we get
|
||||
// and add it to the available free upload
|
||||
add_free_upload(collect_free_download(
|
||||
this->begin(), this->end()));
|
||||
|
||||
// distribute the free upload among the peers
|
||||
m_available_free_upload = distribute_free_upload(
|
||||
this->begin(), this->end(), m_available_free_upload);
|
||||
}
|
||||
}
|
||||
|
||||
// if we're in upload only mode and we're auto-managed
|
||||
|
|
|
@ -580,11 +580,7 @@ namespace libtorrent
|
|||
|
||||
void torrent_handle::set_ratio(float ratio) const
|
||||
{
|
||||
|
||||
TORRENT_ASSERT_PRECOND(ratio >= 0.f);
|
||||
if (ratio < 1.f && ratio > 0.f)
|
||||
ratio = 1.f;
|
||||
TORRENT_ASYNC_CALL1(set_ratio, ratio);
|
||||
}
|
||||
|
||||
bool torrent_handle::is_seed() const
|
||||
|
|
Loading…
Reference in New Issue