Browse Source

reuse_address for ipv6 acceptor

pull/1313/head
orignal 6 years ago
parent
commit
9b1fe4338b
  1. 9
      libi2pd/NTCP2.cpp
  2. 1
      libi2pd/NTCPSession.cpp

9
libi2pd/NTCP2.cpp

@ -935,7 +935,7 @@ namespace transport
htobe16buf (buf + 1, len); // size htobe16buf (buf + 1, len); // size
len += 3; len += 3;
totalLen += len; totalLen += len;
encryptBufs.push_back (std::make_pair (buf, len)); encryptBufs.push_back ( {buf, len} );
if (&it == &msgs.front ()) // first message if (&it == &msgs.front ()) // first message
{ {
// allocate two bytes for length // allocate two bytes for length
@ -949,7 +949,7 @@ namespace transport
auto paddingLen = CreatePaddingBlock (totalLen, buf + len, it->maxLen - it->len - 16); auto paddingLen = CreatePaddingBlock (totalLen, buf + len, it->maxLen - it->len - 16);
if (paddingLen) if (paddingLen)
{ {
encryptBufs.push_back (std::make_pair (buf + len, paddingLen)); encryptBufs.push_back ( {buf + len, paddingLen} );
len += paddingLen; len += paddingLen;
totalLen += paddingLen; totalLen += paddingLen;
} }
@ -969,7 +969,7 @@ namespace transport
auto paddingLen = CreatePaddingBlock (totalLen, m_NextSendBuffer, 287 - 16); auto paddingLen = CreatePaddingBlock (totalLen, m_NextSendBuffer, 287 - 16);
// and padding block to encrypt and send // and padding block to encrypt and send
if (paddingLen) if (paddingLen)
encryptBufs.push_back (std::make_pair (m_NextSendBuffer, paddingLen)); encryptBufs.push_back ( {m_NextSendBuffer, paddingLen} );
bufs.push_back (boost::asio::buffer (m_NextSendBuffer, paddingLen + 16)); bufs.push_back (boost::asio::buffer (m_NextSendBuffer, paddingLen + 16));
macBuf = m_NextSendBuffer + paddingLen; macBuf = m_NextSendBuffer + paddingLen;
totalLen += paddingLen; totalLen += paddingLen;
@ -1001,7 +1001,7 @@ namespace transport
// encrypt // encrypt
uint8_t nonce[12]; uint8_t nonce[12];
CreateNonce (m_SendSequenceNumber, nonce); m_SendSequenceNumber++; CreateNonce (m_SendSequenceNumber, nonce); m_SendSequenceNumber++;
i2p::crypto::AEADChaCha20Poly1305Encrypt ({std::make_pair (m_NextSendBuffer + 2, payloadLen)}, m_SendKey, nonce, m_NextSendBuffer + payloadLen + 2); i2p::crypto::AEADChaCha20Poly1305Encrypt ({ {m_NextSendBuffer + 2, payloadLen} }, m_SendKey, nonce, m_NextSendBuffer + payloadLen + 2);
SetNextSentFrameLength (payloadLen + 16, m_NextSendBuffer); SetNextSentFrameLength (payloadLen + 16, m_NextSendBuffer);
// send // send
m_IsSending = true; m_IsSending = true;
@ -1180,6 +1180,7 @@ namespace transport
{ {
m_NTCP2V6Acceptor->open (boost::asio::ip::tcp::v6()); m_NTCP2V6Acceptor->open (boost::asio::ip::tcp::v6());
m_NTCP2V6Acceptor->set_option (boost::asio::ip::v6_only (true)); m_NTCP2V6Acceptor->set_option (boost::asio::ip::v6_only (true));
m_NTCP2V6Acceptor->set_option (boost::asio::socket_base::reuse_address (true));
m_NTCP2V6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port)); m_NTCP2V6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port));
m_NTCP2V6Acceptor->listen (); m_NTCP2V6Acceptor->listen ();

1
libi2pd/NTCPSession.cpp

@ -843,6 +843,7 @@ namespace transport
{ {
m_NTCPV6Acceptor->open (boost::asio::ip::tcp::v6()); m_NTCPV6Acceptor->open (boost::asio::ip::tcp::v6());
m_NTCPV6Acceptor->set_option (boost::asio::ip::v6_only (true)); m_NTCPV6Acceptor->set_option (boost::asio::ip::v6_only (true));
m_NTCPV6Acceptor->set_option (boost::asio::socket_base::reuse_address (true));
m_NTCPV6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port)); m_NTCPV6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port));
m_NTCPV6Acceptor->listen (); m_NTCPV6Acceptor->listen ();

Loading…
Cancel
Save