mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-18 23:36:39 +01:00
keep own RouterInfo in netdb
This commit is contained in:
parent
2c129b6d39
commit
41bfc7899d
4 changed files with 34 additions and 6 deletions
|
@ -262,6 +262,12 @@ namespace i2p
|
||||||
if (!router) // we send own RouterInfo
|
if (!router) // we send own RouterInfo
|
||||||
router = context.GetSharedRouterInfo ();
|
router = context.GetSharedRouterInfo ();
|
||||||
|
|
||||||
|
if (!router->GetBuffer ())
|
||||||
|
{
|
||||||
|
LogPrint (eLogError, "I2NP: Invalid RouterInfo buffer for DatabaseStore");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
auto m = NewI2NPShortMessage ();
|
auto m = NewI2NPShortMessage ();
|
||||||
uint8_t * payload = m->GetPayload ();
|
uint8_t * payload = m->GetPayload ();
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,18 @@ namespace data
|
||||||
else if (!GetRandomRouter (i2p::context.GetSharedRouterInfo (), false))
|
else if (!GetRandomRouter (i2p::context.GetSharedRouterInfo (), false))
|
||||||
Reseed (); // we don't have a router we can connect to. Trying to reseed
|
Reseed (); // we don't have a router we can connect to. Trying to reseed
|
||||||
|
|
||||||
|
auto it = m_RouterInfos.find (i2p::context.GetIdentHash ());
|
||||||
|
if (it != m_RouterInfos.end ())
|
||||||
|
{
|
||||||
|
// remove own router
|
||||||
|
m_RouterInfos.erase (it);
|
||||||
|
m_Floodfills.remove (it->second);
|
||||||
|
}
|
||||||
|
// insert own router
|
||||||
|
m_RouterInfos.emplace (i2p::context.GetIdentHash (), i2p::context.GetSharedRouterInfo ());
|
||||||
|
if (i2p::context.IsFloodfill ())
|
||||||
|
m_Floodfills.push_back (i2p::context.GetSharedRouterInfo ());
|
||||||
|
|
||||||
i2p::config::GetOption("persist.profiles", m_PersistProfiles);
|
i2p::config::GetOption("persist.profiles", m_PersistProfiles);
|
||||||
|
|
||||||
m_IsRunning = true;
|
m_IsRunning = true;
|
||||||
|
@ -162,10 +174,18 @@ namespace data
|
||||||
bool publish = false;
|
bool publish = false;
|
||||||
if (m_PublishReplyToken)
|
if (m_PublishReplyToken)
|
||||||
{
|
{
|
||||||
|
// next publishing attempt
|
||||||
if (ts - lastPublish >= NETDB_PUBLISH_CONFIRMATION_TIMEOUT) publish = true;
|
if (ts - lastPublish >= NETDB_PUBLISH_CONFIRMATION_TIMEOUT) publish = true;
|
||||||
}
|
}
|
||||||
else if (i2p::context.GetLastUpdateTime () > lastPublish ||
|
else if (i2p::context.GetLastUpdateTime () > lastPublish ||
|
||||||
ts - lastPublish >= NETDB_PUBLISH_INTERVAL) publish = true;
|
ts - lastPublish >= NETDB_PUBLISH_INTERVAL)
|
||||||
|
{
|
||||||
|
// new publish
|
||||||
|
m_PublishExcluded.clear ();
|
||||||
|
if (i2p::context.IsFloodfill ())
|
||||||
|
m_PublishExcluded.insert (i2p::context.GetIdentHash ()); // do publish to ourselves
|
||||||
|
publish = true;
|
||||||
|
}
|
||||||
if (publish) // update timestamp and publish
|
if (publish) // update timestamp and publish
|
||||||
{
|
{
|
||||||
i2p::context.UpdateTimestamp (ts);
|
i2p::context.UpdateTimestamp (ts);
|
||||||
|
@ -567,8 +587,10 @@ namespace data
|
||||||
expirationTimeout = i2p::context.IsFloodfill () ? NETDB_FLOODFILL_EXPIRATION_TIMEOUT*1000LL :
|
expirationTimeout = i2p::context.IsFloodfill () ? NETDB_FLOODFILL_EXPIRATION_TIMEOUT*1000LL :
|
||||||
NETDB_MIN_EXPIRATION_TIMEOUT*1000LL + (NETDB_MAX_EXPIRATION_TIMEOUT - NETDB_MIN_EXPIRATION_TIMEOUT)*1000LL*NETDB_MIN_ROUTERS/total;
|
NETDB_MIN_EXPIRATION_TIMEOUT*1000LL + (NETDB_MAX_EXPIRATION_TIMEOUT - NETDB_MIN_EXPIRATION_TIMEOUT)*1000LL*NETDB_MIN_ROUTERS/total;
|
||||||
|
|
||||||
|
auto own = i2p::context.GetSharedRouterInfo ();
|
||||||
for (auto& it: m_RouterInfos)
|
for (auto& it: m_RouterInfos)
|
||||||
{
|
{
|
||||||
|
if (it.second == own) continue; // skip own
|
||||||
std::string ident = it.second->GetIdentHashBase64();
|
std::string ident = it.second->GetIdentHashBase64();
|
||||||
std::string path = m_Storage.Path(ident);
|
std::string path = m_Storage.Path(ident);
|
||||||
if (it.second->IsUpdated ())
|
if (it.second->IsUpdated ())
|
||||||
|
|
|
@ -69,10 +69,10 @@ namespace garlic
|
||||||
|
|
||||||
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
||||||
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
|
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
|
||||||
std::shared_ptr<const i2p::data::RouterInfo> GetSharedRouterInfo () const
|
std::shared_ptr<i2p::data::RouterInfo> GetSharedRouterInfo ()
|
||||||
{
|
{
|
||||||
return std::shared_ptr<const i2p::data::RouterInfo> (&m_RouterInfo,
|
return std::shared_ptr<i2p::data::RouterInfo> (&m_RouterInfo,
|
||||||
[](const i2p::data::RouterInfo *) {});
|
[](i2p::data::RouterInfo *) {});
|
||||||
}
|
}
|
||||||
std::shared_ptr<i2p::garlic::GarlicDestination> GetSharedDestination ()
|
std::shared_ptr<i2p::garlic::GarlicDestination> GetSharedDestination ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -423,7 +423,7 @@ namespace tunnel
|
||||||
bool StandardSelectPeers(Path & peers, int numHops, bool inbound, SelectHopFunc nextHop)
|
bool StandardSelectPeers(Path & peers, int numHops, bool inbound, SelectHopFunc nextHop)
|
||||||
{
|
{
|
||||||
int start = 0;
|
int start = 0;
|
||||||
auto prevHop = i2p::context.GetSharedRouterInfo ();
|
std::shared_ptr<const i2p::data::RouterInfo> prevHop = i2p::context.GetSharedRouterInfo ();
|
||||||
if(i2p::transport::transports.RoutesRestricted())
|
if(i2p::transport::transports.RoutesRestricted())
|
||||||
{
|
{
|
||||||
/** if routes are restricted prepend trusted first hop */
|
/** if routes are restricted prepend trusted first hop */
|
||||||
|
|
Loading…
Add table
Reference in a new issue