blob: ff046e3cc09b79b7b497c10680c91fb23780713c [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 Afanasyevf4cde4e2016-12-25 13:42:57 -080024#include "ccnx-wrapper.hpp"
25#include "object-db.hpp"
26#include "action-log.hpp"
Zhenkai Zhue42b4572013-01-22 15:57:54 -080027#include <set>
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080028#include <map>
Zhenkai Zhue42b4572013-01-22 15:57:54 -080029#include <boost/thread/shared_mutex.hpp>
30#include <boost/thread/locks.hpp>
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080031#include "scheduler.hpp"
Zhenkai Zhue42b4572013-01-22 15:57:54 -080032
33class ContentServer
34{
35public:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070036 ContentServer(Ndnx::NdnxWrapperPtr ndnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir,
37 const Ndnx::Name &userName, const std::string &sharedFolderName, const std::string &appName,
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080038 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 Afanasyev1dd37ed2013-08-14 18:08:09 -070045 void registerPrefix(const Ndnx::Name &prefix);
46 void deregisterPrefix(const Ndnx::Name &prefix);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080047
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080048private:
Alexander Afanasyev4d086752013-02-07 13:06:04 -080049 void
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070050 filterAndServe (Ndnx::Name forwardingHint, const Ndnx::Name &interest);
Zhenkai Zhuc3a27872013-01-25 19:21:25 -080051
52 void
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070053 filterAndServeImpl (const Ndnx::Name &forwardingHint, const Ndnx::Name &name, const Ndnx::Name &interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080054
55 void
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070056 serve_Action (const Ndnx::Name &forwardingHint, const Ndnx::Name &name, const Ndnx::Name &interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080057
58 void
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070059 serve_File (const Ndnx::Name &forwardingHint, const Ndnx::Name &name, const Ndnx::Name &interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080060
61 void
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070062 serve_Action_Execute(const Ndnx::Name &forwardingHint, const Ndnx::Name &name, const Ndnx::Name &interest);
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080063
64 void
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070065 serve_File_Execute(const Ndnx::Name &forwardingHint, const Ndnx::Name &name, const Ndnx::Name &interest);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080066
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080067 void
68 flushStaleDbCache();
69
Zhenkai Zhue42b4572013-01-22 15:57:54 -080070private:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070071 Ndnx::NdnxWrapperPtr m_ndnx;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080072 ActionLogPtr m_actionLog;
73 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080074
75 typedef boost::unique_lock<Mutex> ScopedLock;
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070076 typedef std::set<Ndnx::Name>::iterator PrefixIt;
77 std::set<Ndnx::Name> m_prefixes;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080078 Mutex m_mutex;
79 boost::filesystem::path m_dbFolder;
Zhenkai Zhu13d224d2013-01-23 19:40:25 -080080 int m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080081
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080082 SchedulerPtr m_scheduler;
83 typedef std::map<Hash, ObjectDbPtr> DbCache;
84 DbCache m_dbCache;
85 Mutex m_dbCacheMutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080086
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070087 Ndnx::Name m_userName;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080088 std::string m_sharedFolderName;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080089 std::string m_appName;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080090};
91#endif // CONTENT_SERVER_H