mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-27 19:27:49 +02:00
#1251 - add ipv6 address preference for NTCP/2, NTCP2 code clean
This commit is contained in:
parent
7c7742a175
commit
7ab29950a4
3 changed files with 170 additions and 153 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2018, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2019, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
|
@ -23,6 +23,10 @@
|
|||
#include "NetDb.hpp"
|
||||
#include "NTCP2.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <linux/in6.h>
|
||||
#endif
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace transport
|
||||
|
@ -1157,7 +1161,7 @@ namespace transport
|
|||
if (!address) continue;
|
||||
if (address->IsPublishedNTCP2 ())
|
||||
{
|
||||
if (address->host.is_v4())
|
||||
if (address->host.is_v4() && context.SupportsV4 ())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1175,12 +1179,17 @@ namespace transport
|
|||
}
|
||||
else if (address->host.is_v6() && context.SupportsV6 ())
|
||||
{
|
||||
m_NTCP2V6Acceptor.reset (new boost::asio::ip::tcp::acceptor (m_Service));
|
||||
try
|
||||
{
|
||||
m_NTCP2V6Acceptor.reset (new boost::asio::ip::tcp::acceptor (m_Service));
|
||||
m_NTCP2V6Acceptor->open (boost::asio::ip::tcp::v6 ());
|
||||
m_NTCP2V6Acceptor->set_option (boost::asio::ip::v6_only (true));
|
||||
m_NTCP2V6Acceptor->set_option (boost::asio::socket_base::reuse_address (true));
|
||||
#ifndef WIN32
|
||||
// Set preference to use public IPv6 address -- works only on linux
|
||||
typedef boost::asio::detail::socket_option::boolean<IPV6_ADDR_PREFERENCES, IPV6_PREFER_SRC_PUBLIC> ipv6PreferPubAddr;
|
||||
m_NTCP2V6Acceptor->set_option (ipv6PreferPubAddr (true));
|
||||
#endif
|
||||
m_NTCP2V6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port));
|
||||
m_NTCP2V6Acceptor->listen ();
|
||||
|
||||
|
@ -1403,4 +1412,3 @@ namespace transport
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
#include "Event.h"
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#include <linux/in6.h>
|
||||
#endif
|
||||
|
||||
using namespace i2p::crypto;
|
||||
|
||||
namespace i2p
|
||||
|
@ -853,6 +857,11 @@ namespace transport
|
|||
m_NTCPV6Acceptor->open (boost::asio::ip::tcp::v6 ());
|
||||
m_NTCPV6Acceptor->set_option (boost::asio::ip::v6_only (true));
|
||||
m_NTCPV6Acceptor->set_option (boost::asio::socket_base::reuse_address (true));
|
||||
#ifndef WIN32
|
||||
// Set preference to use public IPv6 address -- works only on linux
|
||||
typedef boost::asio::detail::socket_option::boolean<IPV6_ADDR_PREFERENCES, IPV6_PREFER_SRC_PUBLIC> ipv6PreferPubAddr;
|
||||
m_NTCPV6Acceptor->set_option (ipv6PreferPubAddr (true));
|
||||
#endif
|
||||
m_NTCPV6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port));
|
||||
m_NTCPV6Acceptor->listen ();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue