blob: c8676a1c6d10d9ad6bf3f6361143cf07792ee0b5 [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, 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
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080024#include "action-log.hpp"
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080025#include "ccnx-wrapper.hpp"
26#include "object-db.hpp"
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080027#include "scheduler.hpp"
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080028#include <boost/thread/locks.hpp>
29#include <boost/thread/shared_mutex.hpp>
30#include <map>
31#include <set>
Zhenkai Zhue42b4572013-01-22 15:57:54 -080032
33class ContentServer
34{
35public:
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080036 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 Zhue42b4572013-01-22 15:57:54 -080039 ~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 Afanasyeveda3b7a2016-12-25 11:26:40 -080045 void
46 registerPrefix(const Ccnx::Name& prefix);
47 void
48 deregisterPrefix(const Ccnx::Name& prefix);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080049
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080050private:
Alexander Afanasyev4d086752013-02-07 13:06:04 -080051 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080052 filterAndServe(Ccnx::Name forwardingHint, const Ccnx::Name& interest);
Zhenkai Zhuc3a27872013-01-25 19:21:25 -080053
54 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080055 filterAndServeImpl(const Ccnx::Name& forwardingHint, const Ccnx::Name& name,
56 const Ccnx::Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080057
58 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080059 serve_Action(const Ccnx::Name& forwardingHint, const Ccnx::Name& name, const Ccnx::Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080060
61 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080062 serve_File(const Ccnx::Name& forwardingHint, const Ccnx::Name& name, const Ccnx::Name& interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080063
64 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080065 serve_Action_Execute(const Ccnx::Name& forwardingHint, const Ccnx::Name& name,
66 const Ccnx::Name& interest);
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080067
68 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080069 serve_File_Execute(const Ccnx::Name& forwardingHint, const Ccnx::Name& name,
70 const Ccnx::Name& interest);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080071
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080072 void
73 flushStaleDbCache();
74
Zhenkai Zhue42b4572013-01-22 15:57:54 -080075private:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070076 Ndnx::NdnxWrapperPtr m_ndnx;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080077 ActionLogPtr m_actionLog;
78 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080079
80 typedef boost::unique_lock<Mutex> ScopedLock;
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070081 typedef std::set<Ndnx::Name>::iterator PrefixIt;
82 std::set<Ndnx::Name> m_prefixes;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080083 Mutex m_mutex;
84 boost::filesystem::path m_dbFolder;
Zhenkai Zhu13d224d2013-01-23 19:40:25 -080085 int m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080086
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080087 SchedulerPtr m_scheduler;
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080088 typedef std::map<Hash, ObjectDbPtr> DbCache;
89 DbCache m_dbCache;
90 Mutex m_dbCacheMutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080091
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080092 Ccnx::Name m_userName;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080093 std::string m_sharedFolderName;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080094 std::string m_appName;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080095};
96#endif // CONTENT_SERVER_H