blob: af49a9b2d4d4e916b1b9a3947d8f586a01ac8624 [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>
Zhenkai Zhu0f054122012-12-25 22:22:50 -08005
Zhenkai Zhu974c5a62012-12-28 14:15:30 -08006#include "ccnx-common.h"
Zhenkai Zhud4924312012-12-28 11:35:12 -08007#include "ccnx-wrapper.h"
8
9#define _OVERRIDE
10#ifdef __GNUC__
11#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
12 #undef _OVERRIDE
13 #define _OVERRIDE override
14#endif // __GNUC__ version
15#endif // __GNUC__
16
Zhenkai Zhu0f054122012-12-25 22:22:50 -080017using namespace std;
18
19// Eventually, Sync::CcnxWrapper should be moved to this namespace.
20// It has nothing to do with Sync.
21namespace Ccnx
22{
23
24class CcnxTunnel : public CcnxWrapper
25{
26public:
Zhenkai Zhu0f054122012-12-25 22:22:50 -080027 typedef multimap<string, InterestCallback> RegisteredInterestTable;
Zhenkai Zhud4924312012-12-28 11:35:12 -080028 typedef multimap<string, InterestCallback>::iterator RitIter;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080029
30
31 CcnxTunnel();
32 virtual ~CcnxTunnel();
33
34 // name is topology-independent
35 virtual int
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080036 publishData(const string &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080037
Zhenkai Zhuf1185262012-12-29 17:06:00 -080038 int
39 publishContentObject(const string &name, const Bytes &contentObject, int freshness);
40
Zhenkai Zhud4924312012-12-28 11:35:12 -080041 virtual int
Zhenkai Zhu9bad2bf2012-12-28 15:31:46 -080042 sendInterest (const Interest &interest, Closure *closure);
Zhenkai Zhud4924312012-12-28 11:35:12 -080043
Zhenkai Zhu0f054122012-12-25 22:22:50 -080044
45 // prefix is topology-independent
46 virtual int
Zhenkai Zhud4924312012-12-28 11:35:12 -080047 setInterestFilter(const string &prefix, const InterestCallback &interestCallback) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080048
49 // prefix is topology-independent
50 // this clears all entries with key equal to prefix
51 virtual void
Zhenkai Zhud4924312012-12-28 11:35:12 -080052 clearInterestFilter(const string &prefix) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080053
54 // subclass should provide translation service from topology-independent name
55 // to routable name
56 virtual string
Zhenkai Zhud4924312012-12-28 11:35:12 -080057 queryRoutableName(const string &name) = 0;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080058
59 // subclass should implement the function to store ContentObject with topoloy-independent
60 // name to the permanent storage; default does nothing
61 virtual void
Zhenkai Zhud4924312012-12-28 11:35:12 -080062 storeContentObject(const string &name, const Bytes &content) {}
Zhenkai Zhu0f054122012-12-25 22:22:50 -080063
64 // should be called when connect to a different network
65 void
66 refreshLocalPrefix();
67
68 static bool
Zhenkai Zhud4924312012-12-28 11:35:12 -080069 isPrefix(const string &prefix, const string &name);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080070
Zhenkai Zhu0f054122012-12-25 22:22:50 -080071 void
Zhenkai Zhud4924312012-12-28 11:35:12 -080072 handleTunneledInterest(const string &tunneldInterest);
73
74 void
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080075 handleTunneledData(const string &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080076
77protected:
78 // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
79 string m_localPrefix;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080080 RegisteredInterestTable m_rit;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080081 Lock m_ritLock;
82};
83
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080084class TunnelClosure : public Closure
Zhenkai Zhud4924312012-12-28 11:35:12 -080085{
86public:
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080087 TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest);
88
89 TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const string &originalInterest);
Zhenkai Zhud4924312012-12-28 11:35:12 -080090
91 virtual void
92 runDataCallback(const string &name, const Bytes &content) _OVERRIDE;
93
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080094 virtual TimeoutCallbackReturnValue
Zhenkai Zhud4924312012-12-28 11:35:12 -080095 runTimeoutCallback(const string &interest) _OVERRIDE;
96
97private:
98 CcnxTunnel *m_tunnel;
99 string m_originalInterest;
100};
101
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800102};
103
104#endif