blob: c17569de1cf7a5f137fd0e305c5cf10dc6bb1c29 [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 <string>
5#include <boost/function.hpp>
6#include <boost/variant.hpp>
7#include <boost/thread/locks.hpp>
8#include <utility>
9#include <map>
10
Zhenkai Zhud4924312012-12-28 11:35:12 -080011#include "ccnx-wrapper.h"
12
13#define _OVERRIDE
14#ifdef __GNUC__
15#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
16 #undef _OVERRIDE
17 #define _OVERRIDE override
18#endif // __GNUC__ version
19#endif // __GNUC__
20
Zhenkai Zhu0f054122012-12-25 22:22:50 -080021using namespace std;
22
23// Eventually, Sync::CcnxWrapper should be moved to this namespace.
24// It has nothing to do with Sync.
25namespace Ccnx
26{
27
28class CcnxTunnel : public CcnxWrapper
29{
30public:
Zhenkai Zhu0f054122012-12-25 22:22:50 -080031 typedef multimap<string, InterestCallback> RegisteredInterestTable;
Zhenkai Zhud4924312012-12-28 11:35:12 -080032 typedef multimap<string, InterestCallback>::iterator RitIter;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080033 typedef boost::shared_mutex Lock;
34 typedef boost::unique_lock<Lock> WriteLock;
35 typedef boost::shared_lock<Lock> ReadLock;
36
37
38 CcnxTunnel();
39 virtual ~CcnxTunnel();
40
41 // name is topology-independent
42 virtual int
Zhenkai Zhud4924312012-12-28 11:35:12 -080043 publishData(const string &name, const char *buf, size_t len, int freshness) _OVERRIDE;
44
45 virtual int
46 sendInterest (const std::string &interest, const DataCallback &dataCallback, int retry = 0, const TimeoutCallback &timeoutCallback = TimeoutCallback()) _OVERRIDE;
47
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
79 handleTunneledData(const string &name, const Bytes &tunneledData, const 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 Zhud4924312012-12-28 11:35:12 -080088class TunnelClosurePass : public ClosurePass
89{
90public:
91 TunnelClosurePass(int retry, const CcnxWrapper::DataCallback &dataCallback, const CcnxWrapper::TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest);
92
93 virtual void
94 runDataCallback(const string &name, const Bytes &content) _OVERRIDE;
95
96 virtual CcnxWrapper::TimeoutCallbackReturnValue
97 runTimeoutCallback(const string &interest) _OVERRIDE;
98
99private:
100 CcnxTunnel *m_tunnel;
101 string m_originalInterest;
102};
103
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800104};
105
106#endif