Browse Source

main netdb can request router info only

pull/120/head
orignal 10 years ago
parent
commit
bbe403fb40
  1. 2
      Destination.cpp
  2. 89
      NetDb.cpp
  3. 14
      NetDb.h
  4. 2
      SAM.cpp
  5. 2
      SOCKS.cpp
  6. 2
      api.cpp

2
Destination.cpp

@ -124,7 +124,7 @@ namespace client
else else
{ {
LogPrint ("All leases of remote LeaseSet expired. Request it"); LogPrint ("All leases of remote LeaseSet expired. Request it");
i2p::data::netdb.RequestDestination (ident, true, m_Pool); RequestDestination (ident);
} }
} }
else else

89
NetDb.cpp

@ -26,14 +26,7 @@ namespace data
{ {
I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination, I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination,
replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory, replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory,
&m_ExcludedPeers, m_IsLeaseSet, m_Pool); &m_ExcludedPeers, false, m_Pool);
if (m_IsLeaseSet) // wrap lookup message into garlic
{
if (m_Pool && m_Pool->GetLocalDestination ())
msg = m_Pool->GetLocalDestination ()->WrapMessage (*router, msg);
else
LogPrint ("Can't create garlic message without destination");
}
m_ExcludedPeers.insert (router->GetIdentHash ()); m_ExcludedPeers.insert (router->GetIdentHash ());
m_LastRouter = router; m_LastRouter = router;
m_CreationTime = i2p::util::GetSecondsSinceEpoch (); m_CreationTime = i2p::util::GetSecondsSinceEpoch ();
@ -62,7 +55,7 @@ namespace data
#endif #endif
NetDb netdb; NetDb netdb;
NetDb::NetDb (): m_IsRunning (false), m_Thread (0) NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr)
{ {
} }
@ -413,46 +406,17 @@ namespace data
} }
} }
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet, i2p::tunnel::TunnelPool * pool) void NetDb::RequestDestination (const IdentHash& destination, i2p::tunnel::TunnelPool * pool)
{ {
if (isLeaseSet) // we request LeaseSet through tunnels // request RouterInfo directly
{ RequestedDestination * dest = CreateRequestedDestination (destination, false, pool);
i2p::tunnel::OutboundTunnel * outbound = pool ? pool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel (); auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
if (outbound) if (floodfill)
{ transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
i2p::tunnel::InboundTunnel * inbound = pool ? pool->GetNextInboundTunnel () :i2p::tunnel::tunnels.GetNextInboundTunnel (); else
if (inbound)
{
RequestedDestination * dest = CreateRequestedDestination (destination, true, false, pool);
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)
}
});
}
else
LogPrint ("No more floodfills found");
}
else
LogPrint ("No inbound tunnels found");
}
else
LogPrint ("No outbound tunnels found");
}
else // RouterInfo is requested directly
{ {
RequestedDestination * dest = CreateRequestedDestination (destination, false, false, pool); LogPrint (eLogError, "No floodfills found");
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); DeleteRequestedDestination (dest);
if (floodfill)
transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
} }
} }
@ -519,17 +483,14 @@ namespace data
{ {
auto nextFloodfill = GetClosestFloodfill (dest->GetDestination (), dest->GetExcludedPeers ()); auto nextFloodfill = GetClosestFloodfill (dest->GetDestination (), dest->GetExcludedPeers ());
if (nextFloodfill) if (nextFloodfill)
{ {
if (!dest->IsLeaseSet ()) // tell floodfill about us
{ msgs.push_back (i2p::tunnel::TunnelMessageBlock
// tell floodfill about us {
msgs.push_back (i2p::tunnel::TunnelMessageBlock i2p::tunnel::eDeliveryTypeRouter,
{ nextFloodfill->GetIdentHash (), 0,
i2p::tunnel::eDeliveryTypeRouter, CreateDatabaseStoreMsg ()
nextFloodfill->GetIdentHash (), 0, });
CreateDatabaseStoreMsg ()
});
}
// request destination // request destination
LogPrint ("Try ", key, " at ", count, " floodfill ", nextFloodfill->GetIdentHash ().ToBase64 ()); LogPrint ("Try ", key, " at ", count, " floodfill ", nextFloodfill->GetIdentHash ().ToBase64 ());
@ -564,7 +525,7 @@ namespace data
LogPrint ("Found new/outdated router. Requesting RouterInfo ..."); LogPrint ("Found new/outdated router. Requesting RouterInfo ...");
if (outbound && inbound && dest->GetLastRouter ()) if (outbound && inbound && dest->GetLastRouter ())
{ {
RequestedDestination * d1 = CreateRequestedDestination (router, false, false, pool); RequestedDestination * d1 = CreateRequestedDestination (router, false, pool);
auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), inbound); auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), inbound);
msgs.push_back (i2p::tunnel::TunnelMessageBlock msgs.push_back (i2p::tunnel::TunnelMessageBlock
{ {
@ -573,7 +534,7 @@ namespace data
}); });
} }
else else
RequestDestination (router, false, pool); RequestDestination (router, pool);
} }
else else
LogPrint ("Bayan"); LogPrint ("Bayan");
@ -586,7 +547,7 @@ namespace data
{ {
// request router // request router
LogPrint ("Found new floodfill. Request it"); LogPrint ("Found new floodfill. Request it");
RequestDestination (router, false, pool); RequestDestination (router, pool);
} }
} }
} }
@ -728,7 +689,7 @@ namespace data
for (int i = 0; i < numDestinations; i++) for (int i = 0; i < numDestinations; i++)
{ {
rnd.GenerateBlock (randomHash, 32); rnd.GenerateBlock (randomHash, 32);
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true, exploratoryPool); RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), true, exploratoryPool);
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ()); auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
if (floodfill && !floodfills.count (floodfill.get ())) // request floodfill only once if (floodfill && !floodfills.count (floodfill.get ())) // request floodfill only once
{ {
@ -774,13 +735,13 @@ namespace data
} }
RequestedDestination * NetDb::CreateRequestedDestination (const IdentHash& dest, RequestedDestination * NetDb::CreateRequestedDestination (const IdentHash& dest,
bool isLeaseSet, bool isExploratory, i2p::tunnel::TunnelPool * pool) bool isExploratory, i2p::tunnel::TunnelPool * pool)
{ {
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex); std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
auto it = m_RequestedDestinations.find (dest); auto it = m_RequestedDestinations.find (dest);
if (it == m_RequestedDestinations.end ()) // not exist yet if (it == m_RequestedDestinations.end ()) // not exist yet
{ {
RequestedDestination * d = new RequestedDestination (dest, isLeaseSet, isExploratory, pool); RequestedDestination * d = new RequestedDestination (dest, isExploratory, pool);
m_RequestedDestinations[dest] = d; m_RequestedDestinations[dest] = d;
return d; return d;
} }

14
NetDb.h

@ -24,9 +24,9 @@ namespace data
{ {
public: public:
RequestedDestination (const IdentHash& destination, bool isLeaseSet, RequestedDestination (const IdentHash& destination, bool isExploratory = false,
bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr): i2p::tunnel::TunnelPool * pool = nullptr):
m_Destination (destination), m_IsLeaseSet (isLeaseSet), m_IsExploratory (isExploratory), m_Destination (destination), m_IsExploratory (isExploratory),
m_Pool (pool), m_CreationTime (0) {}; m_Pool (pool), m_CreationTime (0) {};
const IdentHash& GetDestination () const { return m_Destination; }; const IdentHash& GetDestination () const { return m_Destination; };
@ -36,7 +36,6 @@ namespace data
std::shared_ptr<const RouterInfo> GetLastRouter () const { return m_LastRouter; }; std::shared_ptr<const RouterInfo> GetLastRouter () const { return m_LastRouter; };
i2p::tunnel::TunnelPool * GetTunnelPool () { return m_Pool; }; i2p::tunnel::TunnelPool * GetTunnelPool () { return m_Pool; };
bool IsExploratory () const { return m_IsExploratory; }; bool IsExploratory () const { return m_IsExploratory; };
bool IsLeaseSet () const { return m_IsLeaseSet; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); }; bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
uint64_t GetCreationTime () const { return m_CreationTime; }; uint64_t GetCreationTime () const { return m_CreationTime; };
I2NPMessage * CreateRequestMessage (std::shared_ptr<const RouterInfo>, const i2p::tunnel::InboundTunnel * replyTunnel); I2NPMessage * CreateRequestMessage (std::shared_ptr<const RouterInfo>, const i2p::tunnel::InboundTunnel * replyTunnel);
@ -45,7 +44,7 @@ namespace data
private: private:
IdentHash m_Destination; IdentHash m_Destination;
bool m_IsLeaseSet, m_IsExploratory; bool m_IsExploratory;
i2p::tunnel::TunnelPool * m_Pool; i2p::tunnel::TunnelPool * m_Pool;
std::set<IdentHash> m_ExcludedPeers; std::set<IdentHash> m_ExcludedPeers;
std::shared_ptr<const RouterInfo> m_LastRouter; std::shared_ptr<const RouterInfo> m_LastRouter;
@ -68,8 +67,7 @@ namespace data
std::shared_ptr<RouterInfo> FindRouter (const IdentHash& ident) const; std::shared_ptr<RouterInfo> FindRouter (const IdentHash& ident) const;
LeaseSet * FindLeaseSet (const IdentHash& destination) const; LeaseSet * FindLeaseSet (const IdentHash& destination) const;
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false, void RequestDestination (const IdentHash& destination, i2p::tunnel::TunnelPool * pool = nullptr);
i2p::tunnel::TunnelPool * pool = nullptr);
void HandleDatabaseStoreMsg (I2NPMessage * msg); void HandleDatabaseStoreMsg (I2NPMessage * msg);
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg); void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
@ -100,7 +98,7 @@ namespace data
void ManageRequests (); void ManageRequests ();
RequestedDestination * CreateRequestedDestination (const IdentHash& dest, RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr); bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr);
bool DeleteRequestedDestination (const IdentHash& dest); // returns true if found bool DeleteRequestedDestination (const IdentHash& dest); // returns true if found
void DeleteRequestedDestination (RequestedDestination * dest); void DeleteRequestedDestination (RequestedDestination * dest);

