Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 1 | #ifndef CCNX_TUNNEL_H |
| 2 | #define CCNX_TUNNEL_H |
| 3 | |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 4 | #include <boost/variant.hpp> |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 5 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 6 | #include "ccnx-common.h" |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 7 | #include "ccnx-wrapper.h" |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 8 | #include "ccnx-name.h" |
Zhenkai Zhu | a6472e0 | 2013-01-06 14:33:37 -0800 | [diff] [blame] | 9 | #include "ccnx-selectors.h" |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 10 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 11 | #define _OVERRIDE |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 12 | #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 Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 19 | using namespace std; |
| 20 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 21 | // Eventually, Sync::CcnxWrapper should be moved to this namespace. |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 22 | // It has nothing to do with Sync. |
| 23 | namespace Ccnx |
| 24 | { |
| 25 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 26 | class CcnxTunnel : public CcnxWrapper |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 27 | { |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 28 | public: |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 29 | typedef multimap<Name, InterestCallback> RegisteredInterestTable; |
| 30 | typedef multimap<Name, InterestCallback>::iterator RitIter; |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 31 | |
| 32 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 33 | CcnxTunnel(); |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 34 | virtual ~CcnxTunnel(); |
| 35 | |
| 36 | // name is topology-independent |
| 37 | virtual int |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 38 | publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE; |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 39 | |
Zhenkai Zhu | f118526 | 2012-12-29 17:06:00 -0800 | [diff] [blame] | 40 | int |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 41 | publishContentObject(const Name &name, const Bytes &contentObject, int freshness); |
Zhenkai Zhu | f118526 | 2012-12-29 17:06:00 -0800 | [diff] [blame] | 42 | |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 43 | virtual int |
Zhenkai Zhu | 19f81de | 2013-01-04 22:27:47 -0800 | [diff] [blame] | 44 | sendInterest (const Name &interest, const Closure *closure, const Selectors &selectors = Selectors()); |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 45 | |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 46 | |
| 47 | // prefix is topology-independent |
| 48 | virtual int |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 49 | setInterestFilter(const Name &prefix, const InterestCallback &interestCallback) _OVERRIDE; |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 50 | |
| 51 | // prefix is topology-independent |
| 52 | // this clears all entries with key equal to prefix |
| 53 | virtual void |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 54 | clearInterestFilter(const Name &prefix) _OVERRIDE; |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 55 | |
| 56 | // subclass should provide translation service from topology-independent name |
| 57 | // to routable name |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 58 | virtual Name |
| 59 | queryRoutableName(const Name &name) = 0; |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 60 | |
| 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 Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 64 | storeContentObject(const Name &name, const Bytes &content) {} |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 65 | |
| 66 | // should be called when connect to a different network |
| 67 | void |
| 68 | refreshLocalPrefix(); |
| 69 | |
| 70 | static bool |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 71 | isPrefix(const Name &prefix, const Name &name); |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 72 | |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 73 | void |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 74 | handleTunneledInterest(const Name &tunneldInterest); |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 75 | |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 76 | void |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 77 | handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback); |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 78 | |
Zhenkai Zhu | 90ef9df | 2013-01-04 22:31:59 -0800 | [diff] [blame] | 79 | private: |
| 80 | CcnxTunnel(const CcnxTunnel &other) {} |
| 81 | |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 82 | protected: |
| 83 | // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 84 | Name m_localPrefix; |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 85 | RegisteredInterestTable m_rit; |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 86 | Lock m_ritLock; |
| 87 | }; |
| 88 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 89 | class TunnelClosure : public Closure |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 90 | { |
| 91 | public: |
Zhenkai Zhu | 0ccc9ec | 2013-01-04 19:24:09 -0800 | [diff] [blame] | 92 | TunnelClosure(int retry, const DataCallback &dataCallback, CcnxTunnel *tunnel, const Name &originalInterest, const TimeoutCallback &timeoutCallback = TimeoutCallback()); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 93 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 94 | TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const Name &originalInterest); |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 95 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 96 | virtual void |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 97 | runDataCallback(const Name &name, const Bytes &content) _OVERRIDE; |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 98 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 99 | virtual TimeoutCallbackReturnValue |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 100 | runTimeoutCallback(const Name &interest) _OVERRIDE; |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 101 | |
Zhenkai Zhu | 19f81de | 2013-01-04 22:27:47 -0800 | [diff] [blame] | 102 | virtual Closure * |
| 103 | dup() const _OVERRIDE; |
| 104 | |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 105 | private: |
| 106 | CcnxTunnel *m_tunnel; |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 107 | Name m_originalInterest; |
Zhenkai Zhu | d492431 | 2012-12-28 11:35:12 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
Zhenkai Zhu | 0f05412 | 2012-12-25 22:22:50 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | #endif |