try closest floodfills sequentially

This commit is contained in:
orignal 2014-10-14 20:52:40 -04:00
parent 8a12b71010
commit 9b2e275c45
4 changed files with 61 additions and 82 deletions

View File

@ -520,7 +520,7 @@ namespace util
m_Stream = nullptr; m_Stream = nullptr;
} }
m_Socket->close (); m_Socket->close ();
delete this; //delete this;
} }
void HTTPConnection::Receive () void HTTPConnection::Receive ()
@ -544,8 +544,8 @@ namespace util
m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred); m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred);
Receive (); Receive ();
} }
/*else if (ecode != boost::asio::error::operation_aborted) else if (ecode != boost::asio::error::operation_aborted)
Terminate ();*/ Terminate ();
} }
void HTTPConnection::RunRequest () void HTTPConnection::RunRequest ()

View File

@ -44,7 +44,7 @@ namespace stream
m_Socket->close (); m_Socket->close ();
if (m_Owner) if (m_Owner)
m_Owner->RemoveConnection (this); m_Owner->RemoveConnection (this);
delete this; //delete this;
} }
void I2PTunnelConnection::Receive () void I2PTunnelConnection::Receive ()

View File

@ -307,13 +307,12 @@ namespace data
memcpy (buf, (const uint8_t *)ident, 32); memcpy (buf, (const uint8_t *)ident, 32);
time_t t = time (nullptr); time_t t = time (nullptr);
struct tm tm; struct tm tm;
// WARNING!!! check if it is correct
#ifdef _WIN32 #ifdef _WIN32
gmtime_s(&tm, &t); gmtime_s(&tm, &t);
sprintf_s((char *)(buf + 32), 9, "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday); sprintf_s((char *)(buf + 32), 9, "%4i%2i%2i", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
#else #else
gmtime_r(&t, &tm); gmtime_r(&t, &tm);
sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday); sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
#endif #endif
IdentHash key; IdentHash key;
CryptoPP::SHA256().CalculateDigest((uint8_t *)key, buf, 40); CryptoPP::SHA256().CalculateDigest((uint8_t *)key, buf, 40);

124
NetDb.cpp
View File

@ -376,26 +376,19 @@ namespace data
if (inbound) if (inbound)
{ {
RequestedDestination * dest = CreateRequestedDestination (destination, true, false, pool); RequestedDestination * dest = CreateRequestedDestination (destination, true, false, pool);
std::vector<i2p::tunnel::TunnelMessageBlock> msgs; auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
// request 3 closests floodfills if (floodfill)
for (int i = 0; i < 3; i++)
{ {
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); // DatabaseLookup message
if (floodfill) outbound->SendTunnelDataMsg (
{ {
// DatabaseLookup message i2p::tunnel::TunnelMessageBlock
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{ {
i2p::tunnel::eDeliveryTypeRouter, i2p::tunnel::eDeliveryTypeRouter,
floodfill->GetIdentHash (), 0, floodfill->GetIdentHash (), 0,
dest->CreateRequestMessage (floodfill, inbound) dest->CreateRequestMessage (floodfill, inbound)
}); }
} });
}
if (msgs.size () > 0)
{
dest->ClearExcludedPeers ();
outbound->SendTunnelDataMsg (msgs);
} }
else else
LogPrint ("No more floodfills found"); LogPrint ("No more floodfills found");
@ -468,6 +461,43 @@ namespace data
auto outbound = pool ? pool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel (); auto outbound = pool ? pool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel ();
auto inbound = pool ? pool->GetNextInboundTunnel () : i2p::tunnel::tunnels.GetNextInboundTunnel (); auto inbound = pool ? pool->GetNextInboundTunnel () : i2p::tunnel::tunnels.GetNextInboundTunnel ();
std::vector<i2p::tunnel::TunnelMessageBlock> msgs; std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
if (!dest->IsExploratory ())
{
// reply to our destination. Try other floodfills
if (outbound && inbound )
{
auto count = dest->GetExcludedPeers ().size ();
if (count < 7)
{
auto nextFloodfill = GetClosestFloodfill (dest->GetDestination (), dest->GetExcludedPeers ());
if (nextFloodfill)
{
if (!dest->IsLeaseSet ())
{
// tell floodfill about us
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeRouter,
nextFloodfill->GetIdentHash (), 0,
CreateDatabaseStoreMsg ()
});
}
// request destination
LogPrint ("Try ", key, " at ", count, " floodfill ", nextFloodfill->GetIdentHash ().ToBase64 ());
auto msg = dest->CreateRequestMessage (nextFloodfill, inbound);
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeRouter,
nextFloodfill->GetIdentHash (), 0, msg
});
deleteDest = false;
}
}
else
LogPrint (key, " was not found on 7 floodfills");
}
}
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)
{ {
@ -502,63 +532,13 @@ namespace data
} }
else else
{ {
// reply to our destination. Try other floodfills auto r = FindRouter (router);
if (outbound && inbound && dest->GetLastRouter ()) // do we have that floodfill router in our database?
if (!r)
{ {
auto r = FindRouter (router); // request router
// do we have that floodfill router in our database? LogPrint ("Found new floodfill. Request it");
if (r) RequestDestination (router, false, pool);
{
// we do
if (!dest->IsExcluded (r->GetIdentHash ()) && dest->GetNumExcludedPeers () < 30) // TODO: fix TunnelGateway first
{
LogPrint ("Try ", key, " at floodfill ", peerHash);
if (!dest->IsLeaseSet ())
{
// tell floodfill about us
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeRouter,
r->GetIdentHash (), 0,
CreateDatabaseStoreMsg ()
});
}
// request destination
auto msg = dest->CreateRequestMessage (r, inbound);
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeRouter,
r->GetIdentHash (), 0, msg
});
deleteDest = false;
}
}
else
{
// request router
LogPrint ("Found new floodfill. Request it");
RequestedDestination * d2 = CreateRequestedDestination (router, false, false, pool);
I2NPMessage * msg = d2->CreateRequestMessage (dest->GetLastRouter (), inbound);
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeRouter,
dest->GetLastRouter ()->GetIdentHash (), 0, msg
});
}
}
else // we should send directly
{
if (!dest->IsLeaseSet ()) // if not LeaseSet
{
if (!dest->IsExcluded (router) && dest->GetNumExcludedPeers () < 30)
{
LogPrint ("Try ", key, " at floodfill ", peerHash, " directly");
i2p::transports.SendMessage (router, dest->CreateRequestMessage (router));
deleteDest = false;
}
}
else
LogPrint ("Can't request LeaseSet");
} }
} }
} }
@ -567,7 +547,7 @@ namespace data
outbound->SendTunnelDataMsg (msgs); outbound->SendTunnelDataMsg (msgs);
if (deleteDest) if (deleteDest)
{ {
// no more requests for tha destinationation. delete it // no more requests for the destinationation. delete it
delete it->second; delete it->second;
m_RequestedDestinations.erase (it); m_RequestedDestinations.erase (it);
} }