blob: 05254588224a72af18106c0868a6890c819c169c [file] [log] [blame]
#ifndef CCNX_TUNNEL_H
#define CCNX_TUNNEL_H
#include <boost/variant.hpp>
#include "ccnx-common.h"
#include "ccnx-wrapper.h"
#include "ccnx-name.h"
#define _OVERRIDE
#ifdef __GNUC__
#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
#undef _OVERRIDE
#define _OVERRIDE override
#endif // __GNUC__ version
#endif // __GNUC__
using namespace std;
// Eventually, Sync::CcnxWrapper should be moved to this namespace.
// It has nothing to do with Sync.
namespace Ccnx
{
class CcnxTunnel : public CcnxWrapper
{
public:
typedef multimap<Name, InterestCallback> RegisteredInterestTable;
typedef multimap<Name, InterestCallback>::iterator RitIter;
CcnxTunnel();
virtual ~CcnxTunnel();
// name is topology-independent
virtual int
publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
int
publishContentObject(const Name &name, const Bytes &contentObject, int freshness);
virtual int
sendInterest (const Name &interest, Closure *closure, const Selectors &selectors = Selectors());
// prefix is topology-independent
virtual int
setInterestFilter(const Name &prefix, const InterestCallback &interestCallback) _OVERRIDE;
// prefix is topology-independent
// this clears all entries with key equal to prefix
virtual void
clearInterestFilter(const Name &prefix) _OVERRIDE;
// subclass should provide translation service from topology-independent name
// to routable name
virtual Name
queryRoutableName(const Name &name) = 0;
// subclass should implement the function to store ContentObject with topoloy-independent
// name to the permanent storage; default does nothing
virtual void
storeContentObject(const Name &name, const Bytes &content) {}
// should be called when connect to a different network
void
refreshLocalPrefix();
static bool
isPrefix(const Name &prefix, const Name &name);
void
handleTunneledInterest(const Name &tunneldInterest);
void
handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
protected:
// need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
Name m_localPrefix;
RegisteredInterestTable m_rit;
Lock m_ritLock;
};
class TunnelClosure : public Closure
{
public:
TunnelClosure(int retry, const DataCallback &dataCallback, CcnxTunnel *tunnel, const Name &originalInterest, const TimeoutCallback &timeoutCallback = TimeoutCallback());
TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const Name &originalInterest);
virtual void
runDataCallback(const Name &name, const Bytes &content) _OVERRIDE;
virtual TimeoutCallbackReturnValue
runTimeoutCallback(const Name &interest) _OVERRIDE;
private:
CcnxTunnel *m_tunnel;
Name m_originalInterest;
};
};
#endif