minor http related code cleanup (#1212)
This commit is contained in:
parent
540b5b28d7
commit
8839722bec
|
@ -119,7 +119,7 @@ namespace libtorrent
|
||||||
bool connection_close() const { return m_connection_close; }
|
bool connection_close() const { return m_connection_close; }
|
||||||
|
|
||||||
std::multimap<std::string, std::string> const& headers() const { return m_header; }
|
std::multimap<std::string, std::string> const& headers() const { return m_header; }
|
||||||
std::vector<std::pair<std::int64_t, std::int64_t> > const& chunks() const { return m_chunked_ranges; }
|
std::vector<std::pair<std::int64_t, std::int64_t>> const& chunks() const { return m_chunked_ranges; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::int64_t m_recv_pos = 0;
|
std::int64_t m_recv_pos = 0;
|
||||||
|
|
|
@ -497,7 +497,7 @@ namespace libtorrent
|
||||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
char random_byte() { return random(0xff); }
|
char random_byte() { return char(random(0xff)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_peer_connection::write_pe1_2_dhkey()
|
void bt_peer_connection::write_pe1_2_dhkey()
|
||||||
|
@ -2572,7 +2572,7 @@ namespace libtorrent
|
||||||
|
|
||||||
int sub_transferred = 0;
|
int sub_transferred = 0;
|
||||||
while (bytes_transferred > 0 &&
|
while (bytes_transferred > 0 &&
|
||||||
((sub_transferred = int(m_recv_buffer.advance_pos(int(bytes_transferred)))) > 0))
|
((sub_transferred = m_recv_buffer.advance_pos(int(bytes_transferred))) > 0))
|
||||||
{
|
{
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
std::int64_t cur_payload_dl = m_statistics.last_payload_downloaded();
|
std::int64_t cur_payload_dl = m_statistics.last_payload_downloaded();
|
||||||
|
|
|
@ -395,7 +395,7 @@ void http_connection::start(std::string const& hostname, int port
|
||||||
|| ps->type == settings_pack::socks5_pw))
|
|| ps->type == settings_pack::socks5_pw))
|
||||||
{
|
{
|
||||||
m_hostname = hostname;
|
m_hostname = hostname;
|
||||||
m_port = port;
|
m_port = std::uint16_t(port);
|
||||||
m_endpoints.push_back(tcp::endpoint(address(), port));
|
m_endpoints.push_back(tcp::endpoint(address(), port));
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
@ -407,7 +407,7 @@ void http_connection::start(std::string const& hostname, int port
|
||||||
, me, _1, _2));
|
, me, _1, _2));
|
||||||
}
|
}
|
||||||
m_hostname = hostname;
|
m_hostname = hostname;
|
||||||
m_port = port;
|
m_port = std::uint16_t(port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,8 +218,8 @@ restart_response:
|
||||||
|
|
||||||
while (newline != recv_buffer.end() && m_state == read_header)
|
while (newline != recv_buffer.end() && m_state == read_header)
|
||||||
{
|
{
|
||||||
// if the LF character is preceeded by a CR
|
// if the LF character is preceded by a CR
|
||||||
// charachter, don't copy it into the line string.
|
// character, don't copy it into the line string.
|
||||||
char const* line_end = newline;
|
char const* line_end = newline;
|
||||||
if (pos != line_end && *(line_end - 1) == '\r') --line_end;
|
if (pos != line_end && *(line_end - 1) == '\r') --line_end;
|
||||||
line.assign(pos, line_end);
|
line.assign(pos, line_end);
|
||||||
|
@ -473,8 +473,8 @@ restart_response:
|
||||||
std::string line;
|
std::string line;
|
||||||
while (newline != buf.end())
|
while (newline != buf.end())
|
||||||
{
|
{
|
||||||
// if the LF character is preceeded by a CR
|
// if the LF character is preceded by a CR
|
||||||
// charachter, don't copy it into the line string.
|
// character, don't copy it into the line string.
|
||||||
char const* line_end = newline;
|
char const* line_end = newline;
|
||||||
if (pos != line_end && *(line_end - 1) == '\r') --line_end;
|
if (pos != line_end && *(line_end - 1) == '\r') --line_end;
|
||||||
line.assign(pos, line_end);
|
line.assign(pos, line_end);
|
||||||
|
@ -492,11 +492,10 @@ restart_response:
|
||||||
// the newline alone is two bytes
|
// the newline alone is two bytes
|
||||||
TORRENT_ASSERT(newline - buf.data() > 2);
|
TORRENT_ASSERT(newline - buf.data() > 2);
|
||||||
|
|
||||||
// we were successfull in parsing the headers.
|
// we were successful in parsing the headers.
|
||||||
// add them to the headers in the parser
|
// add them to the headers in the parser
|
||||||
for (std::map<std::string, std::string>::const_iterator i = tail_headers.begin();
|
for (auto const& p : tail_headers)
|
||||||
i != tail_headers.end(); ++i)
|
m_header.insert(p);
|
||||||
m_header.insert(std::make_pair(i->first, i->second));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -561,15 +560,13 @@ restart_response:
|
||||||
// buffer, not start of the body, so subtract the size
|
// buffer, not start of the body, so subtract the size
|
||||||
// of the HTTP header from them
|
// of the HTTP header from them
|
||||||
int const offset = body_start();
|
int const offset = body_start();
|
||||||
std::vector<std::pair<std::int64_t, std::int64_t> > const& c = chunks();
|
for (auto const& i : chunks())
|
||||||
for (std::vector<std::pair<std::int64_t, std::int64_t> >::const_iterator i = c.begin()
|
|
||||||
, end(c.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(i->second - i->first < (std::numeric_limits<int>::max)());
|
TORRENT_ASSERT(i.second - i.first < (std::numeric_limits<int>::max)());
|
||||||
TORRENT_ASSERT(i->second - offset <= size);
|
TORRENT_ASSERT(i.second - offset <= size);
|
||||||
int len = int(i->second - i->first);
|
int len = int(i.second - i.first);
|
||||||
if (i->first - offset + len > size) len = size - int(i->first) + offset;
|
if (i.first - offset + len > size) len = size - int(i.first) + offset;
|
||||||
memmove(write_ptr, buffer + i->first - offset, len);
|
std::memmove(write_ptr, buffer + i.first - offset, len);
|
||||||
write_ptr += len;
|
write_ptr += len;
|
||||||
}
|
}
|
||||||
size = write_ptr - buffer;
|
size = write_ptr - buffer;
|
||||||
|
|
|
@ -412,7 +412,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
if (!m_parser.finished()) return;
|
if (!m_parser.finished()) return;
|
||||||
|
|
||||||
int retry_time = atol(std::string(recv_buffer.begin(), recv_buffer.end()).c_str());
|
int retry_time = std::atoi(std::string(recv_buffer.begin(), recv_buffer.end()).c_str());
|
||||||
if (retry_time <= 0) retry_time = 60;
|
if (retry_time <= 0) retry_time = 60;
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
peer_log(peer_log_alert::info, "CONNECT", "retrying in %d seconds", retry_time);
|
peer_log(peer_log_alert::info, "CONNECT", "retrying in %d seconds", retry_time);
|
||||||
|
|
|
@ -289,7 +289,6 @@ namespace libtorrent
|
||||||
error_code ec;
|
error_code ec;
|
||||||
tcp::endpoint ep = c.socket().remote_endpoint(ec);
|
tcp::endpoint ep = c.socket().remote_endpoint(ec);
|
||||||
m_tracker_ip = ep.address();
|
m_tracker_ip = ep.address();
|
||||||
std::shared_ptr<request_callback> cb = requester();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void http_tracker_connection::on_response(error_code const& ec
|
void http_tracker_connection::on_response(error_code const& ec
|
||||||
|
@ -493,7 +492,6 @@ namespace libtorrent
|
||||||
#if TORRENT_USE_I2P
|
#if TORRENT_USE_I2P
|
||||||
if (0 != (flags & tracker_request::i2p))
|
if (0 != (flags & tracker_request::i2p))
|
||||||
{
|
{
|
||||||
error_code parse_error;
|
|
||||||
for (int i = 0; i < len; i += 32)
|
for (int i = 0; i < len; i += 32)
|
||||||
{
|
{
|
||||||
if (len - i < 32) break;
|
if (len - i < 32) break;
|
||||||
|
|
Loading…
Reference in New Issue