blob: cddfcd5cc0576a80f0f096bbfec509845381850a [file] [log] [blame]
Zhenkai Zhu0f054122012-12-25 22:22:50 -08001#ifndef CCNX_TUNNEL_H
2#define CCNX_TUNNEL_H
3
4#include <sync/sync-ccnx-wrapper.h>
5#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;
24 typedef multimap<string, DataCallback> PendingInterestTable;
25 typedef multimap<string, InterestCallback> RegisteredInterestTable;
26 typedef multimap<string, DataCallback>iterator PitIter;
27 typedef multimap<string, InterestCallback>iterator RitIter;
28 typedef boost::shared_mutex Lock;
29 typedef boost::unique_lock<Lock> WriteLock;
30 typedef boost::shared_lock<Lock> ReadLock;
31
32
33 CcnxTunnel();
34 virtual ~CcnxTunnel();
35
36 // name is topology-independent
37 virtual int
38 publishRawData(const string &name, const char *buf, size_t len, int freshness);
39
40 // prefix is topology-independent
41 virtual int
42 setInterestFilter(const string &prefix, const InterestCallback &interestCallback);
43
44 // prefix is topology-independent
45 // this clears all entries with key equal to prefix
46 virtual void
47 clearInterestFilter(const string &prefix);
48
49 // subclass should provide translation service from topology-independent name
50 // to routable name
51 virtual string
52 queryRoutableName(string &name) = 0;
53
54 // subclass should implement the function to store ContentObject with topoloy-independent
55 // name to the permanent storage; default does nothing
56 virtual void
57 storeContentObject(string &name, ContentObjectPtr co) {}
58
59 // should be called when connect to a different network
60 void
61 refreshLocalPrefix();
62
63 static bool
64 isPrefix(string &prefix, string &name);
65
66protected:
67 void
68 handleTunneledInterest(string tunneldInterest);
69
70 virtual int
71 sendInterest (const std::string &strInterest, void *dataPass);
72
73protected:
74 // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
75 string m_localPrefix;
76 PendingInterestTable m_pit;
77 RegisteredInterestTable m_rit;
78 Lock m_pitLock;
79 Lock m_ritLock;
80};
81
82};
83
84#endif