Browse Source

Code style: Put function return type on a line by itself.

pull/1/head
Jeff Thompson 12 years ago
parent
commit
0050abe882
  1. 3
      ndn-cpp/common.cpp
  2. 3
      ndn-cpp/common.hpp
  3. 21
      ndn-cpp/data.cpp
  4. 110
      ndn-cpp/data.hpp
  5. 3
      ndn-cpp/encoding/binary-xml-decoder.hpp
  6. 3
      ndn-cpp/encoding/binary-xml-element-reader.cpp
  7. 6
      ndn-cpp/encoding/binary-xml-element-reader.hpp
  8. 3
      ndn-cpp/encoding/binary-xml-encoder.hpp
  9. 10
      ndn-cpp/encoding/binary-xml-structure-decoder.hpp
  10. 21
      ndn-cpp/encoding/binary-xml-wire-format.cpp
  11. 18
      ndn-cpp/encoding/binary-xml-wire-format.hpp
  12. 26
      ndn-cpp/encoding/wire-format.cpp
  13. 33
      ndn-cpp/encoding/wire-format.hpp
  14. 6
      ndn-cpp/face.cpp
  15. 18
      ndn-cpp/face.hpp
  16. 6
      ndn-cpp/forwarding-entry.cpp
  17. 56
      ndn-cpp/forwarding-entry.hpp
  18. 15
      ndn-cpp/interest.cpp
  19. 107
      ndn-cpp/interest.hpp
  20. 6
      ndn-cpp/key.cpp
  21. 41
      ndn-cpp/key.hpp
  22. 39
      ndn-cpp/name.cpp
  23. 54
      ndn-cpp/name.hpp
  24. 36
      ndn-cpp/node.cpp
  25. 54
      ndn-cpp/node.hpp
  26. 22
      ndn-cpp/publisher-public-key-digest.hpp
  27. 3
      ndn-cpp/security/identity/identity-manager.cpp
  28. 3
      ndn-cpp/security/identity/identity-manager.hpp
  29. 12
      ndn-cpp/security/key-chain.cpp
  30. 12
      ndn-cpp/security/key-chain.hpp
  31. 9
      ndn-cpp/sha256-with-rsa-signature.cpp
  32. 62
      ndn-cpp/sha256-with-rsa-signature.hpp
  33. 15
      ndn-cpp/transport/tcp-transport.cpp
  34. 9
      ndn-cpp/transport/tcp-transport.hpp
  35. 15
      ndn-cpp/transport/transport.cpp
  36. 18
      ndn-cpp/transport/transport.hpp
  37. 15
      ndn-cpp/transport/udp-transport.cpp
  38. 24
      ndn-cpp/transport/udp-transport.hpp
  39. 6
      ndn-cpp/util/blob.hpp
  40. 3
      ndn-cpp/util/changed-event.cpp
  41. 6
      ndn-cpp/util/changed-event.hpp
  42. 3
      ndn-cpp/util/dynamic-uchar-vector.cpp
  43. 6
      ndn-cpp/util/dynamic-uchar-vector.hpp
  44. 12
      ndn-cpp/util/signed-blob.hpp

3
ndn-cpp/common.cpp

