5 changed files with 192 additions and 0 deletions
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Author: Jeff Thompson |
||||
* |
||||
* BSD license, See the LICENSE file for more information. |
||||
*/ |
||||
|
||||
#include "Interest.hpp" |
||||
|
||||
using namespace std; |
||||
|
||||
namespace ndn { |
||||
|
||||
void Interest::set(struct ndn_Interest &interestStruct)
|
||||
{ |
||||
name_.set(interestStruct.name); |
||||
maxSuffixComponents_ = interestStruct.maxSuffixComponents; |
||||
minSuffixComponents_ = interestStruct.minSuffixComponents; |
||||
|
||||
publisherPublicKeyDigest_.clear(); |
||||
if (interestStruct.publisherPublicKeyDigest) |
||||
publisherPublicKeyDigest_.insert |
||||
(publisherPublicKeyDigest_.begin(), interestStruct.publisherPublicKeyDigest, interestStruct.publisherPublicKeyDigest + interestStruct.publisherPublicKeyDigestLength); |
||||
// TODO: implement exclude
|
||||
childSelector_ = interestStruct.childSelector; |
||||
answerOriginKind_ = interestStruct.answerOriginKind; |
||||
scope_ = interestStruct.scope; |
||||
interestLifetime_ = interestStruct.interestLifetime; |
||||
nonce_.clear(); |
||||
if (interestStruct.nonce) |
||||
nonce_.insert |
||||
(nonce_.begin(), interestStruct.nonce, interestStruct.nonce + interestStruct.nonceLength); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Author: Jeff Thompson |
||||
* |
||||
* BSD license, See the LICENSE file for more information. |
||||
*/ |
||||
|
||||
#ifndef NDN_INTEREST_HPP |
||||
#define NDN_INTEREST_HPP |
||||
|
||||
#include <vector> |
||||
#include "Name.hpp" |
||||
#include "c/Interest.h" |
||||
|
||||
namespace ndn { |
||||
|
||||
class Interest { |
||||
public:
|
||||
void encode(std::vector<unsigned char> &output, WireFormat &wireFormat)
|
||||
{ |
||||
wireFormat.encodeInterest(*this, output); |
||||
} |
||||
void encode(std::vector<unsigned char> &output)
|
||||
{ |
||||
encode(output, BinaryXMLWireFormat::instance()); |
||||
} |
||||
void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat)
|
||||
{ |
||||
wireFormat.decodeInterest(*this, input, inputLength); |
||||
} |
||||
void decode(const unsigned char *input, unsigned int inputLength)
|
||||
{ |
||||
decode(input, inputLength, BinaryXMLWireFormat::instance()); |
||||
} |
||||
void decode(const std::vector<unsigned char> &input, WireFormat &wireFormat)
|
||||
{ |
||||
decode(&input[0], input.size(), wireFormat); |
||||
} |
||||
void decode(const std::vector<unsigned char> &input)
|
||||
{ |
||||
decode(&input[0], input.size()); |
||||
} |
||||
|
||||
Name &getName() { return name_; } |
||||
|
||||
/**
|
||||
* Clear this interest, and set the values by copying from the interest struct. |
||||
* @param interestStruct a C ndn_Interest struct
|
||||
*/ |
||||
void set(struct ndn_Interest &interestStruct); |
||||
|
||||
private: |
||||
|
||||
Name name_; |
||||
int maxSuffixComponents_; |
||||
int minSuffixComponents_; |
||||
|
||||
std::vector<unsigned char> publisherPublicKeyDigest_; |
||||
// TODO: implement exclude
|
||||
int childSelector_; |
||||
int answerOriginKind_; |
||||
int scope_; |
||||
int interestLifetime_; |
||||
std::vector<unsigned char> nonce_; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Author: Jeff Thompson |
||||
* |
||||
* BSD license, See the LICENSE file for more information. |
||||
*/ |
||||
|
||||
#ifndef NDN_INTEREST_H |
||||
#define NDN_INTEREST_H |
||||
|
||||
#include "Name.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
struct ndn_Interest { |
||||
struct ndn_Name name; |
||||
int maxSuffixComponents; /**< -1 for none */ |
||||
int minSuffixComponents; /**< -1 for none */ |
||||
unsigned char *publisherPublicKeyDigest; /**< pointer to pre-allocated buffer. 0 for none */ |
||||
unsigned int publisherPublicKeyDigestLength; /**< length of publisherPublicKeyDigest */ |
||||
// TODO: implement exclude
|
||||
int childSelector; /**< -1 for none */ |
||||
int answerOriginKind; /**< -1 for none */ |
||||
int scope; /**< -1 for none */ |
||||
int interestLifetime; /**< milliseconds. -1 for none */ |
||||
unsigned char *nonce; /**< pointer to pre-allocated buffer. 0 for none */ |
||||
unsigned int nonceLength; /**< length of nonce */ |
||||
}; |
||||
|
||||
static inline void ndn_Interest_init(struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents)
|
||||
{ |
||||
ndn_Name_init(&self->name, nameComponents, maxNameComponents); |
||||
self->maxSuffixComponents = -1; |
||||
self->minSuffixComponents = -1; |
||||
self->publisherPublicKeyDigest = 0; |
||||
// TODO: implement exclude
|
||||
self->childSelector = -1; |
||||
self->answerOriginKind = -1; |
||||
self->scope = -1; |
||||
self->interestLifetime = -1; |
||||
self->nonce = 0; /**< length of nonce */ |
||||
} |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif |
||||
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Author: Jeff Thompson |
||||
* |
||||
* BSD license, See the LICENSE file for more information. |
||||
*/ |
||||
|
||||
#include "BinaryXMLEncoder.h" |
||||
#include "BinaryXMLDecoder.h" |
||||
#include "BinaryXMLInterest.h" |
||||
|
||||
char *ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, unsigned char *input, unsigned int inputLength) |
||||
{ |
||||
|
||||
} |
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Author: Jeff Thompson |
||||
* |
||||
* BSD license, See the LICENSE file for more information. |
||||
*/ |
||||
|
||||
#ifndef NDN_BINARYXMLINTEREST_H |
||||
#define NDN_BINARYXMLINTEREST_H |
||||
|
||||
#include "../Interest.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
char *ndn_encodeBinaryXMLInterest(struct ndn_Interest *interest, struct ndn_BinaryXMLEncoder *encoder); |
||||
|
||||
char *ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, unsigned char *input, unsigned int inputLength); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif |
||||
|
Loading…
Reference in new issue