blob: 45a8cd630c9635f71e7548493fcce279bd982327 [file] [log] [blame]
Ashlesh Gawande08784d42017-09-06 23:40:21 -05001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Nick Gordon0b3beab2018-03-02 13:03:28 -06003 * Copyright (c) 2012-2018 University of California, Los Angeles
Ashlesh Gawande08784d42017-09-06 23:40:21 -05004 *
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});
Nick Gordon0b3beab2018-03-02 13:03:28 -060038 util::DummyClientFace* self = &*face; // to prevent memory leak
39 face->onSendInterest.connect([this, self] (const Interest& interest) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050040 Interest i(interest);
41 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060042 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050043 continue;
44 }
45 m_io.post([=] { otherFace->receive(i); });
46 }
47 });
Nick Gordon0b3beab2018-03-02 13:03:28 -060048 face->onSendData.connect([this, self] (const Data& data) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050049 Data d(data);
50 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060051 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050052 continue;
53 }
54 m_io.post([=] { otherFace->receive(d); });
55 }
56 });
57
Nick Gordon0b3beab2018-03-02 13:03:28 -060058 face->onSendNack.connect([this, self] (const lp::Nack& nack) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050059 lp::Nack n(nack);
60 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060061 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050062 continue;
63 }
64 m_io.post([=] { otherFace->receive(n); });
65 }
66 });
67
68 m_faces.push_back(face);
69 return *face;
70}
71
Nick Gordon0b3beab2018-03-02 13:03:28 -060072void
73DummyForwarder::removeFaces()
74{
75 m_faces.clear();
76}
77
Ashlesh Gawande08784d42017-09-06 23:40:21 -050078} // namespace chronosync
79} // namespace ndn