blob: 4e1eade5b6a6965d4af517a0036d140044895657 [file] [log] [blame]
Zhenkai Zhu0f054122012-12-25 22:22:50 -08001#ifndef CCNX_TUNNEL_H
2#define CCNX_TUNNEL_H
3
Zhenkai Zhu0f054122012-12-25 22:22:50 -08004#include <boost/variant.hpp>
5#include <boost/thread/locks.hpp>
Zhenkai Zhu0f054122012-12-25 22:22:50 -08006
Zhenkai Zhu974c5a62012-12-28 14:15:30 -08007#include "ccnx-common.h"
Zhenkai Zhud4924312012-12-28 11:35:12 -08008#include "ccnx-wrapper.h"
9
10#define _OVERRIDE
11#ifdef __GNUC__
12#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
13 #undef _OVERRIDE
14 #define _OVERRIDE override
15#endif // __GNUC__ version
16#endif // __GNUC__
17
Zhenkai Zhu0f054122012-12-25 22:22:50 -080018using namespace std;
19
20// Eventually, Sync::CcnxWrapper should be moved to this namespace.
21// It has nothing to do with Sync.
22namespace Ccnx
23{
24
25class CcnxTunnel : public CcnxWrapper
26{
27public:
Zhenkai Zhu0f054122012-12-25 22:22:50 -080028 typedef multimap<string, InterestCallback> RegisteredInterestTable;
Zhenkai Zhud4924312012-12-28 11:35:12 -080029 typedef multimap<string, InterestCallback>::iterator RitIter;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080030 typedef boost::shared_mutex Lock;
31 typedef boost::unique_lock<Lock> WriteLock;
32 typedef boost::shared_lock<Lock> ReadLock;
33
34
35 CcnxTunnel();
36 virtual ~CcnxTunnel();
37
38 // name is topology-independent
39 virtual int
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080040 publishData(const string &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080041
42 virtual int
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080043 sendInterest (const std::string &interest, Closure *closure);
Zhenkai Zhud4924312012-12-28 11:35:12 -080044
Zhenkai Zhu0f054122012-12-25 22:22:50 -080045
46 // prefix is topology-independent
47 virtual int
Zhenkai Zhud4924312012-12-28 11:35:12 -080048 setInterestFilter(const string &prefix, const InterestCallback &interestCallback) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080049
50 // prefix is topology-independent
51 // this clears all entries with key equal to prefix
52 virtual void
Zhenkai Zhud4924312012-12-28 11:35:12 -080053 clearInterestFilter(const string &prefix) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080054
55 // subclass should provide translation service from topology-independent name
56 // to routable name
57 virtual string
Zhenkai Zhud4924312012-12-28 11:35:12 -080058 queryRoutableName(const string &name) = 0;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080059
60 // subclass should implement the function to store ContentObject with topoloy-independent
61 // name to the permanent storage; default does nothing
62 virtual void
Zhenkai Zhud4924312012-12-28 11:35:12 -080063 storeContentObject(const string &name, const Bytes &content) {}
Zhenkai Zhu0f054122012-12-25 22:22:50 -080064
65 // should be called when connect to a different network
66 void
67 refreshLocalPrefix();
68
69 static bool
Zhenkai Zhud4924312012-12-28 11:35:12 -080070 isPrefix(const string &prefix, const string &name);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080071
Zhenkai Zhu0f054122012-12-25 22:22:50 -080072 void
Zhenkai Zhud4924312012-12-28 11:35:12 -080073 handleTunneledInterest(const string &tunneldInterest);
74
75 void
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080076 handleTunneledData(const string &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080077
78protected:
79 // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
80 string m_localPrefix;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080081 RegisteredInterestTable m_rit;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080082 Lock m_ritLock;
83};
84
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080085class TunnelClosure : public Closure
Zhenkai Zhud4924312012-12-28 11:35:12 -080086{
87public:
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080088 TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest);
89
90 TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const string &originalInterest);
Zhenkai Zhud4924312012-12-28 11:35:12 -080091
92 virtual void
93 runDataCallback(const string &name, const Bytes &content) _OVERRIDE;
94
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080095 virtual TimeoutCallbackReturnValue
Zhenkai Zhud4924312012-12-28 11:35:12 -080096 runTimeoutCallback(const string &interest) _OVERRIDE;
97
98private:
99 CcnxTunnel *m_tunnel;
100 string m_originalInterest;
101};
102
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800103};
104
105#endif