blob: bc13f9a92bf9c3afeff3b2620e0e4821763cc550 [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"
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -08008#include "ccnx-name.h"
Zhenkai Zhud4924312012-12-28 11:35:12 -08009
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080010#define _OVERRIDE
Zhenkai Zhud4924312012-12-28 11:35:12 -080011#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
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080020// Eventually, Sync::CcnxWrapper should be moved to this namespace.
Zhenkai Zhu0f054122012-12-25 22:22:50 -080021// It has nothing to do with Sync.
22namespace Ccnx
23{
24
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080025class CcnxTunnel : public CcnxWrapper
Zhenkai Zhu0f054122012-12-25 22:22:50 -080026{
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080027public:
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080028 typedef multimap<Name, InterestCallback> RegisteredInterestTable;
29 typedef multimap<Name, InterestCallback>::iterator RitIter;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080030
31
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080032 CcnxTunnel();
Zhenkai Zhu0f054122012-12-25 22:22:50 -080033 virtual ~CcnxTunnel();
34
35 // name is topology-independent
36 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080037 publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080038
Zhenkai Zhuf1185262012-12-29 17:06:00 -080039 int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080040 publishContentObject(const Name &name, const Bytes &contentObject, int freshness);
Zhenkai Zhuf1185262012-12-29 17:06:00 -080041
Zhenkai Zhud4924312012-12-28 11:35:12 -080042 virtual int
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080043 sendInterest (const Name &interest, const Closure *closure, const Selectors &selectors = Selectors());
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 Zhucb2d0dd2013-01-03 14:10:48 -080048 setInterestFilter(const Name &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 Zhucb2d0dd2013-01-03 14:10:48 -080053 clearInterestFilter(const Name &prefix) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080054
55 // subclass should provide translation service from topology-independent name
56 // to routable name
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080057 virtual Name
58 queryRoutableName(const Name &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 Zhucb2d0dd2013-01-03 14:10:48 -080063 storeContentObject(const Name &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 Zhucb2d0dd2013-01-03 14:10:48 -080070 isPrefix(const Name &prefix, const Name &name);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080071
Zhenkai Zhu0f054122012-12-25 22:22:50 -080072 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080073 handleTunneledInterest(const Name &tunneldInterest);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080074
Zhenkai Zhud4924312012-12-28 11:35:12 -080075 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080076 handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080077
Zhenkai Zhu90ef9df2013-01-04 22:31:59 -080078private:
79 CcnxTunnel(const CcnxTunnel &other) {}
80
Zhenkai Zhu0f054122012-12-25 22:22:50 -080081protected:
82 // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080083 Name 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 Zhu0ccc9ec2013-01-04 19:24:09 -080091 TunnelClosure(int retry, const DataCallback &dataCallback, CcnxTunnel *tunnel, const Name &originalInterest, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080092
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080093 TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const Name &originalInterest);
Zhenkai Zhud4924312012-12-28 11:35:12 -080094
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080095 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080096 runDataCallback(const Name &name, const Bytes &content) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080097
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080098 virtual TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080099 runTimeoutCallback(const Name &interest) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800100
Zhenkai Zhu19f81de2013-01-04 22:27:47 -0800101 virtual Closure *
102 dup() const _OVERRIDE;
103
Zhenkai Zhud4924312012-12-28 11:35:12 -0800104private:
105 CcnxTunnel *m_tunnel;
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800106 Name m_originalInterest;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800107};
108
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800109};
110
111#endif