remove the IPv6 enable/disable build config

This commit is contained in:
Arvid Norberg 2018-08-15 00:02:37 +02:00 committed by Arvid Norberg
parent fef1b947f3
commit b90564d418
72 changed files with 16 additions and 604 deletions

View File

@ -628,8 +628,6 @@ target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME extens
DESCRIPTION "Enables protocol extensions" DISABLED TORRENT_DISABLE_EXTENSIONS) DESCRIPTION "Enables protocol extensions" DISABLED TORRENT_DISABLE_EXTENSIONS)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME i2p DEFAULT ON target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME i2p DEFAULT ON
DESCRIPTION "build with I2P support" DISABLED TORRENT_USE_I2P=0) DESCRIPTION "build with I2P support" DISABLED TORRENT_USE_I2P=0)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME ipv6 DEFAULT ON
DESCRIPTION "build with IPv6 support" DISABLED TORRENT_USE_IPV6=0)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME logging DEFAULT ON target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME logging DEFAULT ON
DESCRIPTION "build with logging" DISABLED TORRENT_DISABLE_LOGGING) DESCRIPTION "build with logging" DISABLED TORRENT_DISABLE_LOGGING)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME mutable-torrents DEFAULT ON target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME mutable-torrents DEFAULT ON

View File

@ -417,9 +417,6 @@ rule openssl-include-path ( properties * )
feature openssl-lib : : free path ; feature openssl-lib : : free path ;
feature openssl-include : : free path ; feature openssl-include : : free path ;
feature ipv6 : on off : composite propagated link-incompatible ;
feature.compose <ipv6>off : <define>TORRENT_USE_IPV6=0 ;
feature sanitize : off address memory undefined thread rtc : composite propagated link-incompatible ; feature sanitize : off address memory undefined thread rtc : composite propagated link-incompatible ;
# sanitize is a clang and GCC feature # sanitize is a clang and GCC feature
feature.compose <sanitize>undefined : <cflags>-fsanitize=undefined <cflags>-fsanitize-undefined-trap-on-error <linkflags>-fsanitize=undefined <linkflags>-fsanitize-undefined-trap-on-error ; feature.compose <sanitize>undefined : <cflags>-fsanitize=undefined <cflags>-fsanitize-undefined-trap-on-error <linkflags>-fsanitize=undefined <linkflags>-fsanitize-undefined-trap-on-error ;
@ -538,12 +535,12 @@ variant test_debug : debug
<export-extra>on <threading>multi <asserts>on <export-extra>on <threading>multi <asserts>on
; ;
variant test_barebones : debug variant test_barebones : debug
: <ipv6>off <dht>off <extensions>off <logging>off <boost-link>shared : <dht>off <extensions>off <logging>off <boost-link>shared
<deprecated-functions>off <invariant-checks>off <deprecated-functions>off <invariant-checks>off
<export-extra>on <threading>multi <asserts>on <export-extra>on <threading>multi <asserts>on
; ;
variant test_arm : debug variant test_arm : debug
: <ipv6>off <dht>off <extensions>off <logging>off : <dht>off <extensions>off <logging>off
<deprecated-functions>off <invariant-checks>off <deprecated-functions>off <invariant-checks>off
<export-extra>on <asserts>on <export-extra>on <asserts>on
; ;

View File

@ -626,7 +626,7 @@ def consume_comment(lno, lines):
def trim_define(line): def trim_define(line):
return line.replace('#ifndef', '').replace('#ifdef', '') \ return line.replace('#ifndef', '').replace('#ifdef', '') \
.replace('#if', '').replace('defined', '') \ .replace('#if', '').replace('defined', '') \
.replace('TORRENT_USE_IPV6', '').replace('TORRENT_ABI_VERSION == 1', '') \ .replace('TORRENT_ABI_VERSION == 1', '') \
.replace('||', '').replace('&&', '').replace('(', '').replace(')', '') \ .replace('||', '').replace('&&', '').replace('(', '').replace(')', '') \
.replace('!', '').replace('\\', '').strip() .replace('!', '').replace('\\', '').strip()

View File

@ -81,9 +81,7 @@ using lt::torrent_flags_t;
using lt::seconds; using lt::seconds;
using lt::operator""_sv; using lt::operator""_sv;
using lt::address_v4; using lt::address_v4;
#if TORRENT_USE_IPV6
using lt::address_v6; using lt::address_v6;
#endif
using std::chrono::duration_cast; using std::chrono::duration_cast;
@ -283,11 +281,9 @@ std::string print_endpoint(lt::tcp::endpoint const& ep)
lt::error_code ec; lt::error_code ec;
char buf[200]; char buf[200];
address const& addr = ep.address(); address const& addr = ep.address();
#if TORRENT_USE_IPV6
if (addr.is_v6()) if (addr.is_v6())
std::snprintf(buf, sizeof(buf), "[%s]:%d", addr.to_string(ec).c_str(), ep.port()); std::snprintf(buf, sizeof(buf), "[%s]:%d", addr.to_string(ec).c_str(), ep.port());
else else
#endif
std::snprintf(buf, sizeof(buf), "%s:%d", addr.to_string(ec).c_str(), ep.port()); std::snprintf(buf, sizeof(buf), "%s:%d", addr.to_string(ec).c_str(), ep.port());
return buf; return buf;
} }
@ -1260,10 +1256,8 @@ example alert_masks:
pcf.add_rule(address_v4::from_string("0.0.0.0") pcf.add_rule(address_v4::from_string("0.0.0.0")
, address_v4::from_string("255.255.255.255") , address_v4::from_string("255.255.255.255")
, 1 << static_cast<std::uint32_t>(lt::session::global_peer_class_id)); , 1 << static_cast<std::uint32_t>(lt::session::global_peer_class_id));
#if TORRENT_USE_IPV6
pcf.add_rule(address_v6::from_string("::") pcf.add_rule(address_v6::from_string("::")
, address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 1); , address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 1);
#endif
ses.set_peer_class_filter(pcf); ses.set_peer_class_filter(pcf);
} }

View File

@ -430,12 +430,10 @@ struct peer_conn
char ep_str[200]; char ep_str[200];
address const& addr = s.local_endpoint(e).address(); address const& addr = s.local_endpoint(e).address();
#if TORRENT_USE_IPV6
if (addr.is_v6()) if (addr.is_v6())
std::snprintf(ep_str, sizeof(ep_str), "[%s]:%d", addr.to_string(e).c_str() std::snprintf(ep_str, sizeof(ep_str), "[%s]:%d", addr.to_string(e).c_str()
, s.local_endpoint(e).port()); , s.local_endpoint(e).port());
else else
#endif
std::snprintf(ep_str, sizeof(ep_str), "%s:%d", addr.to_string(e).c_str() std::snprintf(ep_str, sizeof(ep_str), "%s:%d", addr.to_string(e).c_str()
, s.local_endpoint(e).port()); , s.local_endpoint(e).port());
std::printf("%s ep: %s sent: %d received: %d duration: %d ms up: %.1fMB/s down: %.1fMB/s\n" std::printf("%s ep: %s sent: %d received: %d duration: %d ms up: %.1fMB/s down: %.1fMB/s\n"

View File

@ -51,15 +51,11 @@ namespace libtorrent {
#if defined TORRENT_BUILD_SIMULATOR #if defined TORRENT_BUILD_SIMULATOR
using sim::asio::ip::address; using sim::asio::ip::address;
using sim::asio::ip::address_v4; using sim::asio::ip::address_v4;
#if TORRENT_USE_IPV6
using sim::asio::ip::address_v6; using sim::asio::ip::address_v6;
#endif
#else #else
using boost::asio::ip::address; using boost::asio::ip::address;
using boost::asio::ip::address_v4; using boost::asio::ip::address_v4;
#if TORRENT_USE_IPV6
using boost::asio::ip::address_v6; using boost::asio::ip::address_v6;
#endif
#endif // SIMULATOR #endif // SIMULATOR
// the from_string member functions are deprecated starting // the from_string member functions are deprecated starting
@ -67,19 +63,15 @@ namespace libtorrent {
#if BOOST_VERSION >= 106600 && !defined TORRENT_BUILD_SIMULATOR #if BOOST_VERSION >= 106600 && !defined TORRENT_BUILD_SIMULATOR
using boost::asio::ip::make_address; using boost::asio::ip::make_address;
using boost::asio::ip::make_address_v4; using boost::asio::ip::make_address_v4;
#if TORRENT_USE_IPV6
using boost::asio::ip::make_address_v6; using boost::asio::ip::make_address_v6;
#endif
#else #else
inline address make_address(string_view str, boost::system::error_code& ec) inline address make_address(string_view str, boost::system::error_code& ec)
{ return address::from_string(str.data(), ec); } { return address::from_string(str.data(), ec); }
inline address_v4 make_address_v4(string_view str, boost::system::error_code& ec) inline address_v4 make_address_v4(string_view str, boost::system::error_code& ec)
{ return address_v4::from_string(str.data(), ec); } { return address_v4::from_string(str.data(), ec); }
#if TORRENT_USE_IPV6
inline address_v6 make_address_v6(string_view str, boost::system::error_code& ec) inline address_v6 make_address_v6(string_view str, boost::system::error_code& ec)
{ return address_v6::from_string(str.data(), ec); } { return address_v6::from_string(str.data(), ec); }
#endif #endif
#endif
} }
#endif #endif

View File

@ -70,10 +70,8 @@ namespace libtorrent {
// cheap since the lists' size is limited // cheap since the lists' size is limited
using peers4_t = std::vector<std::pair<address_v4::bytes_type, std::uint16_t>>; using peers4_t = std::vector<std::pair<address_v4::bytes_type, std::uint16_t>>;
peers4_t m_peers; peers4_t m_peers;
#if TORRENT_USE_IPV6
using peers6_t = std::vector<std::pair<address_v6::bytes_type, std::uint16_t>>; using peers6_t = std::vector<std::pair<address_v6::bytes_type, std::uint16_t>>;
peers6_t m_peers6; peers6_t m_peers6;
#endif
bool was_introduced_by(tcp::endpoint const& ep); bool was_introduced_by(tcp::endpoint const& ep);

View File

@ -122,7 +122,6 @@ POSSIBILITY OF SUCH DAMAGE.
// ==== AMIGA === // ==== AMIGA ===
#if defined __AMIGA__ || defined __amigaos__ || defined __AROS__ #if defined __AMIGA__ || defined __amigaos__ || defined __AROS__
#define TORRENT_AMIGA #define TORRENT_AMIGA
#define TORRENT_USE_IPV6 0
#define TORRENT_USE_IOSTREAM 0 #define TORRENT_USE_IOSTREAM 0
// set this to 1 to disable all floating point operations // set this to 1 to disable all floating point operations
// (disables some float-dependent APIs) // (disables some float-dependent APIs)
@ -322,7 +321,6 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_HAS_FALLOCATE 0 #define TORRENT_HAS_FALLOCATE 0
#define TORRENT_USE_IFCONF 1 #define TORRENT_USE_IFCONF 1
#define TORRENT_USE_SYSCTL 1 #define TORRENT_USE_SYSCTL 1
#define TORRENT_USE_IPV6 0
#define TORRENT_USE_WRITEV 0 #define TORRENT_USE_WRITEV 0
#define TORRENT_USE_READV 0 #define TORRENT_USE_READV 0
@ -468,10 +466,6 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_USE_IFADDRS 0 #define TORRENT_USE_IFADDRS 0
#endif #endif
#ifndef TORRENT_USE_IPV6
#define TORRENT_USE_IPV6 1
#endif
// if preadv() exists, we assume pwritev() does as well // if preadv() exists, we assume pwritev() does as well
#ifndef TORRENT_USE_PREADV #ifndef TORRENT_USE_PREADV
#define TORRENT_USE_PREADV 0 #define TORRENT_USE_PREADV 0
@ -615,14 +609,6 @@ constexpr std::size_t TORRENT_WRITE_HANDLER_MAX_SIZE = 342;
#endif #endif
#endif // TORRENT_HAS_ARM_CRC32 #endif // TORRENT_HAS_ARM_CRC32
#if TORRENT_USE_IPV6
#define TORRENT_IPV6_NAMESPACE inline namespace v6 {
#define TORRENT_IPV6_NAMESPACE_END }
#else
#define TORRENT_IPV6_NAMESPACE
#define TORRENT_IPV6_NAMESPACE_END
#endif
namespace libtorrent {} namespace libtorrent {}
// create alias // create alias

View File

@ -120,13 +120,11 @@ namespace libtorrent {
address ip = make_address(device_name, ec); address ip = make_address(device_name, ec);
if (!ec) if (!ec)
{ {
#if TORRENT_USE_IPV6
// this is to cover the case where "0.0.0.0" is considered any IPv4 or // this is to cover the case where "0.0.0.0" is considered any IPv4 or
// IPv6 address. If we're asking to be bound to an IPv6 address and // IPv6 address. If we're asking to be bound to an IPv6 address and
// providing 0.0.0.0 as the device, turn it into "::" // providing 0.0.0.0 as the device, turn it into "::"
if (ip == address_v4::any() && protocol == boost::asio::ip::tcp::v6()) if (ip == address_v4::any() && protocol == boost::asio::ip::tcp::v6())
ip = address_v6::any(); ip = address_v6::any();
#endif
bind_ep.address(ip); bind_ep.address(ip);
// it appears to be an IP. Just bind to that address // it appears to be an IP. Just bind to that address
sock.bind(bind_ep, ec); sock.bind(bind_ep, ec);

View File

@ -188,9 +188,7 @@ class hasher;
class hasher512; class hasher512;
// include/libtorrent/ip_filter.hpp // include/libtorrent/ip_filter.hpp
TORRENT_IPV6_NAMESPACE
struct ip_filter; struct ip_filter;
TORRENT_IPV6_NAMESPACE_END
class port_filter; class port_filter;
// include/libtorrent/kademlia/dht_settings.hpp // include/libtorrent/kademlia/dht_settings.hpp
@ -256,10 +254,8 @@ struct storage_interface;
struct storage_params; struct storage_params;
// include/libtorrent/torrent_handle.hpp // include/libtorrent/torrent_handle.hpp
TORRENT_IPV6_NAMESPACE
struct block_info; struct block_info;
struct partial_piece_info; struct partial_piece_info;
TORRENT_IPV6_NAMESPACE_END
struct torrent_handle; struct torrent_handle;
// include/libtorrent/torrent_info.hpp // include/libtorrent/torrent_info.hpp

View File

@ -256,8 +256,6 @@ namespace detail {
} }
TORRENT_IPV6_NAMESPACE
// The ``ip_filter`` class is a set of rules that uniquely categorizes all // The ``ip_filter`` class is a set of rules that uniquely categorizes all
// ip addresses as allowed or disallowed. The default constructor creates // ip addresses as allowed or disallowed. The default constructor creates
// a single rule that allows all addresses (0.0.0.0 - 255.255.255.255 for // a single rule that allows all addresses (0.0.0.0 - 255.255.255.255 for
@ -296,12 +294,8 @@ struct TORRENT_EXPORT ip_filter
// the current filter. // the current filter.
std::uint32_t access(address const& addr) const; std::uint32_t access(address const& addr) const;
#if TORRENT_USE_IPV6
using filter_tuple_t = std::tuple<std::vector<ip_range<address_v4>> using filter_tuple_t = std::tuple<std::vector<ip_range<address_v4>>
, std::vector<ip_range<address_v6>>>; , std::vector<ip_range<address_v6>>>;
#else
using filter_tuple_t = std::vector<ip_range<address_v4>>;
#endif
// This function will return the current state of the filter in the minimum number of // This function will return the current state of the filter in the minimum number of
// ranges possible. They are sorted from ranges in low addresses to high addresses. Each // ranges possible. They are sorted from ranges in low addresses to high addresses. Each
@ -317,13 +311,9 @@ struct TORRENT_EXPORT ip_filter
private: private:
detail::filter_impl<address_v4::bytes_type> m_filter4; detail::filter_impl<address_v4::bytes_type> m_filter4;
#if TORRENT_USE_IPV6
detail::filter_impl<address_v6::bytes_type> m_filter6; detail::filter_impl<address_v6::bytes_type> m_filter6;
#endif
}; };
TORRENT_IPV6_NAMESPACE_END
// the port filter maps non-overlapping port ranges to flags. This // the port filter maps non-overlapping port ranges to flags. This
// is primarily used to indicate whether a range of ports should // is primarily used to indicate whether a range of ports should
// be connected to or not. The default is to have the full port // be connected to or not. The default is to have the full port

View File

@ -111,9 +111,7 @@ namespace libtorrent {
struct TORRENT_EXTRA_EXPORT external_ip struct TORRENT_EXTRA_EXPORT external_ip
{ {
external_ip() external_ip()
#if TORRENT_USE_IPV6
: m_addresses{{address_v4(), address_v6()}, {address_v4(), address_v6()}} : m_addresses{{address_v4(), address_v6()}, {address_v4(), address_v6()}}
#endif
{} {}
external_ip(address const& local4, address const& global4 external_ip(address const& local4, address const& global4

View File

@ -47,17 +47,12 @@ namespace libtorrent { namespace dht {
template<class InIt> template<class InIt>
node_endpoint read_node_endpoint(udp protocol, InIt&& in) node_endpoint read_node_endpoint(udp protocol, InIt&& in)
{ {
#if !TORRENT_USE_IPV6
TORRENT_UNUSED(protocol);
#endif
node_endpoint ep; node_endpoint ep;
std::copy(in, in + 20, ep.id.begin()); std::copy(in, in + 20, ep.id.begin());
in += 20; in += 20;
#if TORRENT_USE_IPV6
if (protocol == udp::v6()) if (protocol == udp::v6())
ep.ep = detail::read_v6_endpoint<udp::endpoint>(in); ep.ep = detail::read_v6_endpoint<udp::endpoint>(in);
else else
#endif
ep.ep = detail::read_v4_endpoint<udp::endpoint>(in); ep.ep = detail::read_v4_endpoint<udp::endpoint>(in);
return ep; return ep;
} }

View File

@ -126,9 +126,7 @@ private:
union addr_t union addr_t
{ {
#if TORRENT_USE_IPV6
address_v6::bytes_type v6; address_v6::bytes_type v6;
#endif
address_v4::bytes_type v4; address_v4::bytes_type v4;
} m_addr; } m_addr;

View File

@ -70,7 +70,6 @@ struct ipv4_hash
} }
}; };
#if TORRENT_USE_IPV6
struct ipv6_hash struct ipv6_hash
{ {
using argument_type = address_v6::bytes_type; using argument_type = address_v6::bytes_type;
@ -80,7 +79,6 @@ struct ipv6_hash
return std::hash<std::uint64_t>()(*reinterpret_cast<std::uint64_t const*>(&ip[0])); return std::hash<std::uint64_t>()(*reinterpret_cast<std::uint64_t const*>(&ip[0]));
} }
}; };
#endif
struct ip_set struct ip_set
{ {
@ -91,26 +89,18 @@ struct ip_set
void clear() void clear()
{ {
m_ip4s.clear(); m_ip4s.clear();
#if TORRENT_USE_IPV6
m_ip6s.clear(); m_ip6s.clear();
#endif
} }
bool operator==(ip_set const& rh) bool operator==(ip_set const& rh)
{ {
#if TORRENT_USE_IPV6
return m_ip4s == rh.m_ip4s && m_ip6s == rh.m_ip6s; return m_ip4s == rh.m_ip4s && m_ip6s == rh.m_ip6s;
#else
return m_ip4s == rh.m_ip4s;
#endif
} }
// these must be multisets because there can be multiple routing table // these must be multisets because there can be multiple routing table
// entries for a single IP when restrict_routing_ips is set to false // entries for a single IP when restrict_routing_ips is set to false
std::unordered_multiset<address_v4::bytes_type, ipv4_hash> m_ip4s; std::unordered_multiset<address_v4::bytes_type, ipv4_hash> m_ip4s;
#if TORRENT_USE_IPV6
std::unordered_multiset<address_v6::bytes_type, ipv6_hash> m_ip6s; std::unordered_multiset<address_v6::bytes_type, ipv6_hash> m_ip6s;
#endif
}; };
// differences in the implementation from the description in // differences in the implementation from the description in

View File

@ -140,9 +140,7 @@ private:
// the IP addresses of the nodes in m_results // the IP addresses of the nodes in m_results
std::set<std::uint32_t> m_peer4_prefixes; std::set<std::uint32_t> m_peer4_prefixes;
#if TORRENT_USE_IPV6
std::set<std::uint64_t> m_peer6_prefixes; std::set<std::uint64_t> m_peer6_prefixes;
#endif
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
void log_timeout(observer_ptr const& o, char const* prefix) const; void log_timeout(observer_ptr const& o, char const* prefix) const;
#endif #endif

View File

@ -67,9 +67,7 @@ private:
// the udp socket used to send and receive // the udp socket used to send and receive
// multicast messages on // multicast messages on
broadcast_socket m_socket; broadcast_socket m_socket;
#if TORRENT_USE_IPV6
broadcast_socket m_socket6; broadcast_socket m_socket6;
#endif
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
bool should_log() const; bool should_log() const;
void debug_log(char const* fmt, ...) const TORRENT_FORMAT(2, 3); void debug_log(char const* fmt, ...) const TORRENT_FORMAT(2, 3);
@ -87,9 +85,7 @@ private:
int m_cookie; int m_cookie;
bool m_disabled; bool m_disabled;
#if TORRENT_USE_IPV6
bool m_disabled6; bool m_disabled6;
#endif
}; };
} }

