blob: 21cbcbb04114a2fda63671235edcd7a37479445b [file] [log] [blame]
Zhenkai Zhu0f054122012-12-25 22:22:50 -08001#ifndef CCNX_TUNNEL_H
2#define CCNX_TUNNEL_H
3
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -08004#include <ccnx-wrapper.h>
Zhenkai Zhu0f054122012-12-25 22:22:50 -08005#include <string>
6#include <boost/function.hpp>
7#include <boost/variant.hpp>
8#include <boost/thread/locks.hpp>
9#include <utility>
10#include <map>
11
12using namespace Sync;
13using namespace std;
14
15// Eventually, Sync::CcnxWrapper should be moved to this namespace.
16// It has nothing to do with Sync.
17namespace Ccnx
18{
19
20class CcnxTunnel : public CcnxWrapper
21{
22public:
23 typedef boost::variant<StringDataCallback, RawDataCallback> DataCallback;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080024 typedef multimap<string, InterestCallback> RegisteredInterestTable;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080025 typedef multimap<string, InterestCallback>iterator RitIter;
26 typedef boost::shared_mutex Lock;
27 typedef boost::unique_lock<Lock> WriteLock;
28 typedef boost::shared_lock<Lock> ReadLock;
29
30
31 CcnxTunnel();
32 virtual ~CcnxTunnel();
33
34 // name is topology-independent
35 virtual int
36 publishRawData(const string &name, const char *buf, size_t len, int freshness);
37
38 // prefix is topology-independent
39 virtual int
40 setInterestFilter(const string &prefix, const InterestCallback &interestCallback);
41
42 // prefix is topology-independent
43 // this clears all entries with key equal to prefix
44 virtual void
45 clearInterestFilter(const string &prefix);
46
47 // subclass should provide translation service from topology-independent name
48 // to routable name
49 virtual string
50 queryRoutableName(string &name) = 0;
51
52 // subclass should implement the function to store ContentObject with topoloy-independent
53 // name to the permanent storage; default does nothing
54 virtual void
55 storeContentObject(string &name, ContentObjectPtr co) {}
56
57 // should be called when connect to a different network
58 void
59 refreshLocalPrefix();
60
61 static bool
62 isPrefix(string &prefix, string &name);
63
64protected:
65 void
66 handleTunneledInterest(string tunneldInterest);
67
68 virtual int
69 sendInterest (const std::string &strInterest, void *dataPass);
70
71protected:
72 // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
73 string m_localPrefix;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080074 RegisteredInterestTable m_rit;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080075 Lock m_ritLock;
76};
77
78};
79
80#endif