Browse Source

binary-xml-wire-format: Partial enabling of binary-xml-wire-format

Due to significant changes, Data abstraction conversion (from and to
wire format) is currently disabled, using empty placeholders instead.

Other data structures should have working conversion (minus
PublisherPublicKeyDigest, which is not part of Interest and
ForwardingEntry data structure anymore).

Change-Id: I51c47495808c35b500fc6b1fcc0c46db217e6598
pull/1/head
Alexander Afanasyev 12 years ago
parent
commit
854808459c
  1. 6
      Makefile.am
  2. 13
      include/ndn-cpp/exclude.hpp
  3. 4
      include/ndn-cpp/interest.hpp
  4. 4
      src/c/encoding/binary-xml-decoder.c
  5. 4
      src/c/encoding/binary-xml-decoder.h
  6. 210
      src/encoding/binary-xml-wire-format.cpp
  7. 15
      src/interest.cpp

6
Makefile.am

@ -81,6 +81,7 @@ libndn_cpp_la_SOURCES = $(libndn_c_la_SOURCES) \
src/encoding/binary-xml-decoder.hpp \
src/encoding/binary-xml-encoder.hpp \
src/encoding/binary-xml-structure-decoder.hpp \
src/encoding/binary-xml-wire-format.cpp \
src/encoding/block.cpp \
src/encoding/cryptopp/asn_ext.cpp \
src/encoding/cryptopp/asn_ext.hpp \
@ -119,11 +120,6 @@ libndn_cpp_la_SOURCES = $(libndn_c_la_SOURCES) \
src/util/string-helper.hpp \
src/util/time.hpp
# Temporary disabled:
# data/interest/forwardingEntry set/get methods need to be
# embedded in BinaryXmlWireFormat class
# src/encoding/binary-xml-wire-format.cpp
libndn_cpp_la_LIBADD = @OPENSSL_LIBS@ @OSX_SECURITY_LIBS@
libndn_cpp_la_LDFLAGS = @OPENSSL_LDFLAGS@ @SQLITE3_LDFLAGS@ @BOOST_LDFLAGS@
libndn_cpp_la_CFLAGS = @OPENSSL_INCLUDES@ @SQLITE3_CFLAGS@ @BOOST_CPPFLAGS@

13
include/ndn-cpp/exclude.hpp

@ -95,6 +95,12 @@ public:
*/
inline bool
empty () const;
/**
* @brief Clear the exclude filter
*/
inline void
clear();
/**
* @brief Get number of exclude terms
@ -177,6 +183,13 @@ Exclude::empty () const
return m_exclude.empty ();
}
inline void
Exclude::clear ()
{
m_exclude.clear ();
}
inline size_t
Exclude::size () const
{

4
include/ndn-cpp/interest.hpp

@ -136,8 +136,10 @@ public:
* @brief Get Interest's nonce
*
* If nonce was not set before this call, it will be automatically assigned to a random value
*
* Const reference needed for C decoding
*/
uint32_t
const uint32_t&
getNonce() const;
void

4
src/c/encoding/binary-xml-decoder.c

