added tracker IP to tracker_response callback and added filtering of local IPs in pex and tracker responses. #409
This commit is contained in:
parent
58a3f6e4a0
commit
70f4303d92
|
@ -85,7 +85,7 @@ namespace libtorrent
|
||||||
{ return boost::intrusive_ptr<http_tracker_connection>(this); }
|
{ return boost::intrusive_ptr<http_tracker_connection>(this); }
|
||||||
|
|
||||||
void on_filter(http_connection& c, std::list<tcp::endpoint>& endpoints);
|
void on_filter(http_connection& c, std::list<tcp::endpoint>& endpoints);
|
||||||
|
void on_connect(http_connection& c);
|
||||||
void on_response(error_code const& ec, http_parser const& parser
|
void on_response(error_code const& ec, http_parser const& parser
|
||||||
, char const* data, int size);
|
, char const* data, int size);
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ namespace libtorrent
|
||||||
boost::shared_ptr<http_connection> m_tracker_connection;
|
boost::shared_ptr<http_connection> m_tracker_connection;
|
||||||
aux::session_impl const& m_ses;
|
aux::session_impl const& m_ses;
|
||||||
address m_bind_iface;
|
address m_bind_iface;
|
||||||
|
address m_tracker_ip;
|
||||||
proxy_settings const& m_ps;
|
proxy_settings const& m_ps;
|
||||||
connection_queue& m_cc;
|
connection_queue& m_cc;
|
||||||
io_service& m_ios;
|
io_service& m_ios;
|
||||||
|
|
|
@ -373,6 +373,7 @@ namespace libtorrent
|
||||||
// or when a failure occured
|
// or when a failure occured
|
||||||
virtual void tracker_response(
|
virtual void tracker_response(
|
||||||
tracker_request const& r
|
tracker_request const& r
|
||||||
|
, address const& tracker_ip
|
||||||
, std::vector<peer_entry>& e, int interval
|
, std::vector<peer_entry>& e, int interval
|
||||||
, int complete, int incomplete, address const& external_ip);
|
, int complete, int incomplete, address const& external_ip);
|
||||||
virtual void tracker_request_timed_out(
|
virtual void tracker_request_timed_out(
|
||||||
|
|
|
@ -122,6 +122,7 @@ namespace libtorrent
|
||||||
, int complete, int incomplete, int downloads) {}
|
, int complete, int incomplete, int downloads) {}
|
||||||
virtual void tracker_response(
|
virtual void tracker_response(
|
||||||
tracker_request const& req
|
tracker_request const& req
|
||||||
|
, address const& tracker_ip
|
||||||
, std::vector<peer_entry>& peers
|
, std::vector<peer_entry>& peers
|
||||||
, int interval
|
, int interval
|
||||||
, int complete
|
, int complete
|
||||||
|
|
|
@ -178,7 +178,8 @@ namespace libtorrent
|
||||||
|
|
||||||
m_tracker_connection.reset(new http_connection(m_ios, m_cc
|
m_tracker_connection.reset(new http_connection(m_ios, m_cc
|
||||||
, boost::bind(&http_tracker_connection::on_response, self(), _1, _2, _3, _4)
|
, boost::bind(&http_tracker_connection::on_response, self(), _1, _2, _3, _4)
|
||||||
, true, http_connect_handler()
|
, true
|
||||||
|
, boost::bind(&http_tracker_connection::on_connect, self(), _1)
|
||||||
, boost::bind(&http_tracker_connection::on_filter, self(), _1, _2)));
|
, boost::bind(&http_tracker_connection::on_filter, self(), _1, _2)));
|
||||||
|
|
||||||
int timeout = tracker_req().event==tracker_request::stopped
|
int timeout = tracker_req().event==tracker_request::stopped
|
||||||
|
@ -223,6 +224,15 @@ namespace libtorrent
|
||||||
fail(-1, "blocked by IP filter");
|
fail(-1, "blocked by IP filter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void http_tracker_connection::on_connect(http_connection& c)
|
||||||
|
{
|
||||||
|
error_code ec;
|
||||||
|
tcp::endpoint ep = c.socket().remote_endpoint(ec);
|
||||||
|
m_tracker_ip = ep.address();
|
||||||
|
boost::shared_ptr<request_callback> cb = requester();
|
||||||
|
if (cb) cb->m_tracker_address = ep;
|
||||||
|
}
|
||||||
|
|
||||||
void http_tracker_connection::on_response(error_code const& ec
|
void http_tracker_connection::on_response(error_code const& ec
|
||||||
, http_parser const& parser, char const* data, int size)
|
, http_parser const& parser, char const* data, int size)
|
||||||
{
|
{
|
||||||
|
@ -466,7 +476,7 @@ namespace libtorrent
|
||||||
if (incomplete_ent && incomplete_ent->type() == entry::int_t)
|
if (incomplete_ent && incomplete_ent->type() == entry::int_t)
|
||||||
incomplete = int(incomplete_ent->integer());
|
incomplete = int(incomplete_ent->integer());
|
||||||
|
|
||||||
cb->tracker_response(tracker_req(), peer_list, interval->integer(), complete
|
cb->tracker_response(tracker_req(), m_tracker_ip, peer_list, interval->integer(), complete
|
||||||
, incomplete, external_ip);
|
, incomplete, external_ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1020,6 +1020,7 @@ namespace libtorrent
|
||||||
|
|
||||||
void torrent::tracker_response(
|
void torrent::tracker_response(
|
||||||
tracker_request const& r
|
tracker_request const& r
|
||||||
|
, address const& tracker_ip
|
||||||
, std::vector<peer_entry>& peer_list
|
, std::vector<peer_entry>& peer_list
|
||||||
, int interval
|
, int interval
|
||||||
, int complete
|
, int complete
|
||||||
|
@ -1098,6 +1099,8 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// ignore local addresses from the tracker (unless the tracker is local too)
|
||||||
|
if (is_local(a.address()) && !is_local(tracker_ip)) continue;
|
||||||
m_policy.peer_from_tracker(a, i->pid, peer_info::tracker, 0);
|
m_policy.peer_from_tracker(a, i->pid, peer_info::tracker, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,7 +417,7 @@ namespace libtorrent
|
||||||
peer_list.push_back(e);
|
peer_list.push_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
cb->tracker_response(tracker_req(), peer_list, interval
|
cb->tracker_response(tracker_req(), m_target.address(), peer_list, interval
|
||||||
, complete, incomplete, address());
|
, complete, incomplete, address());
|
||||||
|
|
||||||
m_man.remove_request(this);
|
m_man.remove_request(this);
|
||||||
|
|
|
@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
#include "libtorrent/torrent.hpp"
|
#include "libtorrent/torrent.hpp"
|
||||||
#include "libtorrent/extensions.hpp"
|
#include "libtorrent/extensions.hpp"
|
||||||
|
#include "libtorrent/broadcast_socket.hpp"
|
||||||
|
|
||||||
#include "libtorrent/extensions/ut_pex.hpp"
|
#include "libtorrent/extensions/ut_pex.hpp"
|
||||||
|
|
||||||
|
@ -258,6 +259,8 @@ namespace libtorrent { namespace
|
||||||
{
|
{
|
||||||
tcp::endpoint adr = detail::read_v4_endpoint<tcp::endpoint>(in);
|
tcp::endpoint adr = detail::read_v4_endpoint<tcp::endpoint>(in);
|
||||||
char flags = *fin++;
|
char flags = *fin++;
|
||||||
|
// ignore local addresses unless the peer is local to us
|
||||||
|
if (is_local(adr.address()) && !is_local(m_pc.remote().address())) continue;
|
||||||
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,6 +283,8 @@ namespace libtorrent { namespace
|
||||||
{
|
{
|
||||||
tcp::endpoint adr = detail::read_v6_endpoint<tcp::endpoint>(in);
|
tcp::endpoint adr = detail::read_v6_endpoint<tcp::endpoint>(in);
|
||||||
char flags = *fin++;
|
char flags = *fin++;
|
||||||
|
// ignore local addresses unless the peer is local to us
|
||||||
|
if (is_local(adr.address()) && !is_local(m_pc.remote().address())) continue;
|
||||||
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue