blob: a49ee1fd9a6dc170c69580aee6e3410dfe738108 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07005 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07006 */
7
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08008#include "common.hpp"
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080010#include "interest.hpp"
Alexander Afanasyeve9fdb802014-02-05 17:36:51 -080011#include "util/random.hpp"
Alexander Afanasyev840139f2013-12-28 15:02:50 -080012
Jeff Thompsonb7f95562013-07-03 18:36:42 -070013using namespace std;
14
15namespace ndn {
Alexander Afanasyev84681982014-01-03 13:26:09 -080016
Alexander Afanasyev85480842014-01-06 14:46:54 -080017const uint32_t&
Alexander Afanasyev840139f2013-12-28 15:02:50 -080018Interest::getNonce() const
19{
Alexander Afanasyevc348f832014-02-17 16:35:17 -080020 if (m_nonce == 0)
21 m_nonce = random::generateWord32();
Alexander Afanasyev840139f2013-12-28 15:02:50 -080022
Alexander Afanasyevc348f832014-02-17 16:35:17 -080023 return m_nonce;
Alexander Afanasyev840139f2013-12-28 15:02:50 -080024}
25
26
Alexander Afanasyev84681982014-01-03 13:26:09 -080027bool
28Interest::matchesName(const Name &name) const
Jeff Thompson25b4e612013-10-10 16:03:24 -070029{
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070030 if (name.size() < m_name.size())
31 return false;
32
Alexander Afanasyevc348f832014-02-17 16:35:17 -080033 if (!m_name.isPrefixOf(name))
Alexander Afanasyev84681982014-01-03 13:26:09 -080034 return false;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070035
Alexander Afanasyevc348f832014-02-17 16:35:17 -080036 if (getMinSuffixComponents() >= 0 &&
Alexander Afanasyev84681982014-01-03 13:26:09 -080037 // Add 1 for the implicit digest.
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070038 !(name.size() + 1 - m_name.size() >= static_cast<size_t>(getMinSuffixComponents())))
Alexander Afanasyev84681982014-01-03 13:26:09 -080039 return false;
40
Alexander Afanasyevc348f832014-02-17 16:35:17 -080041 if (getMaxSuffixComponents() >= 0 &&
Alexander Afanasyev84681982014-01-03 13:26:09 -080042 // Add 1 for the implicit digest.
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070043 !(name.size() + 1 - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents())))
Alexander Afanasyev84681982014-01-03 13:26:09 -080044 return false;
45
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070046 if (!getExclude().empty() &&
47 name.size() > m_name.size() &&
Alexander Afanasyevc348f832014-02-17 16:35:17 -080048 getExclude().isExcluded(name[m_name.size()]))
Alexander Afanasyev84681982014-01-03 13:26:09 -080049 return false;
50
51 return true;
Jeff Thompson25b4e612013-10-10 16:03:24 -070052}
53
Alexander Afanasyev84681982014-01-03 13:26:09 -080054std::ostream &
55operator << (std::ostream &os, const Interest &interest)
Jeff Thompsonfe556862013-07-09 13:52:55 -070056{
Alexander Afanasyev84681982014-01-03 13:26:09 -080057 os << interest.getName();
Jeff Thompsonfe556862013-07-09 13:52:55 -070058
Alexander Afanasyev84681982014-01-03 13:26:09 -080059 char delim = '?';
60
61 if (interest.getMinSuffixComponents() >= 0) {
62 os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
63 delim = '&';
Jeff Thompsonfe556862013-07-09 13:52:55 -070064 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080065 if (interest.getMaxSuffixComponents() >= 0) {
66 os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
67 delim = '&';
Jeff Thompson37527d62013-08-21 11:15:54 -070068 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080069 if (interest.getChildSelector() >= 0) {
70 os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
71 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080072 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080073 if (interest.getMustBeFresh()) {
74 os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
75 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080076 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080077 if (interest.getScope() >= 0) {
78 os << delim << "ndn.Scope=" << interest.getScope();
79 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080080 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070081 if (interest.getInterestLifetime() >= time::milliseconds::zero()
82 && interest.getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) {
Alexander Afanasyev84681982014-01-03 13:26:09 -080083 os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime();
84 delim = '&';
85 }
86
87 if (interest.getNonce() > 0) {
88 os << delim << "ndn.Nonce=" << interest.getNonce();
89 delim = '&';
90 }
91 if (!interest.getExclude().empty()) {
92 os << delim << "ndn.Exclude=" << interest.getExclude();
93 delim = '&';
94 }
95
96 return os;
Jeff Thompson13e280b2013-12-03 13:12:23 -080097}
98
Jeff Thompsonb7f95562013-07-03 18:36:42 -070099}