request RouterInfo connecting directly to a floodfill

This commit is contained in:
orignal 2014-01-26 15:24:21 -05:00
parent f763fd3268
commit ae51b11ced
2 changed files with 60 additions and 35 deletions

View File

@ -9,6 +9,7 @@
#include "Timestamp.h"
#include "I2NPProtocol.h"
#include "Tunnel.h"
#include "Transports.h"
#include "RouterContext.h"
#include "Garlic.h"
#include "NetDb.h"
@ -31,6 +32,16 @@ namespace data
return msg;
}
I2NPMessage * RequestedDestination::CreateRequestMessage (const IdentHash& floodfill)
{
I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination,
i2p::context.GetRouterInfo ().GetIdentHash () , 0, false, &m_ExcludedPeers);
m_ExcludedPeers.insert (floodfill);
m_LastRouter = nullptr;
m_LastReplyTunnel = nullptr;
return msg;
}
NetDb netdb;
NetDb::NetDb (): m_IsRunning (false), m_Thread (0)
@ -251,6 +262,8 @@ namespace data
}
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet)
{
if (isLeaseSet) // we request LeaseSet through tunnels
{
i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
if (outbound)
@ -263,14 +276,6 @@ namespace data
if (floodfill)
{
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
@ -291,6 +296,17 @@ namespace data
else
LogPrint ("No outbound tunnels found");
}
else // RouterInfo is requested directly
{
RequestedDestination * dest = CreateRequestedDestination (destination, false);
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
if (floodfill)
{
dest->SetLastOutboundTunnel (nullptr);
i2p::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
}
}
}
void NetDb::HandleDatabaseStoreMsg (uint8_t * buf, size_t len)
{
@ -403,10 +419,17 @@ namespace data
});
}
}
else // we should send directly
{
if (!dest->IsLeaseSet ()) // if not LeaseSet
i2p::transports.SendMessage (router, dest->CreateRequestMessage (router));
else
LogPrint ("Can't request LeaseSet");
}
}
}
if (msgs.size () > 0)
if (outbound && msgs.size () > 0)
outbound->SendTunnelDataMsg (msgs);
}
else

View File

@ -30,8 +30,10 @@ namespace data
const RouterInfo * GetLastRouter () const { return m_LastRouter; };
const i2p::tunnel::InboundTunnel * GetLastReplyTunnel () const { return m_LastReplyTunnel; };
bool IsExploratory () const { return m_IsExploratory; };
bool IsLeaseSet () const { return m_IsLeaseSet; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
I2NPMessage * CreateRequestMessage (const RouterInfo * router, const i2p::tunnel::InboundTunnel * replyTunnel);
I2NPMessage * CreateRequestMessage (const IdentHash& floodfill);
i2p::tunnel::OutboundTunnel * GetLastOutboundTunnel () const { return m_LastOutboundTunnel; };
void SetLastOutboundTunnel (i2p::tunnel::OutboundTunnel * tunnel) { m_LastOutboundTunnel = tunnel; };