mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
use kademlia to pick floodfill for destination
This commit is contained in:
parent
b409e525ba
commit
a65400471a
43
NetDb.cpp
43
NetDb.cpp
@ -239,16 +239,6 @@ namespace data
|
|||||||
|
|
||||||
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet)
|
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet)
|
||||||
{
|
{
|
||||||
auto floodfill= GetRandomNTCPRouter (true);
|
|
||||||
if (floodfill)
|
|
||||||
RequestDestination (destination, floodfill, isLeaseSet);
|
|
||||||
else
|
|
||||||
LogPrint ("No floodfill routers found");
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetDb::RequestDestination (const IdentHash& destination, const RouterInfo * floodfill, bool isLeaseSet)
|
|
||||||
{
|
|
||||||
if (!floodfill) return;
|
|
||||||
i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
|
i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
|
||||||
if (outbound)
|
if (outbound)
|
||||||
{
|
{
|
||||||
@ -256,9 +246,31 @@ namespace data
|
|||||||
if (inbound)
|
if (inbound)
|
||||||
{
|
{
|
||||||
RequestedDestination * dest = CreateRequestedDestination (destination, isLeaseSet);
|
RequestedDestination * dest = CreateRequestedDestination (destination, isLeaseSet);
|
||||||
dest->SetLastOutboundTunnel (outbound);
|
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
|
||||||
auto msg = dest->CreateRequestMessage (floodfill, inbound);
|
if (floodfill)
|
||||||
outbound->SendTunnelDataMsg (floodfill->GetIdentHash (), 0, msg);
|
{
|
||||||
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
||||||
|
// our RouterInfo
|
||||||
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||||
|
{
|
||||||
|
i2p::tunnel::eDeliveryTypeRouter,
|
||||||
|
floodfill->GetIdentHash (), 0,
|
||||||
|
CreateDatabaseStoreMsg ()
|
||||||
|
});
|
||||||
|
|
||||||
|
// DatabaseLookup message
|
||||||
|
dest->SetLastOutboundTunnel (outbound);
|
||||||
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||||
|
{
|
||||||
|
i2p::tunnel::eDeliveryTypeRouter,
|
||||||
|
floodfill->GetIdentHash (), 0,
|
||||||
|
dest->CreateRequestMessage (floodfill, inbound)
|
||||||
|
});
|
||||||
|
|
||||||
|
outbound->SendTunnelDataMsg (msgs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("No more floodfills found");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint ("No inbound tunnels found");
|
LogPrint ("No inbound tunnels found");
|
||||||
@ -487,7 +499,8 @@ namespace data
|
|||||||
if (msg) m_Queue.Put (msg);
|
if (msg) m_Queue.Put (msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const RouterInfo * NetDb::GetClosestFloodfill (const IdentHash& destination) const
|
const RouterInfo * NetDb::GetClosestFloodfill (const IdentHash& destination,
|
||||||
|
const std::set<IdentHash>& excluded) const
|
||||||
{
|
{
|
||||||
RouterInfo * r = nullptr;
|
RouterInfo * r = nullptr;
|
||||||
XORMetric minMetric;
|
XORMetric minMetric;
|
||||||
@ -495,7 +508,7 @@ namespace data
|
|||||||
minMetric.SetMax ();
|
minMetric.SetMax ();
|
||||||
for (auto it: m_RouterInfos)
|
for (auto it: m_RouterInfos)
|
||||||
{
|
{
|
||||||
if (it.second->IsFloodfill () &&! it.second->IsUnreachable ())
|
if (it.second->IsFloodfill () &&! it.second->IsUnreachable () && !excluded.count (it.first))
|
||||||
{
|
{
|
||||||
XORMetric m = destKey ^ it.second->GetRoutingKey ();
|
XORMetric m = destKey ^ it.second->GetRoutingKey ();
|
||||||
if (m < minMetric)
|
if (m < minMetric)
|
||||||
|
8
NetDb.h
8
NetDb.h
@ -26,7 +26,8 @@ namespace data
|
|||||||
|
|
||||||
const IdentHash& GetDestination () const { return m_Destination; };
|
const IdentHash& GetDestination () const { return m_Destination; };
|
||||||
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
|
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
|
||||||
const RouterInfo * GetLastRouter () const { return m_LastRouter; };
|
const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; };
|
||||||
|
const RouterInfo * GetLastRouter () const { return m_LastRouter; };
|
||||||
const i2p::tunnel::InboundTunnel * GetLastReplyTunnel () const { return m_LastReplyTunnel; };
|
const i2p::tunnel::InboundTunnel * GetLastReplyTunnel () const { return m_LastReplyTunnel; };
|
||||||
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); };
|
||||||
@ -62,8 +63,7 @@ namespace data
|
|||||||
|
|
||||||
void RequestDestination (const char * b32); // in base32
|
void RequestDestination (const char * b32); // in base32
|
||||||
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false);
|
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false);
|
||||||
void RequestDestination (const IdentHash& destination, const RouterInfo * floodfill, bool isLeaseSet = false);
|
|
||||||
|
|
||||||
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
|
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
|
||||||
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
|
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ namespace data
|
|||||||
void SaveUpdated (const char * directory);
|
void SaveUpdated (const char * directory);
|
||||||
void Run (); // exploratory thread
|
void Run (); // exploratory thread
|
||||||
void Explore ();
|
void Explore ();
|
||||||
const RouterInfo * GetClosestFloodfill (const IdentHash& destination) const;
|
const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||||||
|
|
||||||
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
|
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
|
||||||
bool isLeaseSet, bool isExploratory = false);
|
bool isLeaseSet, bool isExploratory = false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user