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. 13
      libi2pd/Transports.cpp
  5. 5
      libi2pd/Transports.h

3
daemon/HTTPServer.cpp

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

1
libi2pd/NetDb.cpp

@ -125,6 +125,7 @@ namespace data @@ -125,6 +125,7 @@ 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

3
libi2pd/RouterContext.h

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

13
libi2pd/Transports.cpp

@ -321,6 +321,7 @@ namespace transport @@ -321,6 +321,7 @@ namespace transport
void Transports::SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr<i2p::I2NPMessage> msg)
{
if (m_IsOnline)
SendMessages (ident, std::vector<std::shared_ptr<i2p::I2NPMessage> > {msg });
}
@ -756,5 +757,17 @@ namespace transport @@ -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);
}
}
}
}

5
libi2pd/Transports.h

@ -94,7 +94,7 @@ namespace transport @@ -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 @@ -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;

Loading…
Cancel
Save