blob: 229e0fb01c6bd243c733cb1e6775f69d787e84da [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
* See COPYING for copyright and distribution information.
*/
#include "common.hpp"
#include "interest.hpp"
#include "util/random.hpp"
using namespace std;
namespace ndn {
const uint32_t&
Interest::getNonce() const
{
if (m_nonce == 0)
m_nonce = random::generateWord32();
return m_nonce;
}
bool
Interest::matchesName(const Name &name) const
{
if (!m_name.isPrefixOf(name))
return false;
if (getMinSuffixComponents() >= 0 &&
// Add 1 for the implicit digest.
!(name.size() + 1 - m_name.size() >= getMinSuffixComponents()))
return false;
if (getMaxSuffixComponents() >= 0 &&
// Add 1 for the implicit digest.
!(name.size() + 1 - m_name.size() <= getMaxSuffixComponents()))
return false;
if (!getExclude().empty() && name.size() > m_name.size() &&
getExclude().isExcluded(name[m_name.size()]))
return false;
return true;
}
std::ostream &
operator << (std::ostream &os, const Interest &interest)
{
os << interest.getName();
char delim = '?';
if (interest.getMinSuffixComponents() >= 0) {
os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
delim = '&';
}
if (interest.getMaxSuffixComponents() >= 0) {
os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
delim = '&';
}
if (interest.getChildSelector() >= 0) {
os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
delim = '&';
}
if (interest.getMustBeFresh()) {
os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
delim = '&';
}
if (interest.getScope() >= 0) {
os << delim << "ndn.Scope=" << interest.getScope();
delim = '&';
}
if (interest.getInterestLifetime() >= time::milliseconds::zero()
&& interest.getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) {
os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime();
delim = '&';
}
if (interest.getNonce() > 0) {
os << delim << "ndn.Nonce=" << interest.getNonce();
delim = '&';
}
if (!interest.getExclude().empty()) {
os << delim << "ndn.Exclude=" << interest.getExclude();
delim = '&';
}
return os;
}
}