@ -11,7 +11,8 @@ using namespace std;
namespace ndn {
string toHex(const vector<unsigned char>& array)
string
toHex(const vector<unsigned char>& array)
{
if (!&array)
return "";

3
ndn-cpp/common.hpp

@ -56,7 +56,8 @@ namespace ndn {
* @param array The array of bytes.
* @return Hex string.
*/
std::string toHex(const std::vector<unsigned char>& array);
std::string
toHex(const std::vector<unsigned char>& array);
}

21
ndn-cpp/data.cpp

@ -16,7 +16,8 @@ Signature::~Signature()
{
}
void MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
void
MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
{
metaInfoStruct.timestampMilliseconds = timestampMilliseconds_;
metaInfoStruct.type = type_;
@ -24,7 +25,8 @@ void MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
finalBlockID_.get(metaInfoStruct.finalBlockID);
}
void MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
void
MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
{
timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds;
type_ = metaInfoStruct.type;
@ -42,7 +44,8 @@ Data::Data(const Name& name)
{
}
void Data::get(struct ndn_Data& dataStruct) const
void
Data::get(struct ndn_Data& dataStruct) const
{
signature_->get(dataStruct.signature);
name_.get(dataStruct.name);
@ -55,7 +58,8 @@ void Data::get(struct ndn_Data& dataStruct) const
dataStruct.content = 0;
}
void Data::set(const struct ndn_Data& dataStruct)
void
Data::set(const struct ndn_Data& dataStruct)
{
signature_->set(dataStruct.signature);
name_.set(dataStruct.name);
@ -65,7 +69,8 @@ void Data::set(const struct ndn_Data& dataStruct)
onChanged();
}
SignedBlob Data::wireEncode(WireFormat& wireFormat)
SignedBlob
Data::wireEncode(WireFormat& wireFormat)
{
unsigned int signedPortionBeginOffset, signedPortionEndOffset;
Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
@ -74,7 +79,8 @@ SignedBlob Data::wireEncode(WireFormat& wireFormat)
return wireEncoding_;
}
void Data::wireDecode(const unsigned char* input, unsigned int inputLength, WireFormat& wireFormat)
void
Data::wireDecode(const unsigned char* input, unsigned int inputLength, WireFormat& wireFormat)
{
unsigned int signedPortionBeginOffset, signedPortionEndOffset;
wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset);
@ -82,7 +88,8 @@ void Data::wireDecode(const unsigned char* input, unsigned int inputLength, Wire
wireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
}
void Data::onChanged()
void
Data::onChanged()
{
wireEncoding_ = SignedBlob();
}

110
ndn-cpp/data.hpp

@ -24,12 +24,14 @@ public:
* Return a pointer to a new Signature which is a copy of this signature.
* This is pure virtual, the subclass must implement it.
*/
virtual ptr_lib::shared_ptr<Signature> clone() const = 0;
virtual ptr_lib::shared_ptr<Signature>
clone() const = 0;
/**
* The virtual destructor.
*/
virtual ~Signature();
virtual
~Signature();
/**
* Set the signatureStruct to point to the values in this signature object, without copying any memory.
@ -37,14 +39,16 @@ public:
* This is pure virtual, the subclass must implement it.
* @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
*/
virtual void get(struct ndn_Signature& signatureStruct) const = 0;
virtual void
get(struct ndn_Signature& signatureStruct) const = 0;
/**
* Clear this signature, and set the values by copying from the ndn_Signature struct.
* This is pure virtual, the subclass must implement it.
* @param signatureStruct a C ndn_Signature struct
*/
virtual void set(const struct ndn_Signature& signatureStruct) = 0;
virtual void
set(const struct ndn_Signature& signatureStruct) = 0;
};
/**
@ -63,30 +67,42 @@ public:
* WARNING: The resulting pointers in metaInfoStruct are invalid after a further use of this object which could reallocate memory.
* @param metaInfoStruct a C ndn_MetaInfo struct where the name components array is already allocated.
*/
void get(struct ndn_MetaInfo& metaInfoStruct) const;
void
get(struct ndn_MetaInfo& metaInfoStruct) const;
/**
* Clear this meta info, and set the values by copying from the ndn_MetaInfo struct.
* @param metaInfoStruct a C ndn_MetaInfo struct
*/
void set(const struct ndn_MetaInfo& metaInfoStruct);
void
set(const struct ndn_MetaInfo& metaInfoStruct);
double getTimestampMilliseconds() const { return timestampMilliseconds_; }
double
getTimestampMilliseconds() const { return timestampMilliseconds_; }
ndn_ContentType getType() const { return type_; }
ndn_ContentType
getType() const { return type_; }
int getFreshnessSeconds() const { return freshnessSeconds_; }
int
getFreshnessSeconds() const { return freshnessSeconds_; }
const Name::Component& getFinalBlockID() const { return finalBlockID_; }
const Name::Component&
getFinalBlockID() const { return finalBlockID_; }
void setTimestampMilliseconds(double timestampMilliseconds) { timestampMilliseconds_ = timestampMilliseconds; }
void
setTimestampMilliseconds(double timestampMilliseconds) { timestampMilliseconds_ = timestampMilliseconds; }
void setType(ndn_ContentType type) { type_ = type; }
void
setType(ndn_ContentType type) { type_ = type; }
void setFreshnessSeconds(int freshnessSeconds) { freshnessSeconds_ = freshnessSeconds; }
void
setFreshnessSeconds(int freshnessSeconds) { freshnessSeconds_ = freshnessSeconds; }
void setFinalBlockID(const std::vector<unsigned char>& finalBlockID) { finalBlockID_ = Name::Component(finalBlockID); }
void setFinalBlockID(const unsigned char* finalBlockID, unsigned int finalBlockIdLength)
void
setFinalBlockID(const std::vector<unsigned char>& finalBlockID) { finalBlockID_ = Name::Component(finalBlockID); }
void
setFinalBlockID(const unsigned char* finalBlockID, unsigned int finalBlockIdLength)
{
finalBlockID_ = Name::Component(finalBlockID, finalBlockIdLength);
}
@ -117,7 +133,8 @@ public:
* @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
* @return The encoded byte array.
*/
SignedBlob wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
SignedBlob
wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
/**
* Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input.
@ -125,14 +142,16 @@ public:
* @param inputLength The length of input.
* @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat().
*/
void wireDecode(const unsigned char* input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
void
wireDecode(const unsigned char* input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
/**
* Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input.
* @param input The input byte array to be decoded.
* @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat().
*/
void wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
void
wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
{
wireDecode(&input[0], input.size(), wireFormat);
}
@ -142,45 +161,58 @@ public:
* WARNING: The resulting pointers in dataStruct are invalid after a further use of this object which could reallocate memory.
* @param dataStruct a C ndn_Data struct where the name components array is already allocated.
*/
void get(struct ndn_Data& dataStruct) const;
void
get(struct ndn_Data& dataStruct) const;
/**
* Clear this data object, and set the values by copying from the ndn_Data struct.
* @param dataStruct a C ndn_Data struct
*/
void set(const struct ndn_Data& dataStruct);
void
set(const struct ndn_Data& dataStruct);
const Signature* getSignature() const { return signature_.get(); }
Signature* getSignature()
const Signature*
getSignature() const { return signature_.get(); }
Signature*
getSignature()
{
// TODO: Should add an OnChanged listener instead of always calling onChanged.
onChanged();
return signature_.get();
}
const Name& getName() const { return name_; }
Name& getName()
const Name&
getName() const { return name_; }
Name&
getName()
{
// TODO: Should add an OnChanged listener instead of always calling onChanged.
onChanged();
return name_;
}
const MetaInfo& getMetaInfo() const { return metaInfo_; }
MetaInfo& getMetaInfo()
const MetaInfo&
getMetaInfo() const { return metaInfo_; }
MetaInfo&
getMetaInfo()
{
// TODO: Should add an OnChanged listener instead of always calling onChanged.
onChanged();
return metaInfo_;
}
const Blob& getContent() const { return content_; }
const Blob&
getContent() const { return content_; }
/**
* Set the signature to a copy of the given signature.
* @param signature The signature object which is cloned.
*/
void setSignature(const Signature& signature)
void
setSignature(const Signature& signature)
{
signature_ = signature.clone();
onChanged();
@ -190,7 +222,8 @@ public:
* Set name to a copy of the given Name.
* @param name The Name which is copied.
*/
void setName(const Name& name)
void
setName(const Name& name)
{
name_ = name;
onChanged();
@ -200,7 +233,8 @@ public:
* Set metaInfo to a copy of the given MetaInfo.
* @param metaInfo The MetaInfo which is copied.
*/
void setMetainfo(const MetaInfo& metaInfo)
void
setMetainfo(const MetaInfo& metaInfo)
{
metaInfo_ = metaInfo;
onChanged();
@ -210,12 +244,14 @@ public:
* Set the content to a copy of the data in the vector.
* @param content A vector whose contents are copied.
*/
void setContent(const std::vector<unsigned char>& content)
void
setContent(const std::vector<unsigned char>& content)
{
content_ = content;
onChanged();
}
void setContent(const unsigned char* content, unsigned int contentLength)
void
setContent(const unsigned char* content, unsigned int contentLength)
{
content_ = Blob(content, contentLength);
onChanged();
@ -226,12 +262,15 @@ public:
* if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
* @param content A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
*/
void setContent(const ptr_lib::shared_ptr<std::vector<unsigned char> > &content)
void
setContent(const ptr_lib::shared_ptr<std::vector<unsigned char> > &content)
{
content_ = content;
onChanged();
}
void setContent(const ptr_lib::shared_ptr<const std::vector<unsigned char> > &content)
void
setContent(const ptr_lib::shared_ptr<const std::vector<unsigned char> > &content)
{
content_ = content;
onChanged();
@ -241,7 +280,8 @@ private:
/**
* Clear the wire encoding.
*/
void onChanged();
void
onChanged();
ptr_lib::shared_ptr<Signature> signature_;
Name name_;

3
ndn-cpp/encoding/binary-xml-decoder.hpp

@ -33,7 +33,8 @@ public:
* @param expectedTag the expected value for DTAG
* @return true if got the expected tag, else false
*/
bool peekDTag(unsigned int expectedTag)
bool
peekDTag(unsigned int expectedTag)
{
int gotExpectedTag;
ndn_Error error;

3
ndn-cpp/encoding/binary-xml-element-reader.cpp

@ -8,7 +8,8 @@
namespace ndn {
void ElementListener::staticOnReceivedElement(struct ndn_ElementListener *self, unsigned char *element, unsigned int elementLength)
void
ElementListener::staticOnReceivedElement(struct ndn_ElementListener *self, unsigned char *element, unsigned int elementLength)
{
((ElementListener *)self)->onReceivedElement(element, elementLength);
}

6
ndn-cpp/encoding/binary-xml-element-reader.hpp

@ -28,7 +28,8 @@ public:
* later, you must copy.
* @param elementLength length of element
*/
virtual void onReceivedElement(const unsigned char *element, unsigned int elementLength) = 0;
virtual void
onReceivedElement(const unsigned char *element, unsigned int elementLength) = 0;
private:
/**
@ -37,7 +38,8 @@ private:
* @param element
* @param elementLength
*/
static void staticOnReceivedElement(struct ndn_ElementListener *self, unsigned char *element, unsigned int elementLength);
static void
staticOnReceivedElement(struct ndn_ElementListener *self, unsigned char *element, unsigned int elementLength);
};
}

3
ndn-cpp/encoding/binary-xml-encoder.hpp

@ -32,7 +32,8 @@ public:
* Resize the output vector to the correct encoding length and return.
* @return The encoding as a shared_ptr. Assume that the caller now owns the vector.
*/
const ptr_lib::shared_ptr<std::vector<unsigned char> >& getOutput()
const ptr_lib::shared_ptr<std::vector<unsigned char> >&
getOutput()
{
output_.get()->resize(offset);
return output_.get();

10
ndn-cpp/encoding/binary-xml-structure-decoder.hpp

@ -30,7 +30,8 @@ public:
* @param inputLength the number of bytes in input.
* @return true if found the element end, false if need to read more. (This is the same as returning gotElementEnd().)
*/
bool findElementEnd(unsigned char *input, unsigned int inputLength)
bool
findElementEnd(unsigned char *input, unsigned int inputLength)
{
ndn_Error error;
if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(this, input, inputLength)))
@ -38,8 +39,11 @@ public:
return gotElementEnd();
}
unsigned int getOffset() const { return offset; }
bool gotElementEnd() const { return gotElementEnd != 0; }
unsigned int
getOffset() const { return offset; }
bool
gotElementEnd() const { return gotElementEnd != 0; }
};
}

21
ndn-cpp/encoding/binary-xml-wire-format.cpp

@ -20,12 +20,14 @@ using namespace std;
namespace ndn {
// This is declared in the WireFormat class.
WireFormat *WireFormat::newInitialDefaultWireFormat()
WireFormat*
WireFormat::newInitialDefaultWireFormat()
{
return new BinaryXmlWireFormat();
}
Blob BinaryXmlWireFormat::encodeInterest(const Interest& interest)
Blob
BinaryXmlWireFormat::encodeInterest(const Interest& interest)
{
struct ndn_NameComponent nameComponents[100];
struct ndn_ExcludeEntry excludeEntries[100];
@ -43,7 +45,8 @@ Blob BinaryXmlWireFormat::encodeInterest(const Interest& interest)
return encoder.getOutput();
}
void BinaryXmlWireFormat::decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength)
void
BinaryXmlWireFormat::decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength)
{
struct ndn_NameComponent nameComponents[100];
struct ndn_ExcludeEntry excludeEntries[100];
@ -60,7 +63,8 @@ void BinaryXmlWireFormat::decodeInterest(Interest& interest, const unsigned char
interest.set(interestStruct);
}
Blob BinaryXmlWireFormat::encodeData(const Data& data, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset)
Blob
BinaryXmlWireFormat::encodeData(const Data& data, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset)
{
struct ndn_NameComponent nameComponents[100];
struct ndn_NameComponent keyNameComponents[100];
@ -78,7 +82,8 @@ Blob BinaryXmlWireFormat::encodeData(const Data& data, unsigned int *signedPorti
return encoder.getOutput();
}
void BinaryXmlWireFormat::decodeData
void
BinaryXmlWireFormat::decodeData
(Data& data, const unsigned char *input, unsigned int inputLength, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset)
{
struct ndn_NameComponent nameComponents[100];
@ -96,7 +101,8 @@ void BinaryXmlWireFormat::decodeData
data.set(dataStruct);
}
Blob BinaryXmlWireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntry)
Blob
BinaryXmlWireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntry)
{
struct ndn_NameComponent prefixNameComponents[100];
struct ndn_ForwardingEntry forwardingEntryStruct;
@ -112,7 +118,8 @@ Blob BinaryXmlWireFormat::encodeForwardingEntry(const ForwardingEntry& forwardin
return encoder.getOutput();
}
void BinaryXmlWireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength)
void
BinaryXmlWireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength)
{
struct ndn_NameComponent prefixNameComponents[100];
struct ndn_ForwardingEntry forwardingEntryStruct;

18
ndn-cpp/encoding/binary-xml-wire-format.hpp

@ -22,7 +22,8 @@ public:
* @param interest The Interest object to encode.
* @return A Blob containing the encoding.
*/
virtual Blob encodeInterest(const Interest& interest);
virtual Blob
encodeInterest(const Interest& interest);
/**
* Decode input as an interest in binary XML and set the fields of the interest object.
@ -30,7 +31,8 @@ public:
* @param input A pointer to the input buffer to decode.
* @param inputLength The number of bytes in input.
*/
virtual void decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength);
virtual void
decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength);
/**
* Encode data with binary XML and return the encoding.
@ -41,7 +43,8 @@ public:
* If you are not encoding in order to sign, you can call encodeData(const Data& data) to ignore this returned value.
* @return A Blob containing the encoding.
*/
virtual Blob encodeData
virtual Blob
encodeData
(const Data& data, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset);
/**
@ -56,7 +59,8 @@ public:
* If you are not decoding in order to verify, you can call
* decodeData(Data& data, const unsigned char *input, unsigned int inputLength) to ignore this returned value.
*/
virtual void decodeData
virtual void
decodeData
(Data& data, const unsigned char *input, unsigned int inputLength, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset);
/**
@ -64,7 +68,8 @@ public:
* @param forwardingEntry The ForwardingEntry object to encode.
* @return A Blob containing the encoding.
*/
virtual Blob encodeForwardingEntry(const ForwardingEntry& forwardingEntry);
virtual Blob
encodeForwardingEntry(const ForwardingEntry& forwardingEntry);
/**
* Decode input as a forwarding entry in binary XML and set the fields of the forwardingEntry object.
@ -72,7 +77,8 @@ public:
* @param input A pointer to the input buffer to decode.
* @param inputLength The number of bytes in input.
*/
virtual void decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength);
virtual void
decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength);
};
}