View File

@ -59,13 +59,11 @@ namespace libtorrent {
std::uint16_t port; std::uint16_t port;
}; };
#if TORRENT_USE_IPV6
struct ipv6_peer_entry struct ipv6_peer_entry
{ {
address_v6::bytes_type ip; address_v6::bytes_type ip;
std::uint16_t port; std::uint16_t port;
}; };
#endif
} }

View File

@ -60,31 +60,24 @@ namespace detail {
template <class Proto> template <class Proto>
std::size_t address_size(Proto p) std::size_t address_size(Proto p)
{ {
TORRENT_UNUSED(p);
#if TORRENT_USE_IPV6
if (p == Proto::v6()) if (p == Proto::v6())
return std::tuple_size<address_v6::bytes_type>::value; return std::tuple_size<address_v6::bytes_type>::value;
else else
#endif
return std::tuple_size<address_v4::bytes_type>::value; return std::tuple_size<address_v4::bytes_type>::value;
} }
template<class OutIt> template<class OutIt>
void write_address(address const& a, OutIt&& out) void write_address(address const& a, OutIt&& out)
{ {
#if TORRENT_USE_IPV6
if (a.is_v4()) if (a.is_v4())
{ {
#endif
write_uint32(a.to_v4().to_ulong(), out); write_uint32(a.to_v4().to_ulong(), out);
#if TORRENT_USE_IPV6
} }
else if (a.is_v6()) else if (a.is_v6())
{ {
for (auto b : a.to_v6().to_bytes()) for (auto b : a.to_v6().to_bytes())
write_uint8(b, out); write_uint8(b, out);
} }
#endif
} }
template<class InIt> template<class InIt>
@ -94,7 +87,6 @@ namespace detail {
return address_v4(ip); return address_v4(ip);
} }
#if TORRENT_USE_IPV6
template<class InIt> template<class InIt>
address read_v6_address(InIt&& in) address read_v6_address(InIt&& in)
{ {
@ -103,7 +95,6 @@ namespace detail {
b = read_uint8(in); b = read_uint8(in);
return address_v6(bytes); return address_v6(bytes);
} }
#endif
template<class Endpoint, class OutIt> template<class Endpoint, class OutIt>
void write_endpoint(Endpoint const& e, OutIt&& out) void write_endpoint(Endpoint const& e, OutIt&& out)
@ -120,7 +111,6 @@ namespace detail {
return Endpoint(addr, port); return Endpoint(addr, port);
} }
#if TORRENT_USE_IPV6
template<class Endpoint, class InIt> template<class Endpoint, class InIt>
Endpoint read_v6_endpoint(InIt&& in) Endpoint read_v6_endpoint(InIt&& in)
{ {
@ -128,7 +118,7 @@ namespace detail {
std::uint16_t port = read_uint16(in); std::uint16_t port = read_uint16(in);
return Endpoint(addr, port); return Endpoint(addr, port);
} }
#endif
template <class EndpointType> template <class EndpointType>
std::vector<EndpointType> read_endpoint_list(libtorrent::bdecode_node const& n) std::vector<EndpointType> read_endpoint_list(libtorrent::bdecode_node const& n)
{ {
@ -142,10 +132,8 @@ namespace detail {
char const* in = e.string_ptr(); char const* in = e.string_ptr();
if (e.string_length() == 6) if (e.string_length() == 6)
ret.push_back(read_v4_endpoint<EndpointType>(in)); ret.push_back(read_v4_endpoint<EndpointType>(in));
#if TORRENT_USE_IPV6
else if (e.string_length() == 18) else if (e.string_length() == 18)
ret.push_back(read_v6_endpoint<EndpointType>(in)); ret.push_back(read_v6_endpoint<EndpointType>(in));
#endif
} }
return ret; return ret;
} }

View File

@ -82,8 +82,6 @@ namespace aux {
using resume_data_flags_t = flags::bitfield_flag<std::uint8_t, struct resume_data_flags_tag>; using resume_data_flags_t = flags::bitfield_flag<std::uint8_t, struct resume_data_flags_tag>;
using queue_position_t = aux::strong_typedef<int, struct queue_position_tag>; using queue_position_t = aux::strong_typedef<int, struct queue_position_tag>;
TORRENT_IPV6_NAMESPACE
// holds the state of a block in a piece. Who we requested // holds the state of a block in a piece. Who we requested
// it from and how far along we are at downloading it. // it from and how far along we are at downloading it.
struct TORRENT_EXPORT block_info struct TORRENT_EXPORT block_info
@ -106,9 +104,7 @@ TORRENT_IPV6_NAMESPACE
union addr_t union addr_t
{ {
address_v4::bytes_type v4; address_v4::bytes_type v4;
#if TORRENT_USE_IPV6
address_v6::bytes_type v6; address_v6::bytes_type v6;
#endif
} addr; } addr;
std::uint16_t port; std::uint16_t port;
@ -117,22 +113,18 @@ TORRENT_IPV6_NAMESPACE
// The peer is the ip address of the peer this block was downloaded from. // The peer is the ip address of the peer this block was downloaded from.
void set_peer(tcp::endpoint const& ep) void set_peer(tcp::endpoint const& ep)
{ {
#if TORRENT_USE_IPV6
is_v6_addr = is_v6(ep); is_v6_addr = is_v6(ep);
if (is_v6_addr) if (is_v6_addr)
addr.v6 = ep.address().to_v6().to_bytes(); addr.v6 = ep.address().to_v6().to_bytes();
else else
#endif
addr.v4 = ep.address().to_v4().to_bytes(); addr.v4 = ep.address().to_v4().to_bytes();
port = ep.port(); port = ep.port();
} }
tcp::endpoint peer() const tcp::endpoint peer() const
{ {
#if TORRENT_USE_IPV6
if (is_v6_addr) if (is_v6_addr)
return tcp::endpoint(address_v6(addr.v6), port); return tcp::endpoint(address_v6(addr.v6), port);
else else
#endif
return tcp::endpoint(address_v4(addr.v4), port); return tcp::endpoint(address_v4(addr.v4), port);
} }
@ -150,10 +142,8 @@ TORRENT_IPV6_NAMESPACE
// by more peers in parallel to speed things up. // by more peers in parallel to speed things up.
unsigned num_peers:14; unsigned num_peers:14;
private: private:
#if TORRENT_USE_IPV6
// the type of the addr union // the type of the addr union
bool is_v6_addr:1; bool is_v6_addr:1;
#endif
}; };
// This class holds information about pieces that have outstanding requests // This class holds information about pieces that have outstanding requests
@ -216,8 +206,6 @@ TORRENT_IPV6_NAMESPACE
#endif #endif
}; };
TORRENT_IPV6_NAMESPACE_END
// for std::hash (and to support using this type in unordered_map etc.) // for std::hash (and to support using this type in unordered_map etc.)
TORRENT_EXPORT std::size_t hash_value(torrent_handle const& h); TORRENT_EXPORT std::size_t hash_value(torrent_handle const& h);

View File

@ -170,11 +170,9 @@ namespace libtorrent {
bool pe_support:1; bool pe_support:1;
#endif #endif
#if TORRENT_USE_IPV6
// this is true if the v6 union member in addr is // this is true if the v6 union member in addr is
// the one to use, false if it's the v4 one // the one to use, false if it's the v4 one
bool is_v6_addr:1; bool is_v6_addr:1;
#endif
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
// set if the i2p_destination is in use in the addr union // set if the i2p_destination is in use in the addr union
bool is_i2p_addr:1; bool is_i2p_addr:1;
@ -230,7 +228,6 @@ namespace libtorrent {
}; };
#endif #endif
#if TORRENT_USE_IPV6
struct TORRENT_EXTRA_EXPORT ipv6_peer : torrent_peer struct TORRENT_EXTRA_EXPORT ipv6_peer : torrent_peer
{ {
ipv6_peer(tcp::endpoint const& ip, bool connectable, peer_source_flags_t src); ipv6_peer(tcp::endpoint const& ip, bool connectable, peer_source_flags_t src);
@ -238,7 +235,6 @@ namespace libtorrent {
const address_v6::bytes_type addr; const address_v6::bytes_type addr;
}; };
#endif
struct peer_address_compare struct peer_address_compare
{ {

View File

@ -84,9 +84,7 @@ namespace libtorrent {
// saves significant overhead // saves significant overhead
boost::pool<> m_ipv4_peer_pool{sizeof(libtorrent::ipv4_peer), 500}; boost::pool<> m_ipv4_peer_pool{sizeof(libtorrent::ipv4_peer), 500};
#if TORRENT_USE_IPV6
boost::pool<> m_ipv6_peer_pool{sizeof(libtorrent::ipv6_peer), 500}; boost::pool<> m_ipv6_peer_pool{sizeof(libtorrent::ipv6_peer), 500};
#endif
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
boost::pool<> m_i2p_peer_pool{sizeof(libtorrent::i2p_peer), 500}; boost::pool<> m_i2p_peer_pool{sizeof(libtorrent::i2p_peer), 500};
#endif #endif

View File

@ -143,9 +143,7 @@ namespace libtorrent {
std::uint32_t key; std::uint32_t key;
int num_want; int num_want;
#if TORRENT_USE_IPV6
std::vector<address_v6> ipv6; std::vector<address_v6> ipv6;
#endif
sha1_hash info_hash; sha1_hash info_hash;
peer_id pid; peer_id pid;
@ -181,9 +179,7 @@ namespace libtorrent {
// peers from the tracker, in various forms // peers from the tracker, in various forms
std::vector<peer_entry> peers; std::vector<peer_entry> peers;
std::vector<ipv4_peer_entry> peers4; std::vector<ipv4_peer_entry> peers4;
#if TORRENT_USE_IPV6
std::vector<ipv6_peer_entry> peers6; std::vector<ipv6_peer_entry> peers6;
#endif
// our external IP address (if the tracker responded with ti, otherwise // our external IP address (if the tracker responded with ti, otherwise
// INADDR_ANY) // INADDR_ANY)
address external_ip; address external_ip;

View File

@ -38,37 +38,27 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent { namespace libtorrent {
TORRENT_IPV6_NAMESPACE
struct union_address struct union_address
{ {
union_address() { *this = address(); } union_address() { *this = address(); }
explicit union_address(address const& a) { *this = a; } explicit union_address(address const& a) { *this = a; }
union_address& operator=(address const& a) & union_address& operator=(address const& a) &
{ {
#if TORRENT_USE_IPV6
v4 = a.is_v4(); v4 = a.is_v4();
if (v4) if (v4)
addr.v4 = a.to_v4().to_bytes(); addr.v4 = a.to_v4().to_bytes();
else else
addr.v6 = a.to_v6().to_bytes(); addr.v6 = a.to_v6().to_bytes();
#else
addr.v4 = a.to_v4().to_bytes();
#endif
return *this; return *this;
} }
bool operator==(union_address const& rh) const bool operator==(union_address const& rh) const
{ {
#if TORRENT_USE_IPV6
if (v4 != rh.v4) return false; if (v4 != rh.v4) return false;
if (v4) if (v4)
return addr.v4 == rh.addr.v4; return addr.v4 == rh.addr.v4;
else else
return addr.v6 == rh.addr.v6; return addr.v6 == rh.addr.v6;
#else
return addr.v4 == rh.addr.v4;
#endif
} }
bool operator!=(union_address const& rh) const bool operator!=(union_address const& rh) const
@ -78,24 +68,16 @@ TORRENT_IPV6_NAMESPACE
operator address() const operator address() const
{ {
#if TORRENT_USE_IPV6
if (v4) return address(address_v4(addr.v4)); if (v4) return address(address_v4(addr.v4));
else return address(address_v6(addr.v6)); else return address(address_v6(addr.v6));
#else
return address(address_v4(addr.v4));
#endif
} }
union addr_t union addr_t
{ {
address_v4::bytes_type v4; address_v4::bytes_type v4;
#if TORRENT_USE_IPV6
address_v6::bytes_type v6; address_v6::bytes_type v6;
#endif
} addr; } addr;
#if TORRENT_USE_IPV6
bool v4:1; bool v4:1;
#endif
}; };
struct union_endpoint struct union_endpoint
@ -126,7 +108,6 @@ TORRENT_IPV6_NAMESPACE
union_address addr; union_address addr;
std::uint16_t port; std::uint16_t port;
}; };
TORRENT_IPV6_NAMESPACE_END
} }
#endif #endif

View File

@ -2116,27 +2116,21 @@ namespace {
{ {
if (is_v4(endp)) if (is_v4(endp))
m_v4_num_peers++; m_v4_num_peers++;
#if TORRENT_USE_IPV6
else else
m_v6_num_peers++; m_v6_num_peers++;
#endif
} }
m_v4_peers_idx = alloc.allocate(m_v4_num_peers * 6); m_v4_peers_idx = alloc.allocate(m_v4_num_peers * 6);
m_v6_peers_idx = alloc.allocate(m_v6_num_peers * 18); m_v6_peers_idx = alloc.allocate(m_v6_num_peers * 18);
char* v4_ptr = alloc.ptr(m_v4_peers_idx); char* v4_ptr = alloc.ptr(m_v4_peers_idx);
#if TORRENT_USE_IPV6
char* v6_ptr = alloc.ptr(m_v6_peers_idx); char* v6_ptr = alloc.ptr(m_v6_peers_idx);
#endif
for (auto const& endp : peers) for (auto const& endp : peers)
{ {
if (is_v4(endp)) if (is_v4(endp))
detail::write_endpoint(endp, v4_ptr); detail::write_endpoint(endp, v4_ptr);
#if TORRENT_USE_IPV6
else else
detail::write_endpoint(endp, v6_ptr); detail::write_endpoint(endp, v6_ptr);
#endif
} }
} }
@ -2169,11 +2163,9 @@ namespace {
char const* v4_ptr = m_alloc.get().ptr(m_v4_peers_idx); char const* v4_ptr = m_alloc.get().ptr(m_v4_peers_idx);
for (int i = 0; i < m_v4_num_peers; i++) for (int i = 0; i < m_v4_num_peers; i++)
peers.push_back(detail::read_v4_endpoint<tcp::endpoint>(v4_ptr)); peers.push_back(detail::read_v4_endpoint<tcp::endpoint>(v4_ptr));
#if TORRENT_USE_IPV6
char const* v6_ptr = m_alloc.get().ptr(m_v6_peers_idx); char const* v6_ptr = m_alloc.get().ptr(m_v6_peers_idx);
for (int i = 0; i < m_v6_num_peers; i++) for (int i = 0; i < m_v6_num_peers; i++)
peers.push_back(detail::read_v6_endpoint<tcp::endpoint>(v6_ptr)); peers.push_back(detail::read_v6_endpoint<tcp::endpoint>(v6_ptr));
#endif
return std::move(peers); return std::move(peers);
} }
@ -2349,19 +2341,15 @@ namespace {
{ {
if (is_v4(n.second)) if (is_v4(n.second))
v4_num_nodes++; v4_num_nodes++;
#if TORRENT_USE_IPV6
else else
v6_num_nodes++; v6_num_nodes++;
#endif
} }
aux::allocation_slot const v4_nodes_idx = alloc.allocate(v4_num_nodes * (20 + 6)); aux::allocation_slot const v4_nodes_idx = alloc.allocate(v4_num_nodes * (20 + 6));
aux::allocation_slot const v6_nodes_idx = alloc.allocate(v6_num_nodes * (20 + 18)); aux::allocation_slot const v6_nodes_idx = alloc.allocate(v6_num_nodes * (20 + 18));
char* v4_ptr = alloc.ptr(v4_nodes_idx); char* v4_ptr = alloc.ptr(v4_nodes_idx);
#if TORRENT_USE_IPV6
char* v6_ptr = alloc.ptr(v6_nodes_idx); char* v6_ptr = alloc.ptr(v6_nodes_idx);
#endif
for (auto const& n : nodes) for (auto const& n : nodes)
{ {
udp::endpoint const& endp = n.second; udp::endpoint const& endp = n.second;
@ -2370,13 +2358,11 @@ namespace {
detail::write_string(n.first.to_string(), v4_ptr); detail::write_string(n.first.to_string(), v4_ptr);
detail::write_endpoint(endp, v4_ptr); detail::write_endpoint(endp, v4_ptr);
} }
#if TORRENT_USE_IPV6
else else
{ {
detail::write_string(n.first.to_string(), v6_ptr); detail::write_string(n.first.to_string(), v6_ptr);
detail::write_endpoint(endp, v6_ptr); detail::write_endpoint(endp, v6_ptr);
} }
#endif
} }
return nodes_slot{v4_num_nodes, v4_nodes_idx, v6_num_nodes, v6_nodes_idx}; return nodes_slot{v4_num_nodes, v4_nodes_idx, v6_num_nodes, v6_nodes_idx};
@ -2398,7 +2384,6 @@ namespace {
v4_ptr += 20; v4_ptr += 20;
nodes.emplace_back(ih, detail::read_v4_endpoint<udp::endpoint>(v4_ptr)); nodes.emplace_back(ih, detail::read_v4_endpoint<udp::endpoint>(v4_ptr));
} }
#if TORRENT_USE_IPV6
char const* v6_ptr = alloc.ptr(v6_nodes_idx); char const* v6_ptr = alloc.ptr(v6_nodes_idx);
for (int i = 0; i < v6_num_nodes; i++) for (int i = 0; i < v6_num_nodes; i++)
{ {
@ -2407,9 +2392,6 @@ namespace {
v6_ptr += 20; v6_ptr += 20;
nodes.emplace_back(ih, detail::read_v6_endpoint<udp::endpoint>(v6_ptr)); nodes.emplace_back(ih, detail::read_v6_endpoint<udp::endpoint>(v6_ptr));
} }
#else
TORRENT_UNUSED(v6_nodes_idx);
#endif
return std::move(nodes); return std::move(nodes);
} }

View File

