blob: e4b8b50226c6445539b9fa8ebb1a7f77ad823707 [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
Zhenkai Zhuf1185262012-12-29 17:06:00 -080042 int
43 publishContentObject(const string &name, const Bytes &contentObject, int freshness);
44
Zhenkai Zhud4924312012-12-28 11:35:12 -080045 virtual int
Zhenkai Zhu9bad2bf2012-12-28 15:31:46 -080046 sendInterest (const Interest &interest, Closure *closure);
Zhenkai Zhud4924312012-12-28 11:35:12 -080047
Zhenkai Zhu0f054122012-12-25 22:22:50 -080048
49 // prefix is topology-independent
50 virtual int
Zhenkai Zhud4924312012-12-28 11:35:12 -080051 setInterestFilter(const string &prefix, const InterestCallback &interestCallback) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080052
53 // prefix is topology-independent
54 // this clears all entries with key equal to prefix
55 virtual void
Zhenkai Zhud4924312012-12-28 11:35:12 -080056 clearInterestFilter(const string &prefix) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080057
58 // subclass should provide translation service from topology-independent name
59 // to routable name
60 virtual string
Zhenkai Zhud4924312012-12-28 11:35:12 -080061 queryRoutableName(const string &name) = 0;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080062
63 // subclass should implement the function to store ContentObject with topoloy-independent
64 // name to the permanent storage; default does nothing
65 virtual void
Zhenkai Zhud4924312012-12-28 11:35:12 -080066 storeContentObject(const string &name, const Bytes &content) {}
Zhenkai Zhu0f054122012-12-25 22:22:50 -080067
68 // should be called when connect to a different network
69 void
70 refreshLocalPrefix();
71
72 static bool
Zhenkai Zhud4924312012-12-28 11:35:12 -080073 isPrefix(const string &prefix, const string &name);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080074
Zhenkai Zhu0f054122012-12-25 22:22:50 -080075 void
Zhenkai Zhud4924312012-12-28 11:35:12 -080076 handleTunneledInterest(const string &tunneldInterest);
77
78 void
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080079 handleTunneledData(const string &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080080
81protected:
82 // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
83 string m_localPrefix;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080084 RegisteredInterestTable m_rit;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080085 Lock m_ritLock;
86};
87
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080088class TunnelClosure : public Closure
Zhenkai Zhud4924312012-12-28 11:35:12 -080089{
90public:
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080091 TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest);
92
93 TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const string &originalInterest);
Zhenkai Zhud4924312012-12-28 11:35:12 -080094
95 virtual void
96 runDataCallback(const string &name, const Bytes &content) _OVERRIDE;
97
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080098 virtual TimeoutCallbackReturnValue
Zhenkai Zhud4924312012-12-28 11:35:12 -080099 runTimeoutCallback(const string &interest) _OVERRIDE;
100
101private:
102 CcnxTunnel *m_tunnel;
103 string m_originalInterest;
104};
105
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800106};
107
108#endif