blob: ff34fb2ea7f9dc7c5e337ee030a79514e1c7cec2 [file] [log] [blame]
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2018, Regents of the University of California
4 *
5 * NAC library is free software: you can redistribute it and/or modify it under the
6 * terms of the GNU Lesser General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later version.
8 *
9 * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12 *
13 * You should have received copies of the GNU General Public License and GNU Lesser
14 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * See AUTHORS.md for complete list of NAC library authors and contributors.
18 */
19
20#include "dummy-forwarder.hpp"
21
22#include <boost/asio/io_service.hpp>
23
24namespace ndn {
25namespace nac {
26namespace tests {
27
28DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain)
29 : m_io(io)
30 , m_keyChain(keyChain)
31{
32}
33
34Face&
35DummyForwarder::addFace()
36{
37 auto face = std::make_shared<util::DummyClientFace>(m_io, m_keyChain, util::
38 DummyClientFace::Options{true, true});
39 face->onSendInterest.connect([this, face] (const Interest& interest) {
40 for (auto& otherFace : m_faces) {
41 if (&*face == &*otherFace) {
42 continue;
43 }
44 otherFace->receive(interest);
45 }
46 });
47
48 face->onSendData.connect([this, face] (const Data& data) {
49 for (auto& otherFace : m_faces) {
50 if (&*face == &*otherFace) {
51 continue;
52 }
53 otherFace->receive(data);
54 }
55 });
56
57 face->onSendNack.connect([this, face] (const lp::Nack& nack) {
58 for (auto& otherFace : m_faces) {
59 if (&*face == &*otherFace) {
60 continue;
61 }
62 otherFace->receive(nack);
63 }
64 });
65
66 m_faces.push_back(face);
67 return *face;
68}
69
70} // namespace tests
71} // namespace nac
72} // namespace ndn