Browse Source

check network status

pull/1558/head
orignal 4 years ago
parent
commit
ffa0f0afd9
  1. 3
      daemon/HTTPServer.cpp
  2. 1
      libi2pd/NetDb.cpp
  3. 3
      libi2pd/RouterContext.h
  4. 15
      libi2pd/Transports.cpp
  5. 5
      libi2pd/Transports.h

3
daemon/HTTPServer.cpp

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

1
libi2pd/NetDb.cpp

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

3
libi2pd/RouterContext.h

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

15
libi2pd/Transports.cpp

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

5
libi2pd/Transports.h

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

Loading…
Cancel
Save