Browse Source

some cleanup

pull/147/head
orignal 10 years ago
parent
commit
717940d969
  1. 79
      NetDb.cpp
  2. 2
      NetDb.h

79
NetDb.cpp

@ -29,7 +29,6 @@ namespace data
replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory, replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory,
&m_ExcludedPeers); &m_ExcludedPeers);
m_ExcludedPeers.insert (router->GetIdentHash ()); m_ExcludedPeers.insert (router->GetIdentHash ());
m_LastRouter = router;
m_CreationTime = i2p::util::GetSecondsSinceEpoch (); m_CreationTime = i2p::util::GetSecondsSinceEpoch ();
return msg; return msg;
} }
@ -39,7 +38,6 @@ namespace data
I2NPMessage * msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination, I2NPMessage * msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
i2p::context.GetRouterInfo ().GetIdentHash () , 0, false, &m_ExcludedPeers); i2p::context.GetRouterInfo ().GetIdentHash () , 0, false, &m_ExcludedPeers);
m_ExcludedPeers.insert (floodfill); m_ExcludedPeers.insert (floodfill);
m_LastRouter = nullptr;
m_CreationTime = i2p::util::GetSecondsSinceEpoch (); m_CreationTime = i2p::util::GetSecondsSinceEpoch ();
return msg; return msg;
} }
@ -508,51 +506,7 @@ namespace data
LogPrint (key, " was not found on 7 floodfills"); LogPrint (key, " was not found on 7 floodfills");
} }
} }
for (int i = 0; i < num; i++)
{
uint8_t * router = buf + 33 + i*32;
char peerHash[48];
int l1 = i2p::data::ByteStreamToBase64 (router, 32, peerHash, 48);
peerHash[l1] = 0;
LogPrint (i,": ", peerHash);
if (dest->IsExploratory ())
{
auto r = FindRouter (router);
if (!r || i2p::util::GetMillisecondsSinceEpoch () > r->GetTimestamp () + 3600*1000LL)
{
// router with ident not found or too old (1 hour)
LogPrint ("Found new/outdated router. Requesting RouterInfo ...");
if (outbound && inbound && dest->GetLastRouter ())
{
RequestedDestination * d1 = CreateRequestedDestination (router, false);
auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), inbound);
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeRouter,
dest->GetLastRouter ()->GetIdentHash (), 0, msg
});
}
else
RequestDestination (router);
}
else
LogPrint ("Bayan");
}
else
{
auto r = FindRouter (router);
// do we have that floodfill router in our database?
if (!r)
{
// request router
LogPrint ("Found new floodfill. Request it");
RequestDestination (router);
}
}
}
if (outbound && msgs.size () > 0) if (outbound && msgs.size () > 0)
outbound->SendTunnelDataMsg (msgs); outbound->SendTunnelDataMsg (msgs);
if (deleteDest) if (deleteDest)
@ -569,20 +523,29 @@ namespace data
m_RequestedDestinations.erase (it); m_RequestedDestinations.erase (it);
} }
} }
else else
{
LogPrint ("Requested destination for ", key, " not found"); LogPrint ("Requested destination for ", key, " not found");
// it might contain new routers
for (int i = 0; i < num; i++) // try responses
{ for (int i = 0; i < num; i++)
IdentHash router (buf + 33 + i*32); {
if (!FindRouter (router)) uint8_t * router = buf + 33 + i*32;
{ char peerHash[48];
LogPrint ("New router ", router.ToBase64 (), " found. Request it"); int l1 = i2p::data::ByteStreamToBase64 (router, 32, peerHash, 48);
RequestDestination (router); peerHash[l1] = 0;
} LogPrint (i,": ", peerHash);
}
auto r = FindRouter (router);
if (!r || i2p::util::GetMillisecondsSinceEpoch () > r->GetTimestamp () + 3600*1000LL)
{
// router with ident not found or too old (1 hour)
LogPrint ("Found new/outdated router. Requesting RouterInfo ...");
RequestDestination (router);
}
else
LogPrint ("Bayan");
} }
i2p::DeleteI2NPMessage (msg); i2p::DeleteI2NPMessage (msg);
} }

2
NetDb.h

@ -31,7 +31,6 @@ namespace data
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); }; int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; }; const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; };
void ClearExcludedPeers (); void ClearExcludedPeers ();
std::shared_ptr<const RouterInfo> GetLastRouter () const { return m_LastRouter; };
bool IsExploratory () const { return m_IsExploratory; }; bool IsExploratory () const { return m_IsExploratory; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); }; bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
uint64_t GetCreationTime () const { return m_CreationTime; }; uint64_t GetCreationTime () const { return m_CreationTime; };
@ -43,7 +42,6 @@ namespace data
IdentHash m_Destination; IdentHash m_Destination;
bool m_IsExploratory; bool m_IsExploratory;
std::set<IdentHash> m_ExcludedPeers; std::set<IdentHash> m_ExcludedPeers;
std::shared_ptr<const RouterInfo> m_LastRouter;
uint64_t m_CreationTime; uint64_t m_CreationTime;
}; };

Loading…
Cancel
Save