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. 130
      NetDb.cpp

6
HTTPServer.cpp

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

2
I2PTunnel.cpp

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

5
Identity.cpp

@ -307,13 +307,12 @@ namespace data @@ -307,13 +307,12 @@ namespace data
memcpy (buf, (const uint8_t *)ident, 32);
time_t t = time (nullptr);
struct tm tm;
// WARNING!!! check if it is correct
#ifdef _WIN32
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
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
IdentHash key;
CryptoPP::SHA256().CalculateDigest((uint8_t *)key, buf, 40);

130
NetDb.cpp

@ -376,26 +376,19 @@ namespace data @@ -376,26 +376,19 @@ namespace data
if (inbound)
{
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 ());
if (floodfill)
{
// DatabaseLookup message
msgs.push_back (i2p::tunnel::TunnelMessageBlock
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
if (floodfill)
{
// DatabaseLookup message
outbound->SendTunnelDataMsg (
{
i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeRouter,
floodfill->GetIdentHash (), 0,
dest->CreateRequestMessage (floodfill, inbound)
});
}
}
if (msgs.size () > 0)
{
dest->ClearExcludedPeers ();
outbound->SendTunnelDataMsg (msgs);
}
});
}
else
LogPrint ("No more floodfills found");
@ -468,6 +461,43 @@ namespace data @@ -468,6 +461,43 @@ namespace data
auto outbound = pool ? pool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel ();
auto inbound = pool ? pool->GetNextInboundTunnel () : i2p::tunnel::tunnels.GetNextInboundTunnel ();
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++)
{
@ -501,64 +531,14 @@ namespace data @@ -501,64 +531,14 @@ namespace data
LogPrint ("Bayan");
}
else
{
// reply to our destination. Try other floodfills
if (outbound && inbound && dest->GetLastRouter ())
{
auto r = FindRouter (router);
// do we have that floodfill router in our database?
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
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");
{
auto r = FindRouter (router);
// do we have that floodfill router in our database?
if (!r)
{
// request router
LogPrint ("Found new floodfill. Request it");
RequestDestination (router, false, pool);
}
}
}
@ -567,7 +547,7 @@ namespace data @@ -567,7 +547,7 @@ namespace data
outbound->SendTunnelDataMsg (msgs);
if (deleteDest)
{
// no more requests for tha destinationation. delete it
// no more requests for the destinationation. delete it
delete it->second;
m_RequestedDestinations.erase (it);
}

Loading…
Cancel
Save