diff --git a/include/libtorrent/enum_net.hpp b/include/libtorrent/enum_net.hpp index 01907a649..1b8db44f1 100644 --- a/include/libtorrent/enum_net.hpp +++ b/include/libtorrent/enum_net.hpp @@ -77,7 +77,8 @@ namespace libtorrent TORRENT_EXTRA_EXPORT std::vector enum_net_interfaces(io_service& ios , error_code& ec); - TORRENT_EXTRA_EXPORT std::vector enum_routes(error_code& ec); + TORRENT_EXTRA_EXPORT std::vector enum_routes(io_service& ios + , error_code& ec); // return (a1 & mask) == (a2 & mask) TORRENT_EXTRA_EXPORT bool match_addr_mask(address const& a1 @@ -90,7 +91,7 @@ namespace libtorrent TORRENT_EXTRA_EXPORT bool in_local_network(std::vector const& net , address const& addr); - TORRENT_EXTRA_EXPORT address get_default_gateway(error_code& ec); + TORRENT_EXTRA_EXPORT address get_default_gateway(io_service& ios, error_code& ec); #ifdef SO_BINDTODEVICE struct bind_to_device_opt diff --git a/simulation/libsimulator b/simulation/libsimulator index b5da40df0..83b77075c 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit b5da40df0a8e5549159841e0ff552909cb289369 +Subproject commit 83b77075c336c8e36e936453bf3d0e49d763114f diff --git a/src/allocator.cpp b/src/allocator.cpp index d38dbeda1..6651b80a3 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -50,7 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_WINDOWS // windows.h must be included after stdlib.h under mingw -#include +#include #endif #ifdef TORRENT_MINGW @@ -80,7 +80,9 @@ namespace libtorrent static int s = 0; if (s != 0) return s; -#ifdef TORRENT_WINDOWS +#ifdef TORRENT_BUILD_SIMULATOR + s = 4096; +#elif defined TORRENT_WINDOWS SYSTEM_INFO si; GetSystemInfo(&si); s = si.dwPageSize; diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 950d656d3..f1b293d12 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -404,7 +404,16 @@ namespace libtorrent { TORRENT_UNUSED(ios); // this may be unused depending on configuration std::vector ret; -#if TORRENT_USE_IFADDRS +#if defined TORRENT_BUILD_SIMULATOR + + ip_interface wan; + wan.interface_address = ios.get_ip(); + wan.netmask = address_v4::from_string("255.255.255.255"); + strcpy(wan.name, "eth0"); + wan.mtu = ios.sim().config().path_mtu(ios.get_ip(), ios.get_ip()); + ret.push_back(wan); + +#elif TORRENT_USE_IFADDRS int s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { @@ -664,9 +673,9 @@ namespace libtorrent return ret; } - address get_default_gateway(error_code& ec) + address get_default_gateway(io_service& ios, error_code& ec) { - std::vector ret = enum_routes(ec); + std::vector ret = enum_routes(ios, ec); #if defined TORRENT_WINDOWS || defined TORRENT_MINGW std::vector::iterator i = std::find_if(ret.begin(), ret.end() , boost::bind(&is_loopback, boost::bind(&ip_route::destination, _1))); @@ -678,11 +687,23 @@ namespace libtorrent return i->gateway; } - std::vector enum_routes(error_code& ec) + std::vector enum_routes(io_service& ios, error_code& ec) { std::vector ret; -#if TORRENT_USE_SYSCTL +#ifdef TORRENT_BUILD_SIMULATOR + + ip_route r; + r.destination = address_v4(); + r.netmask = address_v4::from_string("255.255.255.0"); + address_v4::bytes_type b = ios.get_ip().to_v4().to_bytes(); + b[3] = 1; + r.gateway = address_v4(b); + strcpy(r.name, "eth0"); + r.mtu = ios.sim().config().path_mtu(ios.get_ip(), ios.get_ip()); + ret.push_back(r); + +#elif TORRENT_USE_SYSCTL /* struct rt_msg { diff --git a/src/natpmp.cpp b/src/natpmp.cpp index 8921a6180..1006284e8 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -84,7 +84,7 @@ void natpmp::start() mutex::scoped_lock l(m_mutex); error_code ec; - address gateway = get_default_gateway(ec); + address gateway = get_default_gateway(m_socket.get_io_service(), ec); if (ec) { char msg[200]; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 328776a97..aa1b129af 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5883,7 +5883,7 @@ retry: while (num_pools > m_net_thread_pool.size()) { m_net_thread_pool.push_back(boost::make_shared()); - m_net_thread_pool.back()->set_num_threads(1); + m_net_thread_pool.back()->set_num_threads(num_threads > 0 ? 1 : 0); } while (num_pools < m_net_thread_pool.size()) diff --git a/src/upnp.cpp b/src/upnp.cpp index 1157f4457..a4d873f03 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -406,7 +406,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer bool non_router = false; if (m_ignore_non_routers) { - std::vector routes = enum_routes(ec); + std::vector routes = enum_routes(m_io_service, ec); if (std::find_if(routes.begin(), routes.end() , boost::bind(&ip_route::gateway, _1) == from.address()) == routes.end()) { diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index 65e114341..2675c7bc6 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -94,7 +94,7 @@ namespace libtorrent { m_last_route_update = aux::time_now(); error_code ec; - m_routes = enum_routes(ec); + m_routes = enum_routes(m_sock.get_io_service(), ec); } int mtu = 0; @@ -206,7 +206,7 @@ namespace libtorrent { m_last_route_update = aux::time_now(); error_code ec; - m_routes = enum_routes(ec); + m_routes = enum_routes(m_sock.get_io_service(), ec); if (ec) return socket_ep; }