forked from premiere/premiere-libtorrent
Ported support for magnet x.pe parameter from master (#760)
This commit is contained in:
parent
10393697cb
commit
f8dcf30b2e
|
@ -1,6 +1,7 @@
|
|||
1.1.1 release
|
||||
|
||||
* fixed parsing of IPv6 endpoint with invalid port character separator
|
||||
* added limited support for new x.pe parameter from BEP 9
|
||||
* fixed dht stats counters that weren't being updated
|
||||
* make sure add_torrent_alert is always posted before other alerts for
|
||||
the torrent
|
||||
|
|
|
@ -78,6 +78,9 @@ namespace libtorrent
|
|||
// This function parses out information from the magnet link and populates the
|
||||
// add_torrent_params object.
|
||||
TORRENT_EXPORT void parse_magnet_uri(std::string const& uri, add_torrent_params& p, error_code& ec);
|
||||
|
||||
// internal, delete when merge in master
|
||||
TORRENT_EXTRA_EXPORT void parse_magnet_uri_peers(std::string const& uri, std::vector<tcp::endpoint>& peers);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/announce_entry.hpp"
|
||||
|
||||
#include <string>
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
@ -270,6 +271,24 @@ namespace libtorrent
|
|||
p.info_hash = info_hash;
|
||||
if (!name.empty()) p.name = name;
|
||||
}
|
||||
|
||||
void parse_magnet_uri_peers(std::string const& uri, std::vector<tcp::endpoint>& peers)
|
||||
{
|
||||
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)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4785,6 +4785,19 @@ retry:
|
|||
add_torrent_params params = p;
|
||||
boost::shared_ptr<torrent> const torrent_ptr = add_torrent_impl(params, ec);
|
||||
|
||||
// --- PEERS --- (delete when merged to master)
|
||||
std::vector<tcp::endpoint> peers;
|
||||
parse_magnet_uri_peers(p.url, peers);
|
||||
|
||||
for (std::vector<tcp::endpoint>::const_iterator i = peers.begin()
|
||||
, end(peers.end()); i != end; ++i)
|
||||
{
|
||||
torrent_ptr->add_peer(*i , peer_info::resume_data);
|
||||
}
|
||||
|
||||
if (!peers.empty())
|
||||
torrent_ptr->update_want_peers();
|
||||
|
||||
torrent_handle const handle(torrent_ptr);
|
||||
m_alerts.emplace_alert<add_torrent_alert>(handle, params, ec);
|
||||
|
||||
|
|
|
@ -11579,6 +11579,7 @@ namespace libtorrent
|
|||
{
|
||||
if (!m_apply_ip_filter) return;
|
||||
if (!m_peer_list) return;
|
||||
if (!m_ip_filter) return;
|
||||
|
||||
torrent_state st = get_peer_list_state();
|
||||
std::vector<address> banned;
|
||||
|
|
|
@ -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"
|
||||
|
@ -276,6 +277,20 @@ TORRENT_TEST(parse_space_hash)
|
|||
ec.clear();
|
||||
}
|
||||
|
||||
TORRENT_TEST(parse_peer)
|
||||
{
|
||||
std::vector<tcp::endpoint> peers;
|
||||
parse_magnet_uri_peers("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd&dn=foo&x.pe=127.0.0.1:43&x.pe=<invalid1>&x.pe=<invalid2>:100&x.pe=[::1]:45", peers);
|
||||
#if TORRENT_USE_IPV6
|
||||
TEST_EQUAL(peers.size(), 2);
|
||||
TEST_EQUAL(peers[0], ep("127.0.0.1", 43));
|
||||
TEST_EQUAL(peers[1], ep("::1", 45));
|
||||
#else
|
||||
TEST_EQUAL(peers.size(), 1);
|
||||
TEST_EQUAL(peers[0], ep("127.0.0.1", 43));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
TORRENT_TEST(parse_dht_node)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/torrent.hpp"
|
||||
#include "libtorrent/peer_info.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <iostream>
|
||||
|
@ -212,6 +213,36 @@ TORRENT_TEST(total_wanted)
|
|||
TEST_EQUAL(st.total_wanted_done, 0);
|
||||
}
|
||||
|
||||
TORRENT_TEST(added_peers)
|
||||
{
|
||||
file_storage fs;
|
||||
|
||||
fs.add_file("test_torrent_dir4/tmp1", 1024);
|
||||
|
||||
libtorrent::create_torrent t(fs, 1024);
|
||||
std::vector<char> tmp;
|
||||
bencode(std::back_inserter(tmp), t.generate());
|
||||
error_code ec;
|
||||
boost::shared_ptr<torrent_info> info(boost::make_shared<torrent_info>(
|
||||
&tmp[0], tmp.size(), boost::ref(ec)));
|
||||
|
||||
settings_pack pack;
|
||||
pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:48130");
|
||||
pack.set_int(settings_pack::max_retry_port_bind, 10);
|
||||
lt::session ses(pack);
|
||||
|
||||
add_torrent_params p;
|
||||
p.ti = info;
|
||||
p.save_path = ".";
|
||||
p.url = "?x.pe=127.0.0.1:48081&x.pe=127.0.0.2:48082";
|
||||
|
||||
torrent_handle h = ses.add_torrent(p);
|
||||
|
||||
std::vector<peer_list_entry> v;
|
||||
h.get_full_peer_list(v);
|
||||
TEST_EQUAL(v.size(), 2);
|
||||
}
|
||||
|
||||
TORRENT_TEST(torrent)
|
||||
{
|
||||
/* {
|
||||
|
|
Loading…
Reference in New Issue