store tunnel pool with RoutingDestination

This commit is contained in:
orignal 2014-08-20 21:47:28 -04:00
parent 6c510fadf4
commit b671de27ce
2 changed files with 24 additions and 18 deletions

View file

@ -355,17 +355,17 @@ namespace data
LogPrint (deletedCount," routers deleted");
}
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet)
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet, i2p::tunnel::TunnelPool * pool)
{
if (isLeaseSet) // we request LeaseSet through tunnels
{
i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
i2p::tunnel::OutboundTunnel * outbound = pool ? pool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel ();
if (outbound)
{
i2p::tunnel::InboundTunnel * inbound = i2p::tunnel::tunnels.GetNextInboundTunnel ();
i2p::tunnel::InboundTunnel * inbound = pool ? pool->GetNextInboundTunnel () :i2p::tunnel::tunnels.GetNextInboundTunnel ();
if (inbound)
{
RequestedDestination * dest = CreateRequestedDestination (destination, isLeaseSet);
RequestedDestination * dest = CreateRequestedDestination (destination, isLeaseSet, pool);
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
// request 3 closests floodfills
for (int i = 0; i < 3; i++)
@ -398,7 +398,7 @@ namespace data
}
else // RouterInfo is requested directly
{
RequestedDestination * dest = CreateRequestedDestination (destination, false);
RequestedDestination * dest = CreateRequestedDestination (destination, false, pool);
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
if (floodfill)
i2p::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
@ -451,7 +451,9 @@ namespace data
bool deleteDest = true;
if (num > 0)
{
auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
auto exploratoryPool = dest ? dest->GetTunnelPool () : nullptr;
if (!exploratoryPool)
exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool ();
auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr;
auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr;
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
@ -473,7 +475,7 @@ namespace data
LogPrint ("Found new/outdated router. Requesting RouterInfo ...");
if (outbound && inbound && dest->GetLastRouter ())
{
RequestedDestination * d1 = CreateRequestedDestination (router, false, false);
RequestedDestination * d1 = CreateRequestedDestination (router, false, false, exploratoryPool);
auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), inbound);
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
@ -519,7 +521,7 @@ namespace data
{
// request router
LogPrint ("Found new floodfill. Request it");
RequestedDestination * d2 = CreateRequestedDestination (router, false, false);
RequestedDestination * d2 = CreateRequestedDestination (router, false, false, exploratoryPool);
I2NPMessage * msg = d2->CreateRequestMessage (dest->GetLastRouter (), inbound);
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
@ -689,7 +691,7 @@ namespace data
for (int i = 0; i < numDestinations; i++)
{
rnd.GenerateBlock (randomHash, 32);
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true);
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true, exploratoryPool);
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
if (floodfill && !floodfills.count (floodfill)) // request floodfill only once
{
@ -735,12 +737,12 @@ namespace data
}
RequestedDestination * NetDb::CreateRequestedDestination (const IdentHash& dest,
bool isLeaseSet, bool isExploratory)
bool isLeaseSet, bool isExploratory, i2p::tunnel::TunnelPool * pool)
{
auto it = m_RequestedDestinations.find (dest);
if (it == m_RequestedDestinations.end ()) // not exist yet
{
RequestedDestination * d = new RequestedDestination (dest, isLeaseSet, isExploratory);
RequestedDestination * d = new RequestedDestination (dest, isLeaseSet, isExploratory, pool);
m_RequestedDestinations[dest] = d;
return d;
}
@ -820,13 +822,13 @@ namespace data
return r;
}
void NetDb::Subscribe (const IdentHash& ident)
void NetDb::Subscribe (const IdentHash& ident, i2p::tunnel::TunnelPool * pool)
{
LeaseSet * leaseSet = FindLeaseSet (ident);
if (!leaseSet)
{
LogPrint ("LeaseSet requested");
RequestDestination (ident, true);
RequestDestination (ident, true, pool);
}
else
leaseSet->SetUnsolicited (false);