*** empty log message ***

This commit is contained in:
Arvid Norberg 2003-12-08 01:37:30 +00:00
parent 5e0dbf78b0
commit 3ed0745cb1
6 changed files with 47 additions and 20 deletions

View File

@ -133,6 +133,17 @@ void clear()
#endif
std::string to_string(float v)
{
std::stringstream s;
s.precision(4);
s.flags(std::ios_base::right);
s.width(5);
s.fill(' ');
s << v;
return s.str();
}
std::string add_suffix(float val)
{
const char* prefix[] = {"B ", "kB", "MB", "GB", "TB"};
@ -141,10 +152,10 @@ std::string add_suffix(float val)
for (i = 0; i < num_prefix; ++i)
{
if (val < 1024.f)
return boost::lexical_cast<std::string>(val) + prefix[i];
return to_string(val) + prefix[i];
val /= 1024.f;
}
return boost::lexical_cast<std::string>(val) + prefix[i];
return to_string(val) + prefix[i];
}
int main(int argc, char* argv[])
@ -252,14 +263,14 @@ int main(int argc, char* argv[])
boost::posix_time::time_duration t = s.next_announce;
// std::cout << "next announce: " << boost::posix_time::to_simple_string(t) << "\n";
std::cout << "next announce: " << t.hours() << ":" << t.minutes() << ":" << t.seconds() << "\n";
/*
for (std::vector<peer_info>::iterator i = peers.begin();
i != peers.end();
++i)
{
std::cout << "d: " << add_suffix(i->down_speed) << "/s (" << add_suffix(i->total_download)
<< ") u: " << add_suffix(i->up_speed) << "/s (" << add_suffix(i->total_upload)
<< ") ratio: " << static_cast<float>(i->total_upload+1) / static_cast<float>(i->total_download+1)
<< ") diff: " << add_suffix(i->total_download - i->total_upload)
<< " flags: "
<< static_cast<const char*>((i->flags & peer_info::interesting)?"I":"_")
<< static_cast<const char*>((i->flags & peer_info::choked)?"C":"_")
@ -267,8 +278,8 @@ int main(int argc, char* argv[])
<< static_cast<const char*>((i->flags & peer_info::remote_choked)?"c":"_") << "\n";
}
*/
/*
i->get_download_queue(queue);
for (std::vector<partial_piece_info>::iterator i = queue.begin();
i != queue.end();
@ -283,7 +294,7 @@ int main(int argc, char* argv[])
}
std::cout << "\n";
}
*/
std::cout << "___________________________________\n";
}

View File

@ -342,6 +342,7 @@ namespace libtorrent
// this peer given the current download rate
// and the current share ratio with this peer.
// this limit will maintain a 1:1 share ratio.
// -1 means no limit
int m_send_quota_limit;
// for every valid piece we receive where this
@ -369,6 +370,7 @@ namespace libtorrent
return;
}
assert(m_send_quota_left > 0 || m_send_quota_left == -1);
assert(has_data());
if (!m_added_to_selector)
{

View File

@ -762,15 +762,27 @@ void libtorrent::peer_connection::second_tick()
// both peers uses this technique! It could be
// enough to just have a constant positive bias
// of the send_quota_limit
int bias = (static_cast<int>(m_statistics.total_download())
- static_cast<int>(m_statistics.total_upload())) / 1024;
int diff = static_cast<int>(m_statistics.total_download())
- static_cast<int>(m_statistics.total_upload());
if (diff > m_torrent->torrent_file().piece_length())
{
// if we have downloaded more than one piece more
// than we have uploaded, have an unlimited
// upload rate
m_send_quota = -1;
}
else
{
// if we have downloaded too much, response with an
// upload rate of 10 kB/s more than we dowlload
// if we have uploaded too much, send with a rate of
// 10 kB/s less than we receive
int bias = (diff > 0 ? 10 : -10) * 1024;
// the maximum send_quota given our download rate from this peer
int m_send_quota_limit = m_statistics.download_rate() + bias;
m_send_quota_limit = m_statistics.download_rate() + bias;
if (m_send_quota_limit < 500) m_send_quota_limit = 500;
// TODO: temporary
m_send_quota_limit = 1024*1024;
}
}
// --------------------------

View File

@ -93,7 +93,7 @@ namespace
return;
}
// TODO: IMPLEMENT!
// TODO: upload limit support is currently broken
assert(false);

View File

@ -1427,7 +1427,8 @@ namespace libtorrent {
in.read(buf + buf_pos, read_bytes);
assert(read_bytes == in.gcount());
int actual_read = in.gcount();
assert(read_bytes == actual_read);
left_to_read -= read_bytes;
buf_pos += read_bytes;
@ -1590,7 +1591,7 @@ namespace libtorrent {
std::vector<char> piece_data(m_info.piece_length());
std::size_t piece_offset = 0;
std::size_t current_piece = 0;
int current_piece = 0;
std::size_t bytes_to_read = piece_size;
std::size_t bytes_current_read = 0;
std::size_t seek_into_next = 0;
@ -1679,6 +1680,7 @@ namespace libtorrent {
{
m_unallocated_slots.push_back(current_piece);
++current_piece;
assert(current_piece <= m_info.num_pieces());
}
seek_into_next = pos - file_end;

View File

@ -376,12 +376,12 @@ namespace libtorrent
const entry::dictionary_type& msg = e.dict();
i = msg.find("interval");
if (i == msg.end()) throw std::runtime_error("invalid response from tracker");
if (i == msg.end()) throw std::runtime_error("invalid response from tracker (no interval)");
m_duration = i->second.integer();
i = msg.find("peers");
if (i == msg.end()) throw std::runtime_error("invalid response from tracker");
if (i == msg.end()) throw std::runtime_error("invalid response from tracker (no peers)");
peer_list.clear();