|
|
@ -42,6 +42,11 @@ namespace transport |
|
|
|
if (!address) continue; |
|
|
|
if (!address) continue; |
|
|
|
if (address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) |
|
|
|
if (address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (m_IsThroughProxy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
found = true; |
|
|
|
|
|
|
|
break; // we don't need port for proxy
|
|
|
|
|
|
|
|
} |
|
|
|
auto port = address->port; |
|
|
|
auto port = address->port; |
|
|
|
if (!port) |
|
|
|
if (!port) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -84,7 +89,11 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (found) |
|
|
|
if (found) |
|
|
|
|
|
|
|
{ |
|
|
|
m_ReceiveService.Start (); |
|
|
|
m_ReceiveService.Start (); |
|
|
|
|
|
|
|
if (m_IsThroughProxy) |
|
|
|
|
|
|
|
ConnectToProxy (); |
|
|
|
|
|
|
|
} |
|
|
|
ScheduleTermination (); |
|
|
|
ScheduleTermination (); |
|
|
|
ScheduleResend (false); |
|
|
|
ScheduleResend (false); |
|
|
|
} |
|
|
|
} |
|
|
@ -257,6 +266,9 @@ namespace transport |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (packet) |
|
|
|
if (packet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (m_IsThroughProxy) |
|
|
|
|
|
|
|
ProcessNextPacketFromProxy (packet->buf, packet->len); |
|
|
|
|
|
|
|
else |
|
|
|
ProcessNextPacket (packet->buf, packet->len, packet->from); |
|
|
|
ProcessNextPacket (packet->buf, packet->len, packet->from); |
|
|
|
m_PacketsPool.ReleaseMt (packet); |
|
|
|
m_PacketsPool.ReleaseMt (packet); |
|
|
|
if (m_LastSession && m_LastSession->GetState () != eSSU2SessionStateTerminated) |
|
|
|
if (m_LastSession && m_LastSession->GetState () != eSSU2SessionStateTerminated) |
|
|
@ -266,6 +278,10 @@ namespace transport |
|
|
|
|
|
|
|
|
|
|
|
void SSU2Server::HandleReceivedPackets (std::vector<Packet *> packets) |
|
|
|
void SSU2Server::HandleReceivedPackets (std::vector<Packet *> packets) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (m_IsThroughProxy) |
|
|
|
|
|
|
|
for (auto& packet: packets) |
|
|
|
|
|
|
|
ProcessNextPacketFromProxy (packet->buf, packet->len); |
|
|
|
|
|
|
|
else |
|
|
|
for (auto& packet: packets) |
|
|
|
for (auto& packet: packets) |
|
|
|
ProcessNextPacket (packet->buf, packet->len, packet->from); |
|
|
|
ProcessNextPacket (packet->buf, packet->len, packet->from); |
|
|
|
m_PacketsPool.ReleaseMt (packets); |
|
|
|
m_PacketsPool.ReleaseMt (packets); |
|
|
@ -479,6 +495,11 @@ namespace transport |
|
|
|
void SSU2Server::Send (const uint8_t * header, size_t headerLen, const uint8_t * payload, size_t payloadLen, |
|
|
|
void SSU2Server::Send (const uint8_t * header, size_t headerLen, const uint8_t * payload, size_t payloadLen, |
|
|
|
const boost::asio::ip::udp::endpoint& to) |
|
|
|
const boost::asio::ip::udp::endpoint& to) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (m_IsThroughProxy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SendThroughProxy (header, headerLen, nullptr, 0, payload, payloadLen, to); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
std::vector<boost::asio::const_buffer> bufs |
|
|
|
std::vector<boost::asio::const_buffer> bufs |
|
|
|
{ |
|
|
|
{ |
|
|
|
boost::asio::buffer (header, headerLen), |
|
|
|
boost::asio::buffer (header, headerLen), |
|
|
@ -498,6 +519,11 @@ namespace transport |
|
|
|
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, |
|
|
|
const uint8_t * payload, size_t payloadLen, const boost::asio::ip::udp::endpoint& to) |
|
|
|
const uint8_t * payload, size_t payloadLen, const boost::asio::ip::udp::endpoint& to) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (m_IsThroughProxy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SendThroughProxy (header, headerLen, headerX, headerXLen, payload, payloadLen, to); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
std::vector<boost::asio::const_buffer> bufs |
|
|
|
std::vector<boost::asio::const_buffer> bufs |
|
|
|
{ |
|
|
|
{ |
|
|
|
boost::asio::buffer (header, headerLen), |
|
|
|
boost::asio::buffer (header, headerLen), |
|
|
@ -1250,5 +1276,23 @@ namespace transport |
|
|
|
ReadUDPAssociateSocket (); |
|
|
|
ReadUDPAssociateSocket (); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool SSU2Server::SetProxy (const std::string& address, uint16_t port) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
boost::system::error_code ecode; |
|
|
|
|
|
|
|
auto addr = boost::asio::ip::address::from_string (address, ecode); |
|
|
|
|
|
|
|
if (!ecode && !addr.is_unspecified () && port) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_IsThroughProxy = true; |
|
|
|
|
|
|
|
m_ProxyEndpoint.reset (new boost::asio::ip::tcp::endpoint (addr, port)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (ecode) |
|
|
|
|
|
|
|
LogPrint (eLogError, "SSU2: Invalid proxy address ", address, " ", ecode.message()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|