Browse Source

try closest floodfills sequentially

pull/102/head
orignal 10 years ago
parent
commit
9b2e275c45
  1. 6
      HTTPServer.cpp
  2. 2
      I2PTunnel.cpp
  3. 5
      Identity.cpp
  4. 108
      NetDb.cpp

6
HTTPServer.cpp

@ -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 ()

2
I2PTunnel.cpp

@ -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 ()

5
Identity.cpp

@ -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);

108
NetDb.cpp

@ -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;
// request 3 closests floodfills
for (int i = 0; i < 3; i++)
{
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
if (floodfill) if (floodfill)
{ {
// DatabaseLookup message // DatabaseLookup message
msgs.push_back (i2p::tunnel::TunnelMessageBlock outbound->SendTunnelDataMsg (
{
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++)
{ {
@ -501,64 +531,14 @@ namespace data
LogPrint ("Bayan"); LogPrint ("Bayan");
} }
else else
{
// reply to our destination. Try other floodfills
if (outbound && inbound && dest->GetLastRouter ())
{ {
auto r = FindRouter (router); auto r = FindRouter (router);
// do we have that floodfill router in our database? // do we have that floodfill router in our database?
if (r) if (!r)
{
// 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 // request router
LogPrint ("Found new floodfill. Request it"); LogPrint ("Found new floodfill. Request it");
RequestedDestination * d2 = CreateRequestedDestination (router, false, false, pool); RequestDestination (router, 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);
} }

Loading…
Cancel
Save