blob: 104c7cf52f5747b8beb9ee68683779aa1dd64d61 [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 Zhua6472e02013-01-06 14:33:37 -08009#include "ccnx-selectors.h"
Zhenkai Zhud4924312012-12-28 11:35:12 -080010
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080011#define _OVERRIDE
Zhenkai Zhud4924312012-12-28 11:35:12 -080012#ifdef __GNUC__
13#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
14 #undef _OVERRIDE
15 #define _OVERRIDE override
16#endif // __GNUC__ version
17#endif // __GNUC__
18
Zhenkai Zhu0f054122012-12-25 22:22:50 -080019using namespace std;
20
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080021// Eventually, Sync::CcnxWrapper should be moved to this namespace.
Zhenkai Zhu0f054122012-12-25 22:22:50 -080022// It has nothing to do with Sync.
23namespace Ccnx
24{
25
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080026class CcnxTunnel : public CcnxWrapper
Zhenkai Zhu0f054122012-12-25 22:22:50 -080027{
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080028public:
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080029 typedef multimap<Name, InterestCallback> RegisteredInterestTable;
30 typedef multimap<Name, InterestCallback>::iterator RitIter;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080031
32
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080033 CcnxTunnel();
Zhenkai Zhu0f054122012-12-25 22:22:50 -080034 virtual ~CcnxTunnel();
35
36 // name is topology-independent
37 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080038 publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080039
Zhenkai Zhuf1185262012-12-29 17:06:00 -080040 int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080041 publishContentObject(const Name &name, const Bytes &contentObject, int freshness);
Zhenkai Zhuf1185262012-12-29 17:06:00 -080042
Zhenkai Zhud4924312012-12-28 11:35:12 -080043 virtual int
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080044 sendInterest (const Name &interest, const Closure *closure, const Selectors &selectors = Selectors());
Zhenkai Zhud4924312012-12-28 11:35:12 -080045
Zhenkai Zhu0f054122012-12-25 22:22:50 -080046
47 // prefix is topology-independent
48 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080049 setInterestFilter(const Name &prefix, const InterestCallback &interestCallback) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080050
51 // prefix is topology-independent
52 // this clears all entries with key equal to prefix
53 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080054 clearInterestFilter(const Name &prefix) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080055
56 // subclass should provide translation service from topology-independent name
57 // to routable name
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080058 virtual Name
59 queryRoutableName(const Name &name) = 0;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080060
61 // subclass should implement the function to store ContentObject with topoloy-independent
62 // name to the permanent storage; default does nothing
63 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080064 storeContentObject(const Name &name, const Bytes &content) {}
Zhenkai Zhu0f054122012-12-25 22:22:50 -080065
66 // should be called when connect to a different network
67 void
68 refreshLocalPrefix();
69
70 static bool
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080071 isPrefix(const Name &prefix, const Name &name);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080072
Zhenkai Zhu0f054122012-12-25 22:22:50 -080073 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080074 handleTunneledInterest(const Name &tunneldInterest);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080075
Zhenkai Zhud4924312012-12-28 11:35:12 -080076 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080077 handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080078
Zhenkai Zhu90ef9df2013-01-04 22:31:59 -080079private:
80 CcnxTunnel(const CcnxTunnel &other) {}
81
Zhenkai Zhu0f054122012-12-25 22:22:50 -080082protected:
83 // 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 -080084 Name m_localPrefix;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080085 RegisteredInterestTable m_rit;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080086 Lock m_ritLock;
87};
88
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080089class TunnelClosure : public Closure
Zhenkai Zhud4924312012-12-28 11:35:12 -080090{
91public:
Zhenkai Zhu0ccc9ec2013-01-04 19:24:09 -080092 TunnelClosure(int retry, const DataCallback &dataCallback, CcnxTunnel *tunnel, const Name &originalInterest, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080093
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080094 TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const Name &originalInterest);
Zhenkai Zhud4924312012-12-28 11:35:12 -080095
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080096 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080097 runDataCallback(const Name &name, const Bytes &content) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080098
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080099 virtual TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800100 runTimeoutCallback(const Name &interest) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800101
Zhenkai Zhu19f81de2013-01-04 22:27:47 -0800102 virtual Closure *
103 dup() const _OVERRIDE;
104
Zhenkai Zhud4924312012-12-28 11:35:12 -0800105private:
106 CcnxTunnel *m_tunnel;
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800107 Name m_originalInterest;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800108};
109
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800110};
111
112#endif