lt sync 2020
This commit is contained in:
parent
27ffaab15b
commit
1e02029fe1
|
@ -67,5 +67,21 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define TORRENT_DEPRECATED
|
#define TORRENT_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// set up defines for target environments
|
||||||
|
#if (defined __APPLE__ && __MACH__) || defined __FreeBSD__ || defined __NetBSD__ \
|
||||||
|
|| defined __OpenBSD__ || defined __bsdi__ || defined __DragonFly__ \
|
||||||
|
|| defined __FreeBSD_kernel__
|
||||||
|
#define TORRENT_BSD
|
||||||
|
#elif defined __linux__
|
||||||
|
#define TORRENT_LINUX
|
||||||
|
#elif defined WIN32
|
||||||
|
#define TORRENT_WINDOWS
|
||||||
|
#else
|
||||||
|
#warning unkown OS, assuming BSD
|
||||||
|
#define TORRENT_BSD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // TORRENT_CONFIG_HPP_INCLUDED
|
#endif // TORRENT_CONFIG_HPP_INCLUDED
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,26 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
std::vector<address> enum_net_interfaces(asio::io_service& ios, asio::error_code& ec);
|
|
||||||
|
struct ip_interface
|
||||||
|
{
|
||||||
|
address interface_address;
|
||||||
|
address netmask;
|
||||||
|
};
|
||||||
|
|
||||||
|
// returns a list of the configured IP interfaces
|
||||||
|
// on the machine
|
||||||
|
std::vector<ip_interface> enum_net_interfaces(asio::io_service& ios
|
||||||
|
, asio::error_code& ec);
|
||||||
|
|
||||||
|
// returns true if the specified address is on the same
|
||||||
|
// local network as the specified interface
|
||||||
|
bool in_subnet(address const& addr, ip_interface const& iface);
|
||||||
|
|
||||||
|
// returns true if the specified address is on the same
|
||||||
|
// local network as us
|
||||||
|
bool in_local_network(asio::io_service& ios, address const& addr, asio::error_code& ec);
|
||||||
|
|
||||||
address router_for_interface(address const interface, asio::error_code& ec);
|
address router_for_interface(address const interface, asio::error_code& ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,11 +230,10 @@ private:
|
||||||
|
|
||||||
bool m_disabled;
|
bool m_disabled;
|
||||||
bool m_closing;
|
bool m_closing;
|
||||||
|
bool m_ignore_outside_network;
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -79,12 +79,12 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
// make a best guess of the interface we're using and its IP
|
// make a best guess of the interface we're using and its IP
|
||||||
asio::error_code ec;
|
asio::error_code ec;
|
||||||
std::vector<address> const& interfaces = enum_net_interfaces(ios, ec);
|
std::vector<ip_interface> const& interfaces = enum_net_interfaces(ios, ec);
|
||||||
address ret = address_v4::any();
|
address ret = address_v4::any();
|
||||||
for (std::vector<address>::const_iterator i = interfaces.begin()
|
for (std::vector<ip_interface>::const_iterator i = interfaces.begin()
|
||||||
, end(interfaces.end()); i != end; ++i)
|
, end(interfaces.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
address const& a = *i;
|
address const& a = i->interface_address;
|
||||||
if (is_loopback(a)
|
if (is_loopback(a)
|
||||||
|| is_multicast(a)
|
|| is_multicast(a)
|
||||||
|| is_any(a)) continue;
|
|| is_any(a)) continue;
|
||||||
|
@ -111,20 +111,20 @@ namespace libtorrent
|
||||||
using namespace asio::ip::multicast;
|
using namespace asio::ip::multicast;
|
||||||
|
|
||||||
asio::error_code ec;
|
asio::error_code ec;
|
||||||
std::vector<address> interfaces = enum_net_interfaces(ios, ec);
|
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
|
||||||
|
|
||||||
for (std::vector<address>::const_iterator i = interfaces.begin()
|
for (std::vector<ip_interface>::const_iterator i = interfaces.begin()
|
||||||
, end(interfaces.end()); i != end; ++i)
|
, end(interfaces.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
// only broadcast to IPv4 addresses that are not local
|
// only broadcast to IPv4 addresses that are not local
|
||||||
if (!is_local(*i)) continue;
|
if (!is_local(i->interface_address)) continue;
|
||||||
// only multicast on compatible networks
|
// only multicast on compatible networks
|
||||||
if (i->is_v4() != multicast_endpoint.address().is_v4()) continue;
|
if (i->interface_address.is_v4() != multicast_endpoint.address().is_v4()) continue;
|
||||||
// ignore any loopback interface
|
// ignore any loopback interface
|
||||||
if (is_loopback(*i)) continue;
|
if (is_loopback(i->interface_address)) continue;
|
||||||
|
|
||||||
boost::shared_ptr<datagram_socket> s(new datagram_socket(ios));
|
boost::shared_ptr<datagram_socket> s(new datagram_socket(ios));
|
||||||
if (i->is_v4())
|
if (i->interface_address.is_v4())
|
||||||
{
|
{
|
||||||
s->open(udp::v4(), ec);
|
s->open(udp::v4(), ec);
|
||||||
if (ec) continue;
|
if (ec) continue;
|
||||||
|
@ -134,7 +134,7 @@ namespace libtorrent
|
||||||
if (ec) continue;
|
if (ec) continue;
|
||||||
s->set_option(join_group(multicast_endpoint.address()), ec);
|
s->set_option(join_group(multicast_endpoint.address()), ec);
|
||||||
if (ec) continue;
|
if (ec) continue;
|
||||||
s->set_option(outbound_interface(i->to_v4()), ec);
|
s->set_option(outbound_interface(i->interface_address.to_v4()), ec);
|
||||||
if (ec) continue;
|
if (ec) continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -147,7 +147,7 @@ namespace libtorrent
|
||||||
if (ec) continue;
|
if (ec) continue;
|
||||||
s->set_option(join_group(multicast_endpoint.address()), ec);
|
s->set_option(join_group(multicast_endpoint.address()), ec);
|
||||||
if (ec) continue;
|
if (ec) continue;
|
||||||
// s->set_option(outbound_interface(i->to_v6()), ec);
|
// s->set_option(outbound_interface(i->interface_address.to_v6()), ec);
|
||||||
// if (ec) continue;
|
// if (ec) continue;
|
||||||
}
|
}
|
||||||
s->set_option(hops(255), ec);
|
s->set_option(hops(255), ec);
|
||||||
|
|
|
@ -143,24 +143,28 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
entry::entry(dictionary_type const& v)
|
entry::entry(dictionary_type const& v)
|
||||||
|
: m_type(undefined_t)
|
||||||
{
|
{
|
||||||
new(data) dictionary_type(v);
|
new(data) dictionary_type(v);
|
||||||
m_type = dictionary_t;
|
m_type = dictionary_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry::entry(string_type const& v)
|
entry::entry(string_type const& v)
|
||||||
|
: m_type(undefined_t)
|
||||||
{
|
{
|
||||||
new(data) string_type(v);
|
new(data) string_type(v);
|
||||||
m_type = string_t;
|
m_type = string_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry::entry(list_type const& v)
|
entry::entry(list_type const& v)
|
||||||
|
: m_type(undefined_t)
|
||||||
{
|
{
|
||||||
new(data) list_type(v);
|
new(data) list_type(v);
|
||||||
m_type = list_t;
|
m_type = list_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry::entry(integer_type const& v)
|
entry::entry(integer_type const& v)
|
||||||
|
: m_type(undefined_t)
|
||||||
{
|
{
|
||||||
new(data) integer_type(v);
|
new(data) integer_type(v);
|
||||||
m_type = int_t;
|
m_type = int_t;
|
||||||
|
@ -216,8 +220,7 @@ namespace libtorrent
|
||||||
|
|
||||||
void entry::construct(data_type t)
|
void entry::construct(data_type t)
|
||||||
{
|
{
|
||||||
m_type = t;
|
switch(t)
|
||||||
switch(m_type)
|
|
||||||
{
|
{
|
||||||
case int_t:
|
case int_t:
|
||||||
new(data) integer_type;
|
new(data) integer_type;
|
||||||
|
@ -234,13 +237,14 @@ namespace libtorrent
|
||||||
default:
|
default:
|
||||||
TORRENT_ASSERT(m_type == undefined_t);
|
TORRENT_ASSERT(m_type == undefined_t);
|
||||||
m_type = undefined_t;
|
m_type = undefined_t;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
m_type = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void entry::copy(entry const& e)
|
void entry::copy(entry const& e)
|
||||||
{
|
{
|
||||||
m_type = e.m_type;
|
switch(e.m_type)
|
||||||
switch(m_type)
|
|
||||||
{
|
{
|
||||||
case int_t:
|
case int_t:
|
||||||
new(data) integer_type(e.integer());
|
new(data) integer_type(e.integer());
|
||||||
|
@ -256,7 +260,9 @@ namespace libtorrent
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_type = undefined_t;
|
m_type = undefined_t;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
m_type = e.m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void entry::destruct()
|
void entry::destruct()
|
||||||
|
@ -279,6 +285,7 @@ namespace libtorrent
|
||||||
TORRENT_ASSERT(m_type == undefined_t);
|
TORRENT_ASSERT(m_type == undefined_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
m_type = undefined_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void entry::swap(entry& e)
|
void entry::swap(entry& e)
|
||||||
|
|
|
@ -30,11 +30,13 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined __linux__ || defined __MACH__
|
#include "libtorrent/config.hpp"
|
||||||
|
|
||||||
|
#if defined TORRENT_BSD || defined TORRENT_LINUX
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#elif defined WIN32
|
#elif defined TORRENT_WINDOWS
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,11 +48,58 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
std::vector<address> enum_net_interfaces(asio::io_service& ios, asio::error_code& ec)
|
namespace
|
||||||
{
|
{
|
||||||
std::vector<address> ret;
|
address sockaddr_to_address(sockaddr const* sin)
|
||||||
|
{
|
||||||
|
if (sin->sa_family == AF_INET)
|
||||||
|
{
|
||||||
|
typedef asio::ip::address_v4::bytes_type bytes_t;
|
||||||
|
bytes_t b;
|
||||||
|
memcpy(&b[0], &((sockaddr_in const*)sin)->sin_addr, b.size());
|
||||||
|
return address_v4(b);
|
||||||
|
}
|
||||||
|
else if (sin->sa_family == AF_INET6)
|
||||||
|
{
|
||||||
|
typedef asio::ip::address_v6::bytes_type bytes_t;
|
||||||
|
bytes_t b;
|
||||||
|
memcpy(&b[0], &((sockaddr_in6 const*)sin)->sin6_addr, b.size());
|
||||||
|
return address_v6(b);
|
||||||
|
}
|
||||||
|
return address();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined __linux__ || defined __MACH__ || defined(__FreeBSD__)
|
bool in_subnet(address const& addr, ip_interface const& iface)
|
||||||
|
{
|
||||||
|
if (addr.is_v4() != iface.interface_address.is_v4()) return false;
|
||||||
|
// since netmasks seems unreliable for IPv6 interfaces
|
||||||
|
// (MacOS X returns AF_INET addresses as bitmasks) assume
|
||||||
|
// that any IPv6 address belongs to the subnet of any
|
||||||
|
// interface with an IPv6 address
|
||||||
|
if (addr.is_v6()) return true;
|
||||||
|
|
||||||
|
return (addr.to_v4().to_ulong() & iface.netmask.to_v4().to_ulong())
|
||||||
|
== (iface.interface_address.to_v4().to_ulong() & iface.netmask.to_v4().to_ulong());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool in_local_network(asio::io_service& ios, address const& addr, asio::error_code& ec)
|
||||||
|
{
|
||||||
|
std::vector<ip_interface> const& net = enum_net_interfaces(ios, ec);
|
||||||
|
if (ec) return false;
|
||||||
|
for (std::vector<ip_interface>::const_iterator i = net.begin()
|
||||||
|
, end(net.end()); i != end; ++i)
|
||||||
|
{
|
||||||
|
if (in_subnet(addr, *i)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ip_interface> enum_net_interfaces(asio::io_service& ios, asio::error_code& ec)
|
||||||
|
{
|
||||||
|
std::vector<ip_interface> ret;
|
||||||
|
|
||||||
|
#if defined TORRENT_LINUX || defined TORRENT_BSD
|
||||||
int s = socket(AF_INET, SOCK_DGRAM, 0);
|
int s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
{
|
{
|
||||||
|
@ -63,11 +112,10 @@ namespace libtorrent
|
||||||
ifc.ifc_buf = buf;
|
ifc.ifc_buf = buf;
|
||||||
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
|
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
|
||||||
{
|
{
|
||||||
|
ec = asio::error_code(errno, asio::error::system_category);
|
||||||
close(s);
|
close(s);
|
||||||
ec = asio::error::fault;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
close(s);
|
|
||||||
|
|
||||||
char *ifr = (char*)ifc.ifc_req;
|
char *ifr = (char*)ifc.ifc_req;
|
||||||
int remaining = ifc.ifc_len;
|
int remaining = ifc.ifc_len;
|
||||||
|
@ -75,36 +123,51 @@ namespace libtorrent
|
||||||
while (remaining)
|
while (remaining)
|
||||||
{
|
{
|
||||||
ifreq const& item = *reinterpret_cast<ifreq*>(ifr);
|
ifreq const& item = *reinterpret_cast<ifreq*>(ifr);
|
||||||
if (item.ifr_addr.sa_family == AF_INET)
|
|
||||||
|
if (item.ifr_addr.sa_family == AF_INET
|
||||||
|
|| item.ifr_addr.sa_family == AF_INET6)
|
||||||
{
|
{
|
||||||
typedef asio::ip::address_v4::bytes_type bytes_t;
|
ip_interface iface;
|
||||||
bytes_t b;
|
iface.interface_address = sockaddr_to_address(&item.ifr_addr);
|
||||||
memcpy(&b[0], &((sockaddr_in const*)&item.ifr_addr)->sin_addr, b.size());
|
|
||||||
ret.push_back(address_v4(b));
|
ifreq netmask = item;
|
||||||
|
if (ioctl(s, SIOCGIFNETMASK, &netmask) < 0)
|
||||||
|
{
|
||||||
|
if (iface.interface_address.is_v6())
|
||||||
|
{
|
||||||
|
// this is expected to fail (at least on MacOS X)
|
||||||
|
iface.netmask = address_v6::any();
|
||||||
}
|
}
|
||||||
else if (item.ifr_addr.sa_family == AF_INET6)
|
else
|
||||||
{
|
{
|
||||||
typedef asio::ip::address_v6::bytes_type bytes_t;
|
ec = asio::error_code(errno, asio::error::system_category);
|
||||||
bytes_t b;
|
close(s);
|
||||||
memcpy(&b[0], &((sockaddr_in6 const*)&item.ifr_addr)->sin6_addr, b.size());
|
return ret;
|
||||||
ret.push_back(address_v6(b));
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iface.netmask = sockaddr_to_address(&netmask.ifr_addr);
|
||||||
|
}
|
||||||
|
ret.push_back(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined __MACH__ || defined(__FreeBSD__)
|
#if defined TORRENT_BSD
|
||||||
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
|
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
|
||||||
#elif defined __linux__
|
#elif defined TORRENT_LINUX
|
||||||
int current_size = sizeof(ifreq);
|
int current_size = sizeof(ifreq);
|
||||||
#endif
|
#endif
|
||||||
ifr += current_size;
|
ifr += current_size;
|
||||||
remaining -= current_size;
|
remaining -= current_size;
|
||||||
}
|
}
|
||||||
|
close(s);
|
||||||
|
|
||||||
#elif defined WIN32
|
#elif defined TORRENT_WINDOWS
|
||||||
|
|
||||||
SOCKET s = socket(AF_INET, SOCK_DGRAM, 0);
|
SOCKET s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (s == SOCKET_ERROR)
|
if (s == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
ec = asio::error::fault;
|
ec = asio::error_code(WSAGetLastError(), asio::error::system_category);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,29 +177,36 @@ namespace libtorrent
|
||||||
if (WSAIoctl(s, SIO_GET_INTERFACE_LIST, 0, 0, buffer,
|
if (WSAIoctl(s, SIO_GET_INTERFACE_LIST, 0, 0, buffer,
|
||||||
sizeof(buffer), &size, 0, 0) != 0)
|
sizeof(buffer), &size, 0, 0) != 0)
|
||||||
{
|
{
|
||||||
|
ec = asio::error_code(WSAGetLastError(), asio::error::system_category);
|
||||||
closesocket(s);
|
closesocket(s);
|
||||||
ec = asio::error::fault;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
closesocket(s);
|
closesocket(s);
|
||||||
|
|
||||||
int n = size / sizeof(INTERFACE_INFO);
|
int n = size / sizeof(INTERFACE_INFO);
|
||||||
|
|
||||||
|
ip_interface iface;
|
||||||
for (int i = 0; i < n; ++i)
|
for (int i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
sockaddr_in *sockaddr = (sockaddr_in*)&buffer[i].iiAddress;
|
iface.interface_address = sockaddr_to_address(&buffer[i].iiAddress.Address);
|
||||||
address a(address::from_string(inet_ntoa(sockaddr->sin_addr)));
|
iface.netmask = sockaddr_to_address(&buffer[i].iiNetmask.Address);
|
||||||
if (a == address_v4::any()) continue;
|
if (iface.interface_address == address_v4::any()) continue;
|
||||||
ret.push_back(a);
|
ret.push_back(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#warning THIS OS IS NOT RECOGNIZED, enum_net_interfaces WILL PROBABLY NOT WORK
|
||||||
// make a best guess of the interface we're using and its IP
|
// make a best guess of the interface we're using and its IP
|
||||||
udp::resolver r(ios);
|
udp::resolver r(ios);
|
||||||
udp::resolver::iterator i = r.resolve(udp::resolver::query(asio::ip::host_name(), "0"));
|
udp::resolver::iterator i = r.resolve(udp::resolver::query(asio::ip::host_name(ec), "0"));
|
||||||
|
if (ec) return ret;
|
||||||
|
ip_interface iface;
|
||||||
for (;i != udp::resolver_iterator(); ++i)
|
for (;i != udp::resolver_iterator(); ++i)
|
||||||
{
|
{
|
||||||
ret.push_back(i->endpoint().address());
|
iface.interface_address = i->endpoint().address();
|
||||||
|
if (iface.interface_address.is_v4())
|
||||||
|
iface.netmask = address_v4::netmask(iface.interface_address.to_v4());
|
||||||
|
ret.push_back(iface);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -144,7 +214,7 @@ namespace libtorrent
|
||||||
|
|
||||||
address router_for_interface(address const interface, asio::error_code& ec)
|
address router_for_interface(address const interface, asio::error_code& ec)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef TORRENT_WINDOWS
|
||||||
|
|
||||||
// Load Iphlpapi library
|
// Load Iphlpapi library
|
||||||
HMODULE iphlp = LoadLibraryA("Iphlpapi.dll");
|
HMODULE iphlp = LoadLibraryA("Iphlpapi.dll");
|
||||||
|
@ -184,15 +254,22 @@ namespace libtorrent
|
||||||
address ret;
|
address ret;
|
||||||
if (GetAdaptersInfo(adapter_info, &out_buf_size) == NO_ERROR)
|
if (GetAdaptersInfo(adapter_info, &out_buf_size) == NO_ERROR)
|
||||||
{
|
{
|
||||||
PIP_ADAPTER_INFO adapter = adapter_info;
|
|
||||||
while (adapter != 0)
|
for (PIP_ADAPTER_INFO adapter = adapter_info;
|
||||||
|
adapter != 0; adapter = adapter->Next)
|
||||||
{
|
{
|
||||||
if (interface == address::from_string(adapter->IpAddressList.IpAddress.String, ec))
|
address iface = address::from_string(adapter->IpAddressList.IpAddress.String, ec);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
ec = asio::error_code();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (is_loopback(iface) || is_any(iface)) continue;
|
||||||
|
if (interface == address() || interface == iface)
|
||||||
{
|
{
|
||||||
ret = address::from_string(adapter->GatewayList.IpAddress.String, ec);
|
ret = address::from_string(adapter->GatewayList.IpAddress.String, ec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
adapter = adapter->Next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -334,6 +334,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
++num_requested;
|
++num_requested;
|
||||||
blocks_requested = true;
|
blocks_requested = true;
|
||||||
|
TORRENT_ASSERT(i->info[k].num_peers > 0);
|
||||||
}
|
}
|
||||||
if (i->info[k].state == block_info::state_writing)
|
if (i->info[k].state == block_info::state_writing)
|
||||||
{
|
{
|
||||||
|
|
|
@ -294,6 +294,7 @@ namespace libtorrent
|
||||||
|| std::find(rq.begin(), rq.end(), *i) != rq.end())
|
|| std::find(rq.begin(), rq.end(), *i) != rq.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
TORRENT_ASSERT(p.num_peers(*i) > 0);
|
||||||
busy_pieces.push_back(*i);
|
busy_pieces.push_back(*i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -333,6 +334,8 @@ namespace libtorrent
|
||||||
p.piece_info(i->piece_index, st);
|
p.piece_info(i->piece_index, st);
|
||||||
TORRENT_ASSERT(st.requested + st.finished + st.writing == p.blocks_in_piece(i->piece_index));
|
TORRENT_ASSERT(st.requested + st.finished + st.writing == p.blocks_in_piece(i->piece_index));
|
||||||
#endif
|
#endif
|
||||||
|
TORRENT_ASSERT(p.is_requested(*i));
|
||||||
|
TORRENT_ASSERT(p.num_peers(*i) > 0);
|
||||||
c.add_request(*i);
|
c.add_request(*i);
|
||||||
c.send_block_requests();
|
c.send_block_requests();
|
||||||
}
|
}
|
||||||
|
|
|
@ -617,6 +617,7 @@ namespace detail
|
||||||
"\n";
|
"\n";
|
||||||
m_buffer_usage_logger.open("buffer_stats.log", std::ios::trunc);
|
m_buffer_usage_logger.open("buffer_stats.log", std::ios::trunc);
|
||||||
m_second_counter = 0;
|
m_second_counter = 0;
|
||||||
|
m_buffer_allocations = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ---- generate a peer id ----
|
// ---- generate a peer id ----
|
||||||
|
@ -797,12 +798,13 @@ namespace detail
|
||||||
|
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
TORRENT_ASSERT(s.connection_speed > 0);
|
|
||||||
TORRENT_ASSERT(s.file_pool_size > 0);
|
TORRENT_ASSERT(s.file_pool_size > 0);
|
||||||
|
|
||||||
// less than 5 seconds unchoke interval is insane
|
// less than 5 seconds unchoke interval is insane
|
||||||
TORRENT_ASSERT(s.unchoke_interval >= 5);
|
TORRENT_ASSERT(s.unchoke_interval >= 5);
|
||||||
m_settings = s;
|
m_settings = s;
|
||||||
|
if (m_settings.connection_speed <= 0) m_settings.connection_speed = 200;
|
||||||
|
|
||||||
m_files.resize(m_settings.file_pool_size);
|
m_files.resize(m_settings.file_pool_size);
|
||||||
// replace all occurances of '\n' with ' '.
|
// replace all occurances of '\n' with ' '.
|
||||||
std::string::iterator i = m_settings.user_agent.begin();
|
std::string::iterator i = m_settings.user_agent.begin();
|
||||||
|
@ -959,12 +961,14 @@ namespace detail
|
||||||
{
|
{
|
||||||
// if we're listening on any IPv6 address, enumerate them and
|
// if we're listening on any IPv6 address, enumerate them and
|
||||||
// pick the first non-local address
|
// pick the first non-local address
|
||||||
std::vector<address> const& ifs = enum_net_interfaces(m_io_service, ec);
|
std::vector<ip_interface> const& ifs = enum_net_interfaces(m_io_service, ec);
|
||||||
for (std::vector<address>::const_iterator i = ifs.begin()
|
for (std::vector<ip_interface>::const_iterator i = ifs.begin()
|
||||||
, end(ifs.end()); i != end; ++i)
|
, end(ifs.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
if (i->is_v4() || i->to_v6().is_link_local() || i->to_v6().is_loopback()) continue;
|
if (i->interface_address.is_v4()
|
||||||
m_ipv6_interface = tcp::endpoint(*i, ep.port());
|
|| i->interface_address.to_v6().is_link_local()
|
||||||
|
|| i->interface_address.to_v6().is_loopback()) continue;
|
||||||
|
m_ipv6_interface = tcp::endpoint(i->interface_address, ep.port());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2643,21 +2647,24 @@ namespace detail
|
||||||
|
|
||||||
TORRENT_ASSERT(*slot_iter == p.index);
|
TORRENT_ASSERT(*slot_iter == p.index);
|
||||||
int slot_index = static_cast<int>(slot_iter - tmp_pieces.begin());
|
int slot_index = static_cast<int>(slot_iter - tmp_pieces.begin());
|
||||||
|
const entry* ad = i->find_key("adler32");
|
||||||
|
|
||||||
|
if (ad && ad->type() == entry::int_t)
|
||||||
|
{
|
||||||
unsigned long adler
|
unsigned long adler
|
||||||
= torrent_ptr->filesystem().piece_crc(
|
= torrent_ptr->filesystem().piece_crc(
|
||||||
slot_index
|
slot_index
|
||||||
, torrent_ptr->block_size()
|
, torrent_ptr->block_size()
|
||||||
, p.info);
|
, p.info);
|
||||||
|
|
||||||
const entry& ad = (*i)["adler32"];
|
|
||||||
|
|
||||||
// crc's didn't match, don't use the resume data
|
// crc's didn't match, don't use the resume data
|
||||||
if (ad.integer() != entry::integer_type(adler))
|
if (ad->integer() != entry::integer_type(adler))
|
||||||
{
|
{
|
||||||
error = "checksum mismatch on piece "
|
error = "checksum mismatch on piece "
|
||||||
+ boost::lexical_cast<std::string>(p.index);
|
+ boost::lexical_cast<std::string>(p.index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tmp_unfinished.push_back(p);
|
tmp_unfinished.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1151,7 +1151,7 @@ namespace libtorrent
|
||||||
m_slot_to_piece.begin();
|
m_slot_to_piece.begin();
|
||||||
i != last.base(); ++i)
|
i != last.base(); ++i)
|
||||||
{
|
{
|
||||||
p.push_back(have[*i] ? *i : unassigned);
|
p.push_back((*i >= 0 && have[*i]) ? *i : unassigned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -569,7 +569,7 @@ namespace libtorrent
|
||||||
TORRENT_ASSERT(bits == 8 || j == num_bitmask_bytes - 1);
|
TORRENT_ASSERT(bits == 8 || j == num_bitmask_bytes - 1);
|
||||||
}
|
}
|
||||||
piece_struct["bitmask"] = bitmask;
|
piece_struct["bitmask"] = bitmask;
|
||||||
|
/*
|
||||||
TORRENT_ASSERT(t->filesystem().slot_for(i->index) >= 0);
|
TORRENT_ASSERT(t->filesystem().slot_for(i->index) >= 0);
|
||||||
unsigned long adler
|
unsigned long adler
|
||||||
= t->filesystem().piece_crc(
|
= t->filesystem().piece_crc(
|
||||||
|
@ -578,7 +578,7 @@ namespace libtorrent
|
||||||
, i->info);
|
, i->info);
|
||||||
|
|
||||||
piece_struct["adler32"] = adler;
|
piece_struct["adler32"] = adler;
|
||||||
|
*/
|
||||||
// push the struct onto the unfinished-piece list
|
// push the struct onto the unfinished-piece list
|
||||||
up.push_back(piece_struct);
|
up.push_back(piece_struct);
|
||||||
}
|
}
|
||||||
|
@ -596,6 +596,8 @@ namespace libtorrent
|
||||||
|
|
||||||
policy& pol = t->get_policy();
|
policy& pol = t->get_policy();
|
||||||
|
|
||||||
|
int max_failcount = t->settings().max_failcount;
|
||||||
|
|
||||||
for (policy::iterator i = pol.begin_peer()
|
for (policy::iterator i = pol.begin_peer()
|
||||||
, end(pol.end_peer()); i != end; ++i)
|
, end(pol.end_peer()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
@ -619,6 +621,9 @@ namespace libtorrent
|
||||||
// been banned, don't save it.
|
// been banned, don't save it.
|
||||||
if (i->second.type == policy::peer::not_connectable) continue;
|
if (i->second.type == policy::peer::not_connectable) continue;
|
||||||
|
|
||||||
|
// don't save peers that doesn't work
|
||||||
|
if (i->second.failcount >= max_failcount) continue;
|
||||||
|
|
||||||
tcp::endpoint ip = i->second.ip;
|
tcp::endpoint ip = i->second.ip;
|
||||||
entry peer(entry::dictionary_t);
|
entry peer(entry::dictionary_t);
|
||||||
peer["ip"] = ip.address().to_string(ec);
|
peer["ip"] = ip.address().to_string(ec);
|
||||||
|
|
|
@ -76,27 +76,13 @@ upnp::upnp(io_service& ios, connection_queue& cc
|
||||||
, m_refresh_timer(ios)
|
, m_refresh_timer(ios)
|
||||||
, m_disabled(false)
|
, m_disabled(false)
|
||||||
, m_closing(false)
|
, m_closing(false)
|
||||||
|
, m_ignore_outside_network(ignore_nonrouters)
|
||||||
, m_cc(cc)
|
, m_cc(cc)
|
||||||
{
|
{
|
||||||
#ifdef TORRENT_UPNP_LOGGING
|
#ifdef TORRENT_UPNP_LOGGING
|
||||||
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()
|
||||||
|
@ -281,14 +267,29 @@ 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()
|
asio::error_code ec;
|
||||||
, from.address()) == m_filter.end())
|
if (m_ignore_outside_network && !in_local_network(m_io_service, from.address(), ec))
|
||||||
{
|
{
|
||||||
// this upnp device is filtered because it's not in the
|
// this upnp device is filtered because it's not in the
|
||||||
// list of configured routers
|
// list of configured routers
|
||||||
#ifdef TORRENT_UPNP_LOGGING
|
#ifdef TORRENT_UPNP_LOGGING
|
||||||
m_log << time_now_string() << " <== (" << from << ") Rootdevice "
|
if (ec)
|
||||||
"ignored because it's not out router" << std::endl;
|
{
|
||||||
|
m_log << time_now_string() << " <== (" << from << ") error: "
|
||||||
|
<< ec.message() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::vector<ip_interface> const& net = enum_net_interfaces(m_io_service, ec);
|
||||||
|
m_log << time_now_string() << " <== (" << from << ") UPnP device "
|
||||||
|
"ignored because it's not on our network ";
|
||||||
|
for (std::vector<ip_interface>::const_iterator i = net.begin()
|
||||||
|
, end(net.end()); i != end; ++i)
|
||||||
|
{
|
||||||
|
m_log << "(" << i->interface_address << ", " << i->netmask << ") ";
|
||||||
|
}
|
||||||
|
m_log << std::endl;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue