Browse Source

Rename interestLifetime to interestLifetimeMilliseconds and make it a double

pull/1/head
Jeff Thompson 12 years ago
parent
commit
5a5e8b7eef
  1. 4
      ndn-cpp/Interest.cpp
  2. 8
      ndn-cpp/Interest.hpp
  3. 4
      ndn-cpp/c/Interest.h
  4. 10
      ndn-cpp/c/encoding/BinaryXMLInterest.c
  5. 4
      tests/test-encode-decode-Interest.cpp

4
ndn-cpp/Interest.cpp

@ -48,7 +48,7 @@ void Interest::set(const struct ndn_Interest &interestStruct)
childSelector_ = interestStruct.childSelector;
answerOriginKind_ = interestStruct.answerOriginKind;
scope_ = interestStruct.scope;
interestLifetime_ = interestStruct.interestLifetime;
interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds;
setVector(nonce_, interestStruct.nonce, interestStruct.nonceLength);
}
@ -62,7 +62,7 @@ void Interest::get(struct ndn_Interest &interestStruct) const
interestStruct.childSelector = childSelector_;
interestStruct.answerOriginKind = answerOriginKind_;
interestStruct.scope = scope_;
interestStruct.interestLifetime = interestLifetime_;
interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;
interestStruct.nonceLength = nonce_.size();
if (nonce_.size() > 0)

8
ndn-cpp/Interest.hpp

@ -125,7 +125,7 @@ public:
childSelector_ = -1;
answerOriginKind_ = -1;
scope_ = -1;
interestLifetime_ = -1;
interestLifetimeMilliseconds_ = -1.0;
}
void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const
@ -179,7 +179,7 @@ public:
int getScope() const { return scope_; }
int getInterestLifetime() const { return interestLifetime_; }
double getInterestLifetimeMilliseconds() const { return interestLifetimeMilliseconds_; }
const std::vector<unsigned char> getNonce() const { return nonce_; }
@ -199,7 +199,7 @@ public:
void setScope(int value) { scope_ = value; }
void setInterestLifetime(int value) { interestLifetime_ = value; }
void setInterestLifetimeMilliseconds(double value) { interestLifetimeMilliseconds_ = value; }
void setNonce(const std::vector<unsigned char> &value) { nonce_ = value; }
@ -213,7 +213,7 @@ private:
int childSelector_;
int answerOriginKind_;
int scope_;
int interestLifetime_;
double interestLifetimeMilliseconds_;
std::vector<unsigned char> nonce_;
};

4
ndn-cpp/c/Interest.h

@ -85,7 +85,7 @@ struct ndn_Interest {
int childSelector; /**< -1 for none */
int answerOriginKind; /**< -1 for none */
int scope; /**< -1 for none */
int interestLifetime; /**< milliseconds. -1 for none */
double interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
unsigned char *nonce; /**< pointer to pre-allocated buffer. 0 for none */
unsigned int nonceLength; /**< length of nonce. 0 for none */
};
@ -111,7 +111,7 @@ static inline void ndn_Interest_init
self->childSelector = -1;
self->answerOriginKind = -1;
self->scope = -1;
self->interestLifetime = -1;
self->interestLifetimeMilliseconds = -1.0;
self->nonce = 0;
self->nonceLength = 0;
}

10
ndn-cpp/c/encoding/BinaryXMLInterest.c

@ -155,11 +155,11 @@ ndn_Error ndn_encodeBinaryXMLInterest(struct ndn_Interest *interest, struct ndn_
(encoder, ndn_BinaryXML_DTag_Scope, interest->scope))
return error;
if (interest->interestLifetime >= 0) {
if (interest->interestLifetimeMilliseconds >= 0) {
if (error = ndn_BinaryXMLEncoder_writeElementStartDTag(encoder, ndn_BinaryXML_DTag_InterestLifetime))
return error;
unsigned int ticks = (unsigned int)(((double)interest->interestLifetime / 1000.0) * 4096.0);
unsigned int ticks = (unsigned int)((interest->interestLifetimeMilliseconds / 1000.0) * 4096.0);
if (error = ndn_BinaryXMLEncoder_writeUnsignedIntBigEndianBlob(encoder, ticks))
return error;
@ -225,11 +225,11 @@ ndn_Error ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, struct ndn_
(decoder, ndn_BinaryXML_DTag_InterestLifetime, 0, &interestLifetime, &interestLifetimeLength))
return error;
interest->interestLifetime = (int)(1000.0 *
(double)ndn_BinaryXMLDecoder_bigEndianToUnsignedInt(interestLifetime, interestLifetimeLength) / 4096.0);
interest->interestLifetimeMilliseconds = 1000.0 *
(double)ndn_BinaryXMLDecoder_bigEndianToUnsignedInt(interestLifetime, interestLifetimeLength) / 4096.0;
}
else
interest->interestLifetime = -1;
interest->interestLifetimeMilliseconds = -1.0;
if (error = ndn_BinaryXMLDecoder_readOptionalBinaryDTagElement
(decoder, ndn_BinaryXML_DTag_Nonce, 0, &interest->nonce, &interest->nonceLength))

4
tests/test-encode-decode-Interest.cpp

@ -42,7 +42,7 @@ int main(int argc, char** argv)
cout << "Interest minSuffixComponents " << interest.getMinSuffixComponents() << endl;
cout << "Interest publisherPublicKeyDigest length " << interest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() << endl;
cout << "Interest excludeEntryCount " << interest.getExclude().getEntryCount() << endl;
cout << "InterestLifetime " << interest.getInterestLifetime() << endl;
cout << "InterestLifetimeMilliseconds " << interest.getInterestLifetimeMilliseconds() << endl;
vector<unsigned char> encoding;
interest.encode(encoding);
@ -54,7 +54,7 @@ int main(int argc, char** argv)
cout << "Re-decoded Interest minSuffixComponents " << reDecodedInterest.getMinSuffixComponents() << endl;
cout << "Re-decoded Interest publisherPublicKeyDigest length " << reDecodedInterest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() << endl;
cout << "Re-decoded Interest excludeEntryCount " << reDecodedInterest.getExclude().getEntryCount() << endl;
cout << "Re-decoded InterestLifetime " << reDecodedInterest.getInterestLifetime() << endl;
cout << "Re-decoded InterestLifetimeMilliseconds " << reDecodedInterest.getInterestLifetimeMilliseconds() << endl;
} catch (exception &e) {
cout << "exception: " << e.what() << endl;
}

Loading…
Cancel
Save