|
|
@ -111,6 +111,9 @@ namespace data |
|
|
|
case eI2NPDatabaseLookup: |
|
|
|
case eI2NPDatabaseLookup: |
|
|
|
HandleDatabaseLookupMsg (msg); |
|
|
|
HandleDatabaseLookupMsg (msg); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case eI2NPDeliveryStatus: |
|
|
|
|
|
|
|
HandleDeliveryStatusMsg (msg); |
|
|
|
|
|
|
|
break; |
|
|
|
case eI2NPDummyMsg: |
|
|
|
case eI2NPDummyMsg: |
|
|
|
// plain RouterInfo from NTCP2 with flags for now
|
|
|
|
// plain RouterInfo from NTCP2 with flags for now
|
|
|
|
HandleNTCP2RouterInfoMsg (msg); |
|
|
|
HandleNTCP2RouterInfoMsg (msg); |
|
|
@ -148,10 +151,12 @@ namespace data |
|
|
|
lastDestinationCleanup = ts; |
|
|
|
lastDestinationCleanup = ts; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ts - lastPublish >= NETDB_PUBLISH_INTERVAL) // update timestamp and publish
|
|
|
|
if (!m_HiddenMode && i2p::transport::transports.IsOnline () && |
|
|
|
|
|
|
|
((m_PublishReplyToken && ts - lastPublish >= NETDB_PUBLISH_CONFIRMATION_TIMEOUT) || |
|
|
|
|
|
|
|
ts - lastPublish >= NETDB_PUBLISH_INTERVAL)) // update timestamp and publish
|
|
|
|
{ |
|
|
|
{ |
|
|
|
i2p::context.UpdateTimestamp (ts); |
|
|
|
i2p::context.UpdateTimestamp (ts); |
|
|
|
if (!m_HiddenMode) Publish (); |
|
|
|
Publish (); |
|
|
|
lastPublish = ts; |
|
|
|
lastPublish = ts; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ts - lastExploratory >= 30) // exploratory every 30 seconds
|
|
|
|
if (ts - lastExploratory >= 30) // exploratory every 30 seconds
|
|
|
@ -992,6 +997,16 @@ namespace data |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NetDb::HandleDeliveryStatusMsg (std::shared_ptr<const I2NPMessage> msg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_PublishReplyToken == bufbe32toh (msg->GetPayload () + DELIVERY_STATUS_MSGID_OFFSET)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogInfo, "NetDb: Publishing confirmed. reply token=", m_PublishReplyToken); |
|
|
|
|
|
|
|
m_PublishExcluded.clear (); |
|
|
|
|
|
|
|
m_PublishReplyToken = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NetDb::Explore (int numDestinations) |
|
|
|
void NetDb::Explore (int numDestinations) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// new requests
|
|
|
|
// new requests
|
|
|
@ -1045,18 +1060,22 @@ namespace data |
|
|
|
void NetDb::Publish () |
|
|
|
void NetDb::Publish () |
|
|
|
{ |
|
|
|
{ |
|
|
|
i2p::context.UpdateStats (); // for floodfill
|
|
|
|
i2p::context.UpdateStats (); // for floodfill
|
|
|
|
std::set<IdentHash> excluded; // TODO: fill up later
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) |
|
|
|
if (m_PublishExcluded.size () > NETDB_MAX_PUBLISH_EXCLUDED_FLOODFILLS) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto floodfill = GetClosestFloodfill (i2p::context.GetRouterInfo ().GetIdentHash (), excluded); |
|
|
|
LogPrint (eLogError, "NetDb: Couldn't publish our RouterInfo to ", NETDB_MAX_PUBLISH_EXCLUDED_FLOODFILLS, " closest routers. Try again"); |
|
|
|
|
|
|
|
m_PublishExcluded.clear (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto floodfill = GetClosestFloodfill (i2p::context.GetIdentHash (), m_PublishExcluded); |
|
|
|
if (floodfill) |
|
|
|
if (floodfill) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint32_t replyToken; |
|
|
|
uint32_t replyToken; |
|
|
|
RAND_bytes ((uint8_t *)&replyToken, 4); |
|
|
|
RAND_bytes ((uint8_t *)&replyToken, 4); |
|
|
|
LogPrint (eLogInfo, "NetDb: Publishing our RouterInfo to ", i2p::data::GetIdentHashAbbreviation(floodfill->GetIdentHash ()), ". reply token=", replyToken); |
|
|
|
LogPrint (eLogInfo, "NetDb: Publishing our RouterInfo to ", i2p::data::GetIdentHashAbbreviation(floodfill->GetIdentHash ()), ". reply token=", replyToken); |
|
|
|
|
|
|
|
m_PublishExcluded.insert (floodfill->GetIdentHash ()); |
|
|
|
|
|
|
|
m_PublishReplyToken = replyToken; |
|
|
|
transports.SendMessage (floodfill->GetIdentHash (), CreateDatabaseStoreMsg (i2p::context.GetSharedRouterInfo (), replyToken)); |
|
|
|
transports.SendMessage (floodfill->GetIdentHash (), CreateDatabaseStoreMsg (i2p::context.GetSharedRouterInfo (), replyToken)); |
|
|
|
excluded.insert (floodfill->GetIdentHash ()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|