Updated ndn-js for onSuccessCallback for registration.
This still needs further testing, the code can properly request but
still needs the full backend test to confirm it works.
Change-Id: I33d55b376a1d0ba5254330cd465ecdddaab83f3c
diff --git a/client/catalog-dev/js/catalog.js b/client/catalog-dev/js/catalog.js
index 29cd6f3..7aaef39 100644
--- a/client/catalog-dev/js/catalog.js
+++ b/client/catalog-dev/js/catalog.js
@@ -257,8 +257,8 @@
scope.getResults(0);
}, function(interest){ //Timeout function
- console.warn("Request failed! Timeout");
- scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
+ console.warn("Request failed after 3 attempts!", interest);
+ scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details.");
});
}
@@ -528,24 +528,6 @@
//Retrieval
var retrievePrefix = new Name("/catalog/ui/" + guid());
- //Due to a lack of success callback in the register prefix function, we have to pretend we
- //know it succeeded with an arbitrary timeout.
- var sendTimer = setTimeout(function(){
- var prefix = new Name(dest.text());
- prefix.append(retrievePrefix);
- var interest = new Interest(prefix);
- interest.setInterestLifetimeMilliseconds(3000);
- scope.face.expressInterest(interest,
- function(interest, data){ //Success
- console.log("Request for", prefix.toUri(), "succeeded.", interest, data);
- scope.createAlert("Data retrieval has initiated.", "alert-success");
- }, function(interest){ //Failure
- console.error("Request for", prefix.toUri(), "timed out.", interest);
- scope.createAlert("Request for " + prefix.toUri() + " timed out. This means that the retrieve failed! See console for more details.");
- }
- );
- }, 5000); //Wait 5 seconds
-
scope.face.registerPrefix(retrievePrefix,
function(prefix, interest, face, interestFilterId, filter){ //On Interest
//This function will exist until the page exits but will likely only be used once.
@@ -558,16 +540,38 @@
try {
face.putData(data);
console.log("Responded for", interest.getName().toUri(), data);
+ scope.createAlert("Data retrieval has initiated.", "alert-success");
} catch (e) {
console.error("Failed to respond to", interest.getName().toUri(), data);
scope.createAlert("Data retrieval failed.");
}
}, function(prefix){ //On fail
- clearTimeout(sendTimer); //Cancel the earlier request timer
scope.createAlert("Failed to register the retrieval URI! See console for details.", "alert-danger");
console.error("Failed to register URI:", prefix.toUri(), prefix);
+ }, function(prefix, registeredPrefixId){ //On success
+ var name = new Name(dest.text());
+ name.append(prefix);
+ var interest = new Interest(name);
+ interest.setInterestLifetimeMilliseconds(1500);
+ var count = 3;
+ var run = function(i2){
+
+ if (--count === 0) {
+ console.error("Request for", name.toUri(), "timed out (3 times).", i2);
+ scope.createAlert("Request for " + name.toUri() + " timed out after 3 attempts. This means that the retrieve failed! See console for more details.");
+ return;
+ }
+
+ scope.face.expressInterest(interest,
+ function(interest, data){ //Success
+ console.log("Request for", name.toUri(), "succeeded.", interest, data);
+ },
+ run
+ );
+ }
+ run();
}
);
diff --git a/client/ndn-js b/client/ndn-js
index a54c9eb..84ae11d 160000
--- a/client/ndn-js
+++ b/client/ndn-js
@@ -1 +1 @@
-Subproject commit a54c9eb542cc3596656910c25daab52b5a12e9dd
+Subproject commit 84ae11d023c41d05ba5b4b727d876a912e2ecded