diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp
index 19734038..d00387aa 100644
--- a/daemon/HTTPServer.cpp
+++ b/daemon/HTTPServer.cpp
@@ -259,6 +259,9 @@ namespace http {
case eRouterErrorClockSkew:
s << "
Clock skew";
break;
+ case eRouterErrorOffline:
+ s << "
Offline";
+ break;
default: ;
}
break;
diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp
index 4ce839ee..318db953 100644
--- a/libi2pd/NetDb.cpp
+++ b/libi2pd/NetDb.cpp
@@ -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
{
diff --git a/libi2pd/RouterContext.h b/libi2pd/RouterContext.h
index a576d6b6..37e1791d 100644
--- a/libi2pd/RouterContext.h
+++ b/libi2pd/RouterContext.h
@@ -37,7 +37,8 @@ namespace i2p
enum RouterError
{
eRouterErrorNone = 0,
- eRouterErrorClockSkew = 1
+ eRouterErrorClockSkew = 1,
+ eRouterErrorOffline = 2
};
class RouterContext: public i2p::garlic::GarlicDestination
diff --git a/libi2pd/Transports.cpp b/libi2pd/Transports.cpp
index 19e17f52..8a44bc3e 100644
--- a/libi2pd/Transports.cpp
+++ b/libi2pd/Transports.cpp
@@ -321,7 +321,8 @@ namespace transport
void Transports::SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr msg)
{
- SendMessages (ident, std::vector > {msg });
+ if (m_IsOnline)
+ SendMessages (ident, std::vector > {msg });
}
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector >& 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);
+ }
+ }
}
}
diff --git a/libi2pd/Transports.h b/libi2pd/Transports.h
index c3008b09..661337a2 100644
--- a/libi2pd/Transports.h
+++ b/libi2pd/Transports.h
@@ -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 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;