26
ndn-cpp/encoding/wire-format.cpp

@ -13,9 +13,10 @@ namespace ndn {
static bool gotInitialDefaultWireFormat = false;
WireFormat *WireFormat::defaultWireFormat_ = 0;
WireFormat* WireFormat::defaultWireFormat_ = 0;
WireFormat *WireFormat::getDefaultWireFormat()
WireFormat*
WireFormat::getDefaultWireFormat()
{
if (!defaultWireFormat_ && !gotInitialDefaultWireFormat) {
// There is no defaultWireFormat_ and we have not yet initialized initialDefaultWireFormat_, so initialize and use it.
@ -27,30 +28,39 @@ WireFormat *WireFormat::getDefaultWireFormat()
return defaultWireFormat_;
}
Blob WireFormat::encodeInterest(const Interest& interest)
Blob
WireFormat::encodeInterest(const Interest& interest)
{
throw logic_error("unimplemented");
}
void WireFormat::decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength)
void
WireFormat::decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength)
{
throw logic_error("unimplemented");
}
Blob WireFormat::encodeData(const Data& data, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset)
Blob
WireFormat::encodeData(const Data& data, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset)
{
throw logic_error("unimplemented");
}
void WireFormat::decodeData
void
WireFormat::decodeData
(Data& data, const unsigned char *input, unsigned int inputLength, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset)
{
throw logic_error("unimplemented");
}
Blob WireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntry)
Blob
WireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntry)
{
throw logic_error("unimplemented");
}
void WireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength)
void
WireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength)
{
throw logic_error("unimplemented");
}

33
ndn-cpp/encoding/wire-format.hpp

@ -24,7 +24,8 @@ public:
* @return A Blob containing the encoding.
* @throw logic_error for unimplemented if the derived class does not override.
*/
virtual Blob encodeInterest(const Interest& interest);
virtual Blob
encodeInterest(const Interest& interest);
/**
* Decode input as an interest and set the fields of the interest object. Your derived class should override.
@ -33,7 +34,8 @@ public:
* @param inputLength The number of bytes in input.
* @throw logic_error for unimplemented if the derived class does not override.
*/
virtual void decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength);
virtual void
decodeInterest(Interest& interest, const unsigned char *input, unsigned int inputLength);
/**
* Encode data and return the encoding. Your derived class should override.
@ -45,7 +47,8 @@ public:
* @return A Blob containing the encoding.
* @throw logic_error for unimplemented if the derived class does not override.
*/
virtual Blob encodeData
virtual Blob
encodeData
(const Data& data, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset);
/**
@ -54,7 +57,8 @@ public:
* @return A Blob containing the encoding.
* @throw logic_error for unimplemented if the derived class does not override.
*/
Blob encodeData(const Data& data)
Blob
encodeData(const Data& data)
{
unsigned int dummyBeginOffset, dummyEndOffset;
return encodeData(data, &dummyBeginOffset, &dummyEndOffset);
@ -73,10 +77,12 @@ public:
* decodeData(Data& data, const unsigned char *input, unsigned int inputLength) to ignore this returned value.
* @throw logic_error for unimplemented if the derived class does not override.
*/
virtual void decodeData
virtual void
decodeData
(Data& data, const unsigned char *input, unsigned int inputLength, unsigned int *signedPortionBeginOffset, unsigned int *signedPortionEndOffset);
void decodeData(Data& data, const unsigned char *input, unsigned int inputLength)
void
decodeData(Data& data, const unsigned char *input, unsigned int inputLength)
{
unsigned int dummyBeginOffset, dummyEndOffset;
decodeData(data, input, inputLength, &dummyBeginOffset, &dummyEndOffset);
@ -88,7 +94,8 @@ public:
* @return A Blob containing the encoding.
* @throw logic_error for unimplemented if the derived class does not override.
*/
virtual Blob encodeForwardingEntry(const ForwardingEntry& forwardingEntry);
virtual Blob
encodeForwardingEntry(const ForwardingEntry& forwardingEntry);
/**
* Decode input as a forwarding entry and set the fields of the forwardingEntry object. Your derived class should override.
@ -97,14 +104,16 @@ public:
* @param inputLength The number of bytes in input.
* @throw logic_error for unimplemented if the derived class does not override.
*/
virtual void decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength);
virtual void
decodeForwardingEntry(ForwardingEntry& forwardingEntry, const unsigned char *input, unsigned int inputLength);
/**
* Set the static default WireFormat used by default encoding and decoding methods.
* @param wireFormat A Pointer to an object of a subclass of WireFormat. This does not make a copy and
* the caller must ensure that the object remains allocated.
*/
static void setDefaultWireFormat(WireFormat *wireFormat)
static void
setDefaultWireFormat(WireFormat *wireFormat)
{
defaultWireFormat_ = wireFormat;
}
@ -114,7 +123,8 @@ public:
* setDefaultWireFormat.
* @return A pointer to the WireFormat object.
*/
static WireFormat *getDefaultWireFormat();
static WireFormat*
getDefaultWireFormat();
private:
/**
@ -123,7 +133,8 @@ private:
* needs to include another subclass which defines WireFormat::newInitialDefaultWireFormat.
* @return a new object, which is held by a shared_ptr and freed when the application exits.
*/
static WireFormat *newInitialDefaultWireFormat();
static WireFormat*
newInitialDefaultWireFormat();
static WireFormat *defaultWireFormat_;
};

6
ndn-cpp/face.cpp

