fixed strange User-Agent encoding in HTTP requests. Fixed bug in sequenced_download_threshold code

This commit is contained in:
Arvid Norberg 2006-09-03 22:59:54 +00:00
parent e8c43c868f
commit 7bc1214749
4 changed files with 43 additions and 7 deletions

View File

@ -344,8 +344,7 @@ namespace libtorrent
m_send_buffer += " HTTP/1.0\r\nAccept-Encoding: gzip\r\n"
"User-Agent: ";
m_send_buffer += escape_string(m_settings.user_agent.c_str()
, m_settings.user_agent.length());
m_send_buffer += m_settings.user_agent;
m_send_buffer += " (libtorrent)\r\n"
"Host: ";
m_send_buffer += hostname;

View File

@ -162,6 +162,38 @@ namespace libtorrent
move(p.downloading, p.filtered, prev_priority, p.index);
}
}
typedef std::vector<int> info_t;
if (old_limit < sequenced_download_threshold)
{
INVARIANT_CHECK;
assert(int(m_piece_info.size()) > old_limit);
info_t& in = m_piece_info[old_limit];
std::random_shuffle(in.begin(), in.end());
int c = 0;
for (info_t::iterator i = in.begin()
, end(in.end()); i != end; ++i)
{
m_piece_map[*i].index = c++;
assert(m_piece_map[*i].priority(old_limit) == old_limit);
}
}
else if (int(m_piece_info.size()) > sequenced_download_threshold)
{
INVARIANT_CHECK;
assert(int(m_piece_info.size()) > sequenced_download_threshold);
info_t& in = m_piece_info[sequenced_download_threshold];
std::sort(in.begin(), in.end());
int c = 0;
for (info_t::iterator i = in.begin()
, end(in.end()); i != end; ++i)
{
m_piece_map[*i].index = c++;
assert(m_piece_map[*i].priority(
sequenced_download_threshold) == sequenced_download_threshold);
}
}
}
#ifndef NDEBUG
@ -475,7 +507,9 @@ namespace libtorrent
m_piece_map[replace_index].index = elem_index;
assert((int)src_vec[priority].size() > elem_index);
assert((int)m_piece_map[replace_index].priority(m_sequenced_download_threshold) == priority);
// this may not necessarily be the case. If we've just updated the threshold and are updating
// the piece map
// assert((int)m_piece_map[replace_index].priority(m_sequenced_download_threshold) == priority);
assert((int)m_piece_map[replace_index].index == elem_index);
assert(src_vec[priority][elem_index] == replace_index);
}

View File

@ -507,6 +507,11 @@ namespace libtorrent { namespace detail
}
}
m_settings = s;
// replace all occurances of '\n' with ' '.
std::string::iterator i = m_settings.user_agent.begin();
while ((i = std::find(i, m_settings.user_agent.end(), '\n'))
!= m_settings.user_agent.end())
*i = ' ';
}
void session_impl::open_listen_port()

View File

@ -155,8 +155,7 @@ namespace libtorrent
if (m_first_request)
{
request += "\r\nUser-Agent: ";
request += escape_string(m_ses.m_settings.user_agent.c_str()
, m_ses.m_settings.user_agent.size());
request += m_ses.m_settings.user_agent;
}
if (using_proxy && !m_ses.m_settings.proxy_login.empty())
{
@ -209,8 +208,7 @@ namespace libtorrent
if (m_first_request)
{
request += "\r\nUser-Agent: ";
request += escape_string(m_ses.m_settings.user_agent.c_str()
, m_ses.m_settings.user_agent.size());
request += m_ses.m_settings.user_agent;
}
if (using_proxy && !m_ses.m_settings.proxy_login.empty())
{