Browse Source

store tunnel pool with RoutingDestination

pull/93/head
orignal 10 years ago
parent
commit
b671de27ce
  1. 28
      NetDb.cpp
  2. 14
      NetDb.h

28
NetDb.cpp

@ -355,17 +355,17 @@ namespace data @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);

14
NetDb.h

@ -24,15 +24,17 @@ namespace data @@ -24,15 +24,17 @@ namespace data
{
public:
RequestedDestination (const IdentHash& destination, bool isLeaseSet, bool isExploratory = false):
RequestedDestination (const IdentHash& destination, bool isLeaseSet,
bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr):
m_Destination (destination), m_IsLeaseSet (isLeaseSet), m_IsExploratory (isExploratory),
m_LastRouter (nullptr), m_CreationTime (0) {};
m_Pool (pool), m_LastRouter (nullptr), m_CreationTime (0) {};
const IdentHash& GetDestination () const { return m_Destination; };
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; };
void ClearExcludedPeers ();
const RouterInfo * GetLastRouter () const { return m_LastRouter; };
i2p::tunnel::TunnelPool * GetTunnelPool () { return m_Pool; };
bool IsExploratory () const { return m_IsExploratory; };
bool IsLeaseSet () const { return m_IsLeaseSet; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
@ -44,6 +46,7 @@ namespace data @@ -44,6 +46,7 @@ namespace data
IdentHash m_Destination;
bool m_IsLeaseSet, m_IsExploratory;
i2p::tunnel::TunnelPool * m_Pool;
std::set<IdentHash> m_ExcludedPeers;
const RouterInfo * m_LastRouter;
uint64_t m_CreationTime;
@ -65,10 +68,11 @@ namespace data @@ -65,10 +68,11 @@ namespace data
LeaseSet * FindLeaseSet (const IdentHash& destination) const;
const IdentHash * FindAddress (const std::string& address) { return m_AddressBook.FindAddress (address); }; // TODO: move AddressBook away from NetDb
void Subscribe (const IdentHash& ident); // keep LeaseSets upto date
void Subscribe (const IdentHash& ident, i2p::tunnel::TunnelPool * pool = nullptr); // keep LeaseSets upto date
void Unsubscribe (const IdentHash& ident);
void PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool);
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false);
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false,
i2p::tunnel::TunnelPool * pool = nullptr);
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
@ -97,7 +101,7 @@ namespace data @@ -97,7 +101,7 @@ namespace data
void ManageLeaseSets ();
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
bool isLeaseSet, bool isExploratory = false);
bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr);
bool DeleteRequestedDestination (const IdentHash& dest); // returns true if found
void DeleteRequestedDestination (RequestedDestination * dest);

Loading…
Cancel
Save