@ -10,7 +10,8 @@ using namespace std;
namespace ndn {
void Face::expressInterest(const Name& name, const Interest *interestTemplate, const OnData& onData, const OnTimeout& onTimeout)
void
Face::expressInterest(const Name& name, const Interest *interestTemplate, const OnData& onData, const OnTimeout& onTimeout)
{
if (interestTemplate)
node_.expressInterest(Interest
@ -22,7 +23,8 @@ void Face::expressInterest(const Name& name, const Interest *interestTemplate, c
node_.expressInterest(Interest(name, 4000.0), onData, onTimeout);
}
void Face::shutdown()
void
Face::shutdown()
{
node_.shutdown();
}

18
ndn-cpp/face.hpp

@ -46,7 +46,8 @@ public:
* @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
void expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout = OnTimeout())
void
expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout = OnTimeout())
{
node_.expressInterest(interest, onData, onTimeout);
}
@ -61,7 +62,8 @@ public:
* @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
void expressInterest(const Name& name, const Interest *interestTemplate, const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
void
expressInterest(const Name& name, const Interest *interestTemplate, const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
/**
* Encode name as an Interest, using a default interest lifetime.
@ -72,7 +74,8 @@ public:
* @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
void expressInterest(const Name& name, const OnData& onData, const OnTimeout& onTimeout = OnTimeout())
void
expressInterest(const Name& name, const OnData& onData, const OnTimeout& onTimeout = OnTimeout())
{
expressInterest(name, 0, onData, onTimeout);
}
@ -84,7 +87,8 @@ public:
* use func_lib::ref() as appropriate.
* @param flags The flags for finer control of which interests are forward to the application.
*/
void registerPrefix(const Name& prefix, const OnInterest& onInterest, int flags = 0)
void
registerPrefix(const Name& prefix, const OnInterest& onInterest, int flags = 0)
{
node_.registerPrefix(prefix, onInterest, flags);
}
@ -96,7 +100,8 @@ public:
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
void processEvents()
void
processEvents()
{
// Just call Node's processEvents.
node_.processEvents();
@ -105,7 +110,8 @@ public:
/**
* Shut down and disconnect this Face.
*/
void shutdown();
void
shutdown();
private:
Node node_;

6
ndn-cpp/forwarding-entry.cpp

@ -12,7 +12,8 @@ using namespace std;
namespace ndn {
void ForwardingEntry::set(const struct ndn_ForwardingEntry& forwardingEntryStruct)
void
ForwardingEntry::set(const struct ndn_ForwardingEntry& forwardingEntryStruct)
{
if (forwardingEntryStruct.action && forwardingEntryStruct.actionLength > 0)
action_ = string(forwardingEntryStruct.action, forwardingEntryStruct.action + forwardingEntryStruct.actionLength);
@ -26,7 +27,8 @@ void ForwardingEntry::set(const struct ndn_ForwardingEntry& forwardingEntryStruc
freshnessSeconds_ = forwardingEntryStruct.freshnessSeconds;
}
void ForwardingEntry::get(struct ndn_ForwardingEntry& forwardingEntryStruct) const
void
ForwardingEntry::get(struct ndn_ForwardingEntry& forwardingEntryStruct) const
{
prefix_.get(forwardingEntryStruct.prefix);
publisherPublicKeyDigest_.get(forwardingEntryStruct.publisherPublicKeyDigest);

56
ndn-cpp/forwarding-entry.hpp

@ -32,15 +32,20 @@ public:
{
}
Blob wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
Blob
wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
{
return wireFormat.encodeForwardingEntry(*this);
}
void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
void
wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
{
wireFormat.decodeForwardingEntry(*this, input, inputLength);
}
void wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
void
wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
{
wireDecode(&input[0], input.size(), wireFormat);
}
@ -50,36 +55,53 @@ public:
* WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory.
* @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated.
*/
void get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
void
get(struct ndn_ForwardingEntry& forwardingEntryStruct) const;
const std::string& getAction() const { return action_; }
const std::string&
getAction() const { return action_; }
Name&
getPrefix() { return prefix_; }
const Name&
getPrefix() const { return prefix_; }
Name& getPrefix() { return prefix_; }
const Name& getPrefix() const { return prefix_; }
PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
const PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
int getFaceId() const { return faceId_; }
int
getFaceId() const { return faceId_; }
int getForwardingFlags() const { return forwardingFlags_; }
int
getForwardingFlags() const { return forwardingFlags_; }
int getFreshnessSeconds() const { return freshnessSeconds_; }
int
getFreshnessSeconds() const { return freshnessSeconds_; }
/**
* Clear this forwarding entry, and set the values by copying from forwardingEntryStruct.
* @param forwardingEntryStruct a C ndn_ForwardingEntry struct.
*/
void set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
void
set(const struct ndn_ForwardingEntry& forwardingEntryStruct);
void setAction(const std::string& value) { action_ = value; }
void
setAction(const std::string& value) { action_ = value; }
void setFaceId(int value) { faceId_ = value; }
void
setFaceId(int value) { faceId_ = value; }
void setForwardingFlags(int value) { forwardingFlags_ = value; }
void
setForwardingFlags(int value) { forwardingFlags_ = value; }
void setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
void
setFreshnessSeconds(int value) { freshnessSeconds_ = value; }
private:
std::string action_; /**< empty for none. */
Name prefix_;
PublisherPublicKeyDigest publisherPublicKeyDigest_;

15
ndn-cpp/interest.cpp

@ -12,7 +12,8 @@ using namespace std;
namespace ndn {
void Exclude::get(struct ndn_Exclude& excludeStruct) const
void
Exclude::get(struct ndn_Exclude& excludeStruct) const
{
if (excludeStruct.maxEntries < entries_.size())
throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
@ -22,7 +23,8 @@ void Exclude::get(struct ndn_Exclude& excludeStruct) const
entries_[i].get(excludeStruct.entries[i]);
}
void Exclude::set(const struct ndn_Exclude& excludeStruct)
void
Exclude::set(const struct ndn_Exclude& excludeStruct)
{
entries_.clear();
for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) {
@ -37,7 +39,8 @@ void Exclude::set(const struct ndn_Exclude& excludeStruct)
}
}
string Exclude::toUri() const
string
Exclude::toUri() const
{
if (entries_.size() == 0)
return "";
@ -56,7 +59,8 @@ string Exclude::toUri() const
return result.str();
}
void Interest::set(const struct ndn_Interest& interestStruct)
void
Interest::set(const struct ndn_Interest& interestStruct)
{
name_.set(interestStruct.name);
minSuffixComponents_ = interestStruct.minSuffixComponents;
@ -72,7 +76,8 @@ void Interest::set(const struct ndn_Interest& interestStruct)
nonce_ = Blob(interestStruct.nonce, interestStruct.nonceLength);
}
void Interest::get(struct ndn_Interest& interestStruct) const
void
Interest::get(struct ndn_Interest& interestStruct) const
{
name_.get(interestStruct.name);
interestStruct.minSuffixComponents = minSuffixComponents_;

107
ndn-cpp/interest.hpp

@ -39,7 +39,8 @@ public:
* WARNING: The resulting pointer in excludeEntryStruct is invalid after a further use of this object which could reallocate memory.
* @param excludeEntryStruct the C ndn_NameComponent struct to receive the pointer
*/
void get(struct ndn_ExcludeEntry& excludeEntryStruct) const
void
get(struct ndn_ExcludeEntry& excludeEntryStruct) const
{
excludeEntryStruct.type = type_;
if (type_ == ndn_Exclude_COMPONENT)
@ -66,29 +67,34 @@ public:
Exclude() {
}
unsigned int getEntryCount() const {
unsigned int
getEntryCount() const {
return entries_.size();
}
const ExcludeEntry& getEntry(unsigned int i) const { return entries_[i]; }
const ExcludeEntry&
getEntry(unsigned int i) const { return entries_[i]; }
/**
* Set the excludeStruct to point to the entries in this Exclude, without copying any memory.
* WARNING: The resulting pointers in excludeStruct are invalid after a further use of this object which could reallocate memory.
* @param excludeStruct a C ndn_Exclude struct where the entries array is already allocated
*/
void get(struct ndn_Exclude& excludeStruct) const;
void
get(struct ndn_Exclude& excludeStruct) const;
/**
* Clear this Exclude, and set the entries by copying from the ndn_Exclude struct.
* @param excludeStruct a C ndn_Exclude struct
*/
void set(const struct ndn_Exclude& excludeStruct);
void
set(const struct ndn_Exclude& excludeStruct);
/**
* Add a new entry of type ndn_Exclude_ANY
*/
void addAny()
void
addAny()
{
entries_.push_back(ExcludeEntry());
}
@ -96,7 +102,8 @@ public:
/**
* Add a new entry of type ndn_Exclude_COMPONENT, copying from component of length compnentLength
*/
void addComponent(unsigned char *component, unsigned int componentLen)
void
addComponent(unsigned char *component, unsigned int componentLen)
{
entries_.push_back(ExcludeEntry(component, componentLen));
}
@ -104,7 +111,8 @@ public:
/**
* Clear all the entries.
*/
void clear() {
void
clear() {
entries_.clear();
}
@ -160,15 +168,20 @@ public:
construct();
}
Blob wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
Blob
wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
{
return wireFormat.encodeInterest(*this);
}
void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
void
wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
{
wireFormat.decodeInterest(*this, input, inputLength);
}
void wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
void
wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
{
wireDecode(&input[0], input.size(), wireFormat);
}
@ -178,53 +191,79 @@ public:
* WARNING: The resulting pointers in interestStruct are invalid after a further use of this object which could reallocate memory.
* @param interestStruct a C ndn_Interest struct where the name components array is already allocated.
*/
void get(struct ndn_Interest& interestStruct) const;
void
get(struct ndn_Interest& interestStruct) const;
Name& getName() { return name_; }
const Name& getName() const { return name_; }
Name&
getName() { return name_; }
const Name&
getName() const { return name_; }
int getMinSuffixComponents() const { return minSuffixComponents_; }
int
getMinSuffixComponents() const { return minSuffixComponents_; }
int getMaxSuffixComponents() const { return maxSuffixComponents_; }
int
getMaxSuffixComponents() const { return maxSuffixComponents_; }
PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
const PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
Exclude& getExclude() { return exclude_; }
const Exclude& getExclude() const { return exclude_; }
Exclude&
getExclude() { return exclude_; }
const Exclude&
getExclude() const { return exclude_; }
int getChildSelector() const { return childSelector_; }
int
getChildSelector() const { return childSelector_; }
int getAnswerOriginKind() const { return answerOriginKind_; }
int
getAnswerOriginKind() const { return answerOriginKind_; }
int getScope() const { return scope_; }
int
getScope() const { return scope_; }
double getInterestLifetimeMilliseconds() const { return interestLifetimeMilliseconds_; }
double
getInterestLifetimeMilliseconds() const { return interestLifetimeMilliseconds_; }
const Blob& getNonce() const { return nonce_; }
const Blob&
getNonce() const { return nonce_; }
/**
* Clear this interest, and set the values by copying from the interest struct.
* @param interestStruct a C ndn_Interest struct
*/
void set(const struct ndn_Interest& interestStruct);
void
set(const struct ndn_Interest& interestStruct);
void setMinSuffixComponents(int value) { minSuffixComponents_ = value; }
void
setMinSuffixComponents(int value) { minSuffixComponents_ = value; }
void setMaxSuffixComponents(int value) { maxSuffixComponents_ = value; }
void
setMaxSuffixComponents(int value) { maxSuffixComponents_ = value; }
void setChildSelector(int value) { childSelector_ = value; }
void
setChildSelector(int value) { childSelector_ = value; }
void setAnswerOriginKind(int value) { answerOriginKind_ = value; }
void
setAnswerOriginKind(int value) { answerOriginKind_ = value; }
void setScope(int value) { scope_ = value; }
void
setScope(int value) { scope_ = value; }
void setInterestLifetimeMilliseconds(double value) { interestLifetimeMilliseconds_ = value; }
void
setInterestLifetimeMilliseconds(double value) { interestLifetimeMilliseconds_ = value; }
void setNonce(const std::vector<unsigned char>& value) { nonce_ = value; }
void
setNonce(const std::vector<unsigned char>& value) { nonce_ = value; }
private:
void construct()
void
construct()
{
minSuffixComponents_ = -1;
maxSuffixComponents_ = -1;

6
ndn-cpp/key.cpp

@ -11,7 +11,8 @@ using namespace std;
namespace ndn {
void KeyLocator::get(struct ndn_KeyLocator& keyLocatorStruct) const
void
KeyLocator::get(struct ndn_KeyLocator& keyLocatorStruct) const
{
keyLocatorStruct.type = type_;
@ -25,7 +26,8 @@ void KeyLocator::get(struct ndn_KeyLocator& keyLocatorStruct) const
keyLocatorStruct.keyNameType = keyNameType_;
}
void KeyLocator::set(const struct ndn_KeyLocator& keyLocatorStruct)
void
KeyLocator::set(const struct ndn_KeyLocator& keyLocatorStruct)
{
type_ = keyLocatorStruct.type;
keyData_ = Blob(keyLocatorStruct.keyData, keyLocatorStruct.keyDataLength);

41
ndn-cpp/key.hpp

@ -23,7 +23,8 @@ public:
/**
* Clear the keyData and set the type to none.
*/
void clear()
void
clear()
{
type_ = (ndn_KeyLocatorType)-1;
keyNameType_ = (ndn_KeyNameType)-1;
@ -35,27 +36,39 @@ public:
* WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory.
* @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated.
*/
void get(struct ndn_KeyLocator& keyLocatorStruct) const;
void
get(struct ndn_KeyLocator& keyLocatorStruct) const;
/**
* Clear this key locator, and set the values by copying from the ndn_KeyLocator struct.
* @param keyLocatorStruct a C ndn_KeyLocator struct
*/
void set(const struct ndn_KeyLocator& keyLocatorStruct);
void
set(const struct ndn_KeyLocator& keyLocatorStruct);
ndn_KeyLocatorType getType() const { return type_; }
ndn_KeyLocatorType
getType() const { return type_; }
const Blob& getKeyData() const { return keyData_; }
const Blob&
getKeyData() const { return keyData_; }
const Name& getKeyName() const { return keyName_; }
Name& getKeyName() { return keyName_; }
const Name&
getKeyName() const { return keyName_; }
Name&
getKeyName() { return keyName_; }
ndn_KeyNameType getKeyNameType() const { return keyNameType_; }
ndn_KeyNameType
getKeyNameType() const { return keyNameType_; }
void setType(ndn_KeyLocatorType type) { type_ = type; }
void
setType(ndn_KeyLocatorType type) { type_ = type; }
void
setKeyData(const std::vector<unsigned char>& keyData) { keyData_ = keyData; }
void setKeyData(const std::vector<unsigned char>& keyData) { keyData_ = keyData; }
void setKeyData(const unsigned char *keyData, unsigned int keyDataLength)
void
setKeyData(const unsigned char *keyData, unsigned int keyDataLength)
{
keyData_ = Blob(keyData, keyDataLength);
}
@ -65,9 +78,11 @@ public:
* if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
* @param keyData A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
*/
void setKeyData(const ptr_lib::shared_ptr<std::vector<unsigned char> > &keyData) { keyData_ = keyData; }
void
setKeyData(const ptr_lib::shared_ptr<std::vector<unsigned char> > &keyData) { keyData_ = keyData; }
void setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; }
void
setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; }
private:
ndn_KeyLocatorType type_; /**< -1 for none */

39
ndn-cpp/name.cpp

@ -18,7 +18,8 @@ static const char *WHITESPACE_CHARS = " \n\r\t";
* Modify str in place to erase whitespace on the left.
* @param str
*/
static inline void trimLeft(string& str)
static inline void
trimLeft(string& str)
{
size_t found = str.find_first_not_of(WHITESPACE_CHARS);
if (found != string::npos) {
@ -34,7 +35,8 @@ static inline void trimLeft(string& str)
* Modify str in place to erase whitespace on the right.
* @param str
*/
static inline void trimRight(string& str)
static inline void
trimRight(string& str)
{
size_t found = str.find_last_not_of(WHITESPACE_CHARS);
if (found != string::npos) {
@ -50,7 +52,8 @@ static inline void trimRight(string& str)
* Modify str in place to erase whitespace on the left and right.
* @param str
*/
static void trim(string& str)
static void
trim(string& str)
{
trimLeft(str);
trimRight(str);
@ -61,7 +64,8 @@ static void trim(string& str)
* @param c
* @return
*/
static int fromHexChar(unsigned char c)
static int
fromHexChar(unsigned char c)
{
if (c >= '0' && c <= '9')
return (int)c - (int)'0';
@ -77,7 +81,8 @@ static int fromHexChar(unsigned char c)
* Return a copy of str, converting each escaped "%XX" to the char value.
* @param str
*/
static string unescape(const string& str)
static string
unescape(const string& str)
{
ostringstream result;
@ -103,7 +108,8 @@ static string unescape(const string& str)
return result.str();
}
Blob Name::Component::makeFromEscapedString(const char *escapedString, unsigned int beginOffset, unsigned int endOffset)
Blob
Name::Component::makeFromEscapedString(const char *escapedString, unsigned int beginOffset, unsigned int endOffset)
{
string trimmedString(escapedString + beginOffset, escapedString + endOffset);
trim(trimmedString);
@ -122,7 +128,8 @@ Blob Name::Component::makeFromEscapedString(const char *escapedString, unsigned
return Blob((const unsigned char *)&component[0], component.size());
}
Blob Name::Component::makeSegment(unsigned long segment)
Blob
Name::Component::makeSegment(unsigned long segment)
{
ptr_lib::shared_ptr<vector<unsigned char> > value;
@ -140,7 +147,8 @@ Blob Name::Component::makeSegment(unsigned long segment)
return Blob(value);
}
void Name::set(const char *uri_cstr)
void
Name::set(const char *uri_cstr)
{
components_.clear();
@ -196,7 +204,8 @@ void Name::set(const char *uri_cstr)
}
}
void Name::get(struct ndn_Name& nameStruct) const
void
Name::get(struct ndn_Name& nameStruct) const
{
if (nameStruct.maxComponents < components_.size())
throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()");
@ -206,14 +215,16 @@ void Name::get(struct ndn_Name& nameStruct) const
components_[i].get(nameStruct.components[i]);
}
void Name::set(const struct ndn_Name& nameStruct)
void
Name::set(const struct ndn_Name& nameStruct)
{
clear();
for (unsigned int i = 0; i < nameStruct.nComponents; ++i)
addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength);
}
std::string Name::toUri() const
std::string
Name::toUri() const
{
if (components_.size() == 0)
return "/";
@ -227,7 +238,8 @@ std::string Name::toUri() const
return result.str();
}
bool Name::match(const Name& name) const
bool
Name::match(const Name& name) const
{
// Imitate ndn_Name_match.
@ -248,7 +260,8 @@ bool Name::match(const Name& name) const
return true;
}
void Name::toEscapedString(const vector<unsigned char>& value, ostringstream& result)
void
Name::toEscapedString(const vector<unsigned char>& value, ostringstream& result)
{
bool gotNonDot = false;
for (unsigned i = 0; i < value.size(); ++i) {

54
ndn-cpp/name.hpp

@ -63,7 +63,8 @@ public:
* WARNING: The resulting pointer in componentStruct is invalid after a further use of this object which could reallocate memory.
* @param componentStruct The C ndn_NameComponent struct to receive the pointer.
*/
void get(struct ndn_NameComponent& componentStruct) const
void
get(struct ndn_NameComponent& componentStruct) const
{
componentStruct.valueLength = value_.size();
if (value_.size() > 0)
@ -72,7 +73,8 @@ public:
componentStruct.value = 0;
}
const Blob& getValue() const { return value_; }
const Blob&
getValue() const { return value_; }
/**
* Make a component value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.
@ -83,14 +85,16 @@ public:
* @param endOffset The offset in escapedString of the end of the portion to decode.
* @return The component value as a Blob, or a Blob with a null pointer if escapedString is not a valid escaped component.
*/
static Blob makeFromEscapedString(const char *escapedString, unsigned int beginOffset, unsigned int endOffset);
static Blob
makeFromEscapedString(const char *escapedString, unsigned int beginOffset, unsigned int endOffset);
/**
* Make a component as the encoded segment number.
* @param segment The segment number.
* @return The component value as a Blob.
*/
static Blob makeSegment(unsigned long segment);
static Blob
makeSegment(unsigned long segment);
private:
Blob value_;
@ -125,24 +129,28 @@ public:
* WARNING: The resulting pointers in nameStruct are invalid after a further use of this object which could reallocate memory.
* @param nameStruct A C ndn_Name struct where the components array is already allocated.
*/
void get(struct ndn_Name& nameStruct) const;
void
get(struct ndn_Name& nameStruct) const;
/**
* Clear this name, and set the components by copying from the name struct.
* @param nameStruct A C ndn_Name struct
*/
void set(const struct ndn_Name& nameStruct);
void
set(const struct ndn_Name& nameStruct);
/**
* Parse the uri according to the NDN URI Scheme and set the name with the components.
* @param uri The URI string.
*/
void set(const char *uri);
void
set(const char *uri);
/**
* Add a new component, copying from value of length valueLength.
*/
void addComponent(const unsigned char *value, unsigned int valueLength)
void
addComponent(const unsigned char *value, unsigned int valueLength)
{
components_.push_back(Component(value, valueLength));
}
@ -150,12 +158,14 @@ public:
/**
* Add a new component, copying from value.
*/
void addComponent(const std::vector<unsigned char>& value)
void
addComponent(const std::vector<unsigned char>& value)
{
components_.push_back(value);
}
void addComponent(const Blob &value)
void
addComponent(const Blob &value)
{
components_.push_back(value);
}
@ -163,7 +173,8 @@ public:
/**
* Clear all the components.
*/
void clear() {
void
clear() {
components_.clear();
}
@ -171,22 +182,26 @@ public:
* Get the number of components.
* @return The number of components.
*/
unsigned int getComponentCount() const {
unsigned int
getComponentCount() const {
return components_.size();
}
const Component& getComponent(unsigned int i) const { return components_[i]; }
const Component&
getComponent(unsigned int i) const { return components_[i]; }
/**
* Encode this name as a URI.
* @return The encoded URI.
*/
std::string toUri() const;
std::string
toUri() const;
/**
* @deprecated Use toUri().
*/
std::string to_uri() const
std::string
to_uri() const
{
return toUri();
}
@ -195,7 +210,8 @@ public:
* Append a component with the encoded segment number.
* @param segment The segment number.
*/
void appendSegment(unsigned long segment)
void
appendSegment(unsigned long segment)
{
components_.push_back(Component(Component::makeSegment(segment)));
}
@ -205,7 +221,8 @@ public:
* @param name The Name to check.
* @return true if this matches the given name, otherwise false. This always returns true if this name is empty.
*/
bool match(const Name& name) const;
bool
match(const Name& name) const;
/**
* Write the value to result, escaping characters according to the NDN URI Scheme.
@ -213,7 +230,8 @@ public:
* @param value the buffer with the value to escape
* @param result the string stream to write to.
*/
static void toEscapedString(const std::vector<unsigned char>& value, std::ostringstream& result);
static void
toEscapedString(const std::vector<unsigned char>& value, std::ostringstream& result);
private:
std::vector<Component> components_;

36
ndn-cpp/node.cpp

@ -18,7 +18,8 @@ using namespace ndn::ptr_lib;
namespace ndn {
// Use gettimeofday to return the current time in milliseconds.
static inline double getNowMilliseconds()
static inline double
getNowMilliseconds()
{
timeval t;
gettimeofday(&t, NULL);
@ -31,7 +32,8 @@ Node::Node(const ptr_lib::shared_ptr<Transport>& transport, const ptr_lib::share
{
}
void Node::expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout)
void
Node::expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout)
{
// TODO: Properly check if we are already connected to the expected host.
if (!transport_->getIsConnected())
@ -43,7 +45,8 @@ void Node::expressInterest(const Interest& interest, const OnData& onData, const
transport_->send(*encoding);
}
void Node::registerPrefix(const Name& prefix, const OnInterest& onInterest, int flags)
void
Node::registerPrefix(const Name& prefix, const OnInterest& onInterest, int flags)
{
if (ndndId_.size() == 0) {
// First fetch the ndndId of the connected hub.
@ -55,7 +58,8 @@ void Node::registerPrefix(const Name& prefix, const OnInterest& onInterest, int
registerPrefixHelper(prefix, onInterest, flags);
}
void Node::NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData)
void
Node::NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData)
{
Sha256WithRsaSignature *signature = dynamic_cast<Sha256WithRsaSignature*>(ndndIdData->getSignature());
if (signature && signature->getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0) {
@ -67,12 +71,14 @@ void Node::NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>&
// TODO: else need to log not getting the ndndId.
}
void Node::NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest)
void
Node::NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest)
{
// TODO: Log the timeout.
}
void Node::registerPrefixHelper(const Name& prefix, const OnInterest& onInterest, int flags)
void
Node::registerPrefixHelper(const Name& prefix, const OnInterest& onInterest, int flags)
{
// Create a ForwardingEntry.
ForwardingEntry forwardingEntry("selfreg", prefix, PublisherPublicKeyDigest(), -1, 3, 2147483647);
@ -105,7 +111,8 @@ void Node::registerPrefixHelper(const Name& prefix, const OnInterest& onInterest
transport_->send(*encodedInterest);
}
void Node::processEvents()
void
Node::processEvents()
{
transport_->processEvents();
@ -121,7 +128,8 @@ void Node::processEvents()
}
}
void Node::onReceivedElement(const unsigned char *element, unsigned int elementLength)
void
Node::onReceivedElement(const unsigned char *element, unsigned int elementLength)
{
BinaryXmlDecoder decoder(element, elementLength);
@ -148,12 +156,14 @@ void Node::onReceivedElement(const unsigned char *element, unsigned int elementL
}
}
void Node::shutdown()
void
Node::shutdown()
{
transport_->close();
}
int Node::getEntryIndexForExpressedInterest(const Name& name)
int
Node::getEntryIndexForExpressedInterest(const Name& name)
{
// TODO: Doesn't this belong in the Name class?
vector<struct ndn_NameComponent> nameComponents;
@ -176,7 +186,8 @@ int Node::getEntryIndexForExpressedInterest(const Name& name)
return iResult;
}
Node::PrefixEntry *Node::getEntryForRegisteredPrefix(const Name& name)
Node::PrefixEntry*
Node::getEntryForRegisteredPrefix(const Name& name)
{
int iResult = -1;
@ -214,7 +225,8 @@ Node::PitEntry::PitEntry(const ptr_lib::shared_ptr<const Interest>& interest, co
interest_->get(interestStruct_);
}
bool Node::PitEntry::checkTimeout(Node *parent, double nowMilliseconds)
bool
Node::PitEntry::checkTimeout(Node *parent, double nowMilliseconds)
{
if (timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_) {
if (onTimeout_) {

54
ndn-cpp/node.hpp

@ -50,7 +50,8 @@ public:
* @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
void expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout);
void
expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout);
/**
* Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
@ -59,7 +60,8 @@ public:
* use func_lib::ref() as appropriate.
* @param flags The flags for finer control of which interests are forward to the application.
*/
void registerPrefix(const Name& prefix, const OnInterest& onInterest, int flags);
void
registerPrefix(const Name& prefix, const OnInterest& onInterest, int flags);
/**
* Process any data to receive. For each element received, call onReceivedElement.
@ -68,15 +70,20 @@ public:
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
void processEvents();
void
processEvents();
const ptr_lib::shared_ptr<Transport>& getTransport() { return transport_; }
const ptr_lib::shared_ptr<Transport>&
getTransport() { return transport_; }
const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& getConnectionInfo() { return connectionInfo_; }
const ptr_lib::shared_ptr<const Transport::ConnectionInfo>&
getConnectionInfo() { return connectionInfo_; }
void onReceivedElement(const unsigned char *element, unsigned int elementLength);
void
onReceivedElement(const unsigned char *element, unsigned int elementLength);
void shutdown();
void
shutdown();
private:
class PitEntry {
@ -89,9 +96,11 @@ private:
*/
PitEntry(const ptr_lib::shared_ptr<const Interest>& interest, const OnData& onData, const OnTimeout& onTimeout);
const ptr_lib::shared_ptr<const Interest>& getInterest() { return interest_; }
const ptr_lib::shared_ptr<const Interest>&
getInterest() { return interest_; }
const OnData& getOnData() { return onData_; }
const OnData&
getOnData() { return onData_; }
/**
* Get the struct ndn_Interest for the interest_.
@ -101,7 +110,8 @@ private:
* @return A reference to the ndn_Interest struct.
* WARNING: The resulting pointers in are invalid uses getInterest() to manipulate the object which could reallocate memory.
*/
const struct ndn_Interest& getInterestStruct()
const struct ndn_Interest&
getInterestStruct()
{
return interestStruct_;
}
@ -112,7 +122,8 @@ private:
* @param nowMilliseconds The current time in milliseconds from gettimeofday.
* @return true if this interest timed out and the timeout callback was called, otherwise false.
*/
bool checkTimeout(Node *parent, double nowMilliseconds);
bool
checkTimeout(Node *parent, double nowMilliseconds);
private:
ptr_lib::shared_ptr<const Interest> interest_;
@ -137,9 +148,11 @@ private:
{
}
const ptr_lib::shared_ptr<const Name>& getPrefix() { return prefix_; }
const ptr_lib::shared_ptr<const Name>&
getPrefix() { return prefix_; }
const OnInterest& getOnInterest() { return onInterest_; }
const OnInterest&
getOnInterest() { return onInterest_; }
private:
ptr_lib::shared_ptr<const Name> prefix_;
@ -163,13 +176,15 @@ private:
* @param interest
* @param data
*/
void operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData);
void
operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData);
/**
* We timed out fetching the ndnd ID.
* @param interest
*/
void operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest);
void
operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest);
class Info {
public:
@ -194,14 +209,16 @@ private:
* @param name The name to find the interest for (from the incoming data packet).
* @return The index in pit_ of the pit entry, or -1 if not found.
*/
int getEntryIndexForExpressedInterest(const Name& name);
int
getEntryIndexForExpressedInterest(const Name& name);
/**
* Find the first entry from the registeredPrefixTable_ where the entry prefix is the longest that matches name.
* @param name The name to find the PrefixEntry for (from the incoming interest packet).
* @return A pointer to the entry, or 0 if not found.
*/
PrefixEntry *getEntryForRegisteredPrefix(const Name& name);
PrefixEntry*
getEntryForRegisteredPrefix(const Name& name);
/**
* Do the work of registerPrefix once we know we are connected with an ndndId_.
@ -209,7 +226,8 @@ private:
* @param onInterest
* @param flags
*/
void registerPrefixHelper(const Name& prefix, const OnInterest& onInterest, int flags);
void
registerPrefixHelper(const Name& prefix, const OnInterest& onInterest, int flags);
ptr_lib::shared_ptr<Transport> transport_;
ptr_lib::shared_ptr<const Transport::ConnectionInfo> connectionInfo_;

22
ndn-cpp/publisher-public-key-digest.hpp

@ -27,7 +27,8 @@ public:
* WARNING: The resulting pointers in publisherPublicKeyDigestStruct are invalid after a further use of this object which could reallocate memory.
* @param publisherPublicKeyDigestStruct a C ndn_PublisherPublicKeyDigest struct to receive the pointer
*/
void get(struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct) const
void
get(struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct) const
{
publisherPublicKeyDigestStruct.publisherPublicKeyDigestLength = publisherPublicKeyDigest_.size();
if (publisherPublicKeyDigest_.size() > 0)
@ -40,16 +41,24 @@ public:
* Clear this PublisherPublicKeyDigest, and copy from the ndn_PublisherPublicKeyDigest struct.
* @param excludeStruct a C ndn_Exclude struct
*/
void set(const struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct)
void
set(const struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct)
{
publisherPublicKeyDigest_ =
Blob(publisherPublicKeyDigestStruct.publisherPublicKeyDigest, publisherPublicKeyDigestStruct.publisherPublicKeyDigestLength);
}
const Blob& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
const Blob&
getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
void setPublisherPublicKeyDigest(const std::vector<unsigned char>& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
void setPublisherPublicKeyDigest(const unsigned char *publisherPublicKeyDigest, unsigned int publisherPublicKeyDigestLength)
void
setPublisherPublicKeyDigest(const std::vector<unsigned char>& publisherPublicKeyDigest)
{
publisherPublicKeyDigest_ = publisherPublicKeyDigest;
}
void
setPublisherPublicKeyDigest(const unsigned char *publisherPublicKeyDigest, unsigned int publisherPublicKeyDigestLength)
{
publisherPublicKeyDigest_ = Blob(publisherPublicKeyDigest, publisherPublicKeyDigestLength);
}
@ -57,7 +66,8 @@ public:
/**
* Clear the publisherPublicKeyDigest.
*/
void clear()
void
clear()
{
publisherPublicKeyDigest_.reset();
}

3
ndn-cpp/security/identity/identity-manager.cpp

@ -9,7 +9,8 @@
namespace ndn {
void IdentityManager::signByCertificate(const Data &data, const Name &certificateName, WireFormat& wireFormat)
void
IdentityManager::signByCertificate(const Data &data, const Name &certificateName, WireFormat& wireFormat)
{
}

3
ndn-cpp/security/identity/identity-manager.hpp

@ -22,7 +22,8 @@ public:
* @param certificateName The Name identifying the certificate which identifies the signing key.
* @param wireFormat The WireFormat for calling encodeData, or WireFormat::getDefaultWireFormat() if omitted.
*/
void signByCertificate(const Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
void
signByCertificate(const Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
};
}

12
ndn-cpp/security/key-chain.cpp

@ -66,7 +66,8 @@ static unsigned char DEFAULT_PRIVATE_KEY_DER[] = {
* @param data The Data object with the fields to digest.
* @param digest A pointer to a buffer of size SHA256_DIGEST_LENGTH to receive the data.
*/
static void dataSignedPortionSha256(const Data& data, WireFormat& wireFormat, unsigned char *digest)
static void
dataSignedPortionSha256(const Data& data, WireFormat& wireFormat, unsigned char *digest)
{
unsigned int signedPortionBeginOffset, signedPortionEndOffset;
Blob encoding = wireFormat.encodeData(data, &signedPortionBeginOffset, &signedPortionEndOffset);
@ -74,7 +75,8 @@ static void dataSignedPortionSha256(const Data& data, WireFormat& wireFormat, un
ndn_digestSha256(encoding.buf() + signedPortionBeginOffset, signedPortionEndOffset - signedPortionBeginOffset, digest);
}
void KeyChain::sign
void
KeyChain::sign
(Data& data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength,
const unsigned char *privateKeyDer, unsigned int privateKeyDerLength, WireFormat& wireFormat)
{
@ -108,12 +110,14 @@ void KeyChain::sign
signature->setSignature(signatureBits, signatureBitsLength);
}
void KeyChain::defaultSign(Data& data, WireFormat& wireFormat)
void
KeyChain::defaultSign(Data& data, WireFormat& wireFormat)
{
sign(data, DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER), DEFAULT_PRIVATE_KEY_DER, sizeof(DEFAULT_PRIVATE_KEY_DER), wireFormat);
}
bool KeyChain::selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat)
bool
KeyChain::selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat)
{
// Decode the data packet and digest the data fields.
Data data;

12
ndn-cpp/security/key-chain.hpp

@ -25,7 +25,8 @@ public:
* @param privateKeyDerLength The number of bytes in privateKeyDer.
* @param wireFormat The WireFormat for calling encodeData.
*/
static void sign
static void
sign
(Data& data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength,
const unsigned char *privateKeyDer, unsigned int privateKeyDerLength, WireFormat& wireFormat);
@ -34,7 +35,8 @@ public:
* @param data
* @param wireFormat The WireFormat for calling encodeData, or WireFormat::getDefaultWireFormat() if omitted.
*/
static void defaultSign(Data& data, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
static void
defaultSign(Data& data, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
/**
* Use the WireFormat to decode the input as a Data packet and use the public key in the key locator to
@ -46,9 +48,11 @@ public:
* @return true if the public key in the Data object verifies the object, false if not or if the Data object
* doesn't have a public key.
*/
static bool selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat);
static bool
selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat);
static bool selfVerifyData(const unsigned char *input, unsigned int inputLength)
static bool
selfVerifyData(const unsigned char *input, unsigned int inputLength)
{
return selfVerifyData(input, inputLength, *WireFormat::getDefaultWireFormat());
}

9
ndn-cpp/sha256-with-rsa-signature.cpp

@ -10,12 +10,14 @@ using namespace std;
namespace ndn {
ptr_lib::shared_ptr<Signature> Sha256WithRsaSignature::clone() const
ptr_lib::shared_ptr<Signature>
Sha256WithRsaSignature::clone() const
{
return ptr_lib::shared_ptr<Signature>(new Sha256WithRsaSignature(*this));
}
void Sha256WithRsaSignature::get(struct ndn_Signature& signatureStruct) const
void
Sha256WithRsaSignature::get(struct ndn_Signature& signatureStruct) const
{
signatureStruct.digestAlgorithmLength = digestAlgorithm_.size();
if (digestAlgorithm_.size() > 0)
@ -39,7 +41,8 @@ void Sha256WithRsaSignature::get(struct ndn_Signature& signatureStruct) const
keyLocator_.get(signatureStruct.keyLocator);
}
void Sha256WithRsaSignature::set(const struct ndn_Signature& signatureStruct)
void
Sha256WithRsaSignature::set(const struct ndn_Signature& signatureStruct)
{
digestAlgorithm_ = Blob(signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength);
witness_ = Blob(signatureStruct.witness, signatureStruct.witnessLength);

62
ndn-cpp/sha256-with-rsa-signature.hpp

@ -21,59 +21,83 @@ public:
/**
* Return a pointer to a new Sha256WithRsaSignature which is a copy of this signature.
*/
virtual ptr_lib::shared_ptr<Signature> clone() const;
virtual ptr_lib::shared_ptr<Signature>
clone() const;
/**
* Set the signatureStruct to point to the values in this signature object, without copying any memory.
* WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
* @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
*/
virtual void get(struct ndn_Signature& signatureStruct) const;
virtual void
get(struct ndn_Signature& signatureStruct) const;
/**
* Clear this signature, and set the values by copying from the ndn_Signature struct.
* @param signatureStruct a C ndn_Signature struct
*/
virtual void set(const struct ndn_Signature& signatureStruct);
virtual void
set(const struct ndn_Signature& signatureStruct);
const Blob& getDigestAlgorithm() const { return digestAlgorithm_; }
const Blob&
getDigestAlgorithm() const { return digestAlgorithm_; }
const Blob& getWitness() const { return witness_; }
const Blob&
getWitness() const { return witness_; }
const Blob& getSignature() const { return signature_; }
const Blob&
getSignature() const { return signature_; }
const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
const PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
const KeyLocator& getKeyLocator() const { return keyLocator_; }
KeyLocator& getKeyLocator() { return keyLocator_; }
PublisherPublicKeyDigest&
getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
const KeyLocator&
getKeyLocator() const { return keyLocator_; }
KeyLocator&
getKeyLocator() { return keyLocator_; }
void setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
void setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
void
setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
void
setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
{
digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
}
void setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; }
void setWitness(const unsigned char *witness, unsigned int witnessLength)
void
setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; }
void
setWitness(const unsigned char *witness, unsigned int witnessLength)
{
witness_ = Blob(witness, witnessLength);
}
void setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; }
void setSignature(const unsigned char *signature, unsigned int signatureLength)
void
setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; }
void
setSignature(const unsigned char *signature, unsigned int signatureLength)
{
signature_ = Blob(signature, signatureLength);
}
void setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
void
setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
void setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
void
setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
/**
* Clear all the fields.
*/
void clear()
void
clear()
{
digestAlgorithm_.reset();
witness_.reset();

15
ndn-cpp/transport/tcp-transport.cpp

@ -17,7 +17,8 @@ TcpTransport::ConnectionInfo::~ConnectionInfo()
{
}
void TcpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
void
TcpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
{
const TcpTransport::ConnectionInfo& tcpConnectionInfo = dynamic_cast<const TcpTransport::ConnectionInfo&>(connectionInfo);
@ -35,14 +36,16 @@ void TcpTransport::connect(const Transport::ConnectionInfo& connectionInfo, Elem
elementListener_ = &elementListener;
}
void TcpTransport::send(const unsigned char *data, unsigned int dataLength)
void
TcpTransport::send(const unsigned char *data, unsigned int dataLength)
{
ndn_Error error;
if ((error = ndn_TcpTransport_send(&transport_, (unsigned char *)data, dataLength)))
throw std::runtime_error(ndn_getErrorString(error));
}
void TcpTransport::processEvents()
void
TcpTransport::processEvents()
{
int receiveIsReady;
ndn_Error error;
@ -59,12 +62,14 @@ void TcpTransport::processEvents()
ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
}
bool TcpTransport::getIsConnected()
bool
TcpTransport::getIsConnected()
{
return isConnected_;
}
void TcpTransport::close()
void
TcpTransport::close()
{
ndn_Error error;
if ((error = ndn_TcpTransport_close(&transport_)))

9
ndn-cpp/transport/tcp-transport.hpp

@ -35,15 +35,18 @@ public:
* Get the host given to the constructor.
* @return A string reference for the host.
*/
const std::string& getHost() const { return host_; }
const std::string&
getHost() const { return host_; }
/**
* Get the port given to the constructor.
* @return The port number.
*/
unsigned short getPort() const { return port_; }
unsigned short
getPort() const { return port_; }
virtual ~ConnectionInfo();
virtual
~ConnectionInfo();
private:
std::string host_;

15
ndn-cpp/transport/transport.cpp

@ -15,27 +15,32 @@ Transport::ConnectionInfo::~ConnectionInfo()
{
}
void Transport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
void
Transport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
{
throw logic_error("unimplemented");
}
void Transport::send(const unsigned char *data, unsigned int dataLength)
void
Transport::send(const unsigned char *data, unsigned int dataLength)
{
throw logic_error("unimplemented");
}
void Transport::processEvents()
void
Transport::processEvents()
{
throw logic_error("unimplemented");
}
bool Transport::getIsConnected()
bool
Transport::getIsConnected()
{
throw logic_error("unimplemented");
}
void Transport::close()
void
Transport::close()
{
}

18
ndn-cpp/transport/transport.hpp

@ -28,16 +28,19 @@ public:
* @param connectionInfo A reference to an object of a subclass of ConnectionInfo.
* @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
*/
virtual void connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
virtual void
connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
/**
* Set data to the host
* @param data A pointer to the buffer of data to send.
* @param dataLength The number of bytes in data.
*/
virtual void send(const unsigned char *data, unsigned int dataLength);
virtual void
send(const unsigned char *data, unsigned int dataLength);
void send(const std::vector<unsigned char>& data)
void
send(const std::vector<unsigned char>& data)
{
send(&data[0], data.size());
}
@ -49,14 +52,17 @@ public:
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
virtual void processEvents() = 0;
virtual void
processEvents() = 0;
virtual bool getIsConnected();
virtual bool
getIsConnected();
/**
* Close the connection. This base class implementation does nothing, but your derived class can override.
*/
virtual void close();
virtual void
close();
virtual ~Transport();
};

15
ndn-cpp/transport/udp-transport.cpp

@ -17,7 +17,8 @@ UdpTransport::ConnectionInfo::~ConnectionInfo()
{
}
void UdpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
void
UdpTransport::connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener)
{
const UdpTransport::ConnectionInfo& udpConnectionInfo = dynamic_cast<const UdpTransport::ConnectionInfo&>(connectionInfo);
@ -35,14 +36,16 @@ void UdpTransport::connect(const Transport::ConnectionInfo& connectionInfo, Elem
elementListener_ = &elementListener;
}
void UdpTransport::send(const unsigned char *data, unsigned int dataLength)
void
UdpTransport::send(const unsigned char *data, unsigned int dataLength)
{
ndn_Error error;
if ((error = ndn_UdpTransport_send(&transport_, (unsigned char *)data, dataLength)))
throw std::runtime_error(ndn_getErrorString(error));
}
void UdpTransport::processEvents()
void
UdpTransport::processEvents()
{
int receiveIsReady;
ndn_Error error;
@ -59,12 +62,14 @@ void UdpTransport::processEvents()
ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
}
bool UdpTransport::getIsConnected()
bool
UdpTransport::getIsConnected()
{
return isConnected_;
}
void UdpTransport::close()
void
UdpTransport::close()
{
ndn_Error error;
if ((error = ndn_UdpTransport_close(&transport_)))

24
ndn-cpp/transport/udp-transport.hpp

@ -35,15 +35,18 @@ public:
* Get the host given to the constructor.
* @return A string reference for the host.
*/
const std::string& getHost() const { return host_; }
const std::string&
getHost() const { return host_; }
/**
* Get the port given to the constructor.
* @return The port number.
*/
unsigned short getPort() const { return port_; }
unsigned short
getPort() const { return port_; }
virtual ~ConnectionInfo();
virtual
~ConnectionInfo();
private:
std::string host_;
@ -62,14 +65,16 @@ public:
* @param connectionInfo A reference to a TcpTransport::ConnectionInfo.
* @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
*/
virtual void connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
virtual void
connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
/**
* Set data to the host
* @param data A pointer to the buffer of data to send.
* @param dataLength The number of bytes in data.
*/
virtual void send(const unsigned char *data, unsigned int dataLength);
virtual void
send(const unsigned char *data, unsigned int dataLength);
/**
* Process any data to receive. For each element received, call elementListener.onReceivedElement.
@ -78,14 +83,17 @@ public:
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
virtual void processEvents();
virtual void
processEvents();
virtual bool getIsConnected();
virtual bool
getIsConnected();
/**
* Close the connection to the host.
*/
virtual void close();
virtual void
close();
~UdpTransport();

6
ndn-cpp/util/blob.hpp

@ -68,7 +68,8 @@ public:
/**
* Return the length of the immutable byte array.
*/
unsigned int size() const
unsigned int
size() const
{
if (*this)
return (*this)->size();
@ -79,7 +80,8 @@ public:
/**
* Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null.
*/
const unsigned char* buf() const
const unsigned char*
buf() const
{
if (*this)
return &(*this)->front();

3
ndn-cpp/util/changed-event.cpp

@ -10,7 +10,8 @@ using namespace std;
namespace ndn {
void ChangedEvent::fire()
void
ChangedEvent::fire()
{
for (unsigned int i = 0; i < listeners_.size(); ++i)
listeners_[i]();

6
ndn-cpp/util/changed-event.hpp

@ -23,7 +23,8 @@ public:
* Add onChanged to the listener list. This does not check if a duplicate is already in the list.
* @param onChanged The OnChanged function object.
*/
void add(OnChanged onChanged)
void
add(OnChanged onChanged)
{
listeners_.push_back(onChanged);
}
@ -31,7 +32,8 @@ public:
/**
* Call all the listeners.
*/
void fire();
void
fire();
#if 0
private:

3
ndn-cpp/util/dynamic-uchar-vector.cpp

@ -16,7 +16,8 @@ DynamicUCharVector::DynamicUCharVector(unsigned int initialLength)
ndn_DynamicUCharArray_initialize(this, &vector_->front(), initialLength, DynamicUCharVector::realloc);
}
unsigned char *DynamicUCharVector::realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length)
unsigned char*
DynamicUCharVector::realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length)
{
// Because this method is private, assume there is not a problem with upcasting.
DynamicUCharVector *thisObject = (DynamicUCharVector *)self;

6
ndn-cpp/util/dynamic-uchar-vector.hpp

@ -29,7 +29,8 @@ public:
* Get the shared_ptr to the allocated vector.
* @return The shared_ptr to the allocated vector.
*/
const ptr_lib::shared_ptr<std::vector<unsigned char> >& get() { return vector_; }
const ptr_lib::shared_ptr<std::vector<unsigned char> >&
get() { return vector_; }
private:
/**
@ -39,7 +40,8 @@ private:
* @param length The new length for the vector.
* @return The front of the allocated vector.
*/
static unsigned char *realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length);
static unsigned char*
realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length);
ptr_lib::shared_ptr<std::vector<unsigned char> > vector_;
};

12
ndn-cpp/util/signed-blob.hpp

@ -76,7 +76,8 @@ public:
/**
* Return the length of the signed portion of the immutable byte array, or 0 of the pointer to the array is null.
*/
unsigned int signedSize() const
unsigned int
signedSize() const
{
if (*this)
return signedPortionEndOffset_ - signedPortionBeginOffset_;
@ -88,7 +89,8 @@ public:
* Return a const pointer to the first byte of the signed portion of the immutable byte array, or 0 if the
* pointer to the array is null.
*/
const unsigned char* signedBuf() const
const unsigned char*
signedBuf() const
{
if (*this)
return &(*this)->front() + signedPortionBeginOffset_;
@ -99,12 +101,14 @@ public:
/**
* Return the offset in the array of the beginning of the signed portion.
*/
unsigned int getSignedPortionBeginOffset() { return signedPortionBeginOffset_; }
unsigned int
getSignedPortionBeginOffset() { return signedPortionBeginOffset_; }
/**
* Return the offset in the array of the end of the signed portion.
*/
unsigned int getSignedPortionEndOffset() { return signedPortionEndOffset_; }
unsigned int
getSignedPortionEndOffset() { return signedPortionEndOffset_; }
private:
unsigned int signedPortionBeginOffset_;

Loading…
Cancel
Save