In readBinaryElement, added argument allowNull, and use for ContentObject content.
This fixes some of the connection problems where the initial response from a new hub would not decode.
diff --git a/js/tools/build/ndn-js-uncomp.js b/js/tools/build/ndn-js-uncomp.js
index 0abf8d0..51a90d8 100644
--- a/js/tools/build/ndn-js-uncomp.js
+++ b/js/tools/build/ndn-js-uncomp.js
@@ -975,10 +975,7 @@
this.signedInfo.from_ccnb(decoder);
}
- if (decoder.peekTypeAndVal() == null)
- this.content = null;
- else
- this.content = decoder.readBinaryElement(CCNProtocolDTags.Content);
+ this.content = decoder.readBinaryElement(CCNProtocolDTags.Content, null, true);
this.endSIG = decoder.offset;
@@ -3086,19 +3083,16 @@
};
-// returns a byte[]
+// Returns a Uint8Array.
BinaryXMLDecoder.prototype.readBinaryElement = function(
//long
startTag,
//TreeMap<String, String>
- attributes){
- //byte []
- var blob = null;
-
+ attributes,
+ //boolean
+ allowNull){
this.readStartElement(startTag, attributes);
- blob = this.readBlob();
-
- return blob;
+ return this.readBlob(allowNull);
};
@@ -3130,15 +3124,21 @@
};
-//returns a uint8array
-BinaryXMLDecoder.prototype.readBlob = function() {
- //uint8array
-
- var blob = this.decodeBlob();
- this.readEndElement();
- return blob;
-
- };
+/*
+ * Read a blob as well as the end element. Returns a Uint8Array (or null for missing blob).
+ * If the blob is missing and allowNull is false (default), throw an exception. Otherwise,
+ * just read the end element and return null.
+ */
+BinaryXMLDecoder.prototype.readBlob = function(allowNull) {
+ if (this.istream[this.offset] == XML_CLOSE && allowNull) {
+ this.readEndElement();
+ return null;
+ }
+
+ var blob = this.decodeBlob();
+ this.readEndElement();
+ return blob;
+};
//CCNTime
@@ -7772,7 +7772,7 @@
// Set interest timer.
var timeoutMilliseconds = (interest.interestLifetime || 4000);
var timeoutCallback = function() {
- if (LOG > 3) console.log("Interest time out: " + interest.name.to_uri());
+ if (LOG > 1) console.log("Interest time out: " + interest.name.to_uri());
// Remove PIT entry from NDN.PITTable, even if we add it again later to re-express
// the interest because we don't want to match it in the mean time.
@@ -7784,7 +7784,7 @@
// Raise closure callback
if (closure.upcall(Closure.UPCALL_INTEREST_TIMED_OUT,
new UpcallInfo(thisNDN, interest, 0, null)) == Closure.RESULT_REEXPRESS) {
- if (LOG > 3) console.log("Re-express interest: " + interest.name.to_uri());
+ if (LOG > 1) console.log("Re-express interest: " + interest.name.to_uri());
pitEntry.timerID = setTimeout(timeoutCallback, timeoutMilliseconds);
NDN.PITTable.push(pitEntry);
thisNDN.transport.send(binaryInterest);
@@ -8072,7 +8072,7 @@
this.host = hostAndPort.host;
this.port = hostAndPort.port;
- if (LOG>3) console.log("Connect: trying host from getHostAndPort: " + this.host);
+ if (LOG>0) console.log("connectAndExecute: trying host from getHostAndPort: " + this.host);
// Fetch any content.
var interest = new Interest(new Name("/"));
@@ -8080,7 +8080,7 @@
var thisNDN = this;
var timerID = setTimeout(function() {
- if (LOG>3) console.log("Connect: timeout waiting for host " + thisNDN.host);
+ if (LOG>0) console.log("connectAndExecute: timeout waiting for host " + thisNDN.host);
// Try again.
thisNDN.connectAndExecute(onConnected);
}, 3000);
@@ -8111,6 +8111,7 @@
this.ndn.readyStatus = NDN.OPENED;
this.ndn.onopen();
+ if (LOG>0) console.log("connectAndExecute: connected to host " + this.ndn.host);
this.onConnected();
return Closure.RESULT_OK;