Added query retrying to help with cases that might not fail.

Change-Id: I6b2197c0aa190cfcdd9e43e692e38b854021dd5b
diff --git a/client/catalog-dev/js/catalog.js b/client/catalog-dev/js/catalog.js
index 7aaef39..1e88459 100644
--- a/client/catalog-dev/js/catalog.js
+++ b/client/catalog-dev/js/catalog.js
@@ -273,26 +273,36 @@
       var name = new Name(data.getContent().toString().replace(/[\n\0]/g,""));
 
       var interest = new Interest(name);
-      interest.setInterestLifetimeMilliseconds(5000);
+      interest.setInterestLifetimeMilliseconds(1500);
       interest.setMustBeFresh(true);
 
-      scope.face.expressInterest(interest,
-      function(interest, data){
+      var count = 3;
 
-        if (data.getContent().length !== 0){
-          callback(JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")));
-        } else {
-          callback([]);
+      var run = function(){
+
+        if (--count === 0){
+          console.warn("Interest timed out!", interest);
+          scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details.");
+          return;
         }
 
-      }, function(interest){
-        console.warn("Interest timed out!", interest);
-        scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
-      });
+        scope.face.expressInterest(interest,
+        function(interest, data){
+
+          if (data.getContent().length !== 0){
+            callback(JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")));
+          } else {
+            callback([]);
+          }
+
+        }, run);
+      }
+
+      run();
 
     }, function(interest){
       console.error("Request failed! Timeout", interest);
-      scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
+      scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details.");
     });
 
   }
@@ -416,10 +426,19 @@
     queryPrefix.append(jsonString);
 
     var queryInterest = new Interest(queryPrefix);
-    queryInterest.setInterestLifetimeMilliseconds(4000);
+    queryInterest.setInterestLifetimeMilliseconds(1500);
     queryInterest.setMustBeFresh(true);
 
-    this.face.expressInterest(queryInterest, callback, timeout);
+    var face = this.face;
+    var retry = 3;
+    var run = function(interest){
+      if (--retry === 0){
+        timeout(interest);
+      } else {
+        face.expressInterest(queryInterest, callback, run);
+      }
+    }
+    run();
 
   }
 
@@ -656,20 +675,29 @@
     var scope = this;
     var d = [];
 
+    var count = 3;
+    var retry = function(interest){
+      if (count === 0){
+        timeout(interest);
+      } else {
+        count--;
+        request(interest.getName().get(-1).toSegment());
+      }
+    }
+
     var request = function(segment){
 
       var name = new Name(prefix);
       name.appendSegment(segment);
 
       var interest = new Interest(name);
-      interest.setInterestLifetimeMilliseconds(1000);
+      interest.setInterestLifetimeMilliseconds(1500);
       interest.setMustBeFresh(true); //Is this needed?
 
-      scope.face.expressInterest(interest, handleData, timeout);
+      scope.face.expressInterest(interest, handleData, retry);
 
     }
 
-
     var handleData = function(interest, data){
 
       d.push(data.getContent().toString());
@@ -677,7 +705,7 @@
       if (interest.getName().get(-1).toSegment() == data.getMetaInfo().getFinalBlockId().toSegment()){
         callback(d.join(""));
       } else {
-        request(interest.getName().toSegment()++);
+        request(interest.getName().get(-1).toSegment() + 1);
       }
 
     }