2
SAM.cpp

@ -325,7 +325,7 @@ namespace client
Connect (*leaseSet); Connect (*leaseSet);
else else
{ {
i2p::data::netdb.RequestDestination (dest.GetIdentHash (), true, m_Session->localDestination->GetTunnelPool ()); m_Session->localDestination->RequestDestination (dest.GetIdentHash ());
m_Timer.expires_from_now (boost::posix_time::seconds(SAM_CONNECT_TIMEOUT)); m_Timer.expires_from_now (boost::posix_time::seconds(SAM_CONNECT_TIMEOUT));
m_Timer.async_wait (std::bind (&SAMSocket::HandleStreamDestinationRequestTimer, m_Timer.async_wait (std::bind (&SAMSocket::HandleStreamDestinationRequestTimer,
shared_from_this (), std::placeholders::_1, dest.GetIdentHash ())); shared_from_this (), std::placeholders::_1, dest.GetIdentHash ()));

2
SOCKS.cpp

@ -159,7 +159,7 @@ namespace proxy
LogPrint("--- sock4a find lease set"); LogPrint("--- sock4a find lease set");
m_ls = i2p::data::netdb.FindLeaseSet(m_dest); m_ls = i2p::data::netdb.FindLeaseSet(m_dest);
if (!m_ls || m_ls->HasNonExpiredLeases()) { if (!m_ls || m_ls->HasNonExpiredLeases()) {
i2p::data::netdb.RequestDestination (m_dest, true, i2p::client::context.GetSharedLocalDestination ()->GetTunnelPool ()); i2p::client::context.GetSharedLocalDestination ()->RequestDestination (m_dest);
m_ls_timer.expires_from_now(boost::posix_time::seconds(socks_leaseset_timeout)); m_ls_timer.expires_from_now(boost::posix_time::seconds(socks_leaseset_timeout));
m_ls_timer.async_wait(boost::bind(&SOCKS4AHandler::LeaseSetTimeout, this, boost::asio::placeholders::error)); m_ls_timer.async_wait(boost::bind(&SOCKS4AHandler::LeaseSetTimeout, this, boost::asio::placeholders::error));
} else { } else {

2
api.cpp

@ -76,7 +76,7 @@ namespace api
void RequestLeaseSet (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote) void RequestLeaseSet (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote)
{ {
if (dest) if (dest)
i2p::data::netdb.RequestDestination (remote, true, dest->GetTunnelPool ()); dest->RequestDestination (remote);
} }
std::shared_ptr<i2p::stream::Stream> CreateStream (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote) std::shared_ptr<i2p::stream::Stream> CreateStream (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote)

Loading…
Cancel
Save