common.hpp: time: Added typedef for Milliseconds and MillisecondsSince1970, and use instead of double where appropriate.
diff --git a/include/ndn-cpp/c/common.h b/include/ndn-cpp/c/common.h
index 89392bc..c1706d5 100644
--- a/include/ndn-cpp/c/common.h
+++ b/include/ndn-cpp/c/common.h
@@ -12,4 +12,22 @@
// TODO: Is stddef.h portable?
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * A time interval represented as the number of milliseconds.
+ */
+typedef double ndn_Milliseconds;
+
+/**
+ * The calendar time represented as the number of milliseconds since 1/1/1970.
+ */
+typedef double ndn_MillisecondsSince1970;
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/include/ndn-cpp/common.hpp b/include/ndn-cpp/common.hpp
index f0bd736..1df861b 100644
--- a/include/ndn-cpp/common.hpp
+++ b/include/ndn-cpp/common.hpp
@@ -63,10 +63,17 @@
#endif
namespace ndn {
+
+/**
+ * A time interval represented as the number of milliseconds.
+ */
+typedef double Milliseconds;
-// TODO: Implement Time, used in certificates and DER encoding.
-typedef double Time;
-
+/**
+ * The calendar time represented as the number of milliseconds since 1/1/1970.
+ */
+typedef double MillisecondsSince1970;
+
/**
* Return the hex representation of the bytes in array.
* @param array The array of bytes.
diff --git a/include/ndn-cpp/data.hpp b/include/ndn-cpp/data.hpp
index a99e410..1cd00f6 100644
--- a/include/ndn-cpp/data.hpp
+++ b/include/ndn-cpp/data.hpp
@@ -83,7 +83,7 @@
void
set(const struct ndn_MetaInfo& metaInfoStruct);
- double
+ MillisecondsSince1970
getTimestampMilliseconds() const { return timestampMilliseconds_; }
ndn_ContentType
@@ -96,7 +96,7 @@
getFinalBlockID() const { return finalBlockID_; }
void
- setTimestampMilliseconds(double timestampMilliseconds) { timestampMilliseconds_ = timestampMilliseconds; }
+ setTimestampMilliseconds(MillisecondsSince1970 timestampMilliseconds) { timestampMilliseconds_ = timestampMilliseconds; }
void
setType(ndn_ContentType type) { type_ = type; }
@@ -117,7 +117,7 @@
}
private:
- double timestampMilliseconds_; /**< milliseconds since 1/1/1970. -1 for none */
+ MillisecondsSince1970 timestampMilliseconds_; /**< milliseconds since 1/1/1970. -1 for none */
ndn_ContentType type_; /**< default is ndn_ContentType_DATA. -1 for none */
int freshnessSeconds_; /**< -1 for none */
Name::Component finalBlockID_; /** size 0 for none */
diff --git a/include/ndn-cpp/interest.hpp b/include/ndn-cpp/interest.hpp
index 955d681..f05d575 100644
--- a/include/ndn-cpp/interest.hpp
+++ b/include/ndn-cpp/interest.hpp
@@ -134,7 +134,7 @@
public:
Interest(const Name& name, int minSuffixComponents, int maxSuffixComponents,
const PublisherPublicKeyDigest& publisherPublicKeyDigest, const Exclude& exclude, int childSelector, int answerOriginKind,
- int scope, double interestLifetimeMilliseconds, const std::vector<uint8_t>& nonce)
+ int scope, Milliseconds interestLifetimeMilliseconds, const std::vector<uint8_t>& nonce)
: name_(name), minSuffixComponents_(minSuffixComponents), maxSuffixComponents_(maxSuffixComponents),
publisherPublicKeyDigest_(publisherPublicKeyDigest), exclude_(exclude), childSelector_(childSelector),
answerOriginKind_(answerOriginKind), scope_(scope), interestLifetimeMilliseconds_(interestLifetimeMilliseconds),
@@ -144,14 +144,14 @@
Interest(const Name& name, int minSuffixComponents, int maxSuffixComponents,
const PublisherPublicKeyDigest& publisherPublicKeyDigest, const Exclude& exclude, int childSelector, int answerOriginKind,
- int scope, double interestLifetimeMilliseconds)
+ int scope, Milliseconds interestLifetimeMilliseconds)
: name_(name), minSuffixComponents_(minSuffixComponents), maxSuffixComponents_(maxSuffixComponents),
publisherPublicKeyDigest_(publisherPublicKeyDigest), exclude_(exclude), childSelector_(childSelector),
answerOriginKind_(answerOriginKind), scope_(scope), interestLifetimeMilliseconds_(interestLifetimeMilliseconds)
{
}
- Interest(const Name& name, double interestLifetimeMilliseconds)
+ Interest(const Name& name, Milliseconds interestLifetimeMilliseconds)
: name_(name)
{
construct();
@@ -228,7 +228,7 @@
int
getScope() const { return scope_; }
- double
+ Milliseconds
getInterestLifetimeMilliseconds() const { return interestLifetimeMilliseconds_; }
const Blob&
@@ -257,7 +257,7 @@
setScope(int value) { scope_ = value; }
void
- setInterestLifetimeMilliseconds(double value) { interestLifetimeMilliseconds_ = value; }
+ setInterestLifetimeMilliseconds(Milliseconds value) { interestLifetimeMilliseconds_ = value; }
void
setNonce(const std::vector<uint8_t>& value) { nonce_ = value; }
@@ -282,7 +282,7 @@
int childSelector_;
int answerOriginKind_;
int scope_;
- double interestLifetimeMilliseconds_;
+ Milliseconds interestLifetimeMilliseconds_;
Blob nonce_;
};
diff --git a/include/ndn-cpp/node.hpp b/include/ndn-cpp/node.hpp
index 882ecd8..1e4c001 100644
--- a/include/ndn-cpp/node.hpp
+++ b/include/ndn-cpp/node.hpp
@@ -172,11 +172,11 @@
/**
* If this interest is timed out, call onTimeout_ (if defined) and return true.
* @param parent The parent Node for the UpcallInfo.
- * @param nowMilliseconds The current time in milliseconds from gettimeofday.
+ * @param nowMilliseconds The current time in milliseconds from ndn_getNowMilliseconds.
* @return true if this interest timed out and the timeout callback was called, otherwise false.
*/
bool
- checkTimeout(Node *parent, double nowMilliseconds);
+ checkTimeout(Node *parent, MillisecondsSince1970 nowMilliseconds);
private:
ptr_lib::shared_ptr<const Interest> interest_;
@@ -188,7 +188,7 @@
uint64_t pendingInterestId_; /**< A unique identifier for this entry so it can be deleted */
const OnData onData_;
const OnTimeout onTimeout_;
- double timeoutTimeMilliseconds_; /**< The time when the interest times out in milliseconds according to gettimeofday, or -1 for no timeout. */
+ MillisecondsSince1970 timeoutTimeMilliseconds_; /**< The time when the interest times out in milliseconds according to ndn_getNowMilliseconds, or -1 for no timeout. */
};
class RegisteredPrefix {
diff --git a/include/ndn-cpp/security/certificate/certificate.hpp b/include/ndn-cpp/security/certificate/certificate.hpp
index 21745e2..bc6b355 100644
--- a/include/ndn-cpp/security/certificate/certificate.hpp
+++ b/include/ndn-cpp/security/certificate/certificate.hpp
@@ -61,21 +61,21 @@
addExtension(const CertificateExtension& extension) { extensionList_.push_back(extension); }
void
- setNotBefore(const Time& notBefore) { notBefore_ = notBefore; }
+ setNotBefore(const MillisecondsSince1970& notBefore) { notBefore_ = notBefore; }
- Time&
+ MillisecondsSince1970&
getNotBefore() { return notBefore_; }
- const Time&
+ const MillisecondsSince1970&
getNotBefore() const { return notBefore_; }
void
- setNotAfter(const Time& notAfter) { notAfter_ = notAfter; }
+ setNotAfter(const MillisecondsSince1970& notAfter) { notAfter_ = notAfter; }
- Time&
+ MillisecondsSince1970&
getNotAfter() { return notAfter_; }
- const Time&
+ const MillisecondsSince1970&
getNotAfter() const { return notAfter_; }
void
@@ -113,8 +113,8 @@
protected:
SubjectDescriptionList subjectDescriptionList_;
- Time notBefore_;
- Time notAfter_;
+ MillisecondsSince1970 notBefore_;
+ MillisecondsSince1970 notAfter_;
PublicKey key_;
ExtensionList extensionList_;
};
diff --git a/include/ndn-cpp/security/identity/basic-identity-storage.hpp b/include/ndn-cpp/security/identity/basic-identity-storage.hpp
index ee1a886..d841548 100644
--- a/include/ndn-cpp/security/identity/basic-identity-storage.hpp
+++ b/include/ndn-cpp/security/identity/basic-identity-storage.hpp
@@ -200,7 +200,7 @@
sqlite3 *database_;
#if 0
- Time lastUpdated_;
+ MillisecondsSince1970 lastUpdated_;
#endif
};
diff --git a/include/ndn-cpp/security/identity/identity-manager.hpp b/include/ndn-cpp/security/identity/identity-manager.hpp
index d31e214..1d6df04 100644
--- a/include/ndn-cpp/security/identity/identity-manager.hpp
+++ b/include/ndn-cpp/security/identity/identity-manager.hpp
@@ -106,7 +106,7 @@
* @return The name of generated identity certificate.
*/
Name
- createIdentityCertificate(const Name& keyName, const Name& signerCertificateName, const Time& notBefore, const Time& notAfter);
+ createIdentityCertificate(const Name& keyName, const Name& signerCertificateName, const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter);
/**
* Create an identity certificate for a public key supplied by the caller.
@@ -119,7 +119,7 @@
*/
ptr_lib::shared_ptr<IdentityCertificate>
createIdentityCertificate
- (const Name& keyName, const PublicKey& publickey, const Name& signerCertificateName, const Time& notBefore, const Time& notAfter);
+ (const Name& keyName, const PublicKey& publickey, const Name& signerCertificateName, const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter);
/**
* Add a certificate into the public key identity storage.
diff --git a/ndn-cpp/c/data.h b/ndn-cpp/c/data.h
index 8d14e05..68ed6ed 100644
--- a/ndn-cpp/c/data.h
+++ b/ndn-cpp/c/data.h
@@ -46,10 +46,10 @@
* An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
*/
struct ndn_MetaInfo {
- double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
- ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
- int freshnessSeconds; /**< -1 for none */
- struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
+ ndn_MillisecondsSince1970 timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
+ ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
+ int freshnessSeconds; /**< -1 for none */
+ struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
};
/**
diff --git a/ndn-cpp/c/interest.h b/ndn-cpp/c/interest.h
index 12ca38e..438fecd 100644
--- a/ndn-cpp/c/interest.h
+++ b/ndn-cpp/c/interest.h
@@ -99,7 +99,7 @@
int childSelector; /**< -1 for none */
int answerOriginKind; /**< -1 for none */
int scope; /**< -1 for none */
- double interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
+ ndn_Milliseconds interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
struct ndn_Blob nonce; /**< The blob whose value is a pointer to a pre-allocated buffer. 0 for none */
};
diff --git a/ndn-cpp/c/util/time.c b/ndn-cpp/c/util/time.c
index a794047..9da0e1c 100644
--- a/ndn-cpp/c/util/time.c
+++ b/ndn-cpp/c/util/time.c
@@ -7,7 +7,7 @@
#include <sys/time.h>
#include "time.h"
-double
+ndn_MillisecondsSince1970
ndn_getNowMilliseconds()
{
struct timeval t;
diff --git a/ndn-cpp/c/util/time.h b/ndn-cpp/c/util/time.h
index 36b4dad..adcb0b4 100644
--- a/ndn-cpp/c/util/time.h
+++ b/ndn-cpp/c/util/time.h
@@ -7,6 +7,8 @@
#ifndef NDN_TIME_H
#define NDN_TIME_H
+#include <ndn-cpp/c/common.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -15,7 +17,7 @@
* Use gettimeofday to return the current time in milliseconds.
* @return The current time in milliseconds since 1/1/1970, including fractions of a millisecond according to timeval.tv_usec.
*/
-double
+ndn_MillisecondsSince1970
ndn_getNowMilliseconds();
#ifdef __cplusplus
diff --git a/ndn-cpp/encoding/der/der.cpp b/ndn-cpp/encoding/der/der.cpp
index 7981727..0b5531e 100644
--- a/ndn-cpp/encoding/der/der.cpp
+++ b/ndn-cpp/encoding/der/der.cpp
@@ -576,7 +576,7 @@
/*
* DerGtime
*/
-DerGtime::DerGtime(const Time& time)
+DerGtime::DerGtime(const MillisecondsSince1970& time)
:DerNode(DER_GENERALIZED_TIME)
{
string pTimeStr = toIsoString(time);
@@ -594,14 +594,14 @@
DerGtime::~DerGtime()
{}
-string DerGtime::toIsoString(const Time& time)
+string DerGtime::toIsoString(const MillisecondsSince1970& time)
{
#if 1
throw std::runtime_error("not implemented");
#endif
}
-Time DerGtime::fromIsoString(const string& isoString)
+MillisecondsSince1970 DerGtime::fromIsoString(const string& isoString)
{
#if 1
throw std::runtime_error("not implemented");
diff --git a/ndn-cpp/encoding/der/der.hpp b/ndn-cpp/encoding/der/der.hpp
index 9ed4a2a..ff92c78 100644
--- a/ndn-cpp/encoding/der/der.hpp
+++ b/ndn-cpp/encoding/der/der.hpp
@@ -355,7 +355,7 @@
class DerGtime : public DerNode
{
public:
- DerGtime(const Time& time);
+ DerGtime(const MillisecondsSince1970& time);
DerGtime(std::istream& start);
@@ -372,14 +372,14 @@
* @param time Milliseconds since 1/1/1970.
* @return The ISO string.
*/
- static std::string toIsoString(const Time& time);
+ static std::string toIsoString(const MillisecondsSince1970& time);
/**
* Convert from the ISO string representation to the internal time format.
* @param isoString The ISO time formatted string.
* @return The time in milliseconds since 1/1/1970.
*/
- static Time fromIsoString(const std::string& isoString);
+ static MillisecondsSince1970 fromIsoString(const std::string& isoString);
};
} // der
diff --git a/ndn-cpp/node.cpp b/ndn-cpp/node.cpp
index 35a295a..622d155 100644
--- a/ndn-cpp/node.cpp
+++ b/ndn-cpp/node.cpp
@@ -240,7 +240,7 @@
transport_->processEvents();
// Check for PIT entry timeouts. Go backwards through the list so we can erase entries.
- double nowMilliseconds = ndn_getNowMilliseconds();
+ MillisecondsSince1970 nowMilliseconds = ndn_getNowMilliseconds();
for (int i = (int)pendingInterestTable_.size() - 1; i >= 0; --i) {
if (pendingInterestTable_[i]->checkTimeout(this, nowMilliseconds)) {
pendingInterestTable_.erase(pendingInterestTable_.begin() + i);
@@ -352,7 +352,7 @@
}
bool
-Node::PendingInterest::checkTimeout(Node *parent, double nowMilliseconds)
+Node::PendingInterest::checkTimeout(Node *parent, MillisecondsSince1970 nowMilliseconds)
{
if (timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_) {
if (onTimeout_) {
diff --git a/ndn-cpp/security/certificate/certificate.cpp b/ndn-cpp/security/certificate/certificate.cpp
index 9a01424..a1acfbf 100644
--- a/ndn-cpp/security/certificate/certificate.cpp
+++ b/ndn-cpp/security/certificate/certificate.cpp
@@ -45,7 +45,7 @@
bool
Certificate::isTooEarly()
{
- Time now = ndn_getNowMilliseconds();
+ MillisecondsSince1970 now = ndn_getNowMilliseconds();
if(now < notBefore_)
return true;
else
@@ -55,7 +55,7 @@
bool
Certificate::isTooLate()
{
- Time now = ndn_getNowMilliseconds();
+ MillisecondsSince1970 now = ndn_getNowMilliseconds();
if(now > notAfter_)
return true;
else
diff --git a/ndn-cpp/security/identity/identity-manager.cpp b/ndn-cpp/security/identity/identity-manager.cpp
index f5b4657..c5a7793 100644
--- a/ndn-cpp/security/identity/identity-manager.cpp
+++ b/ndn-cpp/security/identity/identity-manager.cpp
@@ -82,7 +82,7 @@
}
Name
-IdentityManager::createIdentityCertificate(const Name& keyName, const Name& signerCertificateName, const Time& notBefore, const Time& notAfter)
+IdentityManager::createIdentityCertificate(const Name& keyName, const Name& signerCertificateName, const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter)
{
Blob keyBlob = identityStorage_->getKey(keyName);
shared_ptr<PublicKey> publicKey = PublicKey::fromDer(keyBlob);
@@ -97,7 +97,7 @@
ptr_lib::shared_ptr<IdentityCertificate>
IdentityManager::createIdentityCertificate
- (const Name& keyName, const PublicKey& publicKey, const Name& signerCertificateName, const Time& notBefore, const Time& notAfter)
+ (const Name& keyName, const PublicKey& publicKey, const Name& signerCertificateName, const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter)
{
#if 0
shared_ptr<IdentityCertificate> certificate(new IdentityCertificate());
@@ -236,9 +236,9 @@
current.tm_hour = 0;
current.tm_min = 0;
current.tm_sec = 0;
- Time notBefore = boost::posix_time::ptime_from_tm(current);
+ MillisecondsSince1970 notBefore = boost::posix_time::ptime_from_tm(current);
current.tm_year = current.tm_year + 20;
- Time notAfter = boost::posix_time::ptime_from_tm(current);
+ MillisecondsSince1970 notAfter = boost::posix_time::ptime_from_tm(current);
certificate->setNotBefore(notBefore);
certificate->setNotAfter(notAfter);