示例#1
0
文件: cs.cpp 项目: eric135/NFD
void
Cs::find(const Interest& interest,
         const HitCallback& hitCallback,
         const MissCallback& missCallback) const
{
  BOOST_ASSERT(static_cast<bool>(hitCallback));
  BOOST_ASSERT(static_cast<bool>(missCallback));

  const Name& prefix = interest.getName();
  bool isRightmost = interest.getChildSelector() == 1;
  NFD_LOG_DEBUG("find " << prefix << (isRightmost ? " R" : " L"));

  iterator first = m_table.lower_bound(prefix);
  iterator last = m_table.end();
  if (prefix.size() > 0) {
    last = m_table.lower_bound(prefix.getSuccessor());
  }

  iterator match = last;
  if (isRightmost) {
    match = this->findRightmost(interest, first, last);
  }
  else {
    match = this->findLeftmost(interest, first, last);
  }

  if (match == last) {
    NFD_LOG_DEBUG("  no-match");
    missCallback(interest);
    return;
  }
  NFD_LOG_DEBUG("  matching " << match->getName());
  m_policy->beforeUse(match);
  hitCallback(interest, match->getData());
}
示例#2
0
static vector<string>
dumpInterest(const Interest& interest)
{
  vector<string> result;

  result.push_back(dump("name:", interest.getName().toUri()));
  result.push_back(dump("minSuffixComponents:",
    interest.getMinSuffixComponents() >= 0 ?
      toString(interest.getMinSuffixComponents()) : "<none>"));
  result.push_back(dump("maxSuffixComponents:",
    interest.getMaxSuffixComponents() >= 0 ?
      toString(interest.getMaxSuffixComponents()) : "<none>"));
  if ((int)interest.getKeyLocator().getType() >= 0) {
    if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEY_LOCATOR_DIGEST)
      result.push_back(dump("keyLocator: KeyLocatorDigest:",
        interest.getKeyLocator().getKeyData().toHex()));
    else if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME)
      result.push_back(dump("keyLocator: KeyName:",
        interest.getKeyLocator().getKeyName().toUri()));
    else
      result.push_back(dump("keyLocator: <unrecognized KeyLocatorType"));
  }
  else
    result.push_back(dump("keyLocator: <none>"));
  result.push_back(dump("exclude:",
    interest.getExclude().size() > 0 ? interest.getExclude().toUri() :
      "<none>"));
  result.push_back(dump("childSelector:",
    interest.getChildSelector() >= 0 ? toString(interest.getChildSelector()) :
      "<none>"));
  result.push_back(dump("mustBeFresh:",
    interest.getMustBeFresh() ? "True" : "False"));
  result.push_back(dump("nonce:",
    interest.getNonce().size() == 0 ? "<none>" :
      interest.getNonce().toHex()));
  result.push_back(dump("lifetimeMilliseconds:",
    interest.getInterestLifetimeMilliseconds() < 0 ? "<none>" :
      toString(interest.getInterestLifetimeMilliseconds())));

  return result;
};
static void dumpInterest(const Interest& interest)
{
  cout << "name: " << interest.getName().toUri() << endl;
  cout << "minSuffixComponents: ";
  if (interest.getMinSuffixComponents() >= 0)
    cout << interest.getMinSuffixComponents() << endl;
  else
    cout << "<none>" << endl;
  cout << "maxSuffixComponents: ";
  if (interest.getMaxSuffixComponents() >= 0)
    cout << interest.getMaxSuffixComponents() << endl;
  else
    cout << "<none>" << endl;
  cout << "keyLocator: ";
  if ((int)interest.getKeyLocator().getType() >= 0) {
    if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEY_LOCATOR_DIGEST)
      cout << "KeyLocatorDigest: " << interest.getKeyLocator().getKeyData().toHex() << endl;
    else if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME)
      cout << "KeyName: " << interest.getKeyLocator().getKeyName().toUri() << endl;
    else
      cout << "<unrecognized ndn_KeyLocatorType " << interest.getKeyLocator().getType() << ">" << endl;
  }
  else
    cout << "<none>" << endl;

  cout << "exclude: "
       << (interest.getExclude().size() > 0 ? interest.getExclude().toUri() : "<none>") << endl;
  cout << "lifetimeMilliseconds: ";
  if (interest.getInterestLifetimeMilliseconds() >= 0)
    cout << interest.getInterestLifetimeMilliseconds() << endl;
  else
    cout << "<none>" << endl;
  cout << "childSelector: ";
  if (interest.getChildSelector() >= 0)
    cout << interest.getChildSelector() << endl;
  else
    cout << "<none>" << endl;
  cout << "mustBeFresh: " << (interest.getMustBeFresh() ? "true" : "false") << endl;
  cout << "nonce: "
       << (interest.getNonce().size() > 0 ? interest.getNonce().toHex() : "<none>") << endl;
}
示例#4
0
std::pair<int64_t,Name>
Index::selectChild(const Interest& interest,
                   IndexContainer::const_iterator startingPoint) const
{
  BOOST_ASSERT(startingPoint != m_indexContainer.end());
  bool isLeftmost = (interest.getChildSelector() <= 0);
  ndn::ConstBufferPtr hash;
  if (!interest.getPublisherPublicKeyLocator().empty())
    {
      KeyLocator keyLocator = interest.getPublisherPublicKeyLocator();
      const Block& block = keyLocator.wireEncode();
      hash = ndn::crypto::sha256(block.wire(), block.size());
    }

  if (isLeftmost)
    {
      for (IndexContainer::const_iterator it = startingPoint;
           it != m_indexContainer.end(); ++it)
        {
          if (!interest.getName().isPrefixOf(it->getName()))
            return std::make_pair(0, Name());
          if (matchesSimpleSelectors(interest, hash, (*it)))
            return std::make_pair(it->getId(), it->getName());
        }
    }
  else
    {
      IndexContainer::const_iterator boundary = m_indexContainer.lower_bound(interest.getName());
      if (boundary == m_indexContainer.end() || !interest.getName().isPrefixOf(boundary->getName()))
        return std::make_pair(0, Name());
      Name successor = interest.getName().getSuccessor();
      IndexContainer::const_iterator last = interest.getName().size() == 0 ?
                    m_indexContainer.end() : m_indexContainer.lower_bound(interest.getName().getSuccessor());
      while (true)
        {
          IndexContainer::const_iterator prev = last;
            if (prev != boundary) {
                --prev;
            }
          if (prev == boundary)
            {
              bool isMatch = matchesSimpleSelectors(interest, hash, (*prev));
              if (isMatch)
                {
                  return std::make_pair(prev->getId(), prev->getName());
                }
              else
                return std::make_pair(0, Name());
            }
          IndexContainer::const_iterator first =
            m_indexContainer.lower_bound(prev->getName().getPrefix(interest.getName().size() + 1));
          IndexContainer::const_iterator match =
                     std::find_if(first, last, bind(&matchesSimpleSelectors, interest, hash, _1));
          if (match != last)
            {
              return std::make_pair(match->getId(), match->getName());
            }
          last = first;
        }
    }
  return std::make_pair(0, Name());
}