@ -293,7 +293,7 @@ ndn_Error ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
}
ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds)
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds)
{
ndn_Error error;
struct ndn_Blob bytes;
@ -305,7 +305,7 @@ ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
}
ndn_Error ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds)
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds)
{
int gotExpectedTag;
ndn_Error error;

4
src/c/encoding/binary-xml-decoder.h

@ -156,7 +156,7 @@ ndn_Error ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
* @return 0 for success, else an error code, including an error if not the expected tag
*/
ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds);
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds);
/**
* Peek at the next element, and if it has the expectedTag then call ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement.
@ -167,7 +167,7 @@ ndn_Error ndn_BinaryXmlDecoder_readTimeMillisecondsDTagElement
* @return 0 for success, else an error code
*/
ndn_Error ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, double *milliseconds);
(struct ndn_BinaryXmlDecoder *self, unsigned int expectedTag, ndn_MillisecondsSince1970 *milliseconds);
/**
* Interpret the bytes as an unsigned big endian integer and convert to a double. Don't check for overflow.

210
src/encoding/binary-xml-wire-format.cpp

@ -20,6 +20,204 @@ using namespace std;
namespace ndn {
namespace c {
class Exclude : public ndn::Exclude
{
public:
void
get(struct ndn_Exclude& excludeStruct) const
{
if (excludeStruct.maxEntries < size())
throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
int entries = 0;
for (Exclude::const_reverse_iterator i = rbegin (); i != rend (); i++)
{
if (!i->first.empty())
{
excludeStruct.entries[entries].type = ndn_Exclude_COMPONENT;
excludeStruct.entries[entries].component.value.value = const_cast<uint8_t*>(i->first.getValue().buf());
excludeStruct.entries[entries].component.value.length = i->first.getValue().size();
++entries;
}
if (i->second)
{
excludeStruct.entries[entries].type = ndn_Exclude_ANY;
++entries;
}
}
excludeStruct.nEntries = entries;
}
void
set(const struct ndn_Exclude& excludeStruct)
{
clear();
if (excludeStruct.nEntries == 0)
return;
int i = 0;
if (excludeStruct.entries[i].type == ndn_Exclude_ANY) {
appendExclude("/", true);
i++;
}
while (i < excludeStruct.nEntries) {
ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
if (entry->type != ndn_Exclude_COMPONENT)
throw runtime_error("unrecognized ndn_ExcludeType");
Name::Component excludedComponent (entry->component.value.value, entry->component.value.length);
++i;
entry = &excludeStruct.entries[i];
if (i < excludeStruct.nEntries) {
if (entry->type == ndn_Exclude_ANY) {
appendExclude(excludedComponent, true);
++i;
}
else
appendExclude(excludedComponent, false);
}
else
appendExclude(excludedComponent, false);
}
}
};
class Name : public ndn::Name
{
public:
void
get(struct ndn_Name& nameStruct) const
{
if (nameStruct.maxComponents < size())
throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()");
nameStruct.nComponents = size();
for (size_t i = 0; i < nameStruct.nComponents; ++i) {
nameStruct.components[i].value.value = const_cast<uint8_t*>(ndn::Name::get(i).getValue().buf());
nameStruct.components[i].value.length = ndn::Name::get(i).getValue().size();
}
}
void
set(const struct ndn_Name& nameStruct)
{
clear();
for (size_t i = 0; i < nameStruct.nComponents; ++i)
append(nameStruct.components[i].value.value, nameStruct.components[i].value.length);
}
};
class Interest : public ndn::Interest
{
public:
void
get(struct ndn_Interest& interestStruct) const
{
reinterpret_cast<const c::Name&>(getName()).get(interestStruct.name);
interestStruct.minSuffixComponents = getMinSuffixComponents();
interestStruct.maxSuffixComponents = getMaxSuffixComponents();
// publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
reinterpret_cast<const c::Exclude&>(getExclude()).get(interestStruct.exclude);
interestStruct.childSelector = getChildSelector();
interestStruct.answerOriginKind = getMustBeFresh() ?
(ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED)
:
(ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED | ndn_Interest_ANSWER_STALE);
interestStruct.scope = getScope();
interestStruct.interestLifetimeMilliseconds = getInterestLifetime();
interestStruct.nonce.length = 4;
interestStruct.nonce.value = const_cast<uint8_t*>(reinterpret_cast<const uint8_t *>(getNonce()));
}
void
set(const struct ndn_Interest& interestStruct)
{
reinterpret_cast<c::Name&>(getName()).set(interestStruct.name);
setMinSuffixComponents(interestStruct.minSuffixComponents);
setMaxSuffixComponents(interestStruct.maxSuffixComponents);
// publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
reinterpret_cast<c::Exclude&>(getExclude()).set(interestStruct.exclude);
setChildSelector(interestStruct.childSelector);
// answerOriginKind_ = interestStruct.answerOriginKind;
setScope(interestStruct.scope);
setInterestLifetime(interestStruct.interestLifetimeMilliseconds);
setNonce(*reinterpret_cast<uint32_t*>(interestStruct.nonce.value));
}
};
class Data : public ndn::Data
{
public:
void
get(struct ndn_Data& dataStruct) const
{
// signature_->get(dataStruct.signature);
// name_.get(dataStruct.name);
// metaInfo_.get(dataStruct.metaInfo);
// content_.get(dataStruct.content);
}
void
set(const struct ndn_Data& dataStruct)
{
// signature_->set(dataStruct.signature);
// name_.set(dataStruct.name);
// metaInfo_.set(dataStruct.metaInfo);
// content_ = Blob(dataStruct.content);
}
};
class ForwardingEntry : public ndn::ForwardingEntry
{
public:
void
get(struct ndn_ForwardingEntry& forwardingEntryStruct) const
{
reinterpret_cast<const c::Name&>(getPrefix()).get(forwardingEntryStruct.prefix);
// publisherPublicKeyDigest_.get(forwardingEntryStruct.publisherPublicKeyDigest);
forwardingEntryStruct.faceId = getFaceId();
// forwardingEntryStruct.forwardingFlags = getForwardingFlags();
forwardingEntryStruct.freshnessSeconds = getFreshnessPeriod() / 1000;
forwardingEntryStruct.action.length = getAction().size();
if (getAction().size() > 0)
forwardingEntryStruct.action.value = (uint8_t *)&getAction();
else
forwardingEntryStruct.action.value = 0;
}
void
set(const struct ndn_ForwardingEntry& forwardingEntryStruct)
{
if (forwardingEntryStruct.action.value && forwardingEntryStruct.action.length > 0)
setAction(string(forwardingEntryStruct.action.value, forwardingEntryStruct.action.value + forwardingEntryStruct.action.length));
else
setAction("");
Name prefix;
reinterpret_cast<c::Name&>(prefix).set(forwardingEntryStruct.prefix);
setPrefix(prefix);
// publisherPublicKeyDigest_.set(forwardingEntryStruct.publisherPublicKeyDigest);
setFaceId(forwardingEntryStruct.faceId);
// setForwardingFlags(forwardingEntryStruct.forwardingFlags);
setFreshnessPeriod(forwardingEntryStruct.freshnessSeconds * 1000);
}
};
}
// This is declared in the WireFormat class.
WireFormat*
WireFormat::newInitialDefaultWireFormat()
@ -36,7 +234,7 @@ BinaryXmlWireFormat::encodeInterest(const Interest& interest)
ndn_Interest_initialize
(&interestStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0]));
interest.get(interestStruct);
reinterpret_cast<const c::Interest&>(interest).get(interestStruct);
BinaryXmlEncoder encoder;
ndn_Error error;
@ -61,7 +259,7 @@ BinaryXmlWireFormat::decodeInterest(Interest& interest, const uint8_t *input, si
if ((error = ndn_decodeBinaryXmlInterest(&interestStruct, &decoder)))
throw runtime_error(ndn_getErrorString(error));
interest.set(interestStruct);
reinterpret_cast<c::Interest&>(interest).set(interestStruct);
}
Blob
@ -73,7 +271,7 @@ BinaryXmlWireFormat::encodeData(const Data& data, size_t *signedPortionBeginOffs
ndn_Data_initialize
(&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
data.get(dataStruct);
reinterpret_cast<const c::Data&>(data).get(dataStruct);
BinaryXmlEncoder encoder(1500);
ndn_Error error;
@ -99,7 +297,7 @@ BinaryXmlWireFormat::decodeData
if ((error = ndn_decodeBinaryXmlData(&dataStruct, signedPortionBeginOffset, signedPortionEndOffset, &decoder)))
throw runtime_error(ndn_getErrorString(error));
data.set(dataStruct);
reinterpret_cast<c::Data&>(data).set(dataStruct);
}
Blob
@ -109,7 +307,7 @@ BinaryXmlWireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntr
struct ndn_ForwardingEntry forwardingEntryStruct;
ndn_ForwardingEntry_initialize
(&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0]));
forwardingEntry.get(forwardingEntryStruct);
reinterpret_cast<const c::ForwardingEntry&>(forwardingEntry).get(forwardingEntryStruct);
BinaryXmlEncoder encoder;
ndn_Error error;
@ -132,7 +330,7 @@ BinaryXmlWireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, con
if ((error = ndn_decodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &decoder)))
throw runtime_error(ndn_getErrorString(error));
forwardingEntry.set(forwardingEntryStruct);
reinterpret_cast<c::ForwardingEntry&>(forwardingEntry).set(forwardingEntryStruct);
}
}

15
src/interest.cpp

@ -9,13 +9,26 @@
#include <ndn-cpp/common.hpp>
#include <ndn-cpp/interest.hpp>
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreorder"
#pragma clang diagnostic ignored "-Wtautological-compare"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-function"
#elif __GNUC__
#pragma GCC diagnostic ignored "-Wreorder"
#pragma GCC diagnostic ignored "-Wtautological-compare"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
#include <cryptopp/osrng.h>
using namespace std;
namespace ndn {
uint32_t
const uint32_t&
Interest::getNonce() const
{
static CryptoPP::AutoSeededRandomPool rng;

Loading…
Cancel
Save