|
|
@ -17,8 +17,7 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
ClientContext::ClientContext (): m_SharedLocalDestination (nullptr), |
|
|
|
ClientContext::ClientContext (): m_SharedLocalDestination (nullptr), |
|
|
|
m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_SamBridge (nullptr), |
|
|
|
m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_SamBridge (nullptr), |
|
|
|
m_BOBCommandChannel (nullptr), m_I2CPServer (nullptr), |
|
|
|
m_BOBCommandChannel (nullptr), m_I2CPServer (nullptr) |
|
|
|
m_CleanupUDPTimer(m_Service, boost::posix_time::seconds(1)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -88,20 +87,9 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( m_ServiceThread == nullptr ) { |
|
|
|
|
|
|
|
m_ServiceThread = new std::thread([&] () { |
|
|
|
|
|
|
|
LogPrint(eLogInfo, "ClientContext: starting service"); |
|
|
|
|
|
|
|
m_Service.run(); |
|
|
|
|
|
|
|
LogPrint(eLogError, "ClientContext: service died"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
ScheduleCleanupUDP(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// I2P tunnels
|
|
|
|
// I2P tunnels
|
|
|
|
ReadTunnels (); |
|
|
|
ReadTunnels (); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SAM
|
|
|
|
// SAM
|
|
|
|
bool sam; i2p::config::GetOption("sam.enabled", sam); |
|
|
|
bool sam; i2p::config::GetOption("sam.enabled", sam); |
|
|
|
if (sam) { |
|
|
|
if (sam) { |
|
|
@ -149,6 +137,13 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_AddressBook.StartResolvers (); |
|
|
|
m_AddressBook.StartResolvers (); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// start UDP cleanup
|
|
|
|
|
|
|
|
if (!m_ServerForwards.empty ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_CleanupUDPTimer.reset (new boost::asio::deadline_timer(m_SharedLocalDestination->GetService ())); |
|
|
|
|
|
|
|
ScheduleCleanupUDP(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ClientContext::Stop () |
|
|
|
void ClientContext::Stop () |
|
|
@ -216,19 +211,16 @@ namespace client |
|
|
|
m_ClientForwards.clear(); |
|
|
|
m_ClientForwards.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_CleanupUDPTimer) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_CleanupUDPTimer->cancel (); |
|
|
|
|
|
|
|
m_CleanupUDPTimer = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (auto& it: m_Destinations) |
|
|
|
for (auto& it: m_Destinations) |
|
|
|
it.second->Stop (); |
|
|
|
it.second->Stop (); |
|
|
|
m_Destinations.clear (); |
|
|
|
m_Destinations.clear (); |
|
|
|
m_SharedLocalDestination = nullptr; |
|
|
|
m_SharedLocalDestination = nullptr; |
|
|
|
// stop io service thread
|
|
|
|
|
|
|
|
if(m_ServiceThread) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_Service.stop(); |
|
|
|
|
|
|
|
m_ServiceThread->join(); |
|
|
|
|
|
|
|
delete m_ServiceThread; |
|
|
|
|
|
|
|
m_ServiceThread = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ClientContext::ReloadConfig () |
|
|
|
void ClientContext::ReloadConfig () |
|
|
@ -558,9 +550,12 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void ClientContext::ScheduleCleanupUDP() |
|
|
|
void ClientContext::ScheduleCleanupUDP() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// schedule cleanup in 1 second
|
|
|
|
if (m_CleanupUDPTimer) |
|
|
|
m_CleanupUDPTimer.expires_at(m_CleanupUDPTimer.expires_at() + boost::posix_time::seconds(1)); |
|
|
|
{ |
|
|
|
m_CleanupUDPTimer.async_wait(std::bind(&ClientContext::CleanupUDP, this, std::placeholders::_1)); |
|
|
|
// schedule cleanup in 17 seconds
|
|
|
|
|
|
|
|
m_CleanupUDPTimer->expires_from_now (boost::posix_time::seconds (17)); |
|
|
|
|
|
|
|
m_CleanupUDPTimer->async_wait(std::bind(&ClientContext::CleanupUDP, this, std::placeholders::_1)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ClientContext::CleanupUDP(const boost::system::error_code & ecode) |
|
|
|
void ClientContext::CleanupUDP(const boost::system::error_code & ecode) |
|
|
@ -568,7 +563,7 @@ namespace client |
|
|
|
if(!ecode) |
|
|
|
if(!ecode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::lock_guard<std::mutex> lock(m_ForwardsMutex); |
|
|
|
std::lock_guard<std::mutex> lock(m_ForwardsMutex); |
|
|
|
for ( auto & s : m_ServerForwards ) s.second->ExpireStale(); |
|
|
|
for (auto & s : m_ServerForwards ) s.second->ExpireStale(); |
|
|
|
ScheduleCleanupUDP(); |
|
|
|
ScheduleCleanupUDP(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|