simulate IP routes, interfaces and page size when building in simulation mode
This commit is contained in:
parent
6068418def
commit
4fa0aa62da
|
@ -77,7 +77,8 @@ namespace libtorrent
|
|||
TORRENT_EXTRA_EXPORT std::vector<ip_interface> enum_net_interfaces(io_service& ios
|
||||
, error_code& ec);
|
||||
|
||||
TORRENT_EXTRA_EXPORT std::vector<ip_route> enum_routes(error_code& ec);
|
||||
TORRENT_EXTRA_EXPORT std::vector<ip_route> 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<ip_interface> 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
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b5da40df0a8e5549159841e0ff552909cb289369
|
||||
Subproject commit 83b77075c336c8e36e936453bf3d0e49d763114f
|
|
@ -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;
|
||||
|
|
|
@ -404,7 +404,16 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_UNUSED(ios); // this may be unused depending on configuration
|
||||
std::vector<ip_interface> 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<ip_route> ret = enum_routes(ec);
|
||||
std::vector<ip_route> ret = enum_routes(ios, ec);
|
||||
#if defined TORRENT_WINDOWS || defined TORRENT_MINGW
|
||||
std::vector<ip_route>::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<ip_route> enum_routes(error_code& ec)
|
||||
std::vector<ip_route> enum_routes(io_service& ios, error_code& ec)
|
||||
{
|
||||
std::vector<ip_route> 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
|
||||
{
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -5883,7 +5883,7 @@ retry:
|
|||
while (num_pools > m_net_thread_pool.size())
|
||||
{
|
||||
m_net_thread_pool.push_back(boost::make_shared<network_thread_pool>());
|
||||
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())
|
||||
|
|
|
@ -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<ip_route> routes = enum_routes(ec);
|
||||
std::vector<ip_route> 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())
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue