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