*** empty log message ***

This commit is contained in:
Arvid Norberg 2004-01-14 12:53:17 +00:00
parent bbf58b64e5
commit 62f3af5b0f
4 changed files with 56 additions and 70 deletions

View File

@ -59,6 +59,8 @@ namespace libtorrent
struct logger;
#endif
std::string escape_string(const char* str, int len);
struct tracker_alert: alert
{
tracker_alert(const torrent_handle& h

View File

@ -1139,7 +1139,8 @@ namespace libtorrent
// 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 a 1:1 share ratio with all peers.
// maintain the share ratio given by m_ratio
// with all peers.
int diff = share_diff();

View File

@ -210,7 +210,7 @@ namespace
// (and we should consider it free). If the share diff is
// negative, there's no free download to get from this peer.
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;
assert(diff > 0);
@ -233,13 +233,10 @@ namespace
if (free_upload <= 0) return free_upload;
int num_peers = 0;
int total_diff = 0;
for (torrent::peer_iterator i = start; i != end; ++i)
{
int diff=i->second->share_diff();
if(diff==std::numeric_limits<int>::max()) continue;
total_diff += diff;
if (!i->second->is_peer_interested() || diff >= 0) continue;
total_diff += i->second->share_diff();
if (!i->second->is_peer_interested() || i->second->share_diff() >= 0) continue;
++num_peers;
}
@ -305,11 +302,8 @@ namespace libtorrent
if (!c->is_peer_interested())
return &(*i);
// int diff = i->total_download()
// - i->total_upload();
int diff = c->share_diff();
if(diff==std::numeric_limits<int>::max())
diff=0;
int diff = i->total_download()
- i->total_upload();
int weight = static_cast<int>(c->statistics().download_rate() * 10.f)
+ diff
@ -371,6 +365,7 @@ namespace libtorrent
, old_disconnected_peer())
, m_peers.end());
// if the share ratio is 0 (infinite)
// m_available_free_upload isn't used
// because it isn't necessary
@ -417,8 +412,26 @@ namespace libtorrent
++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
// unchoked peers
while (m_num_unchoked > m_max_uploads)
@ -440,40 +453,11 @@ namespace libtorrent
unchoke_one_peer();
}
// make sure we have enough
// unchoked peers
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
check_invariant();

View File

@ -126,33 +126,6 @@ namespace
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
{
find_peer_by_id(const peer_id& i, const torrent* t): id(i), tor(t) {}
@ -207,6 +180,32 @@ namespace
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(
detail::session_impl& ses