tests: Porting forwarding entry test and fixing app tests
Change-Id: Ia6d2a0b39a1105c0873f873bbd4fce49dabb3cca
diff --git a/tests/test-publish-async.cpp b/tests/test-publish-async.cpp
index 270e6fc..4f4ede7 100644
--- a/tests/test-publish-async.cpp
+++ b/tests/test-publish-async.cpp
@@ -12,7 +12,6 @@
#include <ndn-cpp/face.hpp>
#include <ndn-cpp/security/identity/memory-identity-storage.hpp>
#include <ndn-cpp/security/identity/memory-private-key-storage.hpp>
-#include <ndn-cpp/security/policy/no-verify-policy-manager.hpp>
#include <ndn-cpp/security/key-chain.hpp>
using namespace std;
@@ -66,8 +65,10 @@
class Echo {
public:
- Echo(KeyChain &keyChain, const Name& certificateName)
- : keyChain_(keyChain), certificateName_(certificateName), responseCount_(0)
+ Echo(KeyChain &keyChain, Face &face)
+ : keyChain_(keyChain)
+ , face_(face)
+ , responseCount_(0)
{
}
@@ -81,13 +82,17 @@
// Make and sign a Data packet.
Data data(interest->getName());
string content(string("Echo ") + interest->getName().toUri());
+ data.setFreshnessPeriod(1000);
data.setContent((const uint8_t *)&content[0], content.size());
- data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
- keyChain_.sign(data, certificateName_);
- Blob encodedData = data.wireEncode();
- cout << "Sent content " << content << endl;
- transport.send(*encodedData);
+ keyChain_.sign(data);
+
+ // Put data on wire
+ face_.put(data);
+
+ // Unregister prefix to ensure that the processing thread finishes after Data
+ // packet is send out to the forwarder
+ face_.unsetInterestFilter(registeredPrefixId);
}
// onRegisterFailed.
@@ -97,42 +102,39 @@
cout << "Register failed for prefix " << prefix->toUri() << endl;
}
- KeyChain keyChain_;
- Name certificateName_;
+ KeyChain &keyChain_;
+ Face &face_;
int responseCount_;
};
int main(int argc, char** argv)
{
try {
- Face face("localhost");
+ Face face;
ptr_lib::shared_ptr<MemoryIdentityStorage> identityStorage(new MemoryIdentityStorage());
ptr_lib::shared_ptr<MemoryPrivateKeyStorage> privateKeyStorage(new MemoryPrivateKeyStorage());
- KeyChain keyChain
- (ptr_lib::make_shared<IdentityManager>(identityStorage, privateKeyStorage), ptr_lib::shared_ptr<NoVerifyPolicyManager>(new NoVerifyPolicyManager()));
- keyChain.setFace(&face);
-
+ KeyChain keyChain(identityStorage, privateKeyStorage);
+
+ Name keyName("/testname/dsk-123");
+
// Initialize the storage.
- Name keyName("/testname/DSK-123");
- Name certificateName = keyName.getSubName(0, keyName.size() - 1).append("KEY").append
- (keyName.get(keyName.size() - 1)).append("ID-CERT").append("0");
- identityStorage->addKey(keyName, KEY_TYPE_RSA, Blob(DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER)));
- privateKeyStorage->setKeyPairForKeyName
- (keyName, DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER), DEFAULT_PRIVATE_KEY_DER, sizeof(DEFAULT_PRIVATE_KEY_DER));
+ identityStorage->addKey(keyName, KEY_TYPE_RSA,
+ PublicKey(DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER)));
+
+ privateKeyStorage->setKeyPairForKeyName(keyName,
+ DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER),
+ DEFAULT_PRIVATE_KEY_DER, sizeof(DEFAULT_PRIVATE_KEY_DER));
+
+ keyChain.identities().addCertificateAsDefault(*keyChain.identities().selfSign(keyName));
+
- Echo echo(keyChain, certificateName);
+ Echo echo(keyChain, face);
Name prefix("/testecho");
cout << "Register prefix " << prefix.toUri() << endl;
face.setInterestFilter(prefix, func_lib::ref(echo), func_lib::ref(echo));
- // The main event loop.
- // Wait forever to receive one interest for the prefix.
- while (echo.responseCount_ < 1) {
- face.processEvents();
- // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
- usleep(10000);
- }
+ face.processEvents();
} catch (std::exception& e) {
cout << "exception: " << e.what() << endl;
}