lt sync 1912

This commit is contained in:
Marcos Pinto 2008-01-08 05:59:58 +00:00
parent e0fc7f3d2e
commit 7b39f7adf5
4 changed files with 40 additions and 3 deletions

View File

@ -117,6 +117,7 @@ namespace libtorrent
, use_dht_as_fallback(true) , use_dht_as_fallback(true)
#endif #endif
, free_torrent_hashes(true) , free_torrent_hashes(true)
, upnp_ignore_nonrouters(true)
{} {}
// this is the user agent that will be sent to the tracker // this is the user agent that will be sent to the tracker
@ -292,6 +293,11 @@ namespace libtorrent
// make the get_torrent_info() function to return an incomplete // make the get_torrent_info() function to return an incomplete
// torrent object that cannot be passed back to add_torrent() // torrent object that cannot be passed back to add_torrent()
bool free_torrent_hashes; bool free_torrent_hashes;
// when this is true, the upnp port mapper will ignore
// any upnp devices that don't have an address that matches
// our currently configured router.
bool upnp_ignore_nonrouters;
}; };
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT

View File

@ -68,7 +68,7 @@ class upnp : public intrusive_ptr_base<upnp>
public: public:
upnp(io_service& ios, connection_queue& cc upnp(io_service& ios, connection_queue& cc
, address const& listen_interface, std::string const& user_agent , address const& listen_interface, std::string const& user_agent
, portmap_callback_t const& cb); , portmap_callback_t const& cb, bool ignore_nonrouters);
~upnp(); ~upnp();
// maps the ports, if a port is set to 0 // maps the ports, if a port is set to 0
@ -233,6 +233,8 @@ private:
connection_queue& m_cc; connection_queue& m_cc;
std::vector<address> m_filter;
#ifdef TORRENT_UPNP_LOGGING #ifdef TORRENT_UPNP_LOGGING
std::ofstream m_log; std::ofstream m_log;
#endif #endif

View File

@ -2350,7 +2350,8 @@ namespace detail
, m_listen_interface.address() , m_listen_interface.address()
, m_settings.user_agent , m_settings.user_agent
, bind(&session_impl::on_port_mapping , bind(&session_impl::on_port_mapping
, this, _1, _2, _3)); , this, _1, _2, _3)
, m_settings.upnp_ignore_nonrouters);
m_upnp->discover_device(); m_upnp->discover_device();
m_upnp->set_mappings(m_listen_interface.port(), m_upnp->set_mappings(m_listen_interface.port(),

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/http_tracker_connection.hpp" #include "libtorrent/http_tracker_connection.hpp"
#include "libtorrent/xml_parse.hpp" #include "libtorrent/xml_parse.hpp"
#include "libtorrent/connection_queue.hpp" #include "libtorrent/connection_queue.hpp"
#include "libtorrent/enum_net.hpp"
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
@ -61,7 +62,7 @@ namespace libtorrent
upnp::upnp(io_service& ios, connection_queue& cc upnp::upnp(io_service& ios, connection_queue& cc
, address const& listen_interface, std::string const& user_agent , address const& listen_interface, std::string const& user_agent
, portmap_callback_t const& cb) , portmap_callback_t const& cb, bool ignore_nonrouters)
: m_udp_local_port(0) : m_udp_local_port(0)
, m_tcp_local_port(0) , m_tcp_local_port(0)
, m_user_agent(user_agent) , m_user_agent(user_agent)
@ -81,6 +82,21 @@ upnp::upnp(io_service& ios, connection_queue& cc
m_log.open("upnp.log", std::ios::in | std::ios::out | std::ios::trunc); m_log.open("upnp.log", std::ios::in | std::ios::out | std::ios::trunc);
#endif #endif
m_retry_count = 0; m_retry_count = 0;
if (ignore_nonrouters)
{
asio::error_code ec;
std::vector<address> const& net = enum_net_interfaces(m_io_service, ec);
m_filter.reserve(net.size());
for (std::vector<address>::const_iterator i = net.begin()
, end(net.end()); i != end; ++i)
{
asio::error_code e;
address a = router_for_interface(*i, e);
if (e || is_loopback(a)) continue;
m_filter.push_back(a);
}
}
} }
upnp::~upnp() upnp::~upnp()
@ -265,6 +281,18 @@ try
Server:Microsoft-Windows-NT/5.1 UPnP/1.0 UPnP-Device-Host/1.0 Server:Microsoft-Windows-NT/5.1 UPnP/1.0 UPnP-Device-Host/1.0
*/ */
if (!m_filter.empty() && std::find(m_filter.begin(), m_filter.end()
, from.address()) == m_filter.end())
{
// this upnp device is filtered because it's not in the
// list of configured routers
#ifdef TORRENT_UPNP_LOGGING
m_log << time_now_string() << " <== (" << from << ") Rootdevice "
"ignored because it's not out router" << std::endl;
#endif
return;
}
http_parser p; http_parser p;
try try
{ {