blob: 6ee9990141edd0a2f92bacd818d322de9e4d9f4c [file] [log] [blame]
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2017, Regents of the University of California.
4 *
5 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
6 *
7 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
19 */
20
21#include "dummy-forwarder.hpp"
22
23#include <boost/asio/io_service.hpp>
24
25namespace ndn {
26namespace chronoshare {
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 face->onSendData.connect([this, face] (const Data& data) {
48 for (auto& otherFace : m_faces) {
49 if (&*face == &*otherFace) {
50 continue;
51 }
52 otherFace->receive(data);
53 }
54 });
55
56 face->onSendNack.connect([this, face] (const lp::Nack& nack) {
57 for (auto& otherFace : m_faces) {
58 if (&*face == &*otherFace) {
59 continue;
60 }
61 otherFace->receive(nack);
62 }
63 });
64
65 m_faces.push_back(face);
66 return *face;
67}
68
69} // namespace chronoshare
70} // namespace ndn