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