blob: ccba7374967798c0752c2c7e2f8eeb55de26ac68 [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,
48 const std::string& appName, KeyChain& keyChain, int freshness = -1);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080049 ~ContentServer();
50
51 // the assumption is, when the interest comes in, interest is informs of
52 // /some-prefix/topology-independent-name
53 // currently /topology-independent-name must begin with /action or /file
54 // so that ContentServer knows where to look for the content object
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080055 void
Lijing Wang6977ec42016-12-25 14:45:09 -080056 registerPrefix(const Name& prefix);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080057 void
Lijing Wang6977ec42016-12-25 14:45:09 -080058 deregisterPrefix(const Name& prefix);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080059
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080060private:
Alexander Afanasyev4d086752013-02-07 13:06:04 -080061 void
Lijing Wang6977ec42016-12-25 14:45:09 -080062 filterAndServe(const InterestFilter& forwardingHint, const Interest& interest);
Zhenkai Zhuc3a27872013-01-25 19:21:25 -080063
64 void
Lijing Wang6977ec42016-12-25 14:45:09 -080065 filterAndServeImpl(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080066
67 void
Lijing Wang6977ec42016-12-25 14:45:09 -080068 serve_Action(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080069
70 void
Lijing Wang6977ec42016-12-25 14:45:09 -080071 serve_File(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080072
73 void
Lijing Wang6977ec42016-12-25 14:45:09 -080074 serve_Action_Execute(const Name& forwardingHint, const Name& name, const Name& interest);
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080075
76 void
Lijing Wang6977ec42016-12-25 14:45:09 -080077 serve_File_Execute(const Name& forwardingHint, const Name& name, const Name& interest);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080078
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080079 void
80 flushStaleDbCache();
81
Zhenkai Zhue42b4572013-01-22 15:57:54 -080082private:
Lijing Wang6977ec42016-12-25 14:45:09 -080083 Face& m_face;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080084 ActionLogPtr m_actionLog;
85 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080086 typedef boost::unique_lock<Mutex> ScopedLock;
Lijing Wang6977ec42016-12-25 14:45:09 -080087
88 typedef std::map<Name, const RegisteredPrefixId*>::iterator FilterIdIt;
89 std::map<Name, const RegisteredPrefixId*> m_interestFilterIds;
90
Zhenkai Zhue42b4572013-01-22 15:57:54 -080091 Mutex m_mutex;
92 boost::filesystem::path m_dbFolder;
Zhenkai Zhu13d224d2013-01-23 19:40:25 -080093 int m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080094
Lijing Wang6977ec42016-12-25 14:45:09 -080095 Scheduler m_scheduler;
96 util::scheduler::ScopedEventId m_flushStateDbCacheEvent;
97 typedef std::map<Buffer, shared_ptr<ObjectDb>> DbCache;
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080098 DbCache m_dbCache;
99 Mutex m_dbCacheMutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -0800100
Lijing Wang6977ec42016-12-25 14:45:09 -0800101 Name m_userName;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -0800102 std::string m_sharedFolderName;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -0800103 std::string m_appName;
Lijing Wang6977ec42016-12-25 14:45:09 -0800104 KeyChain& m_keyChain;
Zhenkai Zhue42b4572013-01-22 15:57:54 -0800105};
Lijing Wang6977ec42016-12-25 14:45:09 -0800106
107} // namespace chronoshare
108} // namespace ndn
109
Zhenkai Zhue42b4572013-01-22 15:57:54 -0800110#endif // CONTENT_SERVER_H