Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 1 | /* -*- 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 | |
| 24 | namespace ndn { |
| 25 | namespace nac { |
| 26 | namespace tests { |
| 27 | |
| 28 | DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain) |
| 29 | : m_io(io) |
| 30 | , m_keyChain(keyChain) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | Face& |
| 35 | DummyForwarder::addFace() |
| 36 | { |
Alexander Afanasyev | ea96395 | 2018-06-17 22:41:43 +0000 | [diff] [blame] | 37 | 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 Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 47 | } |
Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 48 | } |
| 49 | }); |
| 50 | |
Alexander Afanasyev | ea96395 | 2018-06-17 22:41:43 +0000 | [diff] [blame] | 51 | 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 Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 58 | } |
Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 59 | } |
| 60 | }); |
| 61 | |
Alexander Afanasyev | ea96395 | 2018-06-17 22:41:43 +0000 | [diff] [blame] | 62 | 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 Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 69 | } |
Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 70 | } |
| 71 | }); |
| 72 | |
| 73 | m_faces.push_back(face); |
| 74 | return *face; |
| 75 | } |
| 76 | |
| 77 | } // namespace tests |
| 78 | } // namespace nac |
| 79 | } // namespace ndn |