| 602 | } |
| 603 | |
| 604 | void LeaseSetDestination::Publish () |
| 605 | { |
| 606 | auto leaseSet = GetLeaseSetMt (); |
| 607 | if (!leaseSet || !m_Pool) |
| 608 | { |
| 609 | LogPrint (eLogError, "Destination: Can't publish non-existing LeaseSet"); |
| 610 | return; |
| 611 | } |
| 612 | if (m_PublishReplyToken) |
| 613 | { |
| 614 | LogPrint (eLogDebug, "Destination: Publishing LeaseSet is pending"); |
| 615 | return; |
| 616 | } |
| 617 | auto ts = i2p::util::GetSecondsSinceEpoch (); |
| 618 | if (ts < m_LastSubmissionTime + PUBLISH_MIN_INTERVAL) |
| 619 | { |
| 620 | LogPrint (eLogDebug, "Destination: Publishing LeaseSet is too fast. Wait for ", PUBLISH_MIN_INTERVAL, " seconds"); |
| 621 | m_PublishDelayTimer.cancel (); |
| 622 | m_PublishDelayTimer.expires_after (std::chrono::seconds(PUBLISH_MIN_INTERVAL)); |
| 623 | m_PublishDelayTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishDelayTimer, |
| 624 | shared_from_this (), std::placeholders::_1)); |
| 625 | return; |
| 626 | } |
| 627 | auto floodfill = i2p::data::netdb.GetClosestFloodfill (leaseSet->GetStoreHash (), m_ExcludedFloodfills); |
| 628 | if (!floodfill) |
| 629 | { |
| 630 | LogPrint (eLogError, "Destination: Can't publish LeaseSet, no more floodfills found"); |
| 631 | m_ExcludedFloodfills.clear (); |
| 632 | return; |
| 633 | } |
| 634 | auto outbound = m_Pool->GetNextOutboundTunnel (nullptr, floodfill->GetCompatibleTransports (false)); |
| 635 | auto inbound = m_Pool->GetNextInboundTunnel (nullptr, floodfill->GetCompatibleTransports (true)); |
| 636 | if (!outbound || !inbound) |
| 637 | { |
| 638 | if (!m_Pool->GetInboundTunnels ().empty () && !m_Pool->GetOutboundTunnels ().empty ()) |
| 639 | { |
| 640 | LogPrint (eLogInfo, "Destination: No compatible tunnels with ", floodfill->GetIdentHash ().ToBase64 (), ". Trying another floodfill"); |
| 641 | m_ExcludedFloodfills.insert (floodfill->GetIdentHash ()); |
| 642 | floodfill = i2p::data::netdb.GetClosestFloodfill (leaseSet->GetStoreHash (), m_ExcludedFloodfills); |
| 643 | if (floodfill) |
| 644 | { |
| 645 | outbound = m_Pool->GetNextOutboundTunnel (nullptr, floodfill->GetCompatibleTransports (false)); |
| 646 | if (outbound) |
| 647 | { |
| 648 | inbound = m_Pool->GetNextInboundTunnel (nullptr, floodfill->GetCompatibleTransports (true)); |
| 649 | if (!inbound) |
| 650 | LogPrint (eLogError, "Destination: Can't publish LeaseSet. No inbound tunnels"); |
| 651 | } |
| 652 | else |
| 653 | LogPrint (eLogError, "Destination: Can't publish LeaseSet. No outbound tunnels"); |
| 654 | } |
| 655 | else |
| 656 | LogPrint (eLogError, "Destination: Can't publish LeaseSet, no more floodfills found"); |
| 657 | } |
| 658 | else |
| 659 | LogPrint (eLogDebug, "Destination: No tunnels in pool"); |
| 660 | |
| 661 | if (!floodfill || !outbound || !inbound) |
no test coverage detected