diff --git a/ChangeLog b/ChangeLog index b31aba9ce..8b96c3cca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * added support for parsing new x.pe parameter from BEP 9 * peer_blocked_alert now derives from peer_alert * transitioned exception types to system_error * made alerts move-only diff --git a/include/libtorrent/receive_buffer.hpp b/include/libtorrent/receive_buffer.hpp index 1c60faaa1..773379500 100644 --- a/include/libtorrent/receive_buffer.hpp +++ b/include/libtorrent/receive_buffer.hpp @@ -79,7 +79,7 @@ struct TORRENT_EXTRA_EXPORT receive_buffer // with possible disk buffer usage int reserve(std::array& vec, int size); - // tell the buffer we just receved more bytes at the end of it. This will + // tell the buffer we just received more bytes at the end of it. This will // advance the end cursor void received(int bytes_transferred) { @@ -96,7 +96,7 @@ struct TORRENT_EXTRA_EXPORT receive_buffer // has the read cursor reached the end cursor? bool pos_at_end() { return m_recv_pos == m_recv_end; } - // make the buffer size dividible by 8 bytes (RC4 block size) + // make the buffer size divisible by 8 bytes (RC4 block size) void clamp_size(); void set_soft_packet_size(int size) { m_soft_packet_size = size; } diff --git a/include/libtorrent/string_util.hpp b/include/libtorrent/string_util.hpp index 2f2de1964..fde938bc7 100644 --- a/include/libtorrent/string_util.hpp +++ b/include/libtorrent/string_util.hpp @@ -74,7 +74,7 @@ namespace libtorrent bool ssl; }; - // this parses the string that's used as the liste_interfaces setting. + // this parses the string that's used as the listen_interfaces setting. // it is a comma-separated list of IP or device names with ports. For // example: "eth0:6881,eth1:6881" or "127.0.0.1:6881" TORRENT_EXTRA_EXPORT void parse_listen_interfaces( diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index 5cca31ed1..daf6efe8e 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -32,15 +32,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/magnet_uri.hpp" #include "libtorrent/session.hpp" -#include "libtorrent/torrent_handle.hpp" #include "libtorrent/aux_/escape_string.hpp" -#include "libtorrent/error_code.hpp" #include "libtorrent/torrent_status.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/announce_entry.hpp" #include "libtorrent/hex.hpp" // to_hex, from_hex - -#include +#include "libtorrent/socket_io.hpp" namespace libtorrent { @@ -230,6 +227,21 @@ namespace libtorrent return; } + std::string::size_type peer_pos = std::string::npos; + std::string peer = url_has_argument(uri, "x.pe", &peer_pos); + while (!peer.empty()) + { + error_code e; + tcp::endpoint endp = parse_endpoint(peer, e); + if (!e) + p.peers.push_back(endp); + + peer_pos = uri.find("&x.pe=", peer_pos); + if (peer_pos == std::string::npos) break; + peer_pos += 6; + peer = uri.substr(peer_pos, uri.find('&', peer_pos) - peer_pos); + } + #ifndef TORRENT_DISABLE_DHT std::string::size_type node_pos = std::string::npos; std::string node = url_has_argument(uri, "dht", &node_pos); @@ -238,7 +250,7 @@ namespace libtorrent std::string::size_type divider = node.find_last_of(':'); if (divider != std::string::npos) { - int port = atoi(node.c_str()+divider+1); + int port = atoi(node.c_str() + divider + 1); if (port != 0) p.dht_nodes.push_back(std::make_pair(node.substr(0, divider), port)); } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 74c098b2c..973ac77a7 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -112,11 +112,11 @@ const rlim_t rlim_infinity = RLIM_INFINITY; #include "libtorrent/error.hpp" #include "libtorrent/platform_util.hpp" #include "libtorrent/aux_/bind_to_device.hpp" +#include "libtorrent/hex.hpp" // to_hex, from_hex #ifndef TORRENT_DISABLE_LOGGING #include "libtorrent/socket_io.hpp" -#include "libtorrent/hex.hpp" // to_hex, from_hex // for logging stat layout #include "libtorrent/stat.hpp" diff --git a/src/string_util.cpp b/src/string_util.cpp index c51652993..cdcee3273 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -205,7 +205,7 @@ namespace libtorrent return ret; } - // this parses the string that's used as the liste_interfaces setting. + // this parses the string that's used as the listen_interfaces setting. // it is a comma-separated list of IP or device names with ports. For // example: "eth0:6881,eth1:6881" or "127.0.0.1:6881" void parse_listen_interfaces(std::string const& in diff --git a/test/test_magnet.cpp b/test/test_magnet.cpp index 08049d3ba..f58a42d50 100644 --- a/test/test_magnet.cpp +++ b/test/test_magnet.cpp @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "test.hpp" +#include "setup_transfer.hpp" #include "libtorrent/magnet_uri.hpp" #include "libtorrent/session.hpp" #include "libtorrent/torrent_handle.hpp" @@ -279,6 +280,23 @@ TORRENT_TEST(parse_space_hash) ec.clear(); } +TORRENT_TEST(parse_peer) +{ + error_code ec; + add_torrent_params p; + parse_magnet_uri("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd&dn=foo&x.pe=127.0.0.1:43&x.pe=&x.pe=:100&x.pe=[::1]:45", p, ec); + TEST_CHECK(!ec); +#if TORRENT_USE_IPV6 + TEST_EQUAL(p.peers.size(), 2); + TEST_EQUAL(p.peers[0], ep("127.0.0.1", 43)); + TEST_EQUAL(p.peers[1], ep("::1", 45)); +#else + TEST_EQUAL(p.peers.size(), 1); + TEST_EQUAL(p.peers[0], ep("127.0.0.1", 43)); +#endif + ec.clear(); +} + #ifndef TORRENT_DISABLE_DHT TORRENT_TEST(parse_dht_node) {