Skip to content
/ i2pd Public
forked from PurpleI2P/i2pd

Commit

Permalink
better exploratory
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Dec 25, 2013
1 parent 5d9f292 commit ca51567
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 12 additions & 8 deletions NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ namespace data
if (num > 0)
{
bool isExploratory = !memcmp (m_Exploratory, buf, 32) && m_LastFloodfill;
i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
i2p::tunnel::InboundTunnel * inbound = i2p::tunnel::tunnels.GetNextInboundTunnel ();
i2p::tunnel::OutboundTunnel * outbound = isExploratory ? m_LastOutboundTunnel : i2p::tunnel::tunnels.GetNextOutboundTunnel ();
i2p::tunnel::InboundTunnel * inbound = isExploratory ? m_LastInboundTunnel : i2p::tunnel::tunnels.GetNextInboundTunnel ();

for (int i = 0; i < num; i++)
{
Expand Down Expand Up @@ -327,19 +327,23 @@ namespace data

void NetDb::Explore ()
{
i2p::tunnel::OutboundTunnel * outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
i2p::tunnel::InboundTunnel * inbound = i2p::tunnel::tunnels.GetNextInboundTunnel ();
if (outbound && inbound)
m_LastOutboundTunnel = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
m_LastInboundTunnel = i2p::tunnel::tunnels.GetNextInboundTunnel ();
if (m_LastOutboundTunnel && m_LastInboundTunnel)
{
m_LastFloodfill = GetRandomNTCPRouter (true);
if (m_LastFloodfill)
{
LogPrint ("Exploring new routers ...");
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
rnd.GenerateBlock (m_Exploratory, 32);
I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Exploratory, inbound->GetNextIdentHash (),
inbound->GetNextTunnelID (), true);
outbound->SendTunnelDataMsg (m_LastFloodfill->GetIdentHash (), 0, msg);

m_LastOutboundTunnel->GetTunnelGateway ().PutTunnelDataMsg (m_LastFloodfill->GetIdentHash (), 0,
CreateDatabaseStoreMsg ()); // tell floodfill about us
m_LastOutboundTunnel->GetTunnelGateway ().PutTunnelDataMsg (m_LastFloodfill->GetIdentHash (), 0,
i2p::CreateDatabaseLookupMsg (m_Exploratory, m_LastInboundTunnel->GetNextIdentHash (),
m_LastInboundTunnel->GetNextTunnelID (), true)); // explore
m_LastOutboundTunnel->GetTunnelGateway ().SendBuffer ();
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions NetDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "I2NPProtocol.h"
#include "RouterInfo.h"
#include "LeaseSet.h"
#include "Tunnel.h"

namespace i2p
{
Expand Down Expand Up @@ -57,6 +58,8 @@ namespace data
std::thread * m_Thread;
uint8_t m_Exploratory[32];
const RouterInfo * m_LastFloodfill;
i2p::tunnel::OutboundTunnel * m_LastOutboundTunnel;
i2p::tunnel::InboundTunnel * m_LastInboundTunnel;
i2p::util::Queue<I2NPMessage> m_Queue; // of I2NPDatabaseStoreMsg
};

Expand Down

0 comments on commit ca51567

Please sign in to comment.