blob: 5d53ff17c518ba330f4bd59471a175f54380bd8f [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{
Alexander Afanasyevea963952018-06-17 22:41:43 +000037 auto face = std::make_shared<util::DummyClientFace>(m_io, m_keyChain,
38 util::DummyClientFace::Options{true, true});
39 std::weak_ptr<Face> weakFace(face);
40 face->onSendInterest.connect([this, weakFace] (const Interest& interest) {
41 if (auto face = weakFace.lock()) {
42 for (auto& otherFace : m_faces) {
43 if (&*face == &*otherFace) {
44 continue;
45 }
46 otherFace->receive(interest);
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040047 }
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040048 }
49 });
50
Alexander Afanasyevea963952018-06-17 22:41:43 +000051 face->onSendData.connect([this, weakFace] (const Data& data) {
52 if (auto face = weakFace.lock()) {
53 for (auto& otherFace : m_faces) {
54 if (&*face == &*otherFace) {
55 continue;
56 }
57 otherFace->receive(data);
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040058 }
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040059 }
60 });
61
Alexander Afanasyevea963952018-06-17 22:41:43 +000062 face->onSendNack.connect([this, weakFace] (const lp::Nack& nack) {
63 if (auto face = weakFace.lock()) {
64 for (auto& otherFace : m_faces) {
65 if (&*face == &*otherFace) {
66 continue;
67 }
68 otherFace->receive(nack);
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040069 }
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040070 }
71 });
72
73 m_faces.push_back(face);
74 return *face;
75}
76
77} // namespace tests
78} // namespace nac
79} // namespace ndn