check network status

This commit is contained in:
orignal 2020-10-11 17:51:40 -04:00
parent e21dac21c8
commit ffa0f0afd9
5 changed files with 24 additions and 5 deletions

View File

@ -259,6 +259,9 @@ namespace http {
case eRouterErrorClockSkew:
s << "<br>Clock skew";
break;
case eRouterErrorOffline:
s << "<br>Offline";
break;
default: ;
}
break;

View File

@ -125,7 +125,8 @@ namespace data
}
}
if (!m_IsRunning) break;
if (!i2p::transport::transports.IsOnline ()) continue; // don't manage netdb when offline
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
if (ts - lastManageRequest >= 15) // manage requests every 15 seconds
{

View File

@ -37,7 +37,8 @@ namespace i2p
enum RouterError
{
eRouterErrorNone = 0,
eRouterErrorClockSkew = 1
eRouterErrorClockSkew = 1,
eRouterErrorOffline = 2
};
class RouterContext: public i2p::garlic::GarlicDestination

View File

@ -321,7 +321,8 @@ namespace transport
void Transports::SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr<i2p::I2NPMessage> msg)
{
SendMessages (ident, std::vector<std::shared_ptr<i2p::I2NPMessage> > {msg });
if (m_IsOnline)
SendMessages (ident, std::vector<std::shared_ptr<i2p::I2NPMessage> > {msg });
}
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector<std::shared_ptr<i2p::I2NPMessage> >& msgs)
@ -756,5 +757,17 @@ namespace transport
}
return false;
}
void Transports::SetOnline (bool online)
{
if (m_IsOnline != online)
{
m_IsOnline = online;
if (online)
PeerTest ();
else
i2p::context.SetError (eRouterErrorOffline);
}
}
}
}

View File

@ -94,7 +94,7 @@ namespace transport
bool IsBoundNTCP2() const { return m_NTCP2Server != nullptr; }
bool IsOnline() const { return m_IsOnline; };
void SetOnline (bool online) { m_IsOnline = online; };
void SetOnline (bool online);
boost::asio::io_service& GetService () { return *m_Service; };
std::shared_ptr<i2p::crypto::DHKeys> GetNextDHKeysPair ();
@ -151,7 +151,8 @@ namespace transport
private:
bool m_IsOnline, m_IsRunning, m_IsNAT;
volatile bool m_IsOnline;
bool m_IsRunning, m_IsNAT;
std::thread * m_Thread;
boost::asio::io_service * m_Service;
boost::asio::io_service::work * m_Work;