Use C-based encoding
diff --git a/ndn-cpp/data.cc b/ndn-cpp/data.cc
deleted file mode 100644
index 5a44da8..0000000
--- a/ndn-cpp/data.cc
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "data.h"
-
-namespace ndn {
-
-Data::Data ()
-{
-}
-
-Data::~Data ()
-{
-}
-
-} // namespace ndn
diff --git a/ndn-cpp/data.h b/ndn-cpp/data.h
deleted file mode 100644
index 962bfe5..0000000
--- a/ndn-cpp/data.h
+++ /dev/null
@@ -1,204 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDN_DATA_H
-#define NDN_DATA_H
-
-#include "ndn-cpp/fields/name.h"
-#include "ndn-cpp/fields/content.h"
-#include "ndn-cpp/fields/signature.h"
-#include "ndn-cpp/fields/signed-blob.h"
-
-namespace ndn {
-
-/**
- * @brief Class implementing abstractions to work with NDN Data packets
- */
-class Data
-{
-public:
- /**
- * @brief Create an empty Data with empty payload
- **/
- Data ();
-
- /**
- * @brief Destructor
- */
- ~Data ();
-
- /**
- * @brief Set data packet name
- * @param name name of the data packet
- * @return reference to self (to allow method chaining)
- *
- * In some cases, a direct access to and manipulation of name using getName is more efficient
- */
- inline Data &
- setName (const Name &name);
-
- /**
- * @brief Get data packet name (const reference)
- * @returns name of the data packet
- */
- inline const Name &
- getName () const;
-
- /**
- * @brief Get data packet name (reference)
- * @returns name of the data packet
- */
- inline Name &
- getName ();
-
- /**
- * @brief Get const smart pointer to signature object
- */
- inline ptr_lib::shared_ptr<const Signature>
- getSignature () const;
-
- /**
- * @brief Get smart pointer to signature object
- */
- inline ptr_lib::shared_ptr<Signature>
- getSignature ();
-
- /**
- * @brief Set signature object
- * @param signature smart pointer to a signature object
- */
- inline void
- setSignature (ptr_lib::shared_ptr<Signature> sigature);
-
- /**
- * @brief Get const reference to content object (content info + actual content)
- */
- inline const Content &
- getContent () const;
-
- /**
- * @brief Get reference to content object (content info + actual content)
- */
- inline Content &
- getContent ();
-
- /**
- * @brief Set content object (content info + actual content)
- * @param content reference to a content object
- *
- * More efficient way (that avoids copying):
- * @code
- * Content content (...);
- * getContent ().swap (content);
- * @endcode
- */
- inline void
- setContent (const Content &content);
-
- /**
- * @brief A helper method to directly access actual content data (const reference)
- *
- * This method is equivalent to
- * @code
- * getContent ().getContent ()
- * @endcode
- */
- inline const Blob &
- content () const;
-
- /**
- * @brief A helper method to directly access actual content data (reference)
- *
- * This method is equivalent to
- * @code
- * getContent ().getContent ()
- * @endcode
- */
- inline Blob &
- content ();
-
-private:
- Name m_name;
- ptr_lib::shared_ptr<Signature> m_signature; // signature with its parameters "binds" name and content
- Content m_content;
-
- ptr_lib::shared_ptr<SignedBlob> m_wire;
-};
-
-inline Data &
-Data::setName (const Name &name)
-{
- m_name = name;
- return *this;
-}
-
-inline const Name &
-Data::getName () const
-{
- return m_name;
-}
-
-inline Name &
-Data::getName ()
-{
- return m_name;
-}
-
-inline ptr_lib::shared_ptr<const Signature>
-Data::getSignature () const
-{
- return m_signature;
-}
-
-inline ptr_lib::shared_ptr<Signature>
-Data::getSignature ()
-{
- return m_signature;
-}
-
-inline void
-Data::setSignature (ptr_lib::shared_ptr<Signature> signature)
-{
- m_signature = signature;
-}
-
-inline const Content &
-Data::getContent () const
-{
- return m_content;
-}
-
-inline Content &
-Data::getContent ()
-{
- return m_content;
-}
-
-inline void
-Data::setContent (const Content &content)
-{
- m_content = content;
-}
-
-inline const Blob &
-Data::content () const
-{
- return getContent ().getContent ();
-}
-
-inline Blob &
-Data::content ()
-{
- return getContent ().getContent ();
-}
-
-} // namespace ndn
-
-#endif // NDN_DATA_H
diff --git a/ndn-cpp/encoding/base.h b/ndn-cpp/encoding/base.h
deleted file mode 100644
index 8247d09..0000000
--- a/ndn-cpp/encoding/base.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDN_WIRE_BASE_H
-#define NDN_WIRE_BASE_H
-
-#include "ndn-cpp/fields/signature-sha256-with-rsa.h"
-
-namespace ndn {
-namespace wire {
-
-/**
- * @brief Class defining interface for double dispatch pattern (=visitor pattern)
- * to format variable fields in wire format
- */
-class Base
-{
-public:
- virtual void
- appendSignature (std::ostream &os, const signature::Sha256WithRsa &signature, void *userData) = 0;
-};
-
-} // wire
-} // ndn
-
-#endif // NDN_WIRE_BASE_H
diff --git a/ndn-cpp/encoding/ccnb.cc b/ndn-cpp/encoding/ccnb.cc
deleted file mode 100644
index 86c3f5f..0000000
--- a/ndn-cpp/encoding/ccnb.cc
+++ /dev/null
@@ -1,259 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ccnb.h"
-#include "ndn-cpp/error.h"
-
-#include <boost/lexical_cast.hpp>
-
-namespace ndn {
-namespace wire {
-
-#define CCN_TT_BITS 3
-#define CCN_TT_MASK ((1 << CCN_TT_BITS) - 1)
-#define CCN_MAX_TINY ((1 << (7-CCN_TT_BITS)) - 1)
-#define CCN_TT_HBIT ((unsigned char)(1 << 7))
-
-void
-Ccnb::appendBlockHeader (std::ostream &os, size_t val, Ccnb::ccn_tt tt)
-{
- unsigned char buf[1+8*((sizeof(val)+6)/7)];
- unsigned char *p = &(buf[sizeof(buf)-1]);
- size_t n = 1;
- p[0] = (CCN_TT_HBIT & ~Ccnb::CCN_CLOSE_TAG) |
- ((val & CCN_MAX_TINY) << CCN_TT_BITS) |
- (CCN_TT_MASK & tt);
- val >>= (7-CCN_TT_BITS);
- while (val != 0) {
- (--p)[0] = (((unsigned char)val) & ~CCN_TT_HBIT) | Ccnb::CCN_CLOSE_TAG;
- n++;
- val >>= 7;
- }
- os.write (reinterpret_cast<const char*> (p), n);
- // return n;
-}
-
-void
-Ccnb::appendNumber (std::ostream &os, uint32_t number)
-{
- std::string numberStr = boost::lexical_cast<std::string> (number);
-
- appendBlockHeader (os, numberStr.size (), Ccnb::CCN_UDATA);
- numberStr.size ();
- os.write (numberStr.c_str (), numberStr.size ());
-}
-
-void
-Ccnb::appendName (std::ostream &os, const Name &name)
-{
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_Name, Ccnb::CCN_DTAG); // <Name>
- for (Name::const_iterator component = name.begin (); component != name.end (); component ++)
- {
- appendTaggedBlob (os, Ccnb::CCN_DTAG_Component, component->buf (), component->size ());
- }
- Ccnb::appendCloser (os); // </Name>
-}
-
-void
-Ccnb::appendTimestampBlob (std::ostream &os, const TimeInterval &time)
-{
- // CCNx method function implements some markers, which are not really defined anywhere else...
-
- // Determine miminal number of bytes required to store the timestamp
- int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough
- intmax_t ts = time.total_seconds () >> 4;
- for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
- required_bytes++;
-
- appendBlockHeader(os, required_bytes, Ccnb::CCN_BLOB);
-
- // write part with seconds
- ts = time.total_seconds () >> 4;
- for (int i = 0; i < required_bytes - 2; i++)
- os.put ( ts >> (8 * (required_bytes - 3 - i)) );
-
- /* arithmetic contortions are to avoid overflowing 31 bits */
- ts = ((time.total_seconds () & 15) << 12) +
- (((time.total_nanoseconds () % 1000000000) / 5 * 8 + 195312) / 390625);
- for (int i = required_bytes - 2; i < required_bytes; i++)
- os.put ( ts >> (8 * (required_bytes - 1 - i)) );
-
- // return len + required_bytes;
-}
-
-void
-Ccnb::appendExclude (std::ostream &os, const Exclude &exclude)
-{
- appendBlockHeader (os, Ccnb::CCN_DTAG_Exclude, Ccnb::CCN_DTAG); // <Exclude>
-
- for (Exclude::const_reverse_iterator item = exclude.rbegin (); item != exclude.rend (); item ++)
- {
- if (!item->first.empty ())
- appendTaggedBlob (os, Ccnb::CCN_DTAG_Component, item->first.buf (), item->first.size ());
- if (item->second)
- {
- appendBlockHeader (os, Ccnb::CCN_DTAG_Any, Ccnb::CCN_DTAG); // <Any>
- appendCloser (os); // </Any>
- }
- }
- appendCloser (os); // </Exclude>
-}
-
-void
-Ccnb::appendInterest (std::ostream &os, const Interest &interest)
-{
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_Interest, Ccnb::CCN_DTAG); // <Interest>
-
- // this is used for now as an interest template. Name should be empty
- // Ccnb::appendName (os, interest.getName ());
- Ccnb::appendName (os, Name ()); // <Component>...</Component>...
-
- if (interest.getMinSuffixComponents () != Interest::ncomps)
- {
- appendTaggedNumber (os, Ccnb::CCN_DTAG_MinSuffixComponents, interest.getMinSuffixComponents ());
- }
- if (interest.getMaxSuffixComponents () != Interest::ncomps)
- {
- appendTaggedNumber (os, Ccnb::CCN_DTAG_MaxSuffixComponents, interest.getMaxSuffixComponents ());
- }
- if (interest.getExclude ().size () > 0)
- {
- appendExclude (os, interest.getExclude ());
- }
- if (interest.getChildSelector () != Interest::CHILD_DEFAULT)
- {
- appendTaggedNumber (os, Ccnb::CCN_DTAG_ChildSelector, interest.getChildSelector ());
- }
- if (interest.getAnswerOriginKind () != Interest::AOK_DEFAULT)
- {
- appendTaggedNumber (os, Ccnb::CCN_DTAG_AnswerOriginKind, interest.getAnswerOriginKind ());
- }
- if (interest.getScope () != Interest::NO_SCOPE)
- {
- appendTaggedNumber (os, Ccnb::CCN_DTAG_Scope, interest.getScope ());
- }
- if (!interest.getInterestLifetime ().is_negative ())
- {
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_InterestLifetime, Ccnb::CCN_DTAG);
- Ccnb::appendTimestampBlob (os, interest.getInterestLifetime ());
- Ccnb::appendCloser (os);
- }
- // if (GetNonce()>0)
- // {
- // uint32_t nonce = interest.GetNonce();
- // appendTaggedBlob (start, Ccnb::CCN_DTAG_Nonce, nonce);
- // }
-
- // if (GetNack ()>0)
- // {
- // appendBlockHeader (start, Ccnb::CCN_DTAG_Nack, Ccnb::CCN_DTAG);
- // appendNumber (start, interest.GetNack ());
- // appendCloser (start);
- // }
- Ccnb::appendCloser (os); // </Interest>
-}
-
-static void *SIGNATURE_Block = 0;
-static void *SINATURE_INFO_PublisherPublicKeyDigest = reinterpret_cast<void *> (1);
-static void *SINATURE_INFO_KeyLocator = reinterpret_cast<void *> (2);
-
-static const char TYPES [][3] = {
- {0x0C, 0x04, 0xC0},
- {0x10, 0xD0, 0x91},
- {0x18, 0xE3, 0x44},
- {0x28, 0x46, 0x3F},
- {0x2C, 0x83, 0x4A},
- {0x34, 0x00, 0x8A}
-};
-
-void
-Ccnb::appendSignature (std::ostream &os, const signature::Sha256WithRsa &signature, void *userData)
-{
- if (userData == SIGNATURE_Block)
- {
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_Signature, Ccnb::CCN_DTAG); // <Signature>
- // if (signature.getDigestAlgorithm () != "2.16.840.1.101.3.4.2.1")
- // {
- // appendString (os, Ccnb::CCN_DTAG_DigestAlgorithm, signature.getDigestAlgorithm ());
- // }
- appendTaggedBlob (os, Ccnb::CCN_DTAG_SignatureBits, signature.getSignatureBits ());
- Ccnb::appendCloser (os); // </Signature>
- }
- else if (userData == SINATURE_INFO_PublisherPublicKeyDigest)
- {
- Ccnb::appendTaggedBlob (os, Ccnb::CCN_DTAG_PublisherPublicKeyDigest, signature.getPublisherKeyDigest ());
- }
- else if (userData == SINATURE_INFO_KeyLocator)
- {
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_Signature, Ccnb::CCN_DTAG); // <Signature>
- switch (signature.getKeyLocator ().getType ())
- {
- case KeyLocator::NOTSET:
- break;
- case KeyLocator::KEY:
- Ccnb::appendTaggedBlob (os, Ccnb::CCN_DTAG_Key, signature.getKeyLocator ().getKey ());
- break;
- case KeyLocator::CERTIFICATE:
- Ccnb::appendTaggedBlob (os, Ccnb::CCN_DTAG_Key, signature.getKeyLocator ().getCertificate ());
- break;
- case KeyLocator::KEYNAME:
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_KeyName, Ccnb::CCN_DTAG); // <KeyName>
- Ccnb::appendName (os, signature.getKeyLocator ().getKeyName ());
- Ccnb::appendCloser (os); // </KeyName>
- break;
- }
- Ccnb::appendCloser (os); // </Signature>
- }
- // other cases should not be possible, but don't do anything
-}
-
-void
-Ccnb::appendData (std::ostream &os, const Data &data)
-{
- if (!data.getSignature ())
- BOOST_THROW_EXCEPTION (error::wire::Ccnb ()
- << error::msg ("Signature is required, but not set"));
-
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_ContentObject, Ccnb::CCN_DTAG); // <ContentObject>
-
- // necessary for now, because of the changed storage order
- data.getSignature ()->doubleDispatch (os, *this, SIGNATURE_Block);
-
- Ccnb::appendName (os, data.getName ());
-
- Ccnb::appendBlockHeader (os, Ccnb::CCN_DTAG_SignedInfo, Ccnb::CCN_DTAG); // <SignedInfo>
- data.getSignature ()->doubleDispatch (os, *this, SINATURE_INFO_PublisherPublicKeyDigest);
-
- Ccnb::appendTimestampBlob (os, data.getContent ().getTimestamp ());
-
- BOOST_ASSERT (sizeof (TYPES) == 3 * (static_cast<int> (Content::NACK)+1));
- Ccnb::appendTaggedBlob (os, Ccnb::CCN_DTAG_Type, TYPES [data.getContent ().getType ()], 3);
-
- if (data.getContent ().getFreshness () != Content::noFreshness)
- {
- Ccnb::appendTaggedNumber (os, Ccnb::CCN_DTAG_FreshnessSeconds,
- data.getContent ().getFreshness ().total_seconds ());
- }
-
- if (data.getContent ().getFinalBlockId () != Content::noFinalBlock)
- {
- Ccnb::appendTaggedBlob (os, Ccnb::CCN_DTAG_FinalBlockID, data.getContent ().getFinalBlockId ());
- }
-
- data.getSignature ()->doubleDispatch (os, *this, SINATURE_INFO_KeyLocator);
- Ccnb::appendCloser (os); // </SignedInfo>
-
- Ccnb::appendTaggedBlob (os, Ccnb::CCN_DTAG_Content, data.content ());
-
- Ccnb::appendCloser (os); // </ContentObject>
-}
-
-} // namespace wire
-} // namespace ndn
diff --git a/ndn-cpp/encoding/ccnb.h b/ndn-cpp/encoding/ccnb.h
deleted file mode 100644
index fdc1b57..0000000
--- a/ndn-cpp/encoding/ccnb.h
+++ /dev/null
@@ -1,362 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDN_WIRE_CCNB_H
-#define NDN_WIRE_CCNB_H
-
-#include "base.h"
-
-#include "ndn-cpp/interest.h"
-#include "ndn-cpp/data.h"
-
-namespace ndn {
-namespace wire {
-
-/**
- * @brief Class for working with ccnb encoding
- */
-class Ccnb : public Base
-{
-public:
- /**
- * \brief Type tag for a ccnb start marker.
- *
- * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
- */
- enum ccn_tt {
- CCN_EXT, /**< starts composite extension - numval is subtype */
- CCN_TAG, /**< starts composite - numval is tagnamelen-1 */
- CCN_DTAG, /**< starts composite - numval is tagdict index (enum ccn_dtag) */
- CCN_ATTR, /**< attribute - numval is attrnamelen-1, value follows */
- CCN_DATTR, /**< attribute numval is attrdict index */
- CCN_BLOB, /**< opaque binary data - numval is byte count */
- CCN_UDATA, /**< UTF-8 encoded character data - numval is byte count */
- CCN_NO_TOKEN /**< should not occur in encoding */
- };
-
- /** \brief CCN_CLOSE_TAG terminates composites */
- enum {CCN_CLOSE_TAG = 0};
-
- /**
- * \brief DTAG identifies ccnb-encoded elements.
- *
- * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
- */
- enum ccn_dtag {
- CCN_DTAG_Any = 13,
- CCN_DTAG_Name = 14,
- CCN_DTAG_Component = 15,
- CCN_DTAG_Certificate = 16,
- CCN_DTAG_Collection = 17,
- CCN_DTAG_CompleteName = 18,
- CCN_DTAG_Content = 19,
- CCN_DTAG_SignedInfo = 20,
- CCN_DTAG_ContentDigest = 21,
- CCN_DTAG_ContentHash = 22,
- CCN_DTAG_Count = 24,
- CCN_DTAG_Header = 25,
- CCN_DTAG_Interest = 26, /* 20090915 */
- CCN_DTAG_Key = 27,
- CCN_DTAG_KeyLocator = 28,
- CCN_DTAG_KeyName = 29,
- CCN_DTAG_Length = 30,
- CCN_DTAG_Link = 31,
- CCN_DTAG_LinkAuthenticator = 32,
- CCN_DTAG_NameComponentCount = 33, /* DeprecatedInInterest */
- CCN_DTAG_RootDigest = 36,
- CCN_DTAG_Signature = 37,
- CCN_DTAG_Start = 38,
- CCN_DTAG_Timestamp = 39,
- CCN_DTAG_Type = 40,
- CCN_DTAG_Nonce = 41,
- CCN_DTAG_Scope = 42,
- CCN_DTAG_Exclude = 43,
- CCN_DTAG_Bloom = 44,
- CCN_DTAG_BloomSeed = 45,
- CCN_DTAG_AnswerOriginKind = 47,
- CCN_DTAG_InterestLifetime = 48,
- CCN_DTAG_Witness = 53,
- CCN_DTAG_SignatureBits = 54,
- CCN_DTAG_DigestAlgorithm = 55,
- CCN_DTAG_BlockSize = 56,
- CCN_DTAG_FreshnessSeconds = 58,
- CCN_DTAG_FinalBlockID = 59,
- CCN_DTAG_PublisherPublicKeyDigest = 60,
- CCN_DTAG_PublisherCertificateDigest = 61,
- CCN_DTAG_PublisherIssuerKeyDigest = 62,
- CCN_DTAG_PublisherIssuerCertificateDigest = 63,
- CCN_DTAG_ContentObject = 64, /* 20090915 */
- CCN_DTAG_WrappedKey = 65,
- CCN_DTAG_WrappingKeyIdentifier = 66,
- CCN_DTAG_WrapAlgorithm = 67,
- CCN_DTAG_KeyAlgorithm = 68,
- CCN_DTAG_Label = 69,
- CCN_DTAG_EncryptedKey = 70,
- CCN_DTAG_EncryptedNonceKey = 71,
- CCN_DTAG_WrappingKeyName = 72,
- CCN_DTAG_Action = 73,
- CCN_DTAG_FaceID = 74,
- CCN_DTAG_IPProto = 75,
- CCN_DTAG_Host = 76,
- CCN_DTAG_Port = 77,
- CCN_DTAG_MulticastInterface = 78,
- CCN_DTAG_ForwardingFlags = 79,
- CCN_DTAG_FaceInstance = 80,
- CCN_DTAG_ForwardingEntry = 81,
- CCN_DTAG_MulticastTTL = 82,
- CCN_DTAG_MinSuffixComponents = 83,
- CCN_DTAG_MaxSuffixComponents = 84,
- CCN_DTAG_ChildSelector = 85,
- CCN_DTAG_RepositoryInfo = 86,
- CCN_DTAG_Version = 87,
- CCN_DTAG_RepositoryVersion = 88,
- CCN_DTAG_GlobalPrefix = 89,
- CCN_DTAG_LocalName = 90,
- CCN_DTAG_Policy = 91,
- CCN_DTAG_Namespace = 92,
- CCN_DTAG_GlobalPrefixName = 93,
- CCN_DTAG_PolicyVersion = 94,
- CCN_DTAG_KeyValueSet = 95,
- CCN_DTAG_KeyValuePair = 96,
- CCN_DTAG_IntegerValue = 97,
- CCN_DTAG_DecimalValue = 98,
- CCN_DTAG_StringValue = 99,
- CCN_DTAG_BinaryValue = 100,
- CCN_DTAG_NameValue = 101,
- CCN_DTAG_Entry = 102,
- CCN_DTAG_ACL = 103,
- CCN_DTAG_ParameterizedName = 104,
- CCN_DTAG_Prefix = 105,
- CCN_DTAG_Suffix = 106,
- CCN_DTAG_Root = 107,
- CCN_DTAG_ProfileName = 108,
- CCN_DTAG_Parameters = 109,
- CCN_DTAG_InfoString = 110,
- CCN_DTAG_StatusResponse = 112,
- CCN_DTAG_StatusCode = 113,
- CCN_DTAG_StatusText = 114,
- CCN_DTAG_SyncNode = 115,
- CCN_DTAG_SyncNodeKind = 116,
- CCN_DTAG_SyncNodeElement = 117,
- CCN_DTAG_SyncVersion = 118,
- CCN_DTAG_SyncNodeElements = 119,
- CCN_DTAG_SyncContentHash = 120,
- CCN_DTAG_SyncLeafCount = 121,
- CCN_DTAG_SyncTreeDepth = 122,
- CCN_DTAG_SyncByteCount = 123,
- CCN_DTAG_SyncConfigSlice = 124,
- CCN_DTAG_SyncConfigSliceList = 125,
- CCN_DTAG_SyncConfigSliceOp = 126,
- CCN_DTAG_SyncNodeDeltas = 127,
- CCN_DTAG_SequenceNumber = 256,
- CCN_DTAG_CCNProtocolDataUnit = 17702112
- };
-
-
- /**
- * @brief Append CCNB block header
- * @param os output stream to write
- * @param value dictionary id of the block header
- * @param block_type Type of CCNB block
- */
- static void
- appendBlockHeader (std::ostream &os, size_t value, ccn_tt block_type);
-
- /**
- * @brief Add number in CCNB encoding
- * @param os output stream to write
- * @param number Number to be written
- *
- * @returns written length
- */
- static void
- appendNumber (std::ostream &os, uint32_t number);
-
- /**
- * @brief Append CCNB closer tag (size is 1)
- * @param os output stream to write
- */
- inline static void
- appendCloser (std::ostream &os);
-
- /**
- * @brief Append Name in CCNB encoding
- * @param os output stream to write
- * @param name constant reference to Name object
- *
- * @returns written length
- */
- static void
- appendName (std::ostream &os, const Name &name);
-
- /**
- * Append a binary timestamp as a BLOB using the ccn binary
- * Timestamp representation (12-bit fraction).
- *
- * @param os output stream to write
- * @param time reference to time duration object
- */
- static void
- appendTimestampBlob (std::ostream &os, const TimeInterval ×tamp);
-
- /**
- * Append a binary timestamp as a BLOB using the ccn binary
- * Timestamp representation (12-bit fraction).
- *
- * @param os output stream to write
- * @param time reference to Time (posix_time::ptime) object.
- * This method automatically calculates duration between time and gregorian::date(1970,1,1)
- * and calls the other version of the method
- */
- inline static void
- appendTimestampBlob (std::ostream &os, const Time &time);
-
- /**
- * Append a tagged BLOB
- *
- * This is a ccnb-encoded element with containing the BLOB as content
- *
- * @param os output stream to write
- * @param dtag is the element's dtag
- * @param data points to the binary data
- * @param size is the size of the data, in bytes
- */
- inline static void
- appendTaggedBlob (std::ostream &os, ccn_dtag dtag, const void *data, size_t size);
-
- /**
- * Append a tagged BLOB
- *
- * This is a ccnb-encoded element with containing the BLOB as content
- *
- * @param os output stream to write
- * @param dtag is the element's dtag
- * @param blob reference to the data blob
- */
- inline static void
- appendTaggedBlob (std::ostream &os, ccn_dtag dtag, const Blob &blob);
-
- /**
- * Append a tagged BLOB
- *
- * This is a ccnb-encoded element with containing the BLOB as content
- *
- * @param os output stream to write
- * @param dtag is the element's dtag
- * @param data points to the binary data
- * @param size is the size of the data, in bytes
- */
- inline static void
- appendTaggedNumber (std::ostream &os, ccn_dtag dtag, uint32_t number);
-
- /**
- * Append a tagged string (should be a valid UTF-8 coded string)
- *
- * This is a ccnb-encoded element with containing UDATA as content
- *
- * @param os output stream to write
- * @param dtag is the element's dtag
- * @param string UTF-8 string to be written
- */
- inline static void
- appendString (std::ostream &os, ccn_dtag dtag, const std::string &string);
-
- /**
- * @brief Format interest in CCNb encoding
- * @param os output stream to write
- * @param interest Interest to be formatted
- *
- * @todo For now, this method is used to create Interest template, which doesn't output name to the stream
- */
- static void
- appendInterest (std::ostream &os, const Interest &interest);
-
- /**
- * @brief Append exclude filter in CCNb encoding
- * @param os output stream to write
- * @param exclude Exclude filter to be formatted
- */
- static void
- appendExclude (std::ostream &os, const Exclude &exclude);
-
- /**
- * @brief Append signature in SHA256withRSA format
- */
- virtual void
- appendSignature (std::ostream &os, const signature::Sha256WithRsa &signature, void *userData);
-
- /**
- * @brief Format data in CCNb encoding
- * @param os output stream to write
- * @param data data to be formatted
- */
- void
- appendData (std::ostream &os, const Data &data);
-};
-
-
-inline void
-Ccnb::appendCloser (std::ostream &os)
-{
- os.put (Ccnb::CCN_CLOSE_TAG);
-}
-
-inline void
-Ccnb::appendTimestampBlob (std::ostream &os, const Time &time)
-{
- appendTimestampBlob (os, time - time::UNIX_EPOCH_TIME);
-}
-
-inline void
-Ccnb::appendTaggedBlob (std::ostream &os, Ccnb::ccn_dtag dtag, const void *data, size_t size)
-{
- appendBlockHeader (os, dtag, Ccnb::CCN_DTAG);
- /* 2 */
- if (size>0)
- {
- appendBlockHeader (os, size, Ccnb::CCN_BLOB);
- os.write (reinterpret_cast<const char*> (data), size);
- /* size */
- }
- appendCloser (os);
- /* 1 */
-}
-
-inline void
-Ccnb::appendTaggedBlob (std::ostream &os, ccn_dtag dtag, const Blob &blob)
-{
- appendTaggedBlob (os, dtag, blob.buf (), blob.size ());
-}
-
-inline void
-Ccnb::appendTaggedNumber (std::ostream &os, Ccnb::ccn_dtag dtag, uint32_t number)
-{
- appendBlockHeader (os, dtag, Ccnb::CCN_DTAG);
- {
- appendNumber (os, number);
- }
- appendCloser (os);
-}
-
-inline void
-Ccnb::appendString (std::ostream &os, Ccnb::ccn_dtag dtag, const std::string &string)
-{
- appendBlockHeader (os, dtag, Ccnb::CCN_DTAG);
- {
- appendBlockHeader (os, string.size (), Ccnb::CCN_UDATA);
- os.write (string.c_str (), string.size ());
- }
- appendCloser (os);
-}
-
-} // wire
-} // ndn
-
-#endif // NDN_WIRE_CCNB_H
diff --git a/ndn-cpp/interest.cc b/ndn-cpp/interest.cc
deleted file mode 100644
index 020a0ef..0000000
--- a/ndn-cpp/interest.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- * Zhenkai Zhu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#include "interest.h"
-#include <boost/lexical_cast.hpp>
-
-using namespace std;
-
-namespace ndn {
-
-Interest::Interest ()
- // m_name
- : m_maxSuffixComponents (Interest::ncomps)
- , m_minSuffixComponents (Interest::ncomps)
- , m_answerOriginKind (AOK_DEFAULT)
- , m_interestLifetime (time::Seconds (-1.0))
- , m_scope (NO_SCOPE)
- , m_childSelector (CHILD_DEFAULT)
- // m_publisherKeyDigest
-{
-}
-
-Interest::Interest (const Name &name)
- : m_name (name)
- , m_maxSuffixComponents (Interest::ncomps)
- , m_minSuffixComponents (Interest::ncomps)
- , m_answerOriginKind(AOK_DEFAULT)
- , m_interestLifetime (time::Seconds (-1.0))
- , m_scope (NO_SCOPE)
- , m_childSelector (CHILD_DEFAULT)
- // m_publisherKeyDigest
-{
-}
-
-Interest::Interest (const Interest &other)
-{
- m_name = other.m_name;
- m_maxSuffixComponents = other.m_maxSuffixComponents;
- m_minSuffixComponents = other.m_minSuffixComponents;
- m_answerOriginKind = other.m_answerOriginKind;
- m_interestLifetime = other.m_interestLifetime;
- m_scope = other.m_scope;
- m_childSelector = other.m_childSelector;
- m_publisherPublicKeyDigest = other.m_publisherPublicKeyDigest;
-}
-
-bool
-Interest::operator == (const Interest &other)
-{
- return
- m_name == other.m_name
- && m_maxSuffixComponents == other.m_maxSuffixComponents
- && m_minSuffixComponents == other.m_minSuffixComponents
- && m_answerOriginKind == other.m_answerOriginKind
- && m_interestLifetime == other.m_interestLifetime
- && m_scope == other.m_scope
- && m_childSelector == other.m_childSelector;
-}
-
-} // ndn
diff --git a/ndn-cpp/interest.h b/ndn-cpp/interest.h
deleted file mode 100644
index ace9847..0000000
--- a/ndn-cpp/interest.h
+++ /dev/null
@@ -1,451 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- * Zhenkai Zhu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#ifndef NDN_INTEREST_H
-#define NDN_INTEREST_H
-
-#include <ndn-cpp/common.h>
-#include <ndn-cpp/fields/name.h>
-#include <ndn-cpp/fields/exclude.h>
-#include <ndn-cpp/helpers/hash.h>
-
-namespace ndn {
-
-class Interest;
-/**
- * @brief Class abstracting operations with Interests (constructing and getting access to Interest fields)
- */
-class Interest
-{
-public:
- /**
- * @brief Default constructor, creates an interest for / prefix without any selectors
- */
- Interest ();
-
- /**
- * @brief Create an interest for the name
- * @param name name of the data to request
- */
- Interest (const Name &name);
-
- /**
- * @brief Copy constructor
- * @param interest interest to copy
- */
- Interest (const Interest &interest);
-
- /**
- * @brief Set interest name
- * @param name name of the interest
- * @return reference to self (to allow method chaining)
- *
- * In some cases, a direct access to and manipulation of name using getName is more efficient
- */
- inline Interest &
- setName (const Name &name);
-
- /**
- * @brief Get interest name (const reference)
- * @returns name of the interest
- */
- inline const Name &
- getName () const;
-
- /**
- * @brief Get interest name (reference)
- * @returns name of the interest
- */
- inline Name &
- getName ();
-
- /**
- * @brief Set interest lifetime (time_duration)
- * @param interestLifetime interest lifetime specified as a time_duration value.
- * Negative value means that InterestLifetime is not set.
- * @return reference to self (to allow method chaining)
- */
- inline Interest &
- setInterestLifetime (const TimeInterval &interestLifetime);
-
- /**
- * @brief Set interest lifetime (double)
- * @param interestLifetime interest lifetime expressed in seconds, with possible fractional seconds (double).
- * Negative value means that InterestLifetime is not set.
- * @return reference to self (to allow method chaining)
- */
- inline Interest &
- setInterestLifetime (double interestLifetimeSeconds);
-
- /**
- * @brief Get interest lifetime
- * @return TimeInterval representing lifetime of the interest.
- * Use time_duration::total_seconds () or time_duration::total_microseconds (),
- * if you need interest lifetime as a plain number.
- * @see http://www.boost.org/doc/libs/1_53_0/doc/html/date_time/posix_time.html
- */
- inline const TimeInterval &
- getInterestLifetime () const;
-
- /**
- * @brief Set intended interest scope
- * @param scope requested scope of the interest @see Scope
- * @return reference to self (to allow method chaining)
- */
- inline Interest &
- setScope (uint8_t scope);
-
- /**
- * @brief Get intended interest scope
- * @return intended interest scope @see Scope
- */
- inline uint8_t
- getScope () const;
-
- ///////////////////////////////////////////////////////////////////////
- // SELECTORS //
- ///////////////////////////////////////////////////////////////////////
-
- /**
- * @brief Enum defining constants for AnswerOriginKind selector field
- */
- enum AnswerOriginKind
- {
- AOK_CS = 0x1, ///< @brief request item from the content store
- AOK_NEW = 0x2, ///< @brief request item from the original producer
- AOK_DEFAULT = 0x3, ///< @brief default: either from content store or original producer
- AOK_STALE = 0x4, ///< @brief Allow stale data
- AOK_EXPIRE = 0x10 ///< @brief Allow expired data (?)
- };
-
- /**
- * @brief Enum defining constants for ChildSelector field
- */
- enum ChildSelector
- {
- CHILD_LEFT = 0, ///< @brief request left child
- CHILD_RIGHT = 1, ///< @brief request right child
- CHILD_DEFAULT = 2 ///< @brief do not specify which child is requested
- };
-
- /**
- * @brief Enum defining constants for Scope field
- */
- enum Scope
- {
- NO_SCOPE = 255, ///< @brief Interest scope is not defined
- SCOPE_LOCAL_CCND = 0, ///< @brief Interest scope is only toward local NDN daemon
- SCOPE_LOCAL_HOST = 1, ///< @brief Interest scope is within local host (any local application only)
- SCOPE_NEXT_HOST = 2 ///< @brief Interest scope is within local host and immediate neighboring node
- };
-
- /**
- * @brief Set interest selector for maximum suffix components
- * @param maxSuffixComponents maximum number of suffix components. If Interest::ncomps, then not restricted
- * @return reference to self (to allow method chaining)
- */
- inline Interest &
- setMaxSuffixComponents (uint32_t maxSuffixComponents);
-
- /**
- * \brief Get interest selector for maximum suffix components
- *
- * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
- * and counting the implicit digest, that may occur in the matching ContentObject.
- * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
- **/
- inline uint32_t
- getMaxSuffixComponents () const;
-
- /**
- * @brief Set interest selector for minimum suffix components
- * @param minSuffixComponents minimum number of suffix components. If Interest::ncomps, then not restricted
- * @return reference to self (to allow method chaining)
- */
- inline Interest &
- setMinSuffixComponents (uint32_t minSuffixComponents);
-
- /**
- * \brief Get interest selector for minimum suffix components
- *
- * MinSuffixComponents refer to the number of name components beyond those in the prefix,
- * and counting the implicit digest, that may occur in the matching ContentObject.
- * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
- **/
- inline uint32_t
- getMinSuffixComponents () const;
-
- /**
- * @brief Set interest selector for answer origin kind
- * @param answerOriginKind type of answer @see AnswerOriginKind
- * @return reference to self (to allow method chaining)
- */
- inline Interest &
- setAnswerOriginKind (uint32_t answerOriginKind);
-
- /**
- * @brief Get interest selector for answer origin kind
- */
- inline uint32_t
- getAnswerOriginKind () const;
-
- /**
- * @brief Set interest selector for child selector
- * @param child child selector @see ChildSelector
- * @return reference to self (to allow method chaining)
- *
- * Often a given interest will match more than one ContentObject within a given content store.
- * The ChildSelector provides a way of expressing a preference for which of these should be returned.
- * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred.
- * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
- */
- inline Interest &
- setChildSelector (uint8_t child);
-
- /**
- * @brief Get interest selector for child selector
- */
- inline uint8_t
- getChildSelector () const;
-
- /**
- * @brief Set interest selector for publisher public key digest
- * @param digest publisher public key digest
- * @return reference to self (to allow method chaining)
- *
- * Currently, this method has no effect
- * @todo Implement PublisherPublicKeyDigest
- */
- inline Interest &
- setPublisherPublicKeyDigest(const Hash &digest);
-
- /**
- * @brief Get interest selector for publisher public key digest
- *
- * @todo Implement
- */
- inline const Hash&
- getPublisherPublicKeyDigest () const;
-
- /**
- * @brief Set exclude filter
- * @param exclude An exclude filter to set
- *
- * In some cases, a direct access to and manipulation of exclude filter using getExclude is more efficient
- */
- inline void
- setExclude (const Exclude &exclude);
-
- /**
- * @brief Get exclude filter (const reference)
- */
- inline const Exclude &
- getExclude () const;
-
- /**
- * @brief Get exclude filter (reference)
- */
- inline Exclude &
- getExclude ();
-
- ///////////////////////////////////////////////////////////////////////
- // HELPERS //
- ///////////////////////////////////////////////////////////////////////
-
- /**
- * @brief Compare equality of two interests
- */
- bool
- operator== (const Interest &interest);
-
-public:
- // Data Members (public):
- /// @brief Value indicating that number of components parameter is invalid
- const static uint32_t ncomps = static_cast<uint32_t> (-1);
-
-private:
- Name m_name;
- uint32_t m_maxSuffixComponents;
- uint32_t m_minSuffixComponents;
- uint32_t m_answerOriginKind;
- TimeInterval m_interestLifetime; // lifetime in seconds
-
- uint8_t m_scope;
- uint8_t m_childSelector;
- // not used now
- Hash m_publisherPublicKeyDigest;
- Exclude m_exclude;
-
- ptr_lib::shared_ptr<Blob> m_wire;
-};
-
-namespace Error
-{
-/**
- * @brief Exception that is thrown in case of error during interest construction or parsing
- */
-struct Interest:
- virtual boost::exception, virtual std::exception {};
-}
-
-
-
-inline Interest &
-Interest::setName (const Name &name)
-{
- m_name = name;
- return *this;
-}
-
-inline const Name &
-Interest::getName () const
-{
- return m_name;
-}
-
-inline Name &
-Interest::getName ()
-{
- return m_name;
-}
-
-inline Interest &
-Interest::setInterestLifetime (const TimeInterval &interestLifetime)
-{
- m_interestLifetime = interestLifetime;
- return *this;
-}
-
-inline Interest &
-Interest::setInterestLifetime (double interestLifetimeSeconds)
-{
- m_interestLifetime = time::Seconds (interestLifetimeSeconds);
- return *this;
-}
-
-inline const TimeInterval &
-Interest::getInterestLifetime () const
-{
- return m_interestLifetime;
-}
-
-inline Interest &
-Interest::setScope (uint8_t scope)
-{
- m_scope = scope;
- return *this;
-}
-
-inline uint8_t
-Interest::getScope () const
-{
- return m_scope;
-}
-
-///////////////////////////////////////////////////////////////////////
-// SELECTORS //
-///////////////////////////////////////////////////////////////////////
-
-
-inline Interest &
-Interest::setMaxSuffixComponents (uint32_t maxSuffixComponents)
-{
- m_maxSuffixComponents = maxSuffixComponents;
- return *this;
-}
-
-inline uint32_t
-Interest::getMaxSuffixComponents () const
-{
- return m_maxSuffixComponents;
-}
-
-inline Interest &
-Interest::setMinSuffixComponents (uint32_t minSuffixComponents)
-{
- m_minSuffixComponents = minSuffixComponents;
- return *this;
-}
-
-inline uint32_t
-Interest::getMinSuffixComponents () const
-{
- return m_minSuffixComponents;
-}
-
-inline Interest &
-Interest::setAnswerOriginKind (uint32_t answerOriginKind)
-{
- m_answerOriginKind = answerOriginKind;
- return *this;
-}
-
-inline uint32_t
-Interest::getAnswerOriginKind () const
-{
- return m_answerOriginKind;
-}
-
-inline Interest &
-Interest::setChildSelector (uint8_t childSelector)
-{
- m_childSelector = childSelector;
- return *this;
-}
-
-inline uint8_t
-Interest::getChildSelector () const
-{
- return m_childSelector;
-}
-
-inline Interest &
-Interest::setPublisherPublicKeyDigest(const Hash &publisherPublicKeyDigest)
-{
- m_publisherPublicKeyDigest = publisherPublicKeyDigest;
- return *this;
-}
-
-inline const Hash&
-Interest::getPublisherPublicKeyDigest () const
-{
- return m_publisherPublicKeyDigest;
-}
-
-inline void
-Interest::setExclude (const Exclude &exclude)
-{
- m_exclude = exclude;
-}
-
-/**
- * @brief Get exclude filter (const reference)
- */
-inline const Exclude &
-Interest::getExclude () const
-{
- return m_exclude;
-}
-
-/**
- * @brief Get exclude filter (reference)
- */
-inline Exclude &
-Interest::getExclude ()
-{
- return m_exclude;
-}
-
-
-} // ndn
-
-#endif // NDN_INTEREST_H