*** empty log message ***
This commit is contained in:
parent
bbf58b64e5
commit
62f3af5b0f
|
@ -59,6 +59,8 @@ namespace libtorrent
|
||||||
struct logger;
|
struct logger;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::string escape_string(const char* str, int len);
|
||||||
|
|
||||||
struct tracker_alert: alert
|
struct tracker_alert: alert
|
||||||
{
|
{
|
||||||
tracker_alert(const torrent_handle& h
|
tracker_alert(const torrent_handle& h
|
||||||
|
|
|
@ -1139,7 +1139,8 @@ namespace libtorrent
|
||||||
// we send it data faster, otherwise, slower.
|
// we send it data faster, otherwise, slower.
|
||||||
// It will also depend on how much data the
|
// It will also depend on how much data the
|
||||||
// client has sent us. This is the mean to
|
// client has sent us. This is the mean to
|
||||||
// maintain a 1:1 share ratio with all peers.
|
// maintain the share ratio given by m_ratio
|
||||||
|
// with all peers.
|
||||||
|
|
||||||
int diff = share_diff();
|
int diff = share_diff();
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ namespace
|
||||||
// (and we should consider it free). If the share diff is
|
// (and we should consider it free). If the share diff is
|
||||||
// negative, there's no free download to get from this peer.
|
// negative, there's no free download to get from this peer.
|
||||||
int diff = i->second->share_diff();
|
int diff = i->second->share_diff();
|
||||||
if (i->second->is_peer_interested() || diff <= 0 || diff==std::numeric_limits<int>::max())
|
if (i->second->is_peer_interested() || diff <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
assert(diff > 0);
|
assert(diff > 0);
|
||||||
|
@ -233,13 +233,10 @@ namespace
|
||||||
if (free_upload <= 0) return free_upload;
|
if (free_upload <= 0) return free_upload;
|
||||||
int num_peers = 0;
|
int num_peers = 0;
|
||||||
int total_diff = 0;
|
int total_diff = 0;
|
||||||
|
|
||||||
for (torrent::peer_iterator i = start; i != end; ++i)
|
for (torrent::peer_iterator i = start; i != end; ++i)
|
||||||
{
|
{
|
||||||
int diff=i->second->share_diff();
|
total_diff += i->second->share_diff();
|
||||||
if(diff==std::numeric_limits<int>::max()) continue;
|
if (!i->second->is_peer_interested() || i->second->share_diff() >= 0) continue;
|
||||||
total_diff += diff;
|
|
||||||
if (!i->second->is_peer_interested() || diff >= 0) continue;
|
|
||||||
++num_peers;
|
++num_peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,11 +302,8 @@ namespace libtorrent
|
||||||
if (!c->is_peer_interested())
|
if (!c->is_peer_interested())
|
||||||
return &(*i);
|
return &(*i);
|
||||||
|
|
||||||
// int diff = i->total_download()
|
int diff = i->total_download()
|
||||||
// - i->total_upload();
|
- i->total_upload();
|
||||||
int diff = c->share_diff();
|
|
||||||
if(diff==std::numeric_limits<int>::max())
|
|
||||||
diff=0;
|
|
||||||
|
|
||||||
int weight = static_cast<int>(c->statistics().download_rate() * 10.f)
|
int weight = static_cast<int>(c->statistics().download_rate() * 10.f)
|
||||||
+ diff
|
+ diff
|
||||||
|
@ -371,6 +365,7 @@ namespace libtorrent
|
||||||
, old_disconnected_peer())
|
, old_disconnected_peer())
|
||||||
, m_peers.end());
|
, m_peers.end());
|
||||||
|
|
||||||
|
|
||||||
// if the share ratio is 0 (infinite)
|
// if the share ratio is 0 (infinite)
|
||||||
// m_available_free_upload isn't used
|
// m_available_free_upload isn't used
|
||||||
// because it isn't necessary
|
// because it isn't necessary
|
||||||
|
@ -417,8 +412,26 @@ namespace libtorrent
|
||||||
++m_num_unchoked;
|
++m_num_unchoked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_max_uploads != -1)
|
else
|
||||||
{
|
{
|
||||||
|
// choke peers that have leeched too much without giving anything back
|
||||||
|
for (std::vector<peer>::iterator i = m_peers.begin();
|
||||||
|
i != m_peers.end();
|
||||||
|
++i)
|
||||||
|
{
|
||||||
|
peer_connection* c = i->connection;
|
||||||
|
if (c == 0) continue;
|
||||||
|
|
||||||
|
int diff = i->connection->share_diff();
|
||||||
|
if (diff < -free_upload_amount
|
||||||
|
&& !c->is_choked())
|
||||||
|
{
|
||||||
|
// if we have uploaded more than a piece for free, choke peer and
|
||||||
|
// wait until we catch up with our download.
|
||||||
|
c->send_choke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// make sure we don't have too many
|
// make sure we don't have too many
|
||||||
// unchoked peers
|
// unchoked peers
|
||||||
while (m_num_unchoked > m_max_uploads)
|
while (m_num_unchoked > m_max_uploads)
|
||||||
|
@ -440,40 +453,11 @@ namespace libtorrent
|
||||||
unchoke_one_peer();
|
unchoke_one_peer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// make sure we have enough
|
// make sure we have enough
|
||||||
// unchoked peers
|
// unchoked peers
|
||||||
while (m_num_unchoked < m_max_uploads && unchoke_one_peer());
|
while (m_num_unchoked < m_max_uploads && unchoke_one_peer());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// choke peers that have leeched too much without giving anything back
|
|
||||||
for (std::vector<peer>::iterator i = m_peers.begin();
|
|
||||||
i != m_peers.end();
|
|
||||||
++i)
|
|
||||||
{
|
|
||||||
peer_connection* c = i->connection;
|
|
||||||
if (c == 0) continue;
|
|
||||||
|
|
||||||
int diff=c->share_diff();
|
|
||||||
// no problem if diff returns std::numeric_limits<int>::max()
|
|
||||||
|
|
||||||
if (diff <= -free_upload_amount
|
|
||||||
&& !c->is_choked())
|
|
||||||
{
|
|
||||||
// if we have uploaded more than a piece for free, choke peer and
|
|
||||||
// wait until we catch up with our download.
|
|
||||||
c->send_choke();
|
|
||||||
}
|
|
||||||
else if (diff > -free_upload_amount
|
|
||||||
&& c->is_choked() /* && c->is_peer_interested()*/)
|
|
||||||
{
|
|
||||||
// we have catched up. We have now shared the same amount
|
|
||||||
// to eachother. Unchoke this peer.
|
|
||||||
c->send_unchoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
check_invariant();
|
check_invariant();
|
||||||
|
|
|
@ -126,33 +126,6 @@ namespace
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string escape_string(const char* str, int len)
|
|
||||||
{
|
|
||||||
static const char special_chars[] = "$-_.+!*'(),";
|
|
||||||
|
|
||||||
std::stringstream ret;
|
|
||||||
ret << std::hex << std::setfill('0');
|
|
||||||
for (int i = 0; i < len; ++i)
|
|
||||||
{
|
|
||||||
if (std::isalnum(static_cast<unsigned char>(*str))
|
|
||||||
|| std::count(
|
|
||||||
special_chars
|
|
||||||
, special_chars+sizeof(special_chars)-1
|
|
||||||
, *str))
|
|
||||||
{
|
|
||||||
ret << *str;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret << "%"
|
|
||||||
<< std::setw(2)
|
|
||||||
<< (int)static_cast<unsigned char>(*str);
|
|
||||||
}
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
return ret.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct find_peer_by_id
|
struct find_peer_by_id
|
||||||
{
|
{
|
||||||
find_peer_by_id(const peer_id& i, const torrent* t): id(i), tor(t) {}
|
find_peer_by_id(const peer_id& i, const torrent* t): id(i), tor(t) {}
|
||||||
|
@ -207,6 +180,32 @@ namespace
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
std::string escape_string(const char* str, int len)
|
||||||
|
{
|
||||||
|
static const char special_chars[] = "$-_.+!*'(),";
|
||||||
|
|
||||||
|
std::stringstream ret;
|
||||||
|
ret << std::hex << std::setfill('0');
|
||||||
|
for (int i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
if (std::isalnum(static_cast<unsigned char>(*str))
|
||||||
|
|| std::count(
|
||||||
|
special_chars
|
||||||
|
, special_chars+sizeof(special_chars)-1
|
||||||
|
, *str))
|
||||||
|
{
|
||||||
|
ret << *str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret << "%"
|
||||||
|
<< std::setw(2)
|
||||||
|
<< (int)static_cast<unsigned char>(*str);
|
||||||
|
}
|
||||||
|
++str;
|
||||||
|
}
|
||||||
|
return ret.str();
|
||||||
|
}
|
||||||
|
|
||||||
torrent::torrent(
|
torrent::torrent(
|
||||||
detail::session_impl& ses
|
detail::session_impl& ses
|
||||||
|
|
Loading…
Reference in New Issue