Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, Regents of the University of California. |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 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. |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 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. |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 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. |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 21 | #ifndef CONTENT_SERVER_H |
| 22 | #define CONTENT_SERVER_H |
| 23 | |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 24 | #include "core/chronoshare-common.hpp" |
| 25 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 26 | #include "action-log.hpp" |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 27 | #include "object-db.hpp" |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 28 | |
| 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 Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 34 | #include <map> |
| 35 | #include <set> |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 36 | |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 37 | #include <boost/thread/locks.hpp> |
| 38 | #include <boost/thread/shared_mutex.hpp> |
| 39 | |
| 40 | namespace ndn { |
| 41 | namespace chronoshare { |
| 42 | |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 43 | class ContentServer |
| 44 | { |
| 45 | public: |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 46 | ContentServer(Face& face, ActionLogPtr actionLog, const boost::filesystem::path& rootDir, |
| 47 | const Name& userName, const std::string& sharedFolderName, |
Lijing Wang | 8e56d08 | 2016-12-25 14:45:23 -0800 | [diff] [blame] | 48 | const name::Component& appName, KeyChain& keyChain, |
| 49 | time::milliseconds freshness = time::seconds(5)); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 50 | ~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 Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 56 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 57 | registerPrefix(const Name& prefix); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 58 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 59 | deregisterPrefix(const Name& prefix); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 61 | private: |
Alexander Afanasyev | 4d08675 | 2013-02-07 13:06:04 -0800 | [diff] [blame] | 62 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 63 | filterAndServe(const InterestFilter& forwardingHint, const Interest& interest); |
Zhenkai Zhu | c3a2787 | 2013-01-25 19:21:25 -0800 | [diff] [blame] | 64 | |
| 65 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 66 | filterAndServeImpl(const Name& forwardingHint, const Name& name, const Name& interest); |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 67 | |
| 68 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 69 | serve_Action(const Name& forwardingHint, const Name& name, const Name& interest); |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 70 | |
| 71 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 72 | serve_File(const Name& forwardingHint, const Name& name, const Name& interest); |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 73 | |
| 74 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 75 | serve_Action_Execute(const Name& forwardingHint, const Name& name, const Name& interest); |
Alexander Afanasyev | 3cca13f | 2013-02-07 16:06:46 -0800 | [diff] [blame] | 76 | |
| 77 | void |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 78 | serve_File_Execute(const Name& forwardingHint, const Name& name, const Name& interest); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 79 | |
Zhenkai Zhu | 92bb695 | 2013-02-06 16:43:30 -0800 | [diff] [blame] | 80 | void |
| 81 | flushStaleDbCache(); |
| 82 | |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 83 | private: |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 84 | Face& m_face; |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 85 | ActionLogPtr m_actionLog; |
| 86 | typedef boost::shared_mutex Mutex; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 87 | typedef boost::unique_lock<Mutex> ScopedLock; |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 88 | |
| 89 | typedef std::map<Name, const RegisteredPrefixId*>::iterator FilterIdIt; |
| 90 | std::map<Name, const RegisteredPrefixId*> m_interestFilterIds; |
| 91 | |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 92 | Mutex m_mutex; |
| 93 | boost::filesystem::path m_dbFolder; |
Lijing Wang | 8e56d08 | 2016-12-25 14:45:23 -0800 | [diff] [blame] | 94 | time::milliseconds m_freshness; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 95 | |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 96 | Scheduler m_scheduler; |
| 97 | util::scheduler::ScopedEventId m_flushStateDbCacheEvent; |
| 98 | typedef std::map<Buffer, shared_ptr<ObjectDb>> DbCache; |
Zhenkai Zhu | 92bb695 | 2013-02-06 16:43:30 -0800 | [diff] [blame] | 99 | DbCache m_dbCache; |
| 100 | Mutex m_dbCacheMutex; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 101 | |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 102 | Name m_userName; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 103 | std::string m_sharedFolderName; |
Lijing Wang | 8e56d08 | 2016-12-25 14:45:23 -0800 | [diff] [blame] | 104 | name::Component m_appName; |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 105 | KeyChain& m_keyChain; |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 106 | }; |
Lijing Wang | 6977ec4 | 2016-12-25 14:45:09 -0800 | [diff] [blame] | 107 | |
| 108 | } // namespace chronoshare |
| 109 | } // namespace ndn |
| 110 | |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 111 | #endif // CONTENT_SERVER_H |