@ -56,7 +56,6 @@ namespace libtorrent {
bool is_local(address const& a) bool is_local(address const& a)
{ {
TORRENT_TRY { TORRENT_TRY {
#if TORRENT_USE_IPV6
if (a.is_v6()) if (a.is_v6())
{ {
// NOTE: site local is deprecated but by // NOTE: site local is deprecated but by
@ -73,7 +72,6 @@ namespace libtorrent {
// fc00::/7, unique local address // fc00::/7, unique local address
|| (a6.to_bytes()[0] & 0xfe) == 0xfc; || (a6.to_bytes()[0] & 0xfe) == 0xfc;
} }
#endif
address_v4 a4 = a.to_v4(); address_v4 a4 = a.to_v4();
unsigned long ip = a4.to_ulong(); unsigned long ip = a4.to_ulong();
return ((ip & 0xff000000) == 0x0a000000 // 10.x.x.x return ((ip & 0xff000000) == 0x0a000000 // 10.x.x.x
@ -86,54 +84,39 @@ namespace libtorrent {
bool is_loopback(address const& addr) bool is_loopback(address const& addr)
{ {
#if TORRENT_USE_IPV6
TORRENT_TRY { TORRENT_TRY {
if (addr.is_v4()) if (addr.is_v4())
return addr.to_v4() == address_v4::loopback(); return addr.to_v4() == address_v4::loopback();
else else
return addr.to_v6() == address_v6::loopback(); return addr.to_v6() == address_v6::loopback();
} TORRENT_CATCH(std::exception const&) { return false; } } TORRENT_CATCH(std::exception const&) { return false; }
#else
return addr.to_v4() == address_v4::loopback();
#endif
} }
bool is_any(address const& addr) bool is_any(address const& addr)
{ {
TORRENT_TRY { TORRENT_TRY {
#if TORRENT_USE_IPV6
if (addr.is_v4()) if (addr.is_v4())
return addr.to_v4() == address_v4::any(); return addr.to_v4() == address_v4::any();
else if (addr.to_v6().is_v4_mapped()) else if (addr.to_v6().is_v4_mapped())
return (addr.to_v6().to_v4() == address_v4::any()); return (addr.to_v6().to_v4() == address_v4::any());
else else
return addr.to_v6() == address_v6::any(); return addr.to_v6() == address_v6::any();
#else
return addr.to_v4() == address_v4::any();
#endif
} TORRENT_CATCH(std::exception const&) { return false; } } TORRENT_CATCH(std::exception const&) { return false; }
} }
bool is_teredo(address const& addr) bool is_teredo(address const& addr)
{ {
#if TORRENT_USE_IPV6
TORRENT_TRY { TORRENT_TRY {
if (!addr.is_v6()) return false; if (!addr.is_v6()) return false;
static const std::uint8_t teredo_prefix[] = {0x20, 0x01, 0, 0}; static const std::uint8_t teredo_prefix[] = {0x20, 0x01, 0, 0};
address_v6::bytes_type b = addr.to_v6().to_bytes(); address_v6::bytes_type b = addr.to_v6().to_bytes();
return std::memcmp(b.data(), teredo_prefix, 4) == 0; return std::memcmp(b.data(), teredo_prefix, 4) == 0;
} TORRENT_CATCH(std::exception const&) { return false; } } TORRENT_CATCH(std::exception const&) { return false; }
#else
TORRENT_UNUSED(addr);
return false;
#endif
} }
bool supports_ipv6() bool supports_ipv6()
{ {
#if !TORRENT_USE_IPV6 #if defined TORRENT_BUILD_SIMULATOR
return false;
#elif defined TORRENT_BUILD_SIMULATOR
return true; return true;
#elif defined TORRENT_WINDOWS #elif defined TORRENT_WINDOWS
TORRENT_TRY { TORRENT_TRY {
@ -155,11 +138,7 @@ namespace libtorrent {
address ensure_v6(address const& a) address ensure_v6(address const& a)
{ {
#if TORRENT_USE_IPV6
return a == address_v4() ? address_v6() : a; return a == address_v4() ? address_v6() : a;
#else
return a;
#endif
} }
broadcast_socket::broadcast_socket( broadcast_socket::broadcast_socket(
@ -178,11 +157,9 @@ namespace libtorrent {
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec); std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
#if TORRENT_USE_IPV6
if (is_v6(m_multicast_endpoint)) if (is_v6(m_multicast_endpoint))
open_multicast_socket(ios, address_v6::any(), loopback, ec); open_multicast_socket(ios, address_v6::any(), loopback, ec);
else else
#endif
open_multicast_socket(ios, address_v4::any(), loopback, ec); open_multicast_socket(ios, address_v4::any(), loopback, ec);
for (auto const& i : interfaces) for (auto const& i : interfaces)

View File

@ -123,14 +123,11 @@ namespace {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
bool ut_pex_peer_store::was_introduced_by(tcp::endpoint const &ep) bool ut_pex_peer_store::was_introduced_by(tcp::endpoint const &ep)
{ {
#if TORRENT_USE_IPV6
if (is_v4(ep)) if (is_v4(ep))
{ {
#endif
peers4_t::value_type const v(ep.address().to_v4().to_bytes(), ep.port()); peers4_t::value_type const v(ep.address().to_v4().to_bytes(), ep.port());
auto const i = std::lower_bound(m_peers.begin(), m_peers.end(), v); auto const i = std::lower_bound(m_peers.begin(), m_peers.end(), v);
return i != m_peers.end() && *i == v; return i != m_peers.end() && *i == v;
#if TORRENT_USE_IPV6
} }
else else
{ {
@ -138,7 +135,6 @@ namespace {
auto const i = std::lower_bound(m_peers6.begin(), m_peers6.end(), v); auto const i = std::lower_bound(m_peers6.begin(), m_peers6.end(), v);
return i != m_peers6.end() && *i == v; return i != m_peers6.end() && *i == v;
} }
#endif
} }
#endif // TORRENT_DISABLE_EXTENSIONS #endif // TORRENT_DISABLE_EXTENSIONS
@ -1354,14 +1350,12 @@ namespace {
// IPv4 address // IPv4 address
ep = detail::read_v4_endpoint<tcp::endpoint>(ptr); ep = detail::read_v4_endpoint<tcp::endpoint>(ptr);
} }
#if TORRENT_USE_IPV6
else if (addr_type == 1) else if (addr_type == 1)
{ {
// IPv6 address // IPv6 address
if (int(recv_buffer.size()) < 2 + 18 + 2) return; if (int(recv_buffer.size()) < 2 + 18 + 2) return;
ep = detail::read_v6_endpoint<tcp::endpoint>(ptr); ep = detail::read_v6_endpoint<tcp::endpoint>(ptr);
} }
#endif
else else
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -1750,7 +1744,6 @@ namespace {
, address_v4(bytes) , address_v4(bytes)
, aux::session_interface::source_peer, remote().address()); , aux::session_interface::source_peer, remote().address());
} }
#if TORRENT_USE_IPV6
else if (myip.size() == std::tuple_size<address_v6::bytes_type>::value) else if (myip.size() == std::tuple_size<address_v6::bytes_type>::value)
{ {
address_v6::bytes_type bytes; address_v6::bytes_type bytes;
@ -1765,7 +1758,6 @@ namespace {
, ipv6_address , ipv6_address
, aux::session_interface::source_peer, remote().address()); , aux::session_interface::source_peer, remote().address());
} }
#endif
} }
// if we're finished and this peer is uploading only // if we're finished and this peer is uploading only

View File

@ -127,14 +127,12 @@ namespace {
return address_v4(b); return address_v4(b);
} }
#if TORRENT_USE_IPV6
address_v6 inaddr6_to_address(in6_addr const* ina6, int const len = 16) address_v6 inaddr6_to_address(in6_addr const* ina6, int const len = 16)
{ {
boost::asio::ip::address_v6::bytes_type b = {}; boost::asio::ip::address_v6::bytes_type b = {};
if (len > 0) std::memcpy(b.data(), ina6, std::min(std::size_t(len), b.size())); if (len > 0) std::memcpy(b.data(), ina6, std::min(std::size_t(len), b.size()));
return address_v6(b); return address_v6(b);
} }
#endif
#if !TORRENT_USE_NETLINK #if !TORRENT_USE_NETLINK
int sockaddr_len(sockaddr const* sin) int sockaddr_len(sockaddr const* sin)
@ -151,7 +149,6 @@ namespace {
if (sin->sa_family == AF_INET || assume_family == AF_INET) if (sin->sa_family == AF_INET || assume_family == AF_INET)
return inaddr_to_address(&reinterpret_cast<sockaddr_in const*>(sin)->sin_addr return inaddr_to_address(&reinterpret_cast<sockaddr_in const*>(sin)->sin_addr
, sockaddr_len(sin) - int(offsetof(sockaddr, sa_data))); , sockaddr_len(sin) - int(offsetof(sockaddr, sa_data)));
#if TORRENT_USE_IPV6
else if (sin->sa_family == AF_INET6 || assume_family == AF_INET6) else if (sin->sa_family == AF_INET6 || assume_family == AF_INET6)
{ {
auto saddr = reinterpret_cast<sockaddr_in6 const*>(sin); auto saddr = reinterpret_cast<sockaddr_in6 const*>(sin);
@ -160,7 +157,6 @@ namespace {
ret.scope_id(saddr->sin6_scope_id); ret.scope_id(saddr->sin6_scope_id);
return ret; return ret;
} }
#endif
return address(); return address();
} }
#endif #endif
@ -168,9 +164,7 @@ namespace {
bool valid_addr_family(int family) bool valid_addr_family(int family)
{ {
return (family == AF_INET return (family == AF_INET
#if TORRENT_USE_IPV6
|| family == AF_INET6 || family == AF_INET6
#endif
); );
} }
@ -193,7 +187,6 @@ namespace {
} }
return address_v4(b); return address_v4(b);
} }
#if TORRENT_USE_IPV6
else if (family == AF_INET6) else if (family == AF_INET6)
{ {
address_v6::bytes_type b; address_v6::bytes_type b;
@ -210,7 +203,6 @@ namespace {
} }
return address_v6(b); return address_v6(b);
} }
#endif
else else
{ {
return address(); return address();
@ -299,7 +291,6 @@ namespace {
&& rt_msg->rtm_table != RT_TABLE_LOCAL)) && rt_msg->rtm_table != RT_TABLE_LOCAL))
return false; return false;
#if TORRENT_USE_IPV6
// make sure the defaults have the right address family // make sure the defaults have the right address family
// in case the attributes are not present // in case the attributes are not present
if (rt_msg->rtm_family == AF_INET6) if (rt_msg->rtm_family == AF_INET6)
@ -307,7 +298,6 @@ namespace {
rt_info->gateway = address_v6(); rt_info->gateway = address_v6();
rt_info->destination = address_v6(); rt_info->destination = address_v6();
} }
#endif
int if_index = 0; int if_index = 0;
int rt_len = int(RTM_PAYLOAD(nl_hdr)); int rt_len = int(RTM_PAYLOAD(nl_hdr));
@ -324,25 +314,21 @@ namespace {
if_index = *reinterpret_cast<int*>(RTA_DATA(rt_attr)); if_index = *reinterpret_cast<int*>(RTA_DATA(rt_attr));
break; break;
case RTA_GATEWAY: case RTA_GATEWAY:
#if TORRENT_USE_IPV6
if (rt_msg->rtm_family == AF_INET6) if (rt_msg->rtm_family == AF_INET6)
{ {
rt_info->gateway = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr))); rt_info->gateway = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr)));
} }
else else
#endif
{ {
rt_info->gateway = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr))); rt_info->gateway = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr)));
} }
break; break;
case RTA_DST: case RTA_DST:
#if TORRENT_USE_IPV6
if (rt_msg->rtm_family == AF_INET6) if (rt_msg->rtm_family == AF_INET6)
{ {
rt_info->destination = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr))); rt_info->destination = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr)));
} }
else else
#endif
{ {
rt_info->destination = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr))); rt_info->destination = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr)));
} }
@ -353,14 +339,12 @@ namespace {
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
#if TORRENT_USE_IPV6
if (rt_info->gateway.is_v6() && rt_info->gateway.to_v6().is_link_local()) if (rt_info->gateway.is_v6() && rt_info->gateway.to_v6().is_link_local())
{ {
address_v6 gateway6 = rt_info->gateway.to_v6(); address_v6 gateway6 = rt_info->gateway.to_v6();
gateway6.scope_id(std::uint32_t(if_index)); gateway6.scope_id(std::uint32_t(if_index));
rt_info->gateway = gateway6; rt_info->gateway = gateway6;
} }
#endif
ifreq req = {}; ifreq req = {};
::if_indextoname(std::uint32_t(if_index), req.ifr_name); ::if_indextoname(std::uint32_t(if_index), req.ifr_name);
@ -381,7 +365,6 @@ namespace {
ip_info->preferred = (addr_msg->ifa_flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED | IFA_F_TENTATIVE)) == 0; ip_info->preferred = (addr_msg->ifa_flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED | IFA_F_TENTATIVE)) == 0;
#if TORRENT_USE_IPV6
if (addr_msg->ifa_family == AF_INET6) if (addr_msg->ifa_family == AF_INET6)
{ {
TORRENT_ASSERT(addr_msg->ifa_prefixlen <= 128); TORRENT_ASSERT(addr_msg->ifa_prefixlen <= 128);
@ -403,7 +386,6 @@ namespace {
} }
} }
else else
#endif
{ {
TORRENT_ASSERT(addr_msg->ifa_prefixlen <= 32); TORRENT_ASSERT(addr_msg->ifa_prefixlen <= 32);
if (addr_msg->ifa_prefixlen != 0) if (addr_msg->ifa_prefixlen != 0)
@ -432,7 +414,6 @@ namespace {
break; break;
BOOST_FALLTHROUGH; BOOST_FALLTHROUGH;
case IFA_LOCAL: case IFA_LOCAL:
#if TORRENT_USE_IPV6
if (addr_msg->ifa_family == AF_INET6) if (addr_msg->ifa_family == AF_INET6)
{ {
address_v6 addr = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr))); address_v6 addr = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr)));
@ -441,7 +422,6 @@ namespace {
ip_info->interface_address = addr; ip_info->interface_address = addr;
} }
else else
#endif
{ {
ip_info->interface_address = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr))); ip_info->interface_address = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr)));
} }
@ -535,7 +515,6 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (a1.is_v4() != a2.is_v4()) return false; if (a1.is_v4() != a2.is_v4()) return false;
if (a1.is_v4() != mask.is_v4()) return false; if (a1.is_v4() != mask.is_v4()) return false;
#if TORRENT_USE_IPV6
if (a1.is_v6()) if (a1.is_v6())
{ {
address_v6::bytes_type b1 = a1.to_v6().to_bytes(); address_v6::bytes_type b1 = a1.to_v6().to_bytes();
@ -546,9 +525,8 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
b1[i] &= m[i]; b1[i] &= m[i];
b2[i] &= m[i]; b2[i] &= m[i];
} }
return std::memcmp(b1.data(), b2.data(), b1.size()) == 0; return b1 == b2;
} }
#endif
return (a1.to_v4().to_ulong() & mask.to_v4().to_ulong()) return (a1.to_v4().to_ulong() & mask.to_v4().to_ulong())
== (a2.to_v4().to_ulong() & mask.to_v4().to_ulong()); == (a2.to_v4().to_ulong() & mask.to_v4().to_ulong());
} }
@ -703,14 +681,12 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
std::strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1); std::strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1);
if (ioctl(s, SIOCGIFNETMASK, &req) < 0) if (ioctl(s, SIOCGIFNETMASK, &req) < 0)
{ {
#if TORRENT_USE_IPV6
if (iface.interface_address.is_v6()) if (iface.interface_address.is_v6())
{ {
// this is expected to fail (at least on MacOS X) // this is expected to fail (at least on MacOS X)
iface.netmask = address_v6::any(); iface.netmask = address_v6::any();
} }
else else
#endif
{ {
ec = error_code(errno, system_category()); ec = error_code(errno, system_category());
::close(s); ::close(s);
@ -1142,7 +1118,6 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
{ {
ip_route r; ip_route r;
r.gateway = sockaddr_to_address((const sockaddr*)&routes->Table[i].NextHop); r.gateway = sockaddr_to_address((const sockaddr*)&routes->Table[i].NextHop);
#if TORRENT_USE_IPV6
// The scope_id in NextHop is always zero because that would make // The scope_id in NextHop is always zero because that would make
// things too easy apparently // things too easy apparently
if (r.gateway.is_v6() && r.gateway.to_v6().is_link_local()) if (r.gateway.is_v6() && r.gateway.to_v6().is_link_local())
@ -1151,7 +1126,6 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
gateway6.scope_id(routes->Table[i].InterfaceIndex); gateway6.scope_id(routes->Table[i].InterfaceIndex);
r.gateway = gateway6; r.gateway = gateway6;
} }
#endif
r.destination = sockaddr_to_address( r.destination = sockaddr_to_address(
(const sockaddr*)&routes->Table[i].DestinationPrefix.Prefix); (const sockaddr*)&routes->Table[i].DestinationPrefix.Prefix);
r.netmask = build_netmask(routes->Table[i].DestinationPrefix.PrefixLength r.netmask = build_netmask(routes->Table[i].DestinationPrefix.PrefixLength

View File

@ -172,7 +172,6 @@ namespace libtorrent {
} }
} }
#if TORRENT_USE_IPV6
if (!tracker_req().ipv6.empty() && !i2p) if (!tracker_req().ipv6.empty() && !i2p)
{ {
for (auto const& v6 : tracker_req().ipv6) for (auto const& v6 : tracker_req().ipv6)
@ -184,7 +183,6 @@ namespace libtorrent {
url += escape_string(ip); url += escape_string(ip);
} }
} }
#endif
if (!tracker_req().outgoing_socket) if (!tracker_req().outgoing_socket)
{ {
@ -540,7 +538,6 @@ namespace libtorrent {
peers_ent.clear(); peers_ent.clear();
} }
#if TORRENT_USE_IPV6
bdecode_node ipv6_peers = e.dict_find_string("peers6"); bdecode_node ipv6_peers = e.dict_find_string("peers6");
if (ipv6_peers) if (ipv6_peers)
{ {
@ -561,9 +558,6 @@ namespace libtorrent {
{ {
ipv6_peers.clear(); ipv6_peers.clear();
} }
#else
bdecode_node ipv6_peers;
#endif
/* /*
// if we didn't receive any peers. We don't care if we're stopping anyway // if we didn't receive any peers. We don't care if we're stopping anyway
if (peers_ent == 0 && ipv6_peers == 0 if (peers_ent == 0 && ipv6_peers == 0
@ -579,10 +573,8 @@ namespace libtorrent {
char const* p = ip_ent.string_ptr(); char const* p = ip_ent.string_ptr();
if (ip_ent.string_length() == std::tuple_size<address_v4::bytes_type>::value) if (ip_ent.string_length() == std::tuple_size<address_v4::bytes_type>::value)
resp.external_ip = detail::read_v4_address(p); resp.external_ip = detail::read_v4_address(p);
#if TORRENT_USE_IPV6
else if (ip_ent.string_length() == std::tuple_size<address_v6::bytes_type>::value) else if (ip_ent.string_length() == std::tuple_size<address_v6::bytes_type>::value)
resp.external_ip = detail::read_v6_address(p); resp.external_ip = detail::read_v6_address(p);
#endif
} }
return resp; return resp;

View File

@ -41,13 +41,11 @@ namespace libtorrent {
TORRENT_ASSERT(last.is_v4()); TORRENT_ASSERT(last.is_v4());
m_filter4.add_rule(first.to_v4().to_bytes(), last.to_v4().to_bytes(), flags); m_filter4.add_rule(first.to_v4().to_bytes(), last.to_v4().to_bytes(), flags);
} }
#if TORRENT_USE_IPV6
else if (first.is_v6()) else if (first.is_v6())
{ {
TORRENT_ASSERT(last.is_v6()); TORRENT_ASSERT(last.is_v6());
m_filter6.add_rule(first.to_v6().to_bytes(), last.to_v6().to_bytes(), flags); m_filter6.add_rule(first.to_v6().to_bytes(), last.to_v6().to_bytes(), flags);
} }
#endif
else else
TORRENT_ASSERT_FAIL(); TORRENT_ASSERT_FAIL();
} }
@ -56,22 +54,14 @@ namespace libtorrent {
{ {
if (addr.is_v4()) if (addr.is_v4())
return m_filter4.access(addr.to_v4().to_bytes()); return m_filter4.access(addr.to_v4().to_bytes());
#if TORRENT_USE_IPV6
TORRENT_ASSERT(addr.is_v6()); TORRENT_ASSERT(addr.is_v6());
return m_filter6.access(addr.to_v6().to_bytes()); return m_filter6.access(addr.to_v6().to_bytes());
#else
return 0;
#endif
} }
ip_filter::filter_tuple_t ip_filter::export_filter() const ip_filter::filter_tuple_t ip_filter::export_filter() const
{ {
#if TORRENT_USE_IPV6
return std::make_tuple(m_filter4.export_filter<address_v4>() return std::make_tuple(m_filter4.export_filter<address_v4>()
, m_filter6.export_filter<address_v6>()); , m_filter6.export_filter<address_v6>());
#else
return m_filter4.export_filter<address_v4>();
#endif
} }
void port_filter::add_rule(std::uint16_t first, std::uint16_t last, std::uint32_t flags) void port_filter::add_rule(std::uint16_t first, std::uint16_t last, std::uint32_t flags)

View File

@ -177,10 +177,8 @@ namespace libtorrent {
, address const& local6, address const& global6) , address const& local6, address const& global6)
: m_addresses{{global4, ensure_v6(global6)}, {local4, ensure_v6(local6)}} : m_addresses{{global4, ensure_v6(global6)}, {local4, ensure_v6(local6)}}
{ {
#if TORRENT_USE_IPV6
TORRENT_ASSERT(m_addresses[0][1].is_v6()); TORRENT_ASSERT(m_addresses[0][1].is_v6());
TORRENT_ASSERT(m_addresses[1][1].is_v6()); TORRENT_ASSERT(m_addresses[1][1].is_v6());
#endif
TORRENT_ASSERT(m_addresses[0][0].is_v4()); TORRENT_ASSERT(m_addresses[0][0].is_v4());
TORRENT_ASSERT(m_addresses[1][0].is_v4()); TORRENT_ASSERT(m_addresses[1][0].is_v4());
} }
@ -188,9 +186,7 @@ namespace libtorrent {
address external_ip::external_address(address const& ip) const address external_ip::external_address(address const& ip) const
{ {
address ext = m_addresses[is_local(ip)][ip.is_v6()]; address ext = m_addresses[is_local(ip)][ip.is_v6()];
#if TORRENT_USE_IPV6
if (ip.is_v6() && ext == address_v4()) return address_v6(); if (ip.is_v6() && ext == address_v4()) return address_v6();
#endif
return ext; return ext;
} }
} }

View File

@ -61,10 +61,8 @@ namespace libtorrent { namespace dht {
address addr; address addr;
if (nid.string_length() == 24) if (nid.string_length() == 24)
addr = detail::read_v4_address(in); addr = detail::read_v4_address(in);
#if TORRENT_USE_IPV6
else if (nid.string_length() == 36) else if (nid.string_length() == 36)
addr = detail::read_v6_address(in); addr = detail::read_v6_address(in);
#endif
else else
continue; continue;
ret.emplace_back(addr, id); ret.emplace_back(addr, id);
@ -110,10 +108,8 @@ namespace {
if (bdecode_node const nodes = e.dict_find_list("nodes")) if (bdecode_node const nodes = e.dict_find_list("nodes"))
ret.nodes = detail::read_endpoint_list<udp::endpoint>(nodes); ret.nodes = detail::read_endpoint_list<udp::endpoint>(nodes);
#if TORRENT_USE_IPV6
if (bdecode_node const nodes = e.dict_find_list("nodes6")) if (bdecode_node const nodes = e.dict_find_list("nodes6"))
ret.nodes6 = detail::read_endpoint_list<udp::endpoint>(nodes); ret.nodes6 = detail::read_endpoint_list<udp::endpoint>(nodes);
#endif
return ret; return ret;
} }
@ -130,10 +126,8 @@ namespace {
} }
entry const nodes = save_nodes(state.nodes); entry const nodes = save_nodes(state.nodes);
if (!nodes.list().empty()) ret["nodes"] = nodes; if (!nodes.list().empty()) ret["nodes"] = nodes;
#if TORRENT_USE_IPV6
entry const nodes6 = save_nodes(state.nodes6); entry const nodes6 = save_nodes(state.nodes6);
if (!nodes6.list().empty()) ret["nodes6"] = nodes6; if (!nodes6.list().empty()) ret["nodes6"] = nodes6;
#endif
return ret; return ret;
} }
}} }}

View File

@ -119,13 +119,11 @@ namespace libtorrent { namespace dht {
if (s.is_ssl()) return; if (s.is_ssl()) return;
address const local_address = s.get_local_endpoint().address(); address const local_address = s.get_local_endpoint().address();
#if TORRENT_USE_IPV6
// don't try to start dht nodes on non-global IPv6 addresses // don't try to start dht nodes on non-global IPv6 addresses
// with IPv4 the interface might be behind NAT so we can't skip them based on the scope of the local address // with IPv4 the interface might be behind NAT so we can't skip them based on the scope of the local address
// and we might not have the external address yet // and we might not have the external address yet
if (local_address.is_v6() && is_local(local_address)) if (local_address.is_v6() && is_local(local_address))
return; return;
#endif
auto stored_nid = std::find_if(m_state.nids.begin(), m_state.nids.end() auto stored_nid = std::find_if(m_state.nids.begin(), m_state.nids.end()
, [&](node_ids_t::value_type const& nid) { return nid.first == local_address; }); , [&](node_ids_t::value_type const& nid) { return nid.first == local_address; });
node_id const nid = stored_nid != m_state.nids.end() ? stored_nid->second : node_id(); node_id const nid = stored_nid != m_state.nids.end() ? stored_nid->second : node_id();
@ -160,12 +158,10 @@ namespace libtorrent { namespace dht {
{ {
if (s.is_ssl()) return; if (s.is_ssl()) return;
#if TORRENT_USE_IPV6
address local_address = s.get_local_endpoint().address(); address local_address = s.get_local_endpoint().address();
// since we don't start nodes on local IPv6 interfaces we don't need to remove them either // since we don't start nodes on local IPv6 interfaces we don't need to remove them either
if (local_address.is_v6() && is_local(local_address)) if (local_address.is_v6() && is_local(local_address))
return; return;
#endif
TORRENT_ASSERT(m_nodes.count(s) == 1); TORRENT_ASSERT(m_nodes.count(s) == 1);
m_nodes.erase(s); m_nodes.erase(s);
} }
@ -181,11 +177,9 @@ namespace libtorrent { namespace dht {
n.second.connection_timer.expires_from_now(seconds(1), ec); n.second.connection_timer.expires_from_now(seconds(1), ec);
n.second.connection_timer.async_wait( n.second.connection_timer.async_wait(
std::bind(&dht_tracker::connection_timeout, self(), n.first, _1)); std::bind(&dht_tracker::connection_timeout, self(), n.first, _1));
#if TORRENT_USE_IPV6
if (is_v6(n.first.get_local_endpoint())) if (is_v6(n.first.get_local_endpoint()))
n.second.dht.bootstrap(concat(m_state.nodes6, m_state.nodes), f); n.second.dht.bootstrap(concat(m_state.nodes6, m_state.nodes), f);
else else
#endif
n.second.dht.bootstrap(concat(m_state.nodes, m_state.nodes6), f); n.second.dht.bootstrap(concat(m_state.nodes, m_state.nodes6), f);
} }
@ -626,18 +620,12 @@ namespace libtorrent { namespace dht {
void dht_tracker::add_node(udp::endpoint const& node) void dht_tracker::add_node(udp::endpoint const& node)
{ {
#if !TORRENT_USE_IPV6
TORRENT_ASSERT(is_v4(node));
#endif
for (auto& n : m_nodes) for (auto& n : m_nodes)
n.second.dht.add_node(node); n.second.dht.add_node(node);
} }
void dht_tracker::add_router_node(udp::endpoint const& node) void dht_tracker::add_router_node(udp::endpoint const& node)
{ {
#if !TORRENT_USE_IPV6
TORRENT_ASSERT(is_v4(node));
#endif
for (auto& n : m_nodes) for (auto& n : m_nodes)
n.second.dht.add_router_node(node); n.second.dht.add_router_node(node);
} }

View File

@ -223,10 +223,6 @@ void node::bootstrap(std::vector<udp::endpoint> const& nodes
for (auto const& n : nodes) for (auto const& n : nodes)
{ {
#if !TORRENT_USE_IPV6
if (is_v6(n)) continue;
#endif
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
++count; ++count;
#endif #endif
@ -282,7 +278,6 @@ void node::incoming(aux::listen_socket_handle const& s, msg const& m)
ext_ip = r.dict_find_string("ip"); ext_ip = r.dict_find_string("ip");
} }
#if TORRENT_USE_IPV6
if (ext_ip && ext_ip.string_length() >= 16) if (ext_ip && ext_ip.string_length() >= 16)
{ {
// this node claims we use the wrong node-ID! // this node claims we use the wrong node-ID!
@ -291,9 +286,8 @@ void node::incoming(aux::listen_socket_handle const& s, msg const& m)
if (m_observer != nullptr) if (m_observer != nullptr)
m_observer->set_external_address(m_sock, address_v6(b) m_observer->set_external_address(m_sock, address_v6(b)
, m.addr.address()); , m.addr.address());
} else }
#endif else if (ext_ip && ext_ip.string_length() >= 4)
if (ext_ip && ext_ip.string_length() >= 4)
{ {
address_v4::bytes_type b{}; address_v4::bytes_type b{};
std::memcpy(&b[0], ext_ip.string_ptr(), 4); std::memcpy(&b[0], ext_ip.string_ptr(), 4);

View File

@ -85,14 +85,11 @@ node_id generate_id_impl(address const& ip_, std::uint32_t r)
std::uint8_t* ip = nullptr; std::uint8_t* ip = nullptr;
static const std::uint8_t v4mask[] = { 0x03, 0x0f, 0x3f, 0xff }; static const std::uint8_t v4mask[] = { 0x03, 0x0f, 0x3f, 0xff };
#if TORRENT_USE_IPV6
static const std::uint8_t v6mask[] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; static const std::uint8_t v6mask[] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
#endif
std::uint8_t const* mask = nullptr; std::uint8_t const* mask = nullptr;
int num_octets = 0; int num_octets = 0;
address_v4::bytes_type b4{}; address_v4::bytes_type b4{};
#if TORRENT_USE_IPV6
address_v6::bytes_type b6{}; address_v6::bytes_type b6{};
if (ip_.is_v6()) if (ip_.is_v6())
{ {
@ -102,7 +99,6 @@ node_id generate_id_impl(address const& ip_, std::uint32_t r)
mask = v6mask; mask = v6mask;
} }
else else
#endif
{ {
b4 = ip_.to_v4().to_bytes(); b4 = ip_.to_v4().to_bytes();
ip = b4.data(); ip = b4.data();

View File

@ -78,31 +78,25 @@ namespace {
void ip_set::insert(address const& addr) void ip_set::insert(address const& addr)
{ {
#if TORRENT_USE_IPV6
if (addr.is_v6()) if (addr.is_v6())
m_ip6s.insert(addr.to_v6().to_bytes()); m_ip6s.insert(addr.to_v6().to_bytes());
else else
#endif
m_ip4s.insert(addr.to_v4().to_bytes()); m_ip4s.insert(addr.to_v4().to_bytes());
} }
bool ip_set::exists(address const& addr) const bool ip_set::exists(address const& addr) const
{ {
#if TORRENT_USE_IPV6
if (addr.is_v6()) if (addr.is_v6())
return m_ip6s.find(addr.to_v6().to_bytes()) != m_ip6s.end(); return m_ip6s.find(addr.to_v6().to_bytes()) != m_ip6s.end();
else else
#endif
return m_ip4s.find(addr.to_v4().to_bytes()) != m_ip4s.end(); return m_ip4s.find(addr.to_v4().to_bytes()) != m_ip4s.end();
} }
void ip_set::erase(address const& addr) void ip_set::erase(address const& addr)
{ {
#if TORRENT_USE_IPV6
if (addr.is_v6()) if (addr.is_v6())
erase_one(m_ip6s, addr.to_v6().to_bytes()); erase_one(m_ip6s, addr.to_v6().to_bytes());
else else
#endif
erase_one(m_ip4s, addr.to_v4().to_bytes()); erase_one(m_ip4s, addr.to_v4().to_bytes());
} }
@ -315,7 +309,6 @@ bool compare_ip_cidr(address const& lhs, address const& rhs)
{ {
TORRENT_ASSERT(lhs.is_v4() == rhs.is_v4()); TORRENT_ASSERT(lhs.is_v4() == rhs.is_v4());
#if TORRENT_USE_IPV6
if (lhs.is_v6()) if (lhs.is_v6())
{ {
// if IPv6 addresses is in the same /64, they're too close and we won't // if IPv6 addresses is in the same /64, they're too close and we won't
@ -331,7 +324,6 @@ bool compare_ip_cidr(address const& lhs, address const& rhs)
return mask == 0; return mask == 0;
} }
else else
#endif
{ {
// if IPv4 addresses is in the same /24, they're too close and we won't // if IPv4 addresses is in the same /24, they're too close and we won't
// trust the second one // trust the second one
@ -1021,9 +1013,6 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
void routing_table::add_router_node(udp::endpoint const& router) void routing_table::add_router_node(udp::endpoint const& router)
{ {
#if !TORRENT_USE_IPV6
TORRENT_ASSERT(is_v4(router));
#endif
m_router_nodes.insert(router); m_router_nodes.insert(router);
} }

View File

@ -83,14 +83,12 @@ void observer::set_target(udp::endpoint const& ep)
m_sent = clock_type::now(); m_sent = clock_type::now();
m_port = ep.port(); m_port = ep.port();
#if TORRENT_USE_IPV6
if (is_v6(ep)) if (is_v6(ep))
{ {
flags |= flag_ipv6_address; flags |= flag_ipv6_address;
m_addr.v6 = ep.address().to_v6().to_bytes(); m_addr.v6 = ep.address().to_v6().to_bytes();
} }
else else
#endif
{ {
flags &= ~flag_ipv6_address; flags &= ~flag_ipv6_address;
m_addr.v4 = ep.address().to_v4().to_bytes(); m_addr.v4 = ep.address().to_v4().to_bytes();
@ -99,11 +97,9 @@ void observer::set_target(udp::endpoint const& ep)
address observer::target_addr() const address observer::target_addr() const
{ {
#if TORRENT_USE_IPV6
if (flags & flag_ipv6_address) if (flags & flag_ipv6_address)
return address_v6(m_addr.v6); return address_v6(m_addr.v6);
else else
#endif
return address_v4(m_addr.v4); return address_v4(m_addr.v4);
} }

View File

@ -182,7 +182,6 @@ void traversal_algorithm::add_entry(node_id const& id
if (m_node.settings().restrict_search_ips if (m_node.settings().restrict_search_ips
&& !(flags & observer::flag_initial)) && !(flags & observer::flag_initial))
{ {
#if TORRENT_USE_IPV6
if (o->target_addr().is_v6()) if (o->target_addr().is_v6())
{ {
address_v6::bytes_type addr_bytes = o->target_addr().to_v6().to_bytes(); address_v6::bytes_type addr_bytes = o->target_addr().to_v6().to_bytes();
@ -193,7 +192,6 @@ void traversal_algorithm::add_entry(node_id const& id
goto add_result; goto add_result;
} }
else else
#endif
{ {
// mask the lower octet // mask the lower octet
std::uint32_t const prefix4 std::uint32_t const prefix4

View File

@ -69,15 +69,11 @@ static error_code dummy;
lsd::lsd(io_service& ios, aux::lsd_callback& cb) lsd::lsd(io_service& ios, aux::lsd_callback& cb)
: m_callback(cb) : m_callback(cb)
, m_socket(udp::endpoint(make_address_v4("239.192.152.143", dummy), 6771)) , m_socket(udp::endpoint(make_address_v4("239.192.152.143", dummy), 6771))
#if TORRENT_USE_IPV6
, m_socket6(udp::endpoint(make_address_v6("ff15::efc0:988f", dummy), 6771)) , m_socket6(udp::endpoint(make_address_v6("ff15::efc0:988f", dummy), 6771))
#endif
, m_broadcast_timer(ios) , m_broadcast_timer(ios)
, m_cookie((random(0x7fffffff) ^ std::uintptr_t(this)) & 0x7fffffff) , m_cookie((random(0x7fffffff) ^ std::uintptr_t(this)) & 0x7fffffff)
, m_disabled(false) , m_disabled(false)
#if TORRENT_USE_IPV6
, m_disabled6(false) , m_disabled6(false)
#endif
{ {
} }
@ -107,10 +103,8 @@ void lsd::start(error_code& ec)
, m_broadcast_timer.get_io_service(), ec); , m_broadcast_timer.get_io_service(), ec);
if (ec) return; if (ec) return;
#if TORRENT_USE_IPV6
m_socket6.open(std::bind(&lsd::on_announce, self(), _1, _2) m_socket6.open(std::bind(&lsd::on_announce, self(), _1, _2)
, m_broadcast_timer.get_io_service(), ec); , m_broadcast_timer.get_io_service(), ec);
#endif
} }
lsd::~lsd() = default; lsd::~lsd() = default;
@ -123,11 +117,7 @@ void lsd::announce(sha1_hash const& ih, int listen_port, bool broadcast)
void lsd::announce_impl(sha1_hash const& ih, int const listen_port void lsd::announce_impl(sha1_hash const& ih, int const listen_port
, bool const broadcast, int retry_count) , bool const broadcast, int retry_count)
{ {
#if TORRENT_USE_IPV6
if (m_disabled && m_disabled6) return; if (m_disabled && m_disabled6) return;
#else
if (m_disabled) return;
#endif
char msg[200]; char msg[200];
@ -154,7 +144,6 @@ void lsd::announce_impl(sha1_hash const& ih, int const listen_port
} }
} }
#if TORRENT_USE_IPV6
if (!m_disabled6) if (!m_disabled6)
{ {
int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, aux::to_hex(ih).c_str() int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, aux::to_hex(ih).c_str()
@ -172,16 +161,11 @@ void lsd::announce_impl(sha1_hash const& ih, int const listen_port
#endif #endif
} }
} }
#endif
++retry_count; ++retry_count;
if (retry_count >= 3) return; if (retry_count >= 3) return;
#if TORRENT_USE_IPV6
if (m_disabled && m_disabled6) return; if (m_disabled && m_disabled6) return;
#else
if (m_disabled) return;
#endif
ADD_OUTSTANDING_ASYNC("lsd::resend_announce"); ADD_OUTSTANDING_ASYNC("lsd::resend_announce");
m_broadcast_timer.expires_from_now(seconds(2 * retry_count), ec); m_broadcast_timer.expires_from_now(seconds(2 * retry_count), ec);
@ -292,15 +276,11 @@ void lsd::on_announce(udp::endpoint const& from, span<char const> buf)
void lsd::close() void lsd::close()
{ {
m_socket.close(); m_socket.close();
#if TORRENT_USE_IPV6
m_socket6.close(); m_socket6.close();
#endif
error_code ec; error_code ec;
m_broadcast_timer.cancel(ec); m_broadcast_timer.cancel(ec);
m_disabled = true; m_disabled = true;
#if TORRENT_USE_IPV6
m_disabled6 = true; m_disabled6 = true;
#endif
} }
} // libtorrent namespace } // libtorrent namespace

View File

@ -504,9 +504,6 @@ void natpmp::send_map_request(port_mapping_t const i)
else if (m_version == version_pcp) else if (m_version == version_pcp)
{ {
// PCP requires the use of IPv6 addresses even for IPv4 messages // PCP requires the use of IPv6 addresses even for IPv4 messages
// reference asio's address_v6 class directly so that we can use it
// even if TORRENT_USE_IPV6 is false
using boost::asio::ip::address_v6;
write_uint8(m_version, out); write_uint8(m_version, out);
write_uint8(opcode_map, out); write_uint8(opcode_map, out);
write_uint16(0, out); // reserved write_uint16(0, out); // reserved
@ -763,14 +760,12 @@ void natpmp::on_reply(error_code const& e
if (version == version_natpmp) if (version == version_natpmp)
lifetime = aux::numeric_cast<int>(read_uint32(in)); lifetime = aux::numeric_cast<int>(read_uint32(in));
address external_addr; address external_addr;
#if TORRENT_USE_IPV6
if (version == version_pcp) if (version == version_pcp)
{ {
external_addr = read_v6_address(in); external_addr = read_v6_address(in);
if (external_addr.to_v6().is_v4_mapped()) if (external_addr.to_v6().is_v4_mapped())
external_addr = external_addr.to_v6().to_v4(); external_addr = external_addr.to_v6().to_v4();
} }
#endif
if (version == version_natpmp) if (version == version_natpmp)
{ {

View File

@ -340,7 +340,7 @@ namespace libtorrent {
} }
#endif #endif
} }
#if TORRENT_USE_IPV6 && defined IPV6_TCLASS #if defined IPV6_TCLASS
else if (is_v6(m_remote) && m_settings.get_int(settings_pack::peer_tos) != 0) else if (is_v6(m_remote) && m_settings.get_int(settings_pack::peer_tos) != 0)
{ {
m_socket->set_option(traffic_class(char(m_settings.get_int(settings_pack::peer_tos))), ec); m_socket->set_option(traffic_class(char(m_settings.get_int(settings_pack::peer_tos))), ec);
@ -649,13 +649,11 @@ namespace libtorrent {
address_v4::bytes_type bytes = addr.to_v4().to_bytes(); address_v4::bytes_type bytes = addr.to_v4().to_bytes();
x.assign(reinterpret_cast<char*>(bytes.data()), bytes.size()); x.assign(reinterpret_cast<char*>(bytes.data()), bytes.size());
} }
#if TORRENT_USE_IPV6
else else
{ {
address_v6::bytes_type bytes = addr.to_v6().to_bytes(); address_v6::bytes_type bytes = addr.to_v6().to_bytes();
x.assign(reinterpret_cast<char*>(bytes.data()), bytes.size()); x.assign(reinterpret_cast<char*>(bytes.data()), bytes.size());
} }
#endif
x.append(t->torrent_file().info_hash().data(), 20); x.append(t->torrent_file().info_hash().data(), 20);
sha1_hash hash = hasher(x).final(); sha1_hash hash = hasher(x).final();
@ -6131,7 +6129,7 @@ namespace libtorrent {
} }
#endif #endif
} }
#if TORRENT_USE_IPV6 && defined IPV6_TCLASS #if defined IPV6_TCLASS
else if (is_v6(m_remote) && m_settings.get_int(settings_pack::peer_tos) != 0) else if (is_v6(m_remote) && m_settings.get_int(settings_pack::peer_tos) != 0)
{ {
error_code err; error_code err;

View File

@ -734,21 +734,15 @@ namespace libtorrent {
); );
} }
#if TORRENT_USE_IPV6
bool const is_v6 = lt::is_v6(c.remote()); bool const is_v6 = lt::is_v6(c.remote());
#else
bool const is_v6 = false;
#endif
torrent_peer* p = m_peer_allocator.allocate_peer_entry( torrent_peer* p = m_peer_allocator.allocate_peer_entry(
is_v6 ? torrent_peer_allocator_interface::ipv6_peer_type is_v6 ? torrent_peer_allocator_interface::ipv6_peer_type
: torrent_peer_allocator_interface::ipv4_peer_type); : torrent_peer_allocator_interface::ipv4_peer_type);
if (p == nullptr) return false; if (p == nullptr) return false;
#if TORRENT_USE_IPV6
if (is_v6) if (is_v6)
new (p) ipv6_peer(c.remote(), false, {}); new (p) ipv6_peer(c.remote(), false, {});
else else
#endif
new (p) ipv4_peer(c.remote(), false, {}); new (p) ipv4_peer(c.remote(), false, {});
iter = m_peers.insert(iter, p); iter = m_peers.insert(iter, p);
@ -1043,13 +1037,11 @@ namespace libtorrent {
if (remote_address == address() || remote.port() == 0) if (remote_address == address() || remote.port() == 0)
return nullptr; return nullptr;
#if TORRENT_USE_IPV6
// don't allow link-local IPv6 addresses since they // don't allow link-local IPv6 addresses since they
// can't be used like normal addresses, they require an interface // can't be used like normal addresses, they require an interface
// and will just cause connect() to fail with EINVAL // and will just cause connect() to fail with EINVAL
if (remote_address.is_v6() && remote_address.to_v6().is_link_local()) if (remote_address.is_v6() && remote_address.to_v6().is_link_local())
return nullptr; return nullptr;
#endif
iterator iter; iterator iter;
torrent_peer* p = nullptr; torrent_peer* p = nullptr;
@ -1075,21 +1067,15 @@ namespace libtorrent {
// we don't have any info about this peer. // we don't have any info about this peer.
// add a new entry // add a new entry
#if TORRENT_USE_IPV6
bool const is_v6 = remote_address.is_v6(); bool const is_v6 = remote_address.is_v6();
#else
bool const is_v6 = false;
#endif
p = m_peer_allocator.allocate_peer_entry( p = m_peer_allocator.allocate_peer_entry(
is_v6 ? torrent_peer_allocator_interface::ipv6_peer_type is_v6 ? torrent_peer_allocator_interface::ipv6_peer_type
: torrent_peer_allocator_interface::ipv4_peer_type); : torrent_peer_allocator_interface::ipv4_peer_type);
if (p == nullptr) return nullptr; if (p == nullptr) return nullptr;
#if TORRENT_USE_IPV6
if (is_v6) if (is_v6)
new (p) ipv6_peer(remote, true, src); new (p) ipv6_peer(remote, true, src);
else else
#endif
new (p) ipv4_peer(remote, true, src); new (p) ipv4_peer(remote, true, src);
try try

View File

@ -292,9 +292,7 @@ namespace {
} }
} }
#if TORRENT_USE_IPV6
int const v6_size = 18; int const v6_size = 18;
#endif
int const v4_size = 6; int const v4_size = 6;
using namespace libtorrent::detail; // for read_*_endpoint() using namespace libtorrent::detail; // for read_*_endpoint()
if (bdecode_node const peers_entry = rd.dict_find_string("peers")) if (bdecode_node const peers_entry = rd.dict_find_string("peers"))
@ -304,14 +302,12 @@ namespace {
ret.peers.push_back(read_v4_endpoint<tcp::endpoint>(ptr)); ret.peers.push_back(read_v4_endpoint<tcp::endpoint>(ptr));
} }
#if TORRENT_USE_IPV6
if (bdecode_node const peers_entry = rd.dict_find_string("peers6")) if (bdecode_node const peers_entry = rd.dict_find_string("peers6"))
{ {
char const* ptr = peers_entry.string_ptr(); char const* ptr = peers_entry.string_ptr();
for (int i = v6_size - 1; i < peers_entry.string_length(); i += v6_size) for (int i = v6_size - 1; i < peers_entry.string_length(); i += v6_size)
ret.peers.push_back(read_v6_endpoint<tcp::endpoint>(ptr)); ret.peers.push_back(read_v6_endpoint<tcp::endpoint>(ptr));
} }
#endif
if (bdecode_node const peers_entry = rd.dict_find_string("banned_peers")) if (bdecode_node const peers_entry = rd.dict_find_string("banned_peers"))
{ {
@ -320,14 +316,12 @@ namespace {
ret.banned_peers.push_back(read_v4_endpoint<tcp::endpoint>(ptr)); ret.banned_peers.push_back(read_v4_endpoint<tcp::endpoint>(ptr));
} }
#if TORRENT_USE_IPV6
if (bdecode_node const peers_entry = rd.dict_find_string("banned_peers6")) if (bdecode_node const peers_entry = rd.dict_find_string("banned_peers6"))
{ {
char const* ptr = peers_entry.string_ptr(); char const* ptr = peers_entry.string_ptr();
for (int i = v6_size - 1; i < peers_entry.string_length(); i += v6_size) for (int i = v6_size - 1; i < peers_entry.string_length(); i += v6_size)
ret.banned_peers.push_back(read_v6_endpoint<tcp::endpoint>(ptr)); ret.banned_peers.push_back(read_v6_endpoint<tcp::endpoint>(ptr));
} }
#endif
// parse unfinished pieces // parse unfinished pieces
if (bdecode_node const unfinished_entry = rd.dict_find_list("unfinished")) if (bdecode_node const unfinished_entry = rd.dict_find_list("unfinished"))

View File

@ -301,7 +301,6 @@ namespace aux {
{"127.0.0.0", "127.255.255.255", lfilter}, {"127.0.0.0", "127.255.255.255", lfilter},
}; };
#if TORRENT_USE_IPV6
static const class_mapping v6_classes[] = static const class_mapping v6_classes[] =
{ {
// everything // everything
@ -313,7 +312,6 @@ namespace aux {
// loop-back // loop-back
{"::1", "::1", lfilter}, {"::1", "::1", lfilter},
}; };
#endif
class_mapping const* p = v4_classes; class_mapping const* p = v4_classes;
int len = sizeof(v4_classes) / sizeof(v4_classes[0]); int len = sizeof(v4_classes) / sizeof(v4_classes[0]);
@ -326,7 +324,6 @@ namespace aux {
if (ec) continue; if (ec) continue;
m_peer_class_filter.add_rule(begin, end, p[i].filter); m_peer_class_filter.add_rule(begin, end, p[i].filter);
} }
#if TORRENT_USE_IPV6
p = v6_classes; p = v6_classes;
len = sizeof(v6_classes) / sizeof(v6_classes[0]); len = sizeof(v6_classes) / sizeof(v6_classes[0]);
if (!unlimited_local) len = 1; if (!unlimited_local) len = 1;
@ -338,7 +335,6 @@ namespace aux {
if (ec) continue; if (ec) continue;
m_peer_class_filter.add_rule(begin, end, p[i].filter); m_peer_class_filter.add_rule(begin, end, p[i].filter);
} }
#endif
} }
#if defined TORRENT_USE_OPENSSL && OPENSSL_VERSION_NUMBER >= 0x90812f #if defined TORRENT_USE_OPENSSL && OPENSSL_VERSION_NUMBER >= 0x90812f
@ -1398,7 +1394,6 @@ namespace aux {
} }
#endif // TORRENT_WINDOWS #endif // TORRENT_WINDOWS
#if TORRENT_USE_IPV6
if (is_v6(bind_ep)) if (is_v6(bind_ep))
{ {
error_code err; // ignore errors here error_code err; // ignore errors here
@ -1423,7 +1418,6 @@ namespace aux {
#endif // TORRENT_DISABLE_LOGGING #endif // TORRENT_DISABLE_LOGGING
#endif // TORRENT_WINDOWS #endif // TORRENT_WINDOWS
} }
#endif // TORRENT_USE_IPV6
if (!lep.device.empty()) if (!lep.device.empty())
{ {
@ -1716,10 +1710,7 @@ namespace aux {
address const adr = make_address(device.c_str(), err); address const adr = make_address(device.c_str(), err);
if (!err) if (!err)
{ {
#if !TORRENT_USE_IPV6 eps.emplace_back(adr, port, std::string(), ssl, incoming);
if (adr.is_v4())
#endif
eps.emplace_back(adr, port, std::string(), ssl, incoming);
} }
else else
{ {
@ -1811,13 +1802,11 @@ namespace aux {
interface_to_endpoints(device, port, ssl, incoming, eps); interface_to_endpoints(device, port, ssl, incoming, eps);
} }
#if TORRENT_USE_IPV6
std::vector<ip_interface> const ifs = enum_net_interfaces(m_io_service, ec); std::vector<ip_interface> const ifs = enum_net_interfaces(m_io_service, ec);
if (!ec) if (!ec)
{ {
expand_unspecified_address(ifs, eps); expand_unspecified_address(ifs, eps);
} }
#endif
// if no listen interfaces are specified, create sockets to use // if no listen interfaces are specified, create sockets to use
// any interface // any interface
@ -1825,10 +1814,8 @@ namespace aux {
{ {
eps.emplace_back(address_v4(), 0, "", transport::plaintext eps.emplace_back(address_v4(), 0, "", transport::plaintext
, duplex::only_outgoing); , duplex::only_outgoing);
#if TORRENT_USE_IPV6
eps.emplace_back(address_v6(), 0, "", transport::plaintext eps.emplace_back(address_v6(), 0, "", transport::plaintext
, duplex::only_outgoing); , duplex::only_outgoing);
#endif
} }
auto remove_iter = partition_listen_sockets(eps, m_listen_sockets); auto remove_iter = partition_listen_sockets(eps, m_listen_sockets);
@ -1984,14 +1971,10 @@ namespace aux {
if (eps.empty()) if (eps.empty())
{ {
eps.emplace_back(address_v4(), 0, "", transport::plaintext); eps.emplace_back(address_v4(), 0, "", transport::plaintext);
#if TORRENT_USE_IPV6
eps.emplace_back(address_v6(), 0, "", transport::plaintext); eps.emplace_back(address_v6(), 0, "", transport::plaintext);
#endif
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
eps.emplace_back(address_v4(), 0, "", transport::ssl); eps.emplace_back(address_v4(), 0, "", transport::ssl);
#if TORRENT_USE_IPV6
eps.emplace_back(address_v6(), 0, "", transport::ssl); eps.emplace_back(address_v6(), 0, "", transport::ssl);
#endif
#endif #endif
} }
@ -2111,13 +2094,11 @@ namespace aux {
if (map_handle != port_mapping_t{-1}) m.delete_mapping(map_handle); if (map_handle != port_mapping_t{-1}) m.delete_mapping(map_handle);
map_handle = port_mapping_t{-1}; map_handle = port_mapping_t{-1};
#if TORRENT_USE_IPV6
address const addr = ep.address(); address const addr = ep.address();
// with IPv4 the interface might be behind NAT so we can't skip them // with IPv4 the interface might be behind NAT so we can't skip them
// based on the scope of the local address // based on the scope of the local address
if (addr.is_v6() && is_local(addr)) if (addr.is_v6() && is_local(addr))
return; return;
#endif
// only update this mapping if we actually have a socket listening // only update this mapping if we actually have a socket listening
if (ep != EndpointType()) if (ep != EndpointType())
@ -3575,10 +3556,6 @@ namespace aux {
void session_impl::add_dht_node(udp::endpoint const& n) void session_impl::add_dht_node(udp::endpoint const& n)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
#if !TORRENT_USE_IPV6
if (!is_v4(n)) return;
#endif
if (m_dht) m_dht->add_node(n); if (m_dht) m_dht->add_node(n);
else m_dht_nodes.push_back(n); else m_dht_nodes.push_back(n);
} }
@ -5063,11 +5040,9 @@ namespace aux {
// to the same protocol family as the target endpoint // to the same protocol family as the target endpoint
if (is_any(bind_ep.address())) if (is_any(bind_ep.address()))
{ {
#if TORRENT_USE_IPV6
if (remote_address.is_v6()) if (remote_address.is_v6())
bind_ep.address(address_v6::any()); bind_ep.address(address_v6::any());
else else
#endif
bind_ep.address(address_v4::any()); bind_ep.address(address_v4::any());
} }
@ -5942,9 +5917,6 @@ namespace aux {
for (auto const& addr : addresses) for (auto const& addr : addresses)
{ {
#if !TORRENT_USE_IPV6
if (!addr.is_v4()) continue;
#endif
// router nodes should be added before the DHT is started (and bootstrapped) // router nodes should be added before the DHT is started (and bootstrapped)
udp::endpoint ep(addr, std::uint16_t(port)); udp::endpoint ep(addr, std::uint16_t(port));
if (m_dht) m_dht->add_router_node(ep); if (m_dht) m_dht->add_router_node(ep);
@ -6241,7 +6213,7 @@ namespace aux {
template <typename Socket> template <typename Socket>
void set_tos(Socket& s, int v, error_code& ec) void set_tos(Socket& s, int v, error_code& ec)
{ {
#if TORRENT_USE_IPV6 && defined IPV6_TCLASS #if defined IPV6_TCLASS
if (is_v6(s.local_endpoint(ec))) if (is_v6(s.local_endpoint(ec)))
s.set_option(traffic_class(char(v)), ec); s.set_option(traffic_class(char(v)), ec);
else if (!ec) else if (!ec)
@ -7162,12 +7134,10 @@ namespace aux {
{ {
debug_log(" %s:%d", print_address(address_v4(p.ip)).c_str(), p.port); debug_log(" %s:%d", print_address(address_v4(p.ip)).c_str(), p.port);
} }
#if TORRENT_USE_IPV6
for (auto const& p : resp.peers6) for (auto const& p : resp.peers6)
{ {
debug_log(" [%s]:%d", print_address(address_v6(p.ip)).c_str(), p.port); debug_log(" [%s]:%d", print_address(address_v6(p.ip)).c_str(), p.port);
} }
#endif
} }
void tracker_logger::tracker_request_error(tracker_request const& void tracker_logger::tracker_request_error(tracker_request const&

View File

@ -118,11 +118,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0;
DEPRECATED_SET_STR(mmap_cache, nullptr, nullptr), DEPRECATED_SET_STR(mmap_cache, nullptr, nullptr),
SET(handshake_client_version, nullptr, nullptr), SET(handshake_client_version, nullptr, nullptr),
SET(outgoing_interfaces, "", &session_impl::update_outgoing_interfaces), SET(outgoing_interfaces, "", &session_impl::update_outgoing_interfaces),
#if !TORRENT_USE_IPV6
SET(listen_interfaces, "0.0.0.0:6881", &session_impl::update_listen_interfaces),
#else
SET(listen_interfaces, "0.0.0.0:6881,[::]:6881", &session_impl::update_listen_interfaces), SET(listen_interfaces, "0.0.0.0:6881,[::]:6881", &session_impl::update_listen_interfaces),
#endif
SET(proxy_hostname, "", &session_impl::update_proxy), SET(proxy_hostname, "", &session_impl::update_proxy),
SET(proxy_username, "", &session_impl::update_proxy), SET(proxy_username, "", &session_impl::update_proxy),
SET(proxy_password, "", &session_impl::update_proxy), SET(proxy_password, "", &session_impl::update_proxy),

View File

@ -68,11 +68,9 @@ namespace libtorrent {
{ {
error_code ec; error_code ec;
char buf[200]; char buf[200];
#if TORRENT_USE_IPV6
if (addr.is_v6()) if (addr.is_v6())
std::snprintf(buf, sizeof(buf), "[%s]:%d", addr.to_string(ec).c_str(), port); std::snprintf(buf, sizeof(buf), "[%s]:%d", addr.to_string(ec).c_str(), port);
else else
#endif
std::snprintf(buf, sizeof(buf), "%s:%d", addr.to_string(ec).c_str(), port); std::snprintf(buf, sizeof(buf), "%s:%d", addr.to_string(ec).c_str(), port);
return buf; return buf;
} }
@ -120,11 +118,7 @@ namespace libtorrent {
} }
// shave off the ':' // shave off the ':'
port = port.substr(1); port = port.substr(1);
#if TORRENT_USE_IPV6
ret.address(make_address_v6(addr.to_string(), ec)); ret.address(make_address_v6(addr.to_string(), ec));
#else
ec = boost::asio::error::address_family_not_supported;
#endif
if (ec) return ret; if (ec) return ret;
} }
else else
@ -159,14 +153,12 @@ namespace libtorrent {
sha1_hash hash_address(address const& ip) sha1_hash hash_address(address const& ip)
{ {
#if TORRENT_USE_IPV6
if (ip.is_v6()) if (ip.is_v6())
{ {
address_v6::bytes_type b = ip.to_v6().to_bytes(); address_v6::bytes_type b = ip.to_v6().to_bytes();
return hasher(reinterpret_cast<char const*>(b.data()), int(b.size())).final(); return hasher(reinterpret_cast<char const*>(b.data()), int(b.size())).final();
} }
else else
#endif
{ {
address_v4::bytes_type b = ip.to_v4().to_bytes(); address_v4::bytes_type b = ip.to_v4().to_bytes();
return hasher(reinterpret_cast<char const*>(b.data()), int(b.size())).final(); return hasher(reinterpret_cast<char const*>(b.data()), int(b.size())).final();

View File

@ -177,7 +177,6 @@ namespace libtorrent {
{ {
if (!ret.empty()) ret += ','; if (!ret.empty()) ret += ',';
#if TORRENT_USE_IPV6
error_code ec; error_code ec;
make_address_v6(i.device, ec); make_address_v6(i.device, ec);
if (!ec) if (!ec)
@ -188,7 +187,6 @@ namespace libtorrent {
ret += ']'; ret += ']';
} }
else else
#endif
{ {
ret += i.device; ret += i.device;
} }
@ -220,14 +218,8 @@ namespace libtorrent {
listen_interface_t iface; listen_interface_t iface;
iface.ssl = false; iface.ssl = false;
#if !TORRENT_USE_IPV6
bool ipv6 = false;
#endif
if (in[start] == '[') if (in[start] == '[')
{ {
#if !TORRENT_USE_IPV6
ipv6 = true;
#endif
++start; ++start;
// IPv6 address // IPv6 address
while (start < in.size() && in[start] != ']') while (start < in.size() && in[start] != ']')
@ -285,14 +277,7 @@ namespace libtorrent {
while (start < in.size() && in[start] != ',') while (start < in.size() && in[start] != ',')
++start; ++start;
if (iface.port >= 0 if (iface.port >= 0) out.push_back(iface);
#if !TORRENT_USE_IPV6
&& ipv6 == false
#endif
)
{
out.push_back(iface);
}
// skip the comma // skip the comma
if (start < in.size() && in[start] == ',') if (start < in.size() && in[start] == ',')

View File

@ -2776,7 +2776,6 @@ bool is_downloading_state(int const st)
req.event = e; req.event = e;
#if TORRENT_USE_IPV6
// since sending our IPv6 address to the tracker may be sensitive. Only // since sending our IPv6 address to the tracker may be sensitive. Only
// do that if we're not in anonymous mode and if it's a private torrent // do that if we're not in anonymous mode and if it's a private torrent
if (!settings().get_bool(settings_pack::anonymous_mode) if (!settings().get_bool(settings_pack::anonymous_mode)
@ -2792,7 +2791,6 @@ bool is_downloading_state(int const st)
req.ipv6.push_back(s.get_local_endpoint().address().to_v6()); req.ipv6.push_back(s.get_local_endpoint().address().to_v6());
}); });
} }
#endif
// if we are aborting. we don't want any new peers // if we are aborting. we don't want any new peers
req.num_want = (req.event == tracker_request::stopped) req.num_want = (req.event == tracker_request::stopped)
@ -3215,13 +3213,11 @@ bool is_downloading_state(int const st)
need_update |= bool(add_peer(a, peer_info::tracker) != nullptr); need_update |= bool(add_peer(a, peer_info::tracker) != nullptr);
} }
#if TORRENT_USE_IPV6
for (auto const& i : resp.peers6) for (auto const& i : resp.peers6)
{ {
tcp::endpoint a(address_v6(i.ip), i.port); tcp::endpoint a(address_v6(i.ip), i.port);
need_update |= bool(add_peer(a, peer_info::tracker) != nullptr); need_update |= bool(add_peer(a, peer_info::tracker) != nullptr);
} }
#endif
if (need_update) state_updated(); if (need_update) state_updated();
update_want_peers(); update_want_peers();
@ -3232,9 +3228,7 @@ bool is_downloading_state(int const st)
{ {
m_ses.alerts().emplace_alert<tracker_reply_alert>( m_ses.alerts().emplace_alert<tracker_reply_alert>(
get_handle(), local_endpoint, int(resp.peers.size() + resp.peers4.size()) get_handle(), local_endpoint, int(resp.peers.size() + resp.peers4.size())
#if TORRENT_USE_IPV6
+ int(resp.peers6.size()) + int(resp.peers6.size())
#endif
, r.url); , r.url);
} }
@ -10068,18 +10062,6 @@ bool is_downloading_state(int const st)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
#if !TORRENT_USE_IPV6
if (!is_v4(adr))
{
#ifndef TORRENT_DISABLE_LOGGING
error_code ec;
debug_log("add_peer() %s unsupported address family"
, adr.address().to_string(ec).c_str());
#endif
return nullptr;
}
#endif
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
if (source != peer_info::resume_data) if (source != peer_info::resume_data)
{ {

View File

@ -88,7 +88,6 @@ namespace libtorrent {
detail::write_uint16(e2.port(), ptr); detail::write_uint16(e2.port(), ptr);
ret = crc32c_32(p); ret = crc32c_32(p);
} }
#if TORRENT_USE_IPV6
else if (is_v6(e1)) else if (is_v6(e1))
{ {
static const std::uint8_t v6mask[][8] = { static const std::uint8_t v6mask[][8] = {
@ -109,7 +108,6 @@ namespace libtorrent {
memcpy(&addrbuf[2], b2.data(), 16); memcpy(&addrbuf[2], b2.data(), 16);
ret = crc32c(addrbuf, 4); ret = crc32c(addrbuf, 4);
} }
#endif
else else
{ {
static const std::uint8_t v4mask[][4] = { static const std::uint8_t v4mask[][4] = {
@ -158,9 +156,7 @@ namespace libtorrent {
// retry with encryption // retry with encryption
, pe_support(false) , pe_support(false)
#endif #endif
#if TORRENT_USE_IPV6
, is_v6_addr(false) , is_v6_addr(false)
#endif
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
, is_i2p_addr(false) , is_i2p_addr(false)
#endif #endif
@ -228,9 +224,7 @@ namespace libtorrent {
: torrent_peer(ep.port(), c, src) : torrent_peer(ep.port(), c, src)
, addr(ep.address().to_v4()) , addr(ep.address().to_v4())
{ {
#if TORRENT_USE_IPV6
is_v6_addr = false; is_v6_addr = false;
#endif
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
is_i2p_addr = false; is_i2p_addr = false;
#endif #endif
@ -245,14 +239,11 @@ namespace libtorrent {
: torrent_peer(0, connectable, src) : torrent_peer(0, connectable, src)
, destination(dest) , destination(dest)
{ {
#if TORRENT_USE_IPV6
is_v6_addr = false; is_v6_addr = false;
#endif
is_i2p_addr = true; is_i2p_addr = true;
} }
#endif // TORRENT_USE_I2P #endif // TORRENT_USE_I2P
#if TORRENT_USE_IPV6
ipv6_peer::ipv6_peer(tcp::endpoint const& ep, bool c ipv6_peer::ipv6_peer(tcp::endpoint const& ep, bool c
, peer_source_flags_t const src) , peer_source_flags_t const src)
: torrent_peer(ep.port(), c, src) : torrent_peer(ep.port(), c, src)
@ -266,8 +257,6 @@ namespace libtorrent {
ipv6_peer::ipv6_peer(ipv6_peer const&) = default; ipv6_peer::ipv6_peer(ipv6_peer const&) = default;
#endif // TORRENT_USE_IPV6
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
string_view torrent_peer::dest() const string_view torrent_peer::dest() const
{ {
@ -279,12 +268,10 @@ namespace libtorrent {
libtorrent::address torrent_peer::address() const libtorrent::address torrent_peer::address() const
{ {
#if TORRENT_USE_IPV6
if (is_v6_addr) if (is_v6_addr)
return libtorrent::address_v6( return libtorrent::address_v6(
static_cast<ipv6_peer const*>(this)->addr); static_cast<ipv6_peer const*>(this)->addr);
else else
#endif
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
if (is_i2p_addr) return libtorrent::address(); if (is_i2p_addr) return libtorrent::address();
else else

View File

@ -52,7 +52,6 @@ namespace libtorrent {
++m_live_allocations; ++m_live_allocations;
++m_total_allocations; ++m_total_allocations;
break; break;
#if TORRENT_USE_IPV6
case torrent_peer_allocator_interface::ipv6_peer_type: case torrent_peer_allocator_interface::ipv6_peer_type:
p = static_cast<torrent_peer*>(m_ipv6_peer_pool.malloc()); p = static_cast<torrent_peer*>(m_ipv6_peer_pool.malloc());
if (p == nullptr) return nullptr; if (p == nullptr) return nullptr;
@ -62,7 +61,6 @@ namespace libtorrent {
++m_live_allocations; ++m_live_allocations;
++m_total_allocations; ++m_total_allocations;
break; break;
#endif
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
case torrent_peer_allocator_interface::i2p_peer_type: case torrent_peer_allocator_interface::i2p_peer_type:
p = static_cast<torrent_peer*>(m_i2p_peer_pool.malloc()); p = static_cast<torrent_peer*>(m_i2p_peer_pool.malloc());
@ -82,7 +80,6 @@ namespace libtorrent {
{ {
TORRENT_ASSERT(m_in_use); TORRENT_ASSERT(m_in_use);
TORRENT_ASSERT(p->in_use); TORRENT_ASSERT(p->in_use);
#if TORRENT_USE_IPV6
if (p->is_v6_addr) if (p->is_v6_addr)
{ {
TORRENT_ASSERT(m_ipv6_peer_pool.is_from(static_cast<libtorrent::ipv6_peer*>(p))); TORRENT_ASSERT(m_ipv6_peer_pool.is_from(static_cast<libtorrent::ipv6_peer*>(p)));
@ -94,7 +91,6 @@ namespace libtorrent {
--m_live_allocations; --m_live_allocations;
return; return;
} }
#endif
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
if (p->is_i2p_addr) if (p->is_i2p_addr)
{ {

View File

@ -389,13 +389,11 @@ bool udp_socket::unwrap(udp::endpoint& from, span<char>& buf)
// IPv4 // IPv4
from = read_v4_endpoint<udp::endpoint>(p); from = read_v4_endpoint<udp::endpoint>(p);
} }
#if TORRENT_USE_IPV6
else if (atyp == 4) else if (atyp == 4)
{ {
// IPv6 // IPv6
from = read_v6_endpoint<udp::endpoint>(p); from = read_v6_endpoint<udp::endpoint>(p);
} }
#endif
else else
{ {
int const len = read_uint8(p); int const len = read_uint8(p);
@ -443,7 +441,6 @@ void udp_socket::open(udp const& protocol, error_code& ec)
m_socket.open(protocol, ec); m_socket.open(protocol, ec);
if (ec) return; if (ec) return;
#if TORRENT_USE_IPV6
if (protocol == udp::v6()) if (protocol == udp::v6())
{ {
error_code err; error_code err;
@ -454,7 +451,6 @@ void udp_socket::open(udp const& protocol, error_code& ec)
m_socket.set_option(v6_protection_level(PROTECTION_LEVEL_UNRESTRICTED), err); m_socket.set_option(v6_protection_level(PROTECTION_LEVEL_UNRESTRICTED), err);
#endif // TORRENT_WINDOWS #endif // TORRENT_WINDOWS
} }
#endif
// this is best-effort. ignore errors // this is best-effort. ignore errors
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS

View File

@ -209,16 +209,12 @@ namespace libtorrent {
// we're listening on. To make sure the tracker get our // we're listening on. To make sure the tracker get our
// correct listening address. // correct listening address.
bool is_v4 = bind_address.is_v4(); bool is_v4 = bind_address.is_v4();
#if TORRENT_USE_IPV6
auto scope = is_v4 ? 0 : bind_address.to_v6().scope_id(); auto scope = is_v4 ? 0 : bind_address.to_v6().scope_id();
#endif
for (auto const& addr : addresses) for (auto const& addr : addresses)
{ {
if (addr.is_v4() != is_v4) continue; if (addr.is_v4() != is_v4) continue;
#if TORRENT_USE_IPV6
if (addr.is_v6() && addr.to_v6().scope_id() != scope) if (addr.is_v6() && addr.to_v6().scope_id() != scope)
continue; continue;
#endif
m_endpoints.emplace_back(addr, std::uint16_t(port)); m_endpoints.emplace_back(addr, std::uint16_t(port));
} }
@ -624,11 +620,7 @@ namespace libtorrent {
resp.incomplete = aux::read_int32(buf); resp.incomplete = aux::read_int32(buf);
resp.complete = aux::read_int32(buf); resp.complete = aux::read_int32(buf);
std::size_t const ip_stride = std::size_t const ip_stride = is_v6(m_target) ? 18 : 6;
#if TORRENT_USE_IPV6
is_v6(m_target) ? 18 :
#endif
6;
std::size_t const num_peers = buf.size() / ip_stride; std::size_t const num_peers = buf.size() / ip_stride;
if (buf.size() % ip_stride != 0) if (buf.size() % ip_stride != 0)
@ -651,7 +643,6 @@ namespace libtorrent {
return true; return true;
} }
#if TORRENT_USE_IPV6
if (is_v6(m_target)) if (is_v6(m_target))
{ {
resp.peers6.reserve(num_peers); resp.peers6.reserve(num_peers);
@ -665,7 +656,6 @@ namespace libtorrent {
} }
} }
else else
#endif
{ {
resp.peers4.reserve(num_peers); resp.peers4.reserve(num_peers);
for (std::size_t i = 0; i < num_peers; ++i) for (std::size_t i = 0; i < num_peers; ++i)

View File

@ -113,14 +113,12 @@ namespace libtorrent { namespace {
std::back_insert_iterator<std::string> pla_out(pla); std::back_insert_iterator<std::string> pla_out(pla);
std::back_insert_iterator<std::string> pld_out(pld); std::back_insert_iterator<std::string> pld_out(pld);
std::back_insert_iterator<std::string> plf_out(plf); std::back_insert_iterator<std::string> plf_out(plf);
#if TORRENT_USE_IPV6
std::string& pla6 = pex["added6"].string(); std::string& pla6 = pex["added6"].string();
std::string& pld6 = pex["dropped6"].string(); std::string& pld6 = pex["dropped6"].string();
std::string& plf6 = pex["added6.f"].string(); std::string& plf6 = pex["added6.f"].string();
std::back_insert_iterator<std::string> pla6_out(pla6); std::back_insert_iterator<std::string> pla6_out(pla6);
std::back_insert_iterator<std::string> pld6_out(pld6); std::back_insert_iterator<std::string> pld6_out(pld6);
std::back_insert_iterator<std::string> plf6_out(plf6); std::back_insert_iterator<std::string> plf6_out(plf6);
#endif
std::set<tcp::endpoint> dropped; std::set<tcp::endpoint> dropped;
m_old_peers.swap(dropped); m_old_peers.swap(dropped);
@ -179,13 +177,11 @@ namespace libtorrent { namespace {
detail::write_endpoint(remote, pla_out); detail::write_endpoint(remote, pla_out);
detail::write_uint8(static_cast<std::uint8_t>(flags), plf_out); detail::write_uint8(static_cast<std::uint8_t>(flags), plf_out);
} }
#if TORRENT_USE_IPV6
else else
{ {
detail::write_endpoint(remote, pla6_out); detail::write_endpoint(remote, pla6_out);
detail::write_uint8(static_cast<std::uint8_t>(flags), plf6_out); detail::write_uint8(static_cast<std::uint8_t>(flags), plf6_out);
} }
#endif
++num_added; ++num_added;
++m_peers_in_message; ++m_peers_in_message;
} }
@ -201,10 +197,8 @@ namespace libtorrent { namespace {
{ {
if (is_v4(i)) if (is_v4(i))
detail::write_endpoint(i, pld_out); detail::write_endpoint(i, pld_out);
#if TORRENT_USE_IPV6
else else
detail::write_endpoint(i, pld6_out); detail::write_endpoint(i, pld6_out);
#endif
++m_peers_in_message; ++m_peers_in_message;
} }
@ -352,8 +346,6 @@ namespace libtorrent { namespace {
} }
} }
#if TORRENT_USE_IPV6
bdecode_node p6 = pex_msg.dict_find("dropped6"); bdecode_node p6 = pex_msg.dict_find("dropped6");
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
if (p6) num_dropped += p6.string_length() / 18; if (p6) num_dropped += p6.string_length() / 18;
@ -403,7 +395,6 @@ namespace libtorrent { namespace {
peers_added = true; peers_added = true;
} }
} }
#endif
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
m_pc.peer_log(peer_log_alert::incoming_message, "PEX", "dropped: %d added: %d" m_pc.peer_log(peer_log_alert::incoming_message, "PEX", "dropped: %d added: %d"
, num_dropped, num_added); , num_dropped, num_added);
@ -524,13 +515,11 @@ namespace libtorrent { namespace {
std::back_insert_iterator<std::string> pla_out(pla); std::back_insert_iterator<std::string> pla_out(pla);
std::back_insert_iterator<std::string> plf_out(plf); std::back_insert_iterator<std::string> plf_out(plf);
#if TORRENT_USE_IPV6
pex["dropped6"].string(); pex["dropped6"].string();
std::string& pla6 = pex["added6"].string(); std::string& pla6 = pex["added6"].string();
std::string& plf6 = pex["added6.f"].string(); std::string& plf6 = pex["added6.f"].string();
std::back_insert_iterator<std::string> pla6_out(pla6); std::back_insert_iterator<std::string> pla6_out(pla6);
std::back_insert_iterator<std::string> plf6_out(plf6); std::back_insert_iterator<std::string> plf6_out(plf6);
#endif
int num_added = 0; int num_added = 0;
for (auto const peer : m_torrent) for (auto const peer : m_torrent)
@ -578,13 +567,11 @@ namespace libtorrent { namespace {
detail::write_endpoint(remote, pla_out); detail::write_endpoint(remote, pla_out);
detail::write_uint8(flags, plf_out); detail::write_uint8(flags, plf_out);
} }
#if TORRENT_USE_IPV6
else else
{ {
detail::write_endpoint(remote, pla6_out); detail::write_endpoint(remote, pla6_out);
detail::write_uint8(flags, plf6_out); detail::write_uint8(flags, plf6_out);
} }
#endif
++num_added; ++num_added;
} }
std::vector<char> pex_msg; std::vector<char> pex_msg;

View File

@ -190,16 +190,12 @@ namespace libtorrent {
if (!atp.peers.empty()) if (!atp.peers.empty())
{ {
std::back_insert_iterator<entry::string_type> ptr(ret["peers"].string()); std::back_insert_iterator<entry::string_type> ptr(ret["peers"].string());
#if TORRENT_USE_IPV6
std::back_insert_iterator<entry::string_type> ptr6(ret["peers6"].string()); std::back_insert_iterator<entry::string_type> ptr6(ret["peers6"].string());
#endif
for (auto const& p : atp.peers) for (auto const& p : atp.peers)
{ {
#if TORRENT_USE_IPV6
if (is_v6(p)) if (is_v6(p))
write_endpoint(p, ptr6); write_endpoint(p, ptr6);
else else
#endif
write_endpoint(p, ptr); write_endpoint(p, ptr);
} }
} }
@ -207,16 +203,12 @@ namespace libtorrent {
if (!atp.banned_peers.empty()) if (!atp.banned_peers.empty())
{ {
std::back_insert_iterator<entry::string_type> ptr(ret["banned_peers"].string()); std::back_insert_iterator<entry::string_type> ptr(ret["banned_peers"].string());
#if TORRENT_USE_IPV6
std::back_insert_iterator<entry::string_type> ptr6(ret["banned_peers6"].string()); std::back_insert_iterator<entry::string_type> ptr6(ret["banned_peers6"].string());
#endif
for (auto const& p : atp.banned_peers) for (auto const& p : atp.banned_peers)
{ {
#if TORRENT_USE_IPV6
if (is_v6(p)) if (is_v6(p))
write_endpoint(p, ptr6); write_endpoint(p, ptr6);
else else
#endif
write_endpoint(p, ptr); write_endpoint(p, ptr);
} }
} }

View File

@ -272,12 +272,10 @@ void peer_conn::close(char const* fmt, error_code const& ec)
char ep_str[200]; char ep_str[200];
address const& addr = s.local_endpoint(e).address(); address const& addr = s.local_endpoint(e).address();
#if TORRENT_USE_IPV6
if (addr.is_v6()) if (addr.is_v6())
std::snprintf(ep_str, sizeof(ep_str), "[%s]:%d", addr.to_string(e).c_str() std::snprintf(ep_str, sizeof(ep_str), "[%s]:%d", addr.to_string(e).c_str()
, s.local_endpoint(e).port()); , s.local_endpoint(e).port());
else else
#endif
std::snprintf(ep_str, sizeof(ep_str), "%s:%d", addr.to_string(e).c_str() std::snprintf(ep_str, sizeof(ep_str), "%s:%d", addr.to_string(e).c_str()
, s.local_endpoint(e).port()); , s.local_endpoint(e).port());
std::printf("%s ep: %s sent: %d received: %d duration: %d ms up: %.1fMB/s down: %.1fMB/s\n" std::printf("%s ep: %s sent: %d received: %d duration: %d ms up: %.1fMB/s down: %.1fMB/s\n"

View File

@ -126,7 +126,6 @@ sha1_hash to_hash(char const* s)
return ret; return ret;
} }
#if TORRENT_USE_IPV6
address rand_v6() address rand_v6()
{ {
address_v6::bytes_type bytes; address_v6::bytes_type bytes;
@ -134,7 +133,6 @@ address rand_v6()
bytes[static_cast<std::size_t>(i)] = std::uint8_t(lt::random(0xff)); bytes[static_cast<std::size_t>(i)] = std::uint8_t(lt::random(0xff));
return address_v6(bytes); return address_v6(bytes);
} }
#endif
static std::uint16_t g_port = 0; static std::uint16_t g_port = 0;
@ -1025,7 +1023,6 @@ lt::address_v4 addr4(char const* ip)
return ret; return ret;
} }
#if TORRENT_USE_IPV6
lt::address_v6 addr6(char const* ip) lt::address_v6 addr6(char const* ip)
{ {
lt::error_code ec; lt::error_code ec;
@ -1033,4 +1030,3 @@ lt::address_v6 addr6(char const* ip)
TEST_CHECK(!ec); TEST_CHECK(!ec);
return ret; return ret;
} }
#endif

View File

@ -52,9 +52,7 @@ EXPORT void report_failure(char const* err, char const* file, int line);
EXPORT void init_rand_address(); EXPORT void init_rand_address();
EXPORT lt::address rand_v4(); EXPORT lt::address rand_v4();
#if TORRENT_USE_IPV6
EXPORT lt::address rand_v6(); EXPORT lt::address rand_v6();
#endif
EXPORT lt::tcp::endpoint rand_tcp_ep(lt::address(&rand_addr)() = rand_v4); EXPORT lt::tcp::endpoint rand_tcp_ep(lt::address(&rand_addr)() = rand_v4);
EXPORT lt::udp::endpoint rand_udp_ep(lt::address(&rand_addr)() = rand_v4); EXPORT lt::udp::endpoint rand_udp_ep(lt::address(&rand_addr)() = rand_v4);
@ -121,8 +119,6 @@ EXPORT lt::tcp::endpoint ep(char const* ip, int port);
EXPORT lt::udp::endpoint uep(char const* ip, int port); EXPORT lt::udp::endpoint uep(char const* ip, int port);
EXPORT lt::address addr(char const* ip); EXPORT lt::address addr(char const* ip);
EXPORT lt::address_v4 addr4(char const* ip); EXPORT lt::address_v4 addr4(char const* ip);
#if TORRENT_USE_IPV6
EXPORT lt::address_v6 addr6(char const* ip); EXPORT lt::address_v6 addr6(char const* ip);
#endif
#endif #endif

View File

@ -194,13 +194,8 @@ TORRENT_TEST(dht_get_peers_reply_alert)
tcp::endpoint const ep1 = rand_tcp_ep(rand_v4); tcp::endpoint const ep1 = rand_tcp_ep(rand_v4);
tcp::endpoint const ep2 = rand_tcp_ep(rand_v4); tcp::endpoint const ep2 = rand_tcp_ep(rand_v4);
tcp::endpoint const ep3 = rand_tcp_ep(rand_v4); tcp::endpoint const ep3 = rand_tcp_ep(rand_v4);
#if TORRENT_USE_IPV6
tcp::endpoint const ep4 = rand_tcp_ep(rand_v6); tcp::endpoint const ep4 = rand_tcp_ep(rand_v6);
tcp::endpoint const ep5 = rand_tcp_ep(rand_v6); tcp::endpoint const ep5 = rand_tcp_ep(rand_v6);
#else
tcp::endpoint const ep4 = rand_tcp_ep(rand_v4);
tcp::endpoint const ep5 = rand_tcp_ep(rand_v4);
#endif
std::vector<tcp::endpoint> v = {ep1, ep2, ep3, ep4, ep5}; std::vector<tcp::endpoint> v = {ep1, ep2, ep3, ep4, ep5};
mgr.emplace_alert<dht_get_peers_reply_alert>(ih, v); mgr.emplace_alert<dht_get_peers_reply_alert>(ih, v);
@ -232,13 +227,8 @@ TORRENT_TEST(dht_live_nodes_alert)
udp::endpoint const ep1 = rand_udp_ep(rand_v4); udp::endpoint const ep1 = rand_udp_ep(rand_v4);
udp::endpoint const ep2 = rand_udp_ep(rand_v4); udp::endpoint const ep2 = rand_udp_ep(rand_v4);
udp::endpoint const ep3 = rand_udp_ep(rand_v4); udp::endpoint const ep3 = rand_udp_ep(rand_v4);
#if TORRENT_USE_IPV6
udp::endpoint const ep4 = rand_udp_ep(rand_v6); udp::endpoint const ep4 = rand_udp_ep(rand_v6);
udp::endpoint const ep5 = rand_udp_ep(rand_v6); udp::endpoint const ep5 = rand_udp_ep(rand_v6);
#else
udp::endpoint const ep4 = rand_udp_ep(rand_v4);
udp::endpoint const ep5 = rand_udp_ep(rand_v4);
#endif
std::vector<std::pair<sha1_hash, udp::endpoint>> v; std::vector<std::pair<sha1_hash, udp::endpoint>> v;
v.emplace_back(h1, ep1); v.emplace_back(h1, ep1);
v.emplace_back(h2, ep2); v.emplace_back(h2, ep2);
@ -306,13 +296,8 @@ TORRENT_TEST(dht_sample_infohashes_alert)
udp::endpoint const nep1 = rand_udp_ep(rand_v4); udp::endpoint const nep1 = rand_udp_ep(rand_v4);
udp::endpoint const nep2 = rand_udp_ep(rand_v4); udp::endpoint const nep2 = rand_udp_ep(rand_v4);
udp::endpoint const nep3 = rand_udp_ep(rand_v4); udp::endpoint const nep3 = rand_udp_ep(rand_v4);
#if TORRENT_USE_IPV6
udp::endpoint const nep4 = rand_udp_ep(rand_v6); udp::endpoint const nep4 = rand_udp_ep(rand_v6);
udp::endpoint const nep5 = rand_udp_ep(rand_v6); udp::endpoint const nep5 = rand_udp_ep(rand_v6);
#else
udp::endpoint const nep4 = rand_udp_ep(rand_v4);
udp::endpoint const nep5 = rand_udp_ep(rand_v4);
#endif
std::vector<std::pair<sha1_hash, udp::endpoint>> nv; std::vector<std::pair<sha1_hash, udp::endpoint>> nv;
nv.emplace_back(nh1, nep1); nv.emplace_back(nh1, nep1);
nv.emplace_back(nh2, nep2); nv.emplace_back(nh2, nep2);

View File

@ -143,7 +143,6 @@ std::shared_ptr<aux::listen_socket_t> dummy_listen_socket4()
return ret; return ret;
} }
#if TORRENT_USE_IPV6
std::shared_ptr<aux::listen_socket_t> dummy_listen_socket6() std::shared_ptr<aux::listen_socket_t> dummy_listen_socket6()
{ {
auto ret = std::make_shared<aux::listen_socket_t>(); auto ret = std::make_shared<aux::listen_socket_t>();
@ -152,7 +151,6 @@ std::shared_ptr<aux::listen_socket_t> dummy_listen_socket6()
, aux::session_interface::source_dht, rand_v6()); , aux::session_interface::source_dht, rand_v6());
return ret; return ret;
} }
#endif
node* get_foreign_node_stub(node_id const&, std::string const&) node* get_foreign_node_stub(node_id const&, std::string const&)
{ {
@ -1038,13 +1036,11 @@ TORRENT_TEST(scrape_v4)
test_scrape(rand_v4); test_scrape(rand_v4);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(scrape_v6) TORRENT_TEST(scrape_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
test_scrape(rand_v6); test_scrape(rand_v6);
} }
#endif
namespace { namespace {
@ -1148,13 +1144,11 @@ TORRENT_TEST(id_enforcement_v4)
test_id_enforcement(rand_v4); test_id_enforcement(rand_v4);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(id_enforcement_v6) TORRENT_TEST(id_enforcement_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
test_id_enforcement(rand_v6); test_id_enforcement(rand_v6);
} }
#endif
TORRENT_TEST(bloom_filter) TORRENT_TEST(bloom_filter)
{ {
@ -1578,13 +1572,11 @@ TORRENT_TEST(put_v4)
test_put(rand_v4); test_put(rand_v4);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(put_v6) TORRENT_TEST(put_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
test_put(rand_v6); test_put(rand_v6);
} }
#endif
namespace { namespace {
@ -1608,14 +1600,12 @@ void test_routing_table(address(&rand_addr)())
address node_addr; address node_addr;
address node_near_addr; address node_near_addr;
#if TORRENT_USE_IPV6
if (is_v6(t.source)) if (is_v6(t.source))
{ {
node_addr = addr6("2001:1111:1111:1111:1111:1111:1111:1111"); node_addr = addr6("2001:1111:1111:1111:1111:1111:1111:1111");
node_near_addr = addr6("2001:1111:1111:1111:eeee:eeee:eeee:eeee"); node_near_addr = addr6("2001:1111:1111:1111:eeee:eeee:eeee:eeee");
} }
else else
#endif
{ {
node_addr = addr4("4.4.4.4"); node_addr = addr4("4.4.4.4");
node_near_addr = addr4("4.4.4.5"); node_near_addr = addr4("4.4.4.5");
@ -1802,13 +1792,11 @@ TORRENT_TEST(routing_table_v4)
test_routing_table(rand_v4); test_routing_table(rand_v4);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(routing_table_v6) TORRENT_TEST(routing_table_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
test_routing_table(rand_v6); test_routing_table(rand_v6);
} }
#endif
namespace { namespace {
@ -1907,15 +1895,12 @@ TORRENT_TEST(bootstrap_v4)
test_bootstrap(rand_v4); test_bootstrap(rand_v4);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(bootstrap_v6) TORRENT_TEST(bootstrap_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
test_bootstrap(rand_v6); test_bootstrap(rand_v6);
} }
#endif
#if TORRENT_USE_IPV6
namespace { namespace {
void test_bootstrap_want(address(&rand_addr)()) void test_bootstrap_want(address(&rand_addr)())
@ -1986,7 +1971,6 @@ TORRENT_TEST(bootstrap_want_v6)
{ {
test_bootstrap_want(rand_v6); test_bootstrap_want(rand_v6);
} }
#endif
namespace { namespace {
@ -2070,13 +2054,11 @@ TORRENT_TEST(short_nodes_v4)
test_short_nodes(rand_v4); test_short_nodes(rand_v4);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(short_nodes_v6) TORRENT_TEST(short_nodes_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
test_short_nodes(rand_v6); test_short_nodes(rand_v6);
} }
#endif
namespace { namespace {
@ -2208,13 +2190,11 @@ TORRENT_TEST(get_peers_v4)
test_get_peers(rand_v4); test_get_peers(rand_v4);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(get_peers_v6) TORRENT_TEST(get_peers_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
test_get_peers(rand_v6); test_get_peers(rand_v6);
} }
#endif
namespace { namespace {
@ -2316,7 +2296,6 @@ TORRENT_TEST(mutable_get_salt_v4)
test_mutable_get(rand_v4, true); test_mutable_get(rand_v4, true);
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(mutable_get_v6) TORRENT_TEST(mutable_get_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
@ -2328,7 +2307,6 @@ TORRENT_TEST(mutable_get_salt_v6)
if (supports_ipv6()) if (supports_ipv6())
test_mutable_get(rand_v6, true); test_mutable_get(rand_v6, true);
} }
#endif
TORRENT_TEST(immutable_get) TORRENT_TEST(immutable_get)
{ {
@ -2681,7 +2659,6 @@ TORRENT_TEST(traversal_done)
g_put_count = 0; g_put_count = 0;
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(dht_dual_stack) TORRENT_TEST(dht_dual_stack)
{ {
// TODO: 3 use dht_test_setup class to simplify the node setup // TODO: 3 use dht_test_setup class to simplify the node setup
@ -2820,7 +2797,6 @@ TORRENT_TEST(dht_dual_stack)
TEST_ERROR(error_string); TEST_ERROR(error_string);
} }
} }
#endif
TORRENT_TEST(multi_home) TORRENT_TEST(multi_home)
{ {
@ -3657,7 +3633,6 @@ TORRENT_TEST(compare_ip_cidr)
addr4(std::get<0>(t)), addr4(std::get<1>(t))), std::get<2>(t)); addr4(std::get<0>(t)), addr4(std::get<1>(t))), std::get<2>(t));
} }
#if TORRENT_USE_IPV6
std::vector<tst> const v6tests = { std::vector<tst> const v6tests = {
tst{"::1", "::ffff:ffff:ffff:ffff", true}, tst{"::1", "::ffff:ffff:ffff:ffff", true},
tst{"::2:0000:0000:0000:0000", "::1:ffff:ffff:ffff:ffff", false}, tst{"::2:0000:0000:0000:0000", "::1:ffff:ffff:ffff:ffff", false},
@ -3676,7 +3651,6 @@ TORRENT_TEST(compare_ip_cidr)
TEST_EQUAL(compare_ip_cidr( TEST_EQUAL(compare_ip_cidr(
addr6(std::get<0>(t)), addr6(std::get<1>(t))), std::get<2>(t)); addr6(std::get<0>(t)), addr6(std::get<1>(t))), std::get<2>(t));
} }
#endif
} }
TORRENT_TEST(dht_state) TORRENT_TEST(dht_state)

View File

@ -123,7 +123,6 @@ TORRENT_TEST(announce_peer)
TEST_CHECK(!peers.find_key("values")); TEST_CHECK(!peers.find_key("values"));
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(dual_stack) TORRENT_TEST(dual_stack)
{ {
dht::dht_settings sett = test_settings(); dht::dht_settings sett = test_settings();
@ -149,7 +148,6 @@ TORRENT_TEST(dual_stack)
s->get_peers(n1, false, false, address_v6(), peers6); s->get_peers(n1, false, false, address_v6(), peers6);
TEST_EQUAL(peers6["values"].list().size(), 2); TEST_EQUAL(peers6["values"].list().size(), 2);
} }
#endif
TORRENT_TEST(put_items) TORRENT_TEST(put_items)
{ {

View File

@ -54,13 +54,11 @@ TORRENT_TEST(is_loopback)
error_code ec; error_code ec;
TEST_CHECK(is_loopback(address::from_string("127.0.0.1", ec))); TEST_CHECK(is_loopback(address::from_string("127.0.0.1", ec)));
TEST_CHECK(!ec); TEST_CHECK(!ec);
#if TORRENT_USE_IPV6
if (supports_ipv6()) if (supports_ipv6())
{ {
TEST_CHECK(is_loopback(address::from_string("::1", ec))); TEST_CHECK(is_loopback(address::from_string("::1", ec)));
TEST_CHECK(!ec); TEST_CHECK(!ec);
} }
#endif
} }
TORRENT_TEST(is_any) TORRENT_TEST(is_any)
@ -69,13 +67,11 @@ TORRENT_TEST(is_any)
error_code ec; error_code ec;
TEST_CHECK(!is_any(address::from_string("31.53.21.64", ec))); TEST_CHECK(!is_any(address::from_string("31.53.21.64", ec)));
TEST_CHECK(!ec); TEST_CHECK(!ec);
#if TORRENT_USE_IPV6
if (supports_ipv6()) if (supports_ipv6())
{ {
TEST_CHECK(is_any(address_v6::any())); TEST_CHECK(is_any(address_v6::any()));
TEST_CHECK(!ec); TEST_CHECK(!ec);
} }
#endif
} }
TORRENT_TEST(match_addr_mask) TORRENT_TEST(match_addr_mask)
@ -105,8 +101,6 @@ TORRENT_TEST(is_ip_address)
TEST_EQUAL(is_ip_address("1.2.3.4"), true); TEST_EQUAL(is_ip_address("1.2.3.4"), true);
TEST_EQUAL(is_ip_address("a.b.c.d"), false); TEST_EQUAL(is_ip_address("a.b.c.d"), false);
TEST_EQUAL(is_ip_address("a:b:b:c"), false); TEST_EQUAL(is_ip_address("a:b:b:c"), false);
#if TORRENT_USE_IPV6
TEST_EQUAL(is_ip_address("::1"), true); TEST_EQUAL(is_ip_address("::1"), true);
TEST_EQUAL(is_ip_address("2001:db8:85a3:0:0:8a2e:370:7334"), true); TEST_EQUAL(is_ip_address("2001:db8:85a3:0:0:8a2e:370:7334"), true);
#endif
} }

View File

@ -90,11 +90,7 @@ TORRENT_TEST(session_get_ip_filter)
{ {
session ses(settings()); session ses(settings());
ip_filter const& ipf = ses.get_ip_filter(); ip_filter const& ipf = ses.get_ip_filter();
#if TORRENT_USE_IPV6
TEST_EQUAL(std::get<0>(ipf.export_filter()).size(), 1); TEST_EQUAL(std::get<0>(ipf.export_filter()).size(), 1);
#else
TEST_EQUAL(ipf.export_filter().size(), 1);
#endif
} }
TORRENT_TEST(ip_filter) TORRENT_TEST(ip_filter)
@ -115,11 +111,7 @@ TORRENT_TEST(ip_filter)
f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked); f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked);
f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked);
#if TORRENT_USE_IPV6
range = std::get<0>(f.export_filter()); range = std::get<0>(f.export_filter());
#else
range = f.export_filter();
#endif
test_rules_invariant(range, f); test_rules_invariant(range, f);
TEST_CHECK(range.size() == 3); TEST_CHECK(range.size() == 3);
@ -134,11 +126,7 @@ TORRENT_TEST(ip_filter)
f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked);
f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked); f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked);
#if TORRENT_USE_IPV6
range = std::get<0>(f.export_filter()); range = std::get<0>(f.export_filter());
#else
range = f.export_filter();
#endif
test_rules_invariant(range, f); test_rules_invariant(range, f);
TEST_CHECK(range.size() == 3); TEST_CHECK(range.size() == 3);
@ -154,11 +142,7 @@ TORRENT_TEST(ip_filter)
f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked);
f.add_rule(addr("1.0.0.0"), addr("2.4.0.0"), ip_filter::blocked); f.add_rule(addr("1.0.0.0"), addr("2.4.0.0"), ip_filter::blocked);
#if TORRENT_USE_IPV6
range = std::get<0>(f.export_filter()); range = std::get<0>(f.export_filter());
#else
range = f.export_filter();
#endif
test_rules_invariant(range, f); test_rules_invariant(range, f);
TEST_CHECK(range.size() == 3); TEST_CHECK(range.size() == 3);
@ -174,11 +158,7 @@ TORRENT_TEST(ip_filter)
f.add_rule(addr("1.0.0.0"), addr("2.4.0.0"), ip_filter::blocked); f.add_rule(addr("1.0.0.0"), addr("2.4.0.0"), ip_filter::blocked);
f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked);
#if TORRENT_USE_IPV6
range = std::get<0>(f.export_filter()); range = std::get<0>(f.export_filter());
#else
range = f.export_filter();
#endif
test_rules_invariant(range, f); test_rules_invariant(range, f);
TEST_CHECK(range.size() == 3); TEST_CHECK(range.size() == 3);
@ -198,11 +178,7 @@ TORRENT_TEST(ip_filter)
f.add_rule(addr("1.0.1.0"), addr("9.0.0.0"), ip_filter::blocked); f.add_rule(addr("1.0.1.0"), addr("9.0.0.0"), ip_filter::blocked);
#if TORRENT_USE_IPV6
range = std::get<0>(f.export_filter()); range = std::get<0>(f.export_filter());
#else
range = f.export_filter();
#endif
test_rules_invariant(range, f); test_rules_invariant(range, f);
TEST_CHECK(range.size() == 3); TEST_CHECK(range.size() == 3);
@ -228,11 +204,7 @@ TORRENT_TEST(ip_filter)
f.add_rule(addr("0.0.1.0"), addr("7.0.4.0"), ip_filter::blocked); f.add_rule(addr("0.0.1.0"), addr("7.0.4.0"), ip_filter::blocked);
#if TORRENT_USE_IPV6
range = std::get<0>(f.export_filter()); range = std::get<0>(f.export_filter());
#else
range = f.export_filter();
#endif
test_rules_invariant(range, f); test_rules_invariant(range, f);
TEST_CHECK(range.size() == 3); TEST_CHECK(range.size() == 3);
@ -249,8 +221,6 @@ TORRENT_TEST(ip_filter)
// **** test IPv6 **** // **** test IPv6 ****
#if TORRENT_USE_IPV6
ip_range<address_v6> expected2[] = ip_range<address_v6> expected2[] =
{ {
{addr6("::0"), addr6("0:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 0} {addr6("::0"), addr6("0:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 0}
@ -270,7 +240,6 @@ TORRENT_TEST(ip_filter)
TEST_EQUAL(rangev6.size(), 3); TEST_EQUAL(rangev6.size(), 3);
TEST_CHECK(std::equal(rangev6.begin(), rangev6.end(), expected2, &compare<address_v6>)); TEST_CHECK(std::equal(rangev6.begin(), rangev6.end(), expected2, &compare<address_v6>));
} }
#endif
port_filter pf; port_filter pf;

View File

@ -195,7 +195,6 @@ TORRENT_TEST(ip_voter_2)
address malicious2; address malicious2;
address real_external2; address real_external2;
address malicious_external2; address malicious_external2;
#if TORRENT_USE_IPV6
if (supports_ipv6()) if (supports_ipv6())
{ {
malicious2 = address_v6::from_string("2f90::", ec); malicious2 = address_v6::from_string("2f90::", ec);
@ -205,25 +204,19 @@ TORRENT_TEST(ip_voter_2)
malicious_external2 = address_v6::from_string("2f70::", ec); malicious_external2 = address_v6::from_string("2f70::", ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
} }
#endif
for (int i = 0; i < 50; ++i) for (int i = 0; i < 50; ++i)
{ {
ipv2.cast_vote(real_external1, aux::session_interface::source_dht, rand_v4()); ipv2.cast_vote(real_external1, aux::session_interface::source_dht, rand_v4());
ipv2.cast_vote(malicious_external, aux::session_interface::source_dht, malicious); ipv2.cast_vote(malicious_external, aux::session_interface::source_dht, malicious);
#if TORRENT_USE_IPV6
if (supports_ipv6()) if (supports_ipv6())
{ {
ipv6.cast_vote(real_external2, aux::session_interface::source_dht, rand_v6()); ipv6.cast_vote(real_external2, aux::session_interface::source_dht, rand_v6());
ipv6.cast_vote(malicious_external2, aux::session_interface::source_dht, malicious2); ipv6.cast_vote(malicious_external2, aux::session_interface::source_dht, malicious2);
} }
#endif
} }
TEST_CHECK(ipv2.external_address() == real_external1); TEST_CHECK(ipv2.external_address() == real_external1);
#if TORRENT_USE_IPV6
if (supports_ipv6()) if (supports_ipv6())
TEST_CHECK(ipv6.external_address() == real_external2); TEST_CHECK(ipv6.external_address() == real_external2);
#endif
} }

View File

@ -307,14 +307,9 @@ TORRENT_TEST(parse_peer)
{ {
add_torrent_params p = parse_magnet_uri("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" add_torrent_params p = parse_magnet_uri("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"&dn=foo&x.pe=127.0.0.1:43&x.pe=<invalid1>&x.pe=<invalid2>:100&x.pe=[::1]:45"); "&dn=foo&x.pe=127.0.0.1:43&x.pe=<invalid1>&x.pe=<invalid2>:100&x.pe=[::1]:45");
#if TORRENT_USE_IPV6
TEST_EQUAL(p.peers.size(), 2); TEST_EQUAL(p.peers.size(), 2);
TEST_EQUAL(p.peers[0], ep("127.0.0.1", 43)); TEST_EQUAL(p.peers[0], ep("127.0.0.1", 43));
TEST_EQUAL(p.peers[1], ep("::1", 45)); TEST_EQUAL(p.peers[1], ep("::1", 45));
#else
TEST_EQUAL(p.peers.size(), 1);
TEST_EQUAL(p.peers[0], ep("127.0.0.1", 43));
#endif
} }
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT

View File

@ -131,12 +131,8 @@ TORRENT_TEST(session_peer_class_filter)
, 1 << static_cast<std::uint32_t>(my_class)); , 1 << static_cast<std::uint32_t>(my_class));
ses.set_peer_class_filter(f); ses.set_peer_class_filter(f);
#if TORRENT_USE_IPV6
TEST_CHECK(std::get<0>(ses.get_peer_class_filter().export_filter()) TEST_CHECK(std::get<0>(ses.get_peer_class_filter().export_filter())
== std::get<0>(f.export_filter())); == std::get<0>(f.export_filter()));
#else
TEST_CHECK(ses.get_peer_class_filter().export_filter() == f.export_filter());
#endif
} }
TORRENT_TEST(session_peer_class_type_filter) TORRENT_TEST(session_peer_class_type_filter)

View File

@ -122,10 +122,8 @@ TORRENT_TEST(address_endpoint_io)
TEST_EQUAL(print_endpoint(ep("127.0.0.1", 23)), "127.0.0.1:23"); TEST_EQUAL(print_endpoint(ep("127.0.0.1", 23)), "127.0.0.1:23");
TEST_EQUAL(print_address(addr4("241.124.23.5")), "241.124.23.5"); TEST_EQUAL(print_address(addr4("241.124.23.5")), "241.124.23.5");
#if TORRENT_USE_IPV6
TEST_EQUAL(print_endpoint(ep("ff::1", 1214)), "[ff::1]:1214"); TEST_EQUAL(print_endpoint(ep("ff::1", 1214)), "[ff::1]:1214");
TEST_EQUAL(print_address(addr6("2001:ff::1")), "2001:ff::1"); TEST_EQUAL(print_address(addr6("2001:ff::1")), "2001:ff::1");
#endif
// test address_to_bytes // test address_to_bytes
TEST_EQUAL(address_to_bytes(addr4("10.11.12.13")), "\x0a\x0b\x0c\x0d"); TEST_EQUAL(address_to_bytes(addr4("10.11.12.13")), "\x0a\x0b\x0c\x0d");

View File

@ -113,10 +113,8 @@ TORRENT_TEST(dht_state)
s.nids.emplace_back(addr4("0.0.0.0"), to_hash("0000000000000000000000000000000000000001")); s.nids.emplace_back(addr4("0.0.0.0"), to_hash("0000000000000000000000000000000000000001"));
s.nodes.push_back(uep("1.1.1.1", 1)); s.nodes.push_back(uep("1.1.1.1", 1));
s.nodes.push_back(uep("2.2.2.2", 2)); s.nodes.push_back(uep("2.2.2.2", 2));
#if TORRENT_USE_IPV6
// not important that IPv6 is disabled here // not important that IPv6 is disabled here
s.nids.emplace_back(addr6("::"), to_hash("0000000000000000000000000000000000000002")); s.nids.emplace_back(addr6("::"), to_hash("0000000000000000000000000000000000000002"));
#endif
session_params params(p); session_params params(p);
params.dht_settings = sett; params.dht_settings = sett;
@ -141,11 +139,9 @@ TORRENT_TEST(dht_state)
// not a chance the nid will be the fake initial ones // not a chance the nid will be the fake initial ones
TEST_CHECK(params1.dht_state.nids[0].second != s.nids[0].second); TEST_CHECK(params1.dht_state.nids[0].second != s.nids[0].second);
#if TORRENT_USE_IPV6
// the host machine may not have IPv6 support in which case there will only be one entry // the host machine may not have IPv6 support in which case there will only be one entry
if (params1.dht_state.nids.size() > 1) if (params1.dht_state.nids.size() > 1)
TEST_CHECK(params1.dht_state.nids[1].second != s.nids[1].second); TEST_CHECK(params1.dht_state.nids[1].second != s.nids[1].second);
#endif
} }
#endif #endif

View File

@ -67,7 +67,6 @@ TORRENT_TEST(read_v4_address)
TEST_EQUAL(ep4, uep("16.5.128.1", 1337)); TEST_EQUAL(ep4, uep("16.5.128.1", 1337));
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(read_v6_endpoint) TORRENT_TEST(read_v6_endpoint)
{ {
std::string buf; std::string buf;
@ -85,7 +84,6 @@ TORRENT_TEST(read_v6_endpoint)
udp::endpoint ep6 = read_v6_endpoint<udp::endpoint>(buf.begin()); udp::endpoint ep6 = read_v6_endpoint<udp::endpoint>(buf.begin());
TEST_EQUAL(ep6, uep("1000::ffff", 1337)); TEST_EQUAL(ep6, uep("1000::ffff", 1337));
} }
#endif
TORRENT_TEST(read_endpoint_list) TORRENT_TEST(read_endpoint_list)
{ {
@ -97,12 +95,8 @@ TORRENT_TEST(read_endpoint_list)
TEST_CHECK(!ec); TEST_CHECK(!ec);
std::vector<udp::endpoint> list = read_endpoint_list<udp::endpoint>(e); std::vector<udp::endpoint> list = read_endpoint_list<udp::endpoint>(e);
#if TORRENT_USE_IPV6
TEST_EQUAL(list.size(), 2); TEST_EQUAL(list.size(), 2);
TEST_EQUAL(list[1], uep("1000::ffff", 1337)); TEST_EQUAL(list[1], uep("1000::ffff", 1337));
#else
TEST_EQUAL(list.size(), 1);
#endif
TEST_EQUAL(list[0], uep("16.5.128.1", 1337)); TEST_EQUAL(list[0], uep("16.5.128.1", 1337));
} }
@ -171,7 +165,6 @@ TORRENT_TEST(parse_valid_ip4_endpoint)
ec.clear(); ec.clear();
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(parse_invalid_ipv6_endpoint) TORRENT_TEST(parse_invalid_ipv6_endpoint)
{ {
error_code ec; error_code ec;
@ -221,5 +214,4 @@ TORRENT_TEST(parse_valid_ipv6_endpoint)
TEST_CHECK(!ec); TEST_CHECK(!ec);
ec.clear(); ec.clear();
} }
#endif

View File

@ -388,26 +388,15 @@ TORRENT_TEST(parse_list)
TEST_EQUAL(list[5], "foobar"); TEST_EQUAL(list[5], "foobar");
TEST_EQUAL(list[6], "[::1]"); TEST_EQUAL(list[6], "[::1]");
#if TORRENT_USE_IPV6
test_parse_interface(" a:4,b:35, c : 1000s, d: 351 ,e \t:42,foobar:1337s\n\r,[2001::1]:6881" test_parse_interface(" a:4,b:35, c : 1000s, d: 351 ,e \t:42,foobar:1337s\n\r,[2001::1]:6881"
, {{"a", 4, false}, {"b", 35, false}, {"c", 1000, true}, {"d", 351, false} , {{"a", 4, false}, {"b", 35, false}, {"c", 1000, true}, {"d", 351, false}
, {"e", 42, false}, {"foobar", 1337, true}, {"2001::1", 6881, false}} , {"e", 42, false}, {"foobar", 1337, true}, {"2001::1", 6881, false}}
, "a:4,b:35,c:1000s,d:351,e:42,foobar:1337s,[2001::1]:6881"); , "a:4,b:35,c:1000s,d:351,e:42,foobar:1337s,[2001::1]:6881");
#else
test_parse_interface(" a:4,b:35, c : 1000s, d: 351 ,e \t:42,foobar:1337s\n\r,[2001::1]:6881"
, {{"a", 4, false}, {"b", 35, false}, {"c", 1000, true}, {"d", 351, false}
, {"e", 42, false}, {"foobar", 1337, true}}
, "a:4,b:35,c:1000s,d:351,e:42,foobar:1337s");
#endif
// IPv6 address // IPv6 address
#if TORRENT_USE_IPV6
test_parse_interface("[2001:ffff::1]:6882s" test_parse_interface("[2001:ffff::1]:6882s"
, {{"2001:ffff::1", 6882, true}} , {{"2001:ffff::1", 6882, true}}
, "[2001:ffff::1]:6882s"); , "[2001:ffff::1]:6882s");
#else
test_parse_interface("[2001:ffff::1]:6882s", {}, "");
#endif
// IPv4 address // IPv4 address
test_parse_interface("127.0.0.1:6882" test_parse_interface("127.0.0.1:6882"

View File

@ -252,7 +252,6 @@ TORRENT_TEST(parse_external_ip)
TEST_EQUAL(resp.external_ip, addr4("1.2.3.4")); TEST_EQUAL(resp.external_ip, addr4("1.2.3.4"));
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(parse_external_ip6) TORRENT_TEST(parse_external_ip6)
{ {
char const response[] = "d5:peers0:11:external ip" char const response[] = "d5:peers0:11:external ip"
@ -265,7 +264,6 @@ TORRENT_TEST(parse_external_ip6)
TEST_EQUAL(resp.peers.size(), 0); TEST_EQUAL(resp.peers.size(), 0);
TEST_EQUAL(resp.external_ip, addr6("f102:0304::ffff")); TEST_EQUAL(resp.external_ip, addr6("f102:0304::ffff"));
} }
#endif
namespace { namespace {
peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool expected_ret) peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool expected_ret)
@ -416,7 +414,6 @@ TORRENT_TEST(udp_tracker_v4)
test_udp_tracker("127.0.0.1", address_v4::any(), ep("1.3.3.7", 1337)); test_udp_tracker("127.0.0.1", address_v4::any(), ep("1.3.3.7", 1337));
} }
#if TORRENT_USE_IPV6
TORRENT_TEST(udp_tracker_v6) TORRENT_TEST(udp_tracker_v6)
{ {
if (supports_ipv6()) if (supports_ipv6())
@ -424,7 +421,6 @@ TORRENT_TEST(udp_tracker_v6)
test_udp_tracker("[::1]", address_v6::any(), ep("::1.3.3.7", 1337)); test_udp_tracker("[::1]", address_v6::any(), ep("::1.3.3.7", 1337));
} }
} }
#endif
TORRENT_TEST(http_peers) TORRENT_TEST(http_peers)
{ {
@ -483,9 +479,7 @@ TORRENT_TEST(http_peers)
std::set<tcp::endpoint> expected_peers; std::set<tcp::endpoint> expected_peers;
expected_peers.insert(ep("65.65.65.65", 16962)); expected_peers.insert(ep("65.65.65.65", 16962));
expected_peers.insert(ep("67.67.67.67", 17476)); expected_peers.insert(ep("67.67.67.67", 17476));
#if TORRENT_USE_IPV6
expected_peers.insert(ep("4545:4545:4545:4545:4545:4545:4545:4545", 17990)); expected_peers.insert(ep("4545:4545:4545:4545:4545:4545:4545:4545", 17990));
#endif
for (auto const& ip : ra->params.peers) for (auto const& ip : ra->params.peers)
{ {
TEST_EQUAL(expected_peers.count(ip), 1); TEST_EQUAL(expected_peers.count(ip), 1);

View File

@ -133,7 +133,6 @@ struct udp_tracker
detail::write_uint32(1, ptr); // incomplete detail::write_uint32(1, ptr); // incomplete
detail::write_uint32(1, ptr); // complete detail::write_uint32(1, ptr); // complete
// 1 peers // 1 peers
#if TORRENT_USE_IPV6
if (is_v6(*from)) if (is_v6(*from))
{ {
detail::write_uint32(0, ptr); detail::write_uint32(0, ptr);
@ -146,7 +145,6 @@ struct udp_tracker
detail::write_uint16(1337, ptr); detail::write_uint16(1337, ptr);
} }
else else
#endif
{ {
detail::write_uint8(1, ptr); detail::write_uint8(1, ptr);
detail::write_uint8(3, ptr); detail::write_uint8(3, ptr);

View File

@ -67,8 +67,8 @@ def print_classes(out, classes, keyword):
# also ignore any header in the aux_ directory, those are private # also ignore any header in the aux_ directory, those are private
classes = [l for l in classes if l[0].endswith('.hpp') and not l[0].endswith('/fwd.hpp') and '/aux_/' not in l[0]] classes = [l for l in classes if l[0].endswith('.hpp') and not l[0].endswith('/fwd.hpp') and '/aux_/' not in l[0]]
namespaces = ['TORRENT_VERSION_NAMESPACE_2', 'TORRENT_IPV6_NAMESPACE', namespaces = ['TORRENT_VERSION_NAMESPACE_2',
'TORRENT_VERSION_NAMESPACE_2_END', 'TORRENT_IPV6_NAMESPACE_END'] 'TORRENT_VERSION_NAMESPACE_2_END']
# only include classes with the right kind of export # only include classes with the right kind of export
classes = [ classes = [