|
|
@ -256,27 +256,32 @@ namespace transport |
|
|
|
socket.open (localEndpoint.protocol ()); |
|
|
|
socket.open (localEndpoint.protocol ()); |
|
|
|
if (localEndpoint.address ().is_v6 ()) |
|
|
|
if (localEndpoint.address ().is_v6 ()) |
|
|
|
socket.set_option (boost::asio::ip::v6_only (true)); |
|
|
|
socket.set_option (boost::asio::ip::v6_only (true)); |
|
|
|
boost::asio::socket_base::receive_buffer_size receive_buffer_size_set (SSU2_SOCKET_RECEIVE_BUFFER_SIZE); |
|
|
|
|
|
|
|
boost::asio::socket_base::send_buffer_size send_buffer_size_set (SSU2_SOCKET_SEND_BUFFER_SIZE); |
|
|
|
uint64_t bufferSize = i2p::context.GetBandwidthLimit() * 1024 / 5; // max lag = 200ms
|
|
|
|
socket.set_option (receive_buffer_size_set); |
|
|
|
bufferSize = std::max(SSU2_SOCKET_MIN_BUFFER_SIZE, std::min(bufferSize, SSU2_SOCKET_MAX_BUFFER_SIZE)); |
|
|
|
socket.set_option (send_buffer_size_set); |
|
|
|
|
|
|
|
boost::asio::socket_base::receive_buffer_size receive_buffer_size_get; |
|
|
|
boost::asio::socket_base::receive_buffer_size receiveBufferSizeSet (bufferSize); |
|
|
|
boost::asio::socket_base::send_buffer_size send_buffer_size_get; |
|
|
|
boost::asio::socket_base::send_buffer_size sendBufferSizeSet (bufferSize); |
|
|
|
socket.get_option (receive_buffer_size_get); |
|
|
|
socket.set_option (receiveBufferSizeSet); |
|
|
|
socket.get_option (send_buffer_size_get); |
|
|
|
socket.set_option (sendBufferSizeSet); |
|
|
|
if (receive_buffer_size_get.value () != receive_buffer_size_set.value () || |
|
|
|
boost::asio::socket_base::receive_buffer_size receiveBufferSizeGet; |
|
|
|
send_buffer_size_get.value () != send_buffer_size_set.value ()) |
|
|
|
boost::asio::socket_base::send_buffer_size sendBufferSizeGet; |
|
|
|
|
|
|
|
socket.get_option (receiveBufferSizeGet); |
|
|
|
|
|
|
|
socket.get_option (sendBufferSizeGet); |
|
|
|
|
|
|
|
if (receiveBufferSizeGet.value () != receiveBufferSizeSet.value () || |
|
|
|
|
|
|
|
sendBufferSizeGet.value () != sendBufferSizeSet.value ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogWarning, "SSU2: Socket receive buffer size: requested = ", |
|
|
|
LogPrint (eLogWarning, "SSU2: Socket receive buffer size: requested = ", |
|
|
|
receive_buffer_size_set.value (), ", got = ", receive_buffer_size_get.value ()); |
|
|
|
receiveBufferSizeSet.value (), ", got = ", receiveBufferSizeGet.value ()); |
|
|
|
LogPrint (eLogWarning, "SSU2: Socket send buffer size: requested = ", |
|
|
|
LogPrint (eLogWarning, "SSU2: Socket send buffer size: requested = ", |
|
|
|
send_buffer_size_set.value (), ", got = ", send_buffer_size_get.value ()); |
|
|
|
sendBufferSizeSet.value (), ", got = ", sendBufferSizeGet.value ()); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogInfo, "SSU2: Socket receive buffer size: ", receive_buffer_size_get.value ()); |
|
|
|
LogPrint (eLogInfo, "SSU2: Socket receive buffer size: ", receiveBufferSizeGet.value ()); |
|
|
|
LogPrint (eLogInfo, "SSU2: Socket send buffer size: ", send_buffer_size_get.value ()); |
|
|
|
LogPrint (eLogInfo, "SSU2: Socket send buffer size: ", sendBufferSizeGet.value ()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
socket.non_blocking (true); |
|
|
|
socket.non_blocking (true); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (std::exception& ex ) |
|
|
|
catch (std::exception& ex ) |
|
|
@ -657,7 +662,10 @@ namespace transport |
|
|
|
if (!ec) |
|
|
|
if (!ec) |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + payloadLen); |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + payloadLen); |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to); |
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (ec == boost::asio::error::would_block ? eLogInfo : eLogError, |
|
|
|
|
|
|
|
"SSU2: Send exception: ", ec.message (), " to ", to); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SSU2Server::Send (const uint8_t * header, size_t headerLen, const uint8_t * headerX, size_t headerXLen, |
|
|
|
void SSU2Server::Send (const uint8_t * header, size_t headerLen, const uint8_t * headerX, size_t headerXLen, |
|
|
@ -691,7 +699,10 @@ namespace transport |
|
|
|
if (!ec) |
|
|
|
if (!ec) |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + headerXLen + payloadLen); |
|
|
|
i2p::transport::transports.UpdateSentBytes (headerLen + headerXLen + payloadLen); |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to); |
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (ec == boost::asio::error::would_block ? eLogInfo : eLogError, |
|
|
|
|
|
|
|
"SSU2: Send exception: ", ec.message (), " to ", to); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SSU2Server::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, |
|
|
|
bool SSU2Server::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, |
|
|
|