/**
 * If ProxyDestination is already stored in this object - returns it;
 * otherwise, returns nullptr.
 */
std::shared_ptr<ProxyDestination> ProxyDestinationMap::find(
    const AccessPoint& ap, std::chrono::milliseconds timeout) const {
  auto key = genProxyDestinationKey(ap, timeout);
  {
    std::lock_guard<std::mutex> lck(destinationsLock_);
    return find(key);
  }
}
std::shared_ptr<ProxyDestination>
ProxyDestinationMap::emplace(std::shared_ptr<AccessPoint> ap,
                             std::chrono::milliseconds timeout,
                             uint64_t qosClass,
                             uint64_t qosPath) {
  auto key = genProxyDestinationKey(*ap, timeout);
  auto destination = ProxyDestination::create(*proxy_, std::move(ap),
      timeout, qosClass, qosPath);
  {
    std::lock_guard<std::mutex> lck(destinationsLock_);
    auto destIt = destinations_.emplace(key, destination);
    destination->pdstnKey_ = destIt.first->first;
  }

  // Update shared area of ProxyDestinations with same key from different
  // threads. This shared area is represented with TkoTracker class.
  proxy_->router().tkoTrackerMap().updateTracker(
    *destination,
    proxy_->router().opts().failures_until_tko,
    proxy_->router().opts().maximum_soft_tkos);

  return destination;
}