mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
recconnect to proxy
This commit is contained in:
parent
f1f66d7b8f
commit
1738d118f7
@ -1157,6 +1157,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
LogPrint (eLogError, "SSU2: Can't connect to proxy ", *m_ProxyEndpoint, " ", ecode.message ());
|
LogPrint (eLogError, "SSU2: Can't connect to proxy ", *m_ProxyEndpoint, " ", ecode.message ());
|
||||||
m_UDPAssociateSocket.reset (nullptr);
|
m_UDPAssociateSocket.reset (nullptr);
|
||||||
|
ReconnectToProxy ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
HandshakeWithProxy ();
|
HandshakeWithProxy ();
|
||||||
@ -1177,6 +1178,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
LogPrint(eLogError, "SSU2: Proxy write error ", ecode.message());
|
LogPrint(eLogError, "SSU2: Proxy write error ", ecode.message());
|
||||||
m_UDPAssociateSocket.reset (nullptr);
|
m_UDPAssociateSocket.reset (nullptr);
|
||||||
|
ReconnectToProxy ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ReadHandshakeWithProxyReply ();
|
ReadHandshakeWithProxyReply ();
|
||||||
@ -1194,6 +1196,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
LogPrint(eLogError, "SSU2: Proxy read error ", ecode.message());
|
LogPrint(eLogError, "SSU2: Proxy read error ", ecode.message());
|
||||||
m_UDPAssociateSocket.reset (nullptr);
|
m_UDPAssociateSocket.reset (nullptr);
|
||||||
|
ReconnectToProxy ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1224,6 +1227,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
LogPrint(eLogError, "SSU2: Proxy write error ", ecode.message());
|
LogPrint(eLogError, "SSU2: Proxy write error ", ecode.message());
|
||||||
m_UDPAssociateSocket.reset (nullptr);
|
m_UDPAssociateSocket.reset (nullptr);
|
||||||
|
ReconnectToProxy ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ReadUDPAssociateReply ();
|
ReadUDPAssociateReply ();
|
||||||
@ -1241,6 +1245,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
LogPrint(eLogError, "SSU2: Proxy read error ", ecode.message());
|
LogPrint(eLogError, "SSU2: Proxy read error ", ecode.message());
|
||||||
m_UDPAssociateSocket.reset (nullptr);
|
m_UDPAssociateSocket.reset (nullptr);
|
||||||
|
ReconnectToProxy ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1280,14 +1285,36 @@ namespace transport
|
|||||||
(void) bytes_transferred;
|
(void) bytes_transferred;
|
||||||
if (ecode)
|
if (ecode)
|
||||||
{
|
{
|
||||||
LogPrint(eLogError, "SSU2: Proxy UDP Associate socket error ", ecode.message());
|
LogPrint(eLogWarning, "SSU2: Proxy UDP Associate socket error ", ecode.message());
|
||||||
m_UDPAssociateSocket.reset (nullptr);
|
m_UDPAssociateSocket.reset (nullptr);
|
||||||
|
m_ProxyRelayEndpoint.reset (nullptr);
|
||||||
|
ConnectToProxy (); // try to reconnect immediately
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ReadUDPAssociateSocket ();
|
ReadUDPAssociateSocket ();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSU2Server::ReconnectToProxy ()
|
||||||
|
{
|
||||||
|
LogPrint(eLogInfo, "SSU2: Reconnect to proxy after ", SSU2_PROXY_CONNECT_RETRY_TIMEOUT, " seconds");
|
||||||
|
if (m_ProxyConnectRetryTimer)
|
||||||
|
m_ProxyConnectRetryTimer->cancel ();
|
||||||
|
else
|
||||||
|
m_ProxyConnectRetryTimer.reset (new boost::asio::deadline_timer (m_ReceiveService.GetService ()));
|
||||||
|
m_ProxyConnectRetryTimer->expires_from_now (boost::posix_time::seconds (SSU2_PROXY_CONNECT_RETRY_TIMEOUT));
|
||||||
|
m_ProxyConnectRetryTimer->async_wait (
|
||||||
|
[this](const boost::system::error_code& ecode)
|
||||||
|
{
|
||||||
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
|
{
|
||||||
|
m_UDPAssociateSocket.reset (nullptr);
|
||||||
|
m_ProxyRelayEndpoint.reset (nullptr);
|
||||||
|
ConnectToProxy ();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool SSU2Server::SetProxy (const std::string& address, uint16_t port)
|
bool SSU2Server::SetProxy (const std::string& address, uint16_t port)
|
||||||
{
|
{
|
||||||
boost::system::error_code ecode;
|
boost::system::error_code ecode;
|
||||||
|
@ -27,8 +27,9 @@ namespace transport
|
|||||||
const size_t SSU2_MAX_NUM_INTRODUCERS = 3;
|
const size_t SSU2_MAX_NUM_INTRODUCERS = 3;
|
||||||
const int SSU2_TO_INTRODUCER_SESSION_DURATION = 3600; // 1 hour
|
const int SSU2_TO_INTRODUCER_SESSION_DURATION = 3600; // 1 hour
|
||||||
const int SSU2_TO_INTRODUCER_SESSION_EXPIRATION = 4800; // 80 minutes
|
const int SSU2_TO_INTRODUCER_SESSION_EXPIRATION = 4800; // 80 minutes
|
||||||
const int SSU2_KEEP_ALIVE_INTERVAL = 30; // 30 seconds
|
const int SSU2_KEEP_ALIVE_INTERVAL = 30; // in seconds
|
||||||
|
const int SSU2_PROXY_CONNECT_RETRY_TIMEOUT = 30; // in seconds
|
||||||
|
|
||||||
class SSU2Server: private i2p::util::RunnableServiceWithWork
|
class SSU2Server: private i2p::util::RunnableServiceWithWork
|
||||||
{
|
{
|
||||||
struct Packet
|
struct Packet
|
||||||
@ -124,6 +125,7 @@ namespace transport
|
|||||||
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);
|
||||||
void ProcessNextPacketFromProxy (uint8_t * buf, size_t len);
|
void ProcessNextPacketFromProxy (uint8_t * buf, size_t len);
|
||||||
void ConnectToProxy ();
|
void ConnectToProxy ();
|
||||||
|
void ReconnectToProxy ();
|
||||||
void HandshakeWithProxy ();
|
void HandshakeWithProxy ();
|
||||||
void ReadHandshakeWithProxyReply ();
|
void ReadHandshakeWithProxyReply ();
|
||||||
void SendUDPAssociateRequest ();
|
void SendUDPAssociateRequest ();
|
||||||
@ -155,6 +157,7 @@ namespace transport
|
|||||||
std::unique_ptr<boost::asio::ip::tcp::endpoint> m_ProxyEndpoint;
|
std::unique_ptr<boost::asio::ip::tcp::endpoint> m_ProxyEndpoint;
|
||||||
std::unique_ptr<boost::asio::ip::tcp::socket> m_UDPAssociateSocket;
|
std::unique_ptr<boost::asio::ip::tcp::socket> m_UDPAssociateSocket;
|
||||||
std::unique_ptr<boost::asio::ip::udp::endpoint> m_ProxyRelayEndpoint;
|
std::unique_ptr<boost::asio::ip::udp::endpoint> m_ProxyRelayEndpoint;
|
||||||
|
std::unique_ptr<boost::asio::deadline_timer> m_ProxyConnectRetryTimer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user