示例#1
0
void NetDbRequests::ManageRequests() {
  uint64_t ts = i2p::util::GetSecondsSinceEpoch();
  std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
  for (auto it = m_RequestedDestinations.begin();
      it != m_RequestedDestinations.end();) {
    auto& dest = it->second;
    bool done = false;
    // request is worthless after 1 minute
    if (ts < dest->GetCreationTime() + 60) {
      // no response for 5 seconds
      if (ts > dest->GetCreationTime() + 5)  {
        auto count = dest->GetExcludedPeers().size();
        std::size_t attempts(7);
        if (!dest->IsExploratory() && count < attempts) {
          auto pool = i2p::tunnel::tunnels.GetExploratoryPool();
          auto outbound = pool->GetNextOutboundTunnel();
          auto inbound = pool->GetNextInboundTunnel();
          auto nextFloodfill = netdb.GetClosestFloodfill(
              dest->GetDestination(),
              dest->GetExcludedPeers());
          if (nextFloodfill && outbound && inbound) {
            outbound->SendTunnelDataMsg(
                nextFloodfill->GetIdentHash(),
                0,
                dest->CreateRequestMessage(
                  nextFloodfill,
                  inbound));
          } else {
            done = true;
            if (!inbound)
              LogPrint(eLogWarn, "NetDbRequests: no inbound tunnels");
            if (!outbound)
              LogPrint(eLogWarn, "NetDbRequests: no outbound tunnels");
            if (!nextFloodfill)
              LogPrint(eLogWarn, "NetDbRequests: no more floodfills");
          }
        } else {
          if (!dest->IsExploratory())
            LogPrint(eLogWarn,
                "NetDbRequests: ", dest->GetDestination().ToBase64(),
                " not found after ", attempts, " attempts");
          done = true;
        }
      }
    } else {  // delete obsolete request
      done = true;
    }
    if (done)
      it = m_RequestedDestinations.erase(it);
    else
      it++;
  }
}
示例#2
0
void TunnelPool::RecreateOutboundTunnel(
    std::shared_ptr<OutboundTunnel> tunnel) {
  auto inboundTunnel = GetNextInboundTunnel();
  if (!inboundTunnel)
    inboundTunnel = tunnels.GetNextInboundTunnel();
  if (inboundTunnel) {
    LogPrint("Re-creating destination outbound tunnel...");
    auto newTunnel = tunnels.CreateTunnel<OutboundTunnel> (
      tunnel->GetTunnelConfig()->Clone(
        inboundTunnel->GetTunnelConfig()));
    newTunnel->SetTunnelPool(shared_from_this());
  } else {
    LogPrint("Can't re-create outbound tunnel. No inbound tunnels found");
  }
}
示例#3
0
	void TunnelPool::RecreateOutboundTunnel (std::shared_ptr<OutboundTunnel> tunnel)
	{
		auto inboundTunnel = GetNextInboundTunnel ();
		if (!inboundTunnel)
			inboundTunnel = tunnels.GetNextInboundTunnel ();
		if (inboundTunnel)
		{	
			LogPrint (eLogDebug, "Tunnels: Re-creating destination outbound tunnel...");
			auto newTunnel = tunnels.CreateTunnel<OutboundTunnel> (
				std::make_shared<TunnelConfig> (tunnel->GetPeers (),
					inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()));
			newTunnel->SetTunnelPool (shared_from_this ());
		}	
		else
			LogPrint (eLogDebug, "Tunnels: Can't re-create outbound tunnel, no inbound tunnels found");
	}		
示例#4
0
	void TunnelPool::CreateOutboundTunnel ()
	{
		auto inboundTunnel = GetNextInboundTunnel ();
		if (!inboundTunnel)
			inboundTunnel = tunnels.GetNextInboundTunnel ();
		if (inboundTunnel)
		{	
			LogPrint (eLogDebug, "Tunnels: Creating destination outbound tunnel...");
			std::vector<std::shared_ptr<const i2p::data::IdentityEx> > peers;
			if (SelectPeers (peers, false))
			{	
				auto tunnel = tunnels.CreateTunnel<OutboundTunnel> (
					std::make_shared<TunnelConfig> (peers, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()));
				tunnel->SetTunnelPool (shared_from_this ());
			}	
			else
				LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no peers available");
		}	
		else
			LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no inbound tunnels found");
	}	
示例#5
0
void TunnelPool::CreateOutboundTunnel() {
  auto inboundTunnel = GetNextInboundTunnel();
  if (!inboundTunnel)
    inboundTunnel = tunnels.GetNextInboundTunnel();
  if (inboundTunnel) {
    LogPrint("Creating destination outbound tunnel...");
    std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops;
    if (SelectPeers(hops, false)) {
      auto tunnel = tunnels.CreateTunnel<OutboundTunnel> (
        std::make_shared<TunnelConfig> (
          hops,
          inboundTunnel->GetTunnelConfig()));
      tunnel->SetTunnelPool(shared_from_this());
    } else {
      LogPrint(eLogError,
          "Can't create outbound tunnel. No peers available");
    }
  } else {
    LogPrint(eLogError,
        "Can't create outbound tunnel. No inbound tunnels found");
  }
}