Browse Source

request RouterInfo connecting directly to a floodfill

pull/14/head
orignal 11 years ago
parent
commit
ae51b11ced
  1. 91
      NetDb.cpp
  2. 4
      NetDb.h

91
NetDb.cpp

@ -9,6 +9,7 @@
#include "Timestamp.h" #include "Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "Transports.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Garlic.h" #include "Garlic.h"
#include "NetDb.h" #include "NetDb.h"
@ -30,6 +31,16 @@ namespace data
m_LastReplyTunnel = replyTunnel; m_LastReplyTunnel = replyTunnel;
return msg; 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;
@ -252,44 +263,49 @@ namespace data
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet) void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet)
{ {
i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel (); if (isLeaseSet) // we request LeaseSet through tunnels
if (outbound) {
{ i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
i2p::tunnel::InboundTunnel * inbound = i2p::tunnel::tunnels.GetNextInboundTunnel (); if (outbound)
if (inbound)
{ {
RequestedDestination * dest = CreateRequestedDestination (destination, isLeaseSet); i2p::tunnel::InboundTunnel * inbound = i2p::tunnel::tunnels.GetNextInboundTunnel ();
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); if (inbound)
if (floodfill) {
{ RequestedDestination * dest = CreateRequestedDestination (destination, isLeaseSet);
std::vector<i2p::tunnel::TunnelMessageBlock> msgs; auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
// our RouterInfo if (floodfill)
msgs.push_back (i2p::tunnel::TunnelMessageBlock {
{ std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
i2p::tunnel::eDeliveryTypeRouter, // DatabaseLookup message
floodfill->GetIdentHash (), 0, dest->SetLastOutboundTunnel (outbound);
CreateDatabaseStoreMsg () msgs.push_back (i2p::tunnel::TunnelMessageBlock
}); {
i2p::tunnel::eDeliveryTypeRouter,
// DatabaseLookup message floodfill->GetIdentHash (), 0,
dest->SetLastOutboundTunnel (outbound); dest->CreateRequestMessage (floodfill, inbound)
msgs.push_back (i2p::tunnel::TunnelMessageBlock });
{
i2p::tunnel::eDeliveryTypeRouter,
floodfill->GetIdentHash (), 0,
dest->CreateRequestMessage (floodfill, inbound)
});
outbound->SendTunnelDataMsg (msgs); outbound->SendTunnelDataMsg (msgs);
}
else
LogPrint ("No more floodfills found");
} }
else else
LogPrint ("No more floodfills found"); LogPrint ("No inbound tunnels found");
} }
else else
LogPrint ("No inbound tunnels found"); LogPrint ("No outbound tunnels found");
} }
else else // RouterInfo is requested directly
LogPrint ("No outbound tunnels found"); {
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) void NetDb::HandleDatabaseStoreMsg (uint8_t * buf, size_t len)
@ -402,11 +418,18 @@ namespace data
dest->GetLastRouter ()->GetIdentHash (), 0, msg dest->GetLastRouter ()->GetIdentHash (), 0, msg
}); });
} }
}
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); outbound->SendTunnelDataMsg (msgs);
} }
else else

4
NetDb.h

@ -30,9 +30,11 @@ namespace data
const RouterInfo * GetLastRouter () const { return m_LastRouter; }; 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 IsLeaseSet () const { return m_IsLeaseSet; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); }; bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
I2NPMessage * CreateRequestMessage (const RouterInfo * router, const i2p::tunnel::InboundTunnel * replyTunnel); I2NPMessage * CreateRequestMessage (const RouterInfo * router, const i2p::tunnel::InboundTunnel * replyTunnel);
I2NPMessage * CreateRequestMessage (const IdentHash& floodfill);
i2p::tunnel::OutboundTunnel * GetLastOutboundTunnel () const { return m_LastOutboundTunnel; }; i2p::tunnel::OutboundTunnel * GetLastOutboundTunnel () const { return m_LastOutboundTunnel; };
void SetLastOutboundTunnel (i2p::tunnel::OutboundTunnel * tunnel) { m_LastOutboundTunnel = tunnel; }; void SetLastOutboundTunnel (i2p::tunnel::OutboundTunnel * tunnel) { m_LastOutboundTunnel = tunnel; };

Loading…
Cancel
Save