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