Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, 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 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 24 | #include "action-log.hpp" |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 25 | #include "ccnx-wrapper.hpp" |
| 26 | #include "object-db.hpp" |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 27 | #include "scheduler.hpp" |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 28 | #include <boost/thread/locks.hpp> |
| 29 | #include <boost/thread/shared_mutex.hpp> |
| 30 | #include <map> |
| 31 | #include <set> |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 32 | |
| 33 | class ContentServer |
| 34 | { |
| 35 | public: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 36 | ContentServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, |
| 37 | const boost::filesystem::path& rootDir, const Ccnx::Name& userName, |
| 38 | const std::string& sharedFolderName, const std::string& appName, int freshness = -1); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 39 | ~ContentServer(); |
| 40 | |
| 41 | // the assumption is, when the interest comes in, interest is informs of |
| 42 | // /some-prefix/topology-independent-name |
| 43 | // currently /topology-independent-name must begin with /action or /file |
| 44 | // so that ContentServer knows where to look for the content object |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 45 | void |
| 46 | registerPrefix(const Ccnx::Name& prefix); |
| 47 | void |
| 48 | deregisterPrefix(const Ccnx::Name& prefix); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 50 | private: |
Alexander Afanasyev | 4d08675 | 2013-02-07 13:06:04 -0800 | [diff] [blame] | 51 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 52 | filterAndServe(Ccnx::Name forwardingHint, const Ccnx::Name& interest); |
Zhenkai Zhu | c3a2787 | 2013-01-25 19:21:25 -0800 | [diff] [blame] | 53 | |
| 54 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 55 | filterAndServeImpl(const Ccnx::Name& forwardingHint, const Ccnx::Name& name, |
| 56 | const Ccnx::Name& interest); |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 57 | |
| 58 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 59 | serve_Action(const Ccnx::Name& forwardingHint, const Ccnx::Name& name, const Ccnx::Name& interest); |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 60 | |
| 61 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 62 | serve_File(const Ccnx::Name& forwardingHint, const Ccnx::Name& name, const Ccnx::Name& interest); |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 63 | |
| 64 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 65 | serve_Action_Execute(const Ccnx::Name& forwardingHint, const Ccnx::Name& name, |
| 66 | const Ccnx::Name& interest); |
Alexander Afanasyev | 3cca13f | 2013-02-07 16:06:46 -0800 | [diff] [blame] | 67 | |
| 68 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 69 | serve_File_Execute(const Ccnx::Name& forwardingHint, const Ccnx::Name& name, |
| 70 | const Ccnx::Name& interest); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 71 | |
Zhenkai Zhu | 92bb695 | 2013-02-06 16:43:30 -0800 | [diff] [blame] | 72 | void |
| 73 | flushStaleDbCache(); |
| 74 | |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 75 | private: |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 76 | Ndnx::NdnxWrapperPtr m_ndnx; |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 77 | ActionLogPtr m_actionLog; |
| 78 | typedef boost::shared_mutex Mutex; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 79 | |
| 80 | typedef boost::unique_lock<Mutex> ScopedLock; |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 81 | typedef std::set<Ndnx::Name>::iterator PrefixIt; |
| 82 | std::set<Ndnx::Name> m_prefixes; |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 83 | Mutex m_mutex; |
| 84 | boost::filesystem::path m_dbFolder; |
Zhenkai Zhu | 13d224d | 2013-01-23 19:40:25 -0800 | [diff] [blame] | 85 | int m_freshness; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 87 | SchedulerPtr m_scheduler; |
Zhenkai Zhu | 92bb695 | 2013-02-06 16:43:30 -0800 | [diff] [blame] | 88 | typedef std::map<Hash, ObjectDbPtr> DbCache; |
| 89 | DbCache m_dbCache; |
| 90 | Mutex m_dbCacheMutex; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 92 | Ccnx::Name m_userName; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 93 | std::string m_sharedFolderName; |
Alexander Afanasyev | 1d1cc83 | 2013-02-05 20:03:36 -0800 | [diff] [blame] | 94 | std::string m_appName; |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 95 | }; |
| 96 | #endif // CONTENT_SERVER_H |