mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
recreate http and socks proxy upon reload
This commit is contained in:
parent
85fa728d41
commit
162bd592f8
@ -35,81 +35,18 @@ namespace client
|
|||||||
|
|
||||||
void ClientContext::Start ()
|
void ClientContext::Start ()
|
||||||
{
|
{
|
||||||
|
// shared local destination
|
||||||
if (!m_SharedLocalDestination)
|
if (!m_SharedLocalDestination)
|
||||||
CreateNewSharedLocalDestination ();
|
CreateNewSharedLocalDestination ();
|
||||||
|
|
||||||
|
// addressbook
|
||||||
m_AddressBook.Start ();
|
m_AddressBook.Start ();
|
||||||
|
|
||||||
std::shared_ptr<ClientDestination> localDestination;
|
// HTTP proxy
|
||||||
bool httproxy; i2p::config::GetOption("httpproxy.enabled", httproxy);
|
ReadHttpProxy ();
|
||||||
if (httproxy)
|
|
||||||
{
|
|
||||||
std::string httpProxyKeys; i2p::config::GetOption("httpproxy.keys", httpProxyKeys);
|
|
||||||
std::string httpProxyAddr; i2p::config::GetOption("httpproxy.address", httpProxyAddr);
|
|
||||||
uint16_t httpProxyPort; i2p::config::GetOption("httpproxy.port", httpProxyPort);
|
|
||||||
i2p::data::SigningKeyType sigType; i2p::config::GetOption("httpproxy.signaturetype", sigType);
|
|
||||||
std::string httpOutProxyURL; i2p::config::GetOption("httpproxy.outproxy", httpOutProxyURL);
|
|
||||||
LogPrint(eLogInfo, "Clients: starting HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort);
|
|
||||||
if (httpProxyKeys.length () > 0)
|
|
||||||
{
|
|
||||||
i2p::data::PrivateKeys keys;
|
|
||||||
if(LoadPrivateKeys (keys, httpProxyKeys, sigType))
|
|
||||||
{
|
|
||||||
std::map<std::string, std::string> params;
|
|
||||||
ReadI2CPOptionsFromConfig ("httpproxy.", params);
|
|
||||||
localDestination = CreateNewLocalDestination (keys, false, ¶ms);
|
|
||||||
localDestination->Acquire ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LogPrint(eLogError, "Clients: failed to load HTTP Proxy key");
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort, httpOutProxyURL, localDestination);
|
|
||||||
m_HttpProxy->Start();
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
|
||||||
LogPrint(eLogError, "Clients: Exception in HTTP Proxy: ", e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
localDestination = nullptr;
|
// SOCKS proxy
|
||||||
bool socksproxy; i2p::config::GetOption("socksproxy.enabled", socksproxy);
|
ReadSocksProxy ();
|
||||||
if (socksproxy)
|
|
||||||
{
|
|
||||||
std::string socksProxyKeys; i2p::config::GetOption("socksproxy.keys", socksProxyKeys);
|
|
||||||
std::string socksProxyAddr; i2p::config::GetOption("socksproxy.address", socksProxyAddr);
|
|
||||||
uint16_t socksProxyPort; i2p::config::GetOption("socksproxy.port", socksProxyPort);
|
|
||||||
bool socksOutProxy; i2p::config::GetOption("socksproxy.outproxy.enabled", socksOutProxy);
|
|
||||||
std::string socksOutProxyAddr; i2p::config::GetOption("socksproxy.outproxy", socksOutProxyAddr);
|
|
||||||
uint16_t socksOutProxyPort; i2p::config::GetOption("socksproxy.outproxyport", socksOutProxyPort);
|
|
||||||
i2p::data::SigningKeyType sigType; i2p::config::GetOption("socksproxy.signaturetype", sigType);
|
|
||||||
LogPrint(eLogInfo, "Clients: starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort);
|
|
||||||
if (socksProxyKeys.length () > 0)
|
|
||||||
{
|
|
||||||
i2p::data::PrivateKeys keys;
|
|
||||||
if (LoadPrivateKeys (keys, socksProxyKeys, sigType))
|
|
||||||
{
|
|
||||||
std::map<std::string, std::string> params;
|
|
||||||
ReadI2CPOptionsFromConfig ("socksproxy.", params);
|
|
||||||
localDestination = CreateNewLocalDestination (keys, false, ¶ms);
|
|
||||||
localDestination->Acquire ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LogPrint(eLogError, "Clients: failed to load SOCKS Proxy key");
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_SocksProxy = new i2p::proxy::SOCKSProxy("SOCKS", socksProxyAddr, socksProxyPort,
|
|
||||||
socksOutProxy, socksOutProxyAddr, socksOutProxyPort, localDestination);
|
|
||||||
m_SocksProxy->Start();
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
|
||||||
LogPrint(eLogError, "Clients: Exception in SOCKS Proxy: ", e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// I2P tunnels
|
// I2P tunnels
|
||||||
ReadTunnels ();
|
ReadTunnels ();
|
||||||
@ -265,6 +202,22 @@ namespace client
|
|||||||
m_SharedLocalDestination->Release ();
|
m_SharedLocalDestination->Release ();
|
||||||
CreateNewSharedLocalDestination ();
|
CreateNewSharedLocalDestination ();
|
||||||
|
|
||||||
|
// recreate HTTP proxy
|
||||||
|
if (m_HttpProxy)
|
||||||
|
{
|
||||||
|
m_HttpProxy->Stop ();
|
||||||
|
m_HttpProxy = nullptr;
|
||||||
|
}
|
||||||
|
ReadHttpProxy ();
|
||||||
|
|
||||||
|
// recreate SOCKS proxy
|
||||||
|
if (m_SocksProxy)
|
||||||
|
{
|
||||||
|
m_SocksProxy->Stop ();
|
||||||
|
m_SocksProxy = nullptr;
|
||||||
|
}
|
||||||
|
ReadSocksProxy ();
|
||||||
|
|
||||||
// delete unused destinations
|
// delete unused destinations
|
||||||
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
||||||
for (auto it = m_Destinations.begin (); it != m_Destinations.end ();)
|
for (auto it = m_Destinations.begin (); it != m_Destinations.end ();)
|
||||||
@ -722,6 +675,83 @@ namespace client
|
|||||||
LogPrint (eLogInfo, "Clients: ", numServerTunnels, " I2P server tunnels created");
|
LogPrint (eLogInfo, "Clients: ", numServerTunnels, " I2P server tunnels created");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientContext::ReadHttpProxy ()
|
||||||
|
{
|
||||||
|
std::shared_ptr<ClientDestination> localDestination;
|
||||||
|
bool httproxy; i2p::config::GetOption("httpproxy.enabled", httproxy);
|
||||||
|
if (httproxy)
|
||||||
|
{
|
||||||
|
std::string httpProxyKeys; i2p::config::GetOption("httpproxy.keys", httpProxyKeys);
|
||||||
|
std::string httpProxyAddr; i2p::config::GetOption("httpproxy.address", httpProxyAddr);
|
||||||
|
uint16_t httpProxyPort; i2p::config::GetOption("httpproxy.port", httpProxyPort);
|
||||||
|
i2p::data::SigningKeyType sigType; i2p::config::GetOption("httpproxy.signaturetype", sigType);
|
||||||
|
std::string httpOutProxyURL; i2p::config::GetOption("httpproxy.outproxy", httpOutProxyURL);
|
||||||
|
LogPrint(eLogInfo, "Clients: starting HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort);
|
||||||
|
if (httpProxyKeys.length () > 0)
|
||||||
|
{
|
||||||
|
i2p::data::PrivateKeys keys;
|
||||||
|
if(LoadPrivateKeys (keys, httpProxyKeys, sigType))
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string> params;
|
||||||
|
ReadI2CPOptionsFromConfig ("httpproxy.", params);
|
||||||
|
localDestination = CreateNewLocalDestination (keys, false, ¶ms);
|
||||||
|
localDestination->Acquire ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint(eLogError, "Clients: failed to load HTTP Proxy key");
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort, httpOutProxyURL, localDestination);
|
||||||
|
m_HttpProxy->Start();
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
LogPrint(eLogError, "Clients: Exception in HTTP Proxy: ", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientContext::ReadSocksProxy ()
|
||||||
|
{
|
||||||
|
std::shared_ptr<ClientDestination> localDestination;
|
||||||
|
bool socksproxy; i2p::config::GetOption("socksproxy.enabled", socksproxy);
|
||||||
|
if (socksproxy)
|
||||||
|
{
|
||||||
|
std::string socksProxyKeys; i2p::config::GetOption("socksproxy.keys", socksProxyKeys);
|
||||||
|
std::string socksProxyAddr; i2p::config::GetOption("socksproxy.address", socksProxyAddr);
|
||||||
|
uint16_t socksProxyPort; i2p::config::GetOption("socksproxy.port", socksProxyPort);
|
||||||
|
bool socksOutProxy; i2p::config::GetOption("socksproxy.outproxy.enabled", socksOutProxy);
|
||||||
|
std::string socksOutProxyAddr; i2p::config::GetOption("socksproxy.outproxy", socksOutProxyAddr);
|
||||||
|
uint16_t socksOutProxyPort; i2p::config::GetOption("socksproxy.outproxyport", socksOutProxyPort);
|
||||||
|
i2p::data::SigningKeyType sigType; i2p::config::GetOption("socksproxy.signaturetype", sigType);
|
||||||
|
LogPrint(eLogInfo, "Clients: starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort);
|
||||||
|
if (socksProxyKeys.length () > 0)
|
||||||
|
{
|
||||||
|
i2p::data::PrivateKeys keys;
|
||||||
|
if (LoadPrivateKeys (keys, socksProxyKeys, sigType))
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string> params;
|
||||||
|
ReadI2CPOptionsFromConfig ("socksproxy.", params);
|
||||||
|
localDestination = CreateNewLocalDestination (keys, false, ¶ms);
|
||||||
|
localDestination->Acquire ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint(eLogError, "Clients: failed to load SOCKS Proxy key");
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_SocksProxy = new i2p::proxy::SOCKSProxy("SOCKS", socksProxyAddr, socksProxyPort,
|
||||||
|
socksOutProxy, socksOutProxyAddr, socksOutProxyPort, localDestination);
|
||||||
|
m_SocksProxy->Start();
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
LogPrint(eLogError, "Clients: Exception in SOCKS Proxy: ", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ClientContext::ScheduleCleanupUDP()
|
void ClientContext::ScheduleCleanupUDP()
|
||||||
{
|
{
|
||||||
if (m_CleanupUDPTimer)
|
if (m_CleanupUDPTimer)
|
||||||
|
@ -87,6 +87,8 @@ namespace client
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void ReadTunnels ();
|
void ReadTunnels ();
|
||||||
|
void ReadHttpProxy ();
|
||||||
|
void ReadSocksProxy ();
|
||||||
template<typename Section, typename Type>
|
template<typename Section, typename Type>
|
||||||
std::string GetI2CPOption (const Section& section, const std::string& name, const Type& value) const;
|
std::string GetI2CPOption (const Section& section, const std::string& name, const Type& value) const;
|
||||||
template<typename Section>
|
template<typename Section>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user