blob: 7af328fd83c16cffdbc2a03a071eacc398000079 [file] [log] [blame]
Steve DiBenedetto5b433982014-01-29 17:14:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "internal-face.hpp"
8
9namespace nfd {
10
Steve DiBenedetto3970c892014-01-31 23:31:13 -070011NFD_LOG_INIT("InternalFace");
12
13InternalFace::InternalFace()
Steve DiBenedetto5b433982014-01-29 17:14:27 -070014{
15
16}
17
18void
19InternalFace::sendInterest(const Interest& interest)
20{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070021 if (m_interestFilters.size() == 0)
22 {
23 NFD_LOG_DEBUG("no Interest filters to match against");
24 return;
25 }
26
Steve DiBenedetto3970c892014-01-31 23:31:13 -070027 const Name& interestName(interest.getName());
28 NFD_LOG_DEBUG("received Interest: " << interestName);
Steve DiBenedetto5b433982014-01-29 17:14:27 -070029
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070030 std::map<Name, OnInterest>::const_iterator filter =
31 m_interestFilters.lower_bound(interestName);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070032
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070033 // lower_bound gives us the first Name that is
34 // an exact match OR ordered after interestName.
35 //
36 // If we reach the end of the map, then we need
37 // only check if the before-end element is a match.
38 //
39 // If we match an element, then the current
40 // position or the previous element are potential
41 // matches.
42 //
43 // If we hit begin, the element is either an exact
44 // match or there is no matching prefix in the map.
45
46
Steve DiBenedettobdedce92014-02-02 22:49:39 -070047 if (filter == m_interestFilters.end() && filter != m_interestFilters.begin())
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070048 {
49 // We hit the end, check if the previous element
50 // is a match
51 --filter;
52 if (filter->first.isPrefixOf(interestName))
Steve DiBenedetto3970c892014-01-31 23:31:13 -070053 {
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070054 NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (before end match)");
Steve DiBenedetto3970c892014-01-31 23:31:13 -070055 filter->second(interestName, interest);
56 }
57 else
58 {
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070059 NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (before end)");
Steve DiBenedetto3970c892014-01-31 23:31:13 -070060 }
Steve DiBenedetto5b433982014-01-29 17:14:27 -070061 }
Steve DiBenedettobdedce92014-02-02 22:49:39 -070062 else if (filter->first == interestName)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070063 {
64 NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (exact match)");
65 filter->second(interestName, interest);
66 }
67 else if (filter != m_interestFilters.begin())
68 {
69 // the element we found is canonically
70 // ordered after interestName.
71 // Check the previous element.
72 --filter;
73 if (filter->first.isPrefixOf(interestName))
74 {
75 NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (previous match)");
76 filter->second(interestName, interest);
77 }
78 else
79 {
80 NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (previous)");
81 }
82 }
83 else
84 {
85 NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (begin)");
86 }
Steve DiBenedetto5b433982014-01-29 17:14:27 -070087 //Drop Interest
88}
89
90void
91InternalFace::sendData(const Data& data)
92{
93
94}
95
96void
97InternalFace::setInterestFilter(const Name& filter,
98 OnInterest onInterest)
99{
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700100 NFD_LOG_INFO("registering callback for " << filter);
101 m_interestFilters[filter] = onInterest;
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700102}
103
104void
105InternalFace::put(const Data& data)
106{
107 onReceiveData(data);
108}
109
110InternalFace::~InternalFace()
111{
112
113}
114
115} // namespace nfd