fix up i2p merge

This commit is contained in:
arvidn 2015-08-13 22:22:20 -04:00
parent 68bc4f2cf4
commit 2c89fa40e2
2 changed files with 13 additions and 9 deletions

View File

@ -115,7 +115,7 @@ namespace libtorrent
url += "?"; url += "?";
url += "info_hash="; url += "info_hash=";
url += escape_string((const char*)&tracker_req().info_hash[0], 20); url += escape_string(tracker_req().info_hash.data(), 20);
if (0 == (tracker_req().kind & tracker_request::scrape_request)) if (0 == (tracker_req().kind & tracker_request::scrape_request))
{ {
@ -135,7 +135,7 @@ namespace libtorrent
"&numwant=%d" "&numwant=%d"
"&compact=1" "&compact=1"
"&no_peer_id=1" "&no_peer_id=1"
, escape_string((const char*)&tracker_req().pid[0], 20).c_str() , escape_string(tracker_req().pid.data(), 20).c_str()
// the i2p tracker seems to verify that the port is not 0, // the i2p tracker seems to verify that the port is not 0,
// even though it ignores it otherwise // even though it ignores it otherwise
, i2p ? 1 : tracker_req().listen_port , i2p ? 1 : tracker_req().listen_port
@ -169,10 +169,15 @@ namespace libtorrent
if (i2p && tracker_req().i2pconn) if (i2p && tracker_req().i2pconn)
{ {
if (tracker_req().i2pconn->local_endpoint().empty()) if (tracker_req().i2pconn->local_endpoint().empty())
{
fail(error_code(errors::no_i2p_endpoint), -1, "Waiting for i2p acceptor from SAM bridge", 5); fail(error_code(errors::no_i2p_endpoint), -1, "Waiting for i2p acceptor from SAM bridge", 5);
return;
}
else else
{
url += "&ip=" + tracker_req ().i2pconn->local_endpoint () + ".i2p"; url += "&ip=" + tracker_req ().i2pconn->local_endpoint () + ".i2p";
} }
}
else else
#endif #endif
if (!settings.get_bool(settings_pack::anonymous_mode)) if (!settings.get_bool(settings_pack::anonymous_mode))
@ -363,9 +368,9 @@ namespace libtorrent
std::list<address> ip_list; std::list<address> ip_list;
if (m_tracker_connection) if (m_tracker_connection)
{ {
error_code ec; error_code ignore;
ip_list.push_back( ip_list.push_back(
m_tracker_connection->socket().remote_endpoint(ec).address()); m_tracker_connection->socket().remote_endpoint(ignore).address());
std::vector<tcp::endpoint> const& epts = m_tracker_connection->endpoints(); std::vector<tcp::endpoint> const& epts = m_tracker_connection->endpoints();
for (std::vector<tcp::endpoint>::const_iterator i = epts.begin() for (std::vector<tcp::endpoint>::const_iterator i = epts.begin()
, end(epts.end()); i != end; ++i) , end(epts.end()); i != end; ++i)
@ -416,7 +421,7 @@ namespace libtorrent
ec.assign(errors::invalid_tracker_response, get_libtorrent_category()); ec.assign(errors::invalid_tracker_response, get_libtorrent_category());
return false; return false;
} }
ret.port = (unsigned short)i.int_value(); ret.port = boost::uint16_t(i.int_value());
return true; return true;
} }
@ -521,7 +526,6 @@ namespace libtorrent
if (len - i < 6) break; if (len - i < 6) break;
ipv4_peer_entry p; ipv4_peer_entry p;
error_code ec;
p.ip = detail::read_v4_address(peers).to_v4().to_bytes(); p.ip = detail::read_v4_address(peers).to_v4().to_bytes();
p.port = detail::read_uint16(peers); p.port = detail::read_uint16(peers);
resp.peers4.push_back(p); resp.peers4.push_back(p);

View File

@ -104,7 +104,7 @@ TORRENT_TEST(parse_peers4)
TORRENT_TEST(parse_i2p_peers) TORRENT_TEST(parse_i2p_peers)
{ {
// d8:completei8e10:incompletei4e8:intervali3600e5:peers352: ... // d8:completei8e10:incompletei4e8:intervali3600e5:peers352: ...
char const response[] = { 0x64, 0x38, 0x3a, 0x63, 0x6f, 0x6d, boost::uint8_t const response[] = { 0x64, 0x38, 0x3a, 0x63, 0x6f, 0x6d,
0x70, 0x6c, 0x65, 0x74, 0x65, 0x69, 0x38, 0x65, 0x31, 0x30, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x69, 0x38, 0x65, 0x31, 0x30,
0x3a, 0x69, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x3a, 0x69, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74,
0x65, 0x69, 0x34, 0x65, 0x38, 0x3a, 0x69, 0x6e, 0x74, 0x65, 0x65, 0x69, 0x34, 0x65, 0x38, 0x3a, 0x69, 0x6e, 0x74, 0x65,
@ -147,7 +147,8 @@ TORRENT_TEST(parse_i2p_peers)
0xc2, 0x8a, 0x22, 0x6b, 0x47, 0xc1, 0xd1, 0x52, 0x61, 0x66, 0xc2, 0x8a, 0x22, 0x6b, 0x47, 0xc1, 0xd1, 0x52, 0x61, 0x66,
0xa0, 0x75, 0xab, 0x65 }; 0xa0, 0x75, 0xab, 0x65 };
error_code ec; error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) tracker_response resp = parse_tracker_response(
reinterpret_cast<char const*>(response), sizeof(response)
, ec, tracker_request::i2p, sha1_hash()); , ec, tracker_request::i2p, sha1_hash());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
@ -156,7 +157,6 @@ TORRENT_TEST(parse_i2p_peers)
if (resp.peers.size() == 11) if (resp.peers.size() == 11)
{ {
TEST_EQUAL(resp.peers[0].hostname, "wgcobfq73pzmtmcttiy2knon5bm2a7gn6j6idaiccf53ikwrecdq.b32.i2p"); TEST_EQUAL(resp.peers[0].hostname, "wgcobfq73pzmtmcttiy2knon5bm2a7gn6j6idaiccf53ikwrecdq.b32.i2p");
// TEST_EQUAL(resp.peers[9].hostname, "cbmvhhhgdmxha4toqj5qhphse2n3henk6g5geev3orfxardudgza.b32.i2p");
TEST_EQUAL(resp.peers[10].hostname, "ufunemgwuun5t2sn3oay4zv7jvwdezwcrirgwr6b2fjgczvaowvq.b32.i2p"); TEST_EQUAL(resp.peers[10].hostname, "ufunemgwuun5t2sn3oay4zv7jvwdezwcrirgwr6b2fjgczvaowvq.b32.i2p");
} }
} }