blob: 809b2e91e6986bb97f9dead6e0bb883ad7ab00c2 [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Lijing Wang6977ec42016-12-25 14:45:09 -08003 * Copyright (c) 2013-2017, Regents of the University of California.
Zhenkai Zhue42b4572013-01-22 15:57:54 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Zhenkai Zhue42b4572013-01-22 15:57:54 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * 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.
Zhenkai Zhue42b4572013-01-22 15:57:54 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * 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.
Zhenkai Zhue42b4572013-01-22 15:57:54 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * 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.
Zhenkai Zhue42b4572013-01-22 15:57:54 -080019 */
20
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080021#ifndef CONTENT_SERVER_H
22#define CONTENT_SERVER_H
23
Lijing Wang6977ec42016-12-25 14:45:09 -080024#include "core/chronoshare-common.hpp"
25
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080026#include "action-log.hpp"
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080027#include "object-db.hpp"
Lijing Wang6977ec42016-12-25 14:45:09 -080028
29#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/security/key-chain.hpp>
31#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
32#include <ndn-cxx/util/scheduler.hpp>
33
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080034#include <map>
35#include <set>
Zhenkai Zhue42b4572013-01-22 15:57:54 -080036
Lijing Wang6977ec42016-12-25 14:45:09 -080037#include <boost/thread/locks.hpp>
38#include <boost/thread/shared_mutex.hpp>
39
40namespace ndn {
41namespace chronoshare {
42
Zhenkai Zhue42b4572013-01-22 15:57:54 -080043class ContentServer
44{
45public:
Lijing Wang6977ec42016-12-25 14:45:09 -080046 ContentServer(Face& face, ActionLogPtr actionLog, const boost::filesystem::path& rootDir,
47 const Name& userName, const std::string& sharedFolderName,
Lijing Wang8e56d082016-12-25 14:45:23 -080048 const name::Component& appName, KeyChain& keyChain,
49 time::milliseconds freshness = time::seconds(5));
Zhenkai Zhue42b4572013-01-22 15:57:54 -080050 ~ContentServer();
51
52 // the assumption is, when the interest comes in, interest is informs of
53 // /some-prefix/topology-independent-name
54 // currently /topology-independent-name must begin with /action or /file
55 // so that ContentServer knows where to look for the content object
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080056 void
Lijing Wang6977ec42016-12-25 14:45:09 -080057 registerPrefix(const Name& prefix);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080058 void
Lijing Wang6977ec42016-12-25 14:45:09 -080059 deregisterPrefix(const Name& prefix);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080060
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080061private:
Alexander Afanasyev4d086752013-02-07 13:06:04 -080062 void
Lijing Wang6977ec42016-12-25 14:45:09 -080063 filterAndServe(const InterestFilter& forwardingHint, const Interest& interest);
Zhenkai Zhuc3a27872013-01-25 19:21:25 -080064
65 void
Lijing Wang6977ec42016-12-25 14:45:09 -080066 filterAndServeImpl(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080067
68 void
Lijing Wang6977ec42016-12-25 14:45:09 -080069 serve_Action(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080070
71 void
Lijing Wang6977ec42016-12-25 14:45:09 -080072 serve_File(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080073
74 void
Lijing Wang6977ec42016-12-25 14:45:09 -080075 serve_Action_Execute(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080076
77 void
Lijing Wang6977ec42016-12-25 14:45:09 -080078 serve_File_Execute(const Name& forwardingHint, const Name& name, const Name& interest);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080079
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080080 void
81 flushStaleDbCache();
82
Zhenkai Zhue42b4572013-01-22 15:57:54 -080083private:
Lijing Wang6977ec42016-12-25 14:45:09 -080084 Face& m_face;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080085 ActionLogPtr m_actionLog;
86 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080087 typedef boost::unique_lock<Mutex> ScopedLock;
Lijing Wang6977ec42016-12-25 14:45:09 -080088
89 typedef std::map<Name, const RegisteredPrefixId*>::iterator FilterIdIt;
90 std::map<Name, const RegisteredPrefixId*> m_interestFilterIds;
91
Zhenkai Zhue42b4572013-01-22 15:57:54 -080092 Mutex m_mutex;
93 boost::filesystem::path m_dbFolder;
Lijing Wang8e56d082016-12-25 14:45:23 -080094 time::milliseconds m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080095
Lijing Wang6977ec42016-12-25 14:45:09 -080096 Scheduler m_scheduler;
97 util::scheduler::ScopedEventId m_flushStateDbCacheEvent;
98 typedef std::map<Buffer, shared_ptr<ObjectDb>> DbCache;
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080099 DbCache m_dbCache;
100 Mutex m_dbCacheMutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -0800101
Lijing Wang6977ec42016-12-25 14:45:09 -0800102 Name m_userName;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -0800103 std::string m_sharedFolderName;
Lijing Wang8e56d082016-12-25 14:45:23 -0800104 name::Component m_appName;
Lijing Wang6977ec42016-12-25 14:45:09 -0800105 KeyChain& m_keyChain;
Zhenkai Zhue42b4572013-01-22 15:57:54 -0800106};
Lijing Wang6977ec42016-12-25 14:45:09 -0800107
108} // namespace chronoshare
109} // namespace ndn
110
Zhenkai Zhue42b4572013-01-22 15:57:54 -0800111#endif // CONTENT_SERVER_H