algorithm.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "algorithm.hpp"
27 
28 namespace nfd {
29 namespace scope_prefix {
30 const Name LOCALHOST("ndn:/localhost");
31 const Name LOCALHOP("ndn:/localhop");
32 } // namespace scope_prefix
33 
34 namespace fw {
35 
36 bool
37 wouldViolateScope(const Face& inFace, const Interest& interest, const Face& outFace)
38 {
39  if (outFace.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
40  // forwarding to a local face is always allowed
41  return false;
42  }
43 
44  if (scope_prefix::LOCALHOST.isPrefixOf(interest.getName())) {
45  // localhost Interests cannot be forwarded to a non-local face
46  return true;
47  }
48 
49  if (scope_prefix::LOCALHOP.isPrefixOf(interest.getName())) {
50  // localhop Interests can be forwarded to a non-local face only if it comes from a local face
51  return inFace.getScope() != ndn::nfd::FACE_SCOPE_LOCAL;
52  }
53 
54  // Interest name is not subject to scope control
55  return false;
56 }
57 
58 bool
59 canForwardToLegacy(const pit::Entry& pitEntry, const Face& face)
60 {
61  time::steady_clock::TimePoint now = time::steady_clock::now();
62 
63  bool hasUnexpiredOutRecord = std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
64  [&face, &now] (const pit::OutRecord& outRecord) {
65  return &outRecord.getFace() == &face && outRecord.getExpiry() >= now;
66  });
67  if (hasUnexpiredOutRecord) {
68  return false;
69  }
70 
71  bool hasUnexpiredOtherInRecord = std::any_of(pitEntry.in_begin(), pitEntry.in_end(),
72  [&face, &now] (const pit::InRecord& inRecord) {
73  return &inRecord.getFace() != &face && inRecord.getExpiry() >= now;
74  });
75  if (!hasUnexpiredOtherInRecord) {
76  return false;
77  }
78 
79  return true;
80 }
81 
82 int
83 findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face)
84 {
85  int dnw = DUPLICATE_NONCE_NONE;
86 
87  for (const pit::InRecord& inRecord : pitEntry.getInRecords()) {
88  if (inRecord.getLastNonce() == nonce) {
89  if (&inRecord.getFace() == &face) {
91  }
92  else {
94  }
95  }
96  }
97 
98  for (const pit::OutRecord& outRecord : pitEntry.getOutRecords()) {
99  if (outRecord.getLastNonce() == nonce) {
100  if (&outRecord.getFace() == &face) {
102  }
103  else {
105  }
106  }
107  }
108 
109  return dnw;
110 }
111 
112 bool
114 {
115  time::steady_clock::TimePoint now = time::steady_clock::now();
116  return std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
117  [&now] (const pit::OutRecord& outRecord) {
118  return outRecord.getExpiry() >= now &&
119  outRecord.getIncomingNack() == nullptr;
120  });
121 }
122 
123 } // namespace fw
124 } // namespace nfd
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
Definition: algorithm.cpp:59
const InRecordCollection & getInRecords() const
Definition: pit-entry.hpp:93
contains information about an Interest toward an outgoing face
an Interest table entry
Definition: pit-entry.hpp:57
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
contains information about an Interest from an incoming face
const Name LOCALHOP
ndn:/localhop
InRecordCollection::iterator in_end()
Definition: pit-entry.hpp:122
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
Definition: algorithm.cpp:113
const Name LOCALHOST
ndn:/localhost
no duplicate Nonce is found
int findDuplicateNonce(const pit::Entry &pitEntry, uint32_t nonce, const Face &face)
determine whether pitEntry has duplicate Nonce nonce
Definition: algorithm.cpp:83
OutRecordCollection::iterator out_begin()
Definition: pit-entry.hpp:177
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
OutRecordCollection::iterator out_end()
Definition: pit-entry.hpp:189
const OutRecordCollection & getOutRecords() const
Definition: pit-entry.hpp:159
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
Definition: algorithm.cpp:37
InRecordCollection::iterator in_begin()
Definition: pit-entry.hpp:110