Support null closure
diff --git a/js/tools/build/ndn-js-uncomp.js b/js/tools/build/ndn-js-uncomp.js
index 6f3a295..e4117eb 100644
--- a/js/tools/build/ndn-js-uncomp.js
+++ b/js/tools/build/ndn-js-uncomp.js
@@ -297,7 +297,7 @@
if (LOG > 3) console.log("Fetch key according to keylocator");
var nextClosure = new KeyFetchClosure(co, currentClosure, keylocator.keyName, sigHex, wit);
var interest = new Interest(keylocator.keyName.contentName.getPrefix(4));
- interest.interestLifetime = 4.0;
+ interest.interestLifetime = 4000; // milliseconds
self.expressInterest(ndn, interest, nextClosure);
}
}
@@ -379,26 +379,30 @@
var bytearray = new Uint8Array(binaryInterest.length);
bytearray.set(binaryInterest);
- var pitEntry = new PITEntry(interest, closure);
- NDN.PITTable.push(pitEntry);
+ if (closure != null) {
+ var pitEntry = new PITEntry(interest, closure);
+ NDN.PITTable.push(pitEntry);
+ }
this.ws.send(bytearray.buffer);
if (LOG > 3) console.log('ws.send() returned.');
// Set interest timer
- closure.timerID = setTimeout(function() {
- if (LOG > 3) console.log("Interest time out.");
-
- // Remove PIT entry from NDN.PITTable
- var index = NDN.PITTable.indexOf(pitEntry);
- //console.log(NDN.PITTable);
- if (index >= 0)
- NDN.PITTable.splice(index, 1);
- //console.log(NDN.PITTable);
- // Raise closure callback
- closure.upcall(Closure.UPCALL_INTEREST_TIMED_OUT, new UpcallInfo(ndn, interest, 0, null));
- }, interest.interestLifetime); // interestLifetime is in milliseconds.
- //console.log(closure.timerID);
+ if (closure != null) {
+ closure.timerID = setTimeout(function() {
+ if (LOG > 3) console.log("Interest time out.");
+
+ // Remove PIT entry from NDN.PITTable
+ var index = NDN.PITTable.indexOf(pitEntry);
+ //console.log(NDN.PITTable);
+ if (index >= 0)
+ NDN.PITTable.splice(index, 1);
+ //console.log(NDN.PITTable);
+ // Raise closure callback
+ closure.upcall(Closure.UPCALL_INTEREST_TIMED_OUT, new UpcallInfo(ndn, interest, 0, null));
+ }, interest.interestLifetime); // interestLifetime is in milliseconds.
+ //console.log(closure.timerID);
+ }
}
else
console.log('WebSocket connection is not established.');
diff --git a/js/tools/build/ndn-js.js b/js/tools/build/ndn-js.js
index bbd7bd1..5b29d9b 100644
--- a/js/tools/build/ndn-js.js
+++ b/js/tools/build/ndn-js.js
@@ -8,11 +8,11 @@
a.readyStatus=NDN.CLOSED,a.onclose()):(b.ccndid=d.signedInfo.publisher.publisherPublicKeyDigest,3<LOG&&console.log(b.ccndid),a.readyStatus=NDN.OPENED,a.onopen());else{if(f=NDN.getEntryForExpressedInterest(d.name),null!=f){var g=NDN.PITTable.indexOf(f);0<=g&&NDN.PITTable.splice(g,1);f=f.closure;clearTimeout(f.timerID);var j=function(a,b,c,d,e){this.contentObject=a;this.closure=b;this.keyName=c;this.sigHex=d;this.witness=e;Closure.call(this)};j.prototype.upcall=function(b,c){if(b==Closure.UPCALL_INTEREST_TIMED_OUT)console.log("In KeyFetchClosure.upcall: interest time out."),
console.log(this.keyName.contentName.getName());else if(b==Closure.UPCALL_CONTENT){var d=decodeSubjectPublicKeyInfo(c.contentObject.content),e=!0==d.verifyByteArray(this.contentObject.rawSignatureData,this.witness,this.sigHex)?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD;this.closure.upcall(e,new UpcallInfo(a,null,0,this.contentObject));d=new KeyStoreEntry(l.keyName,d,(new Date).getTime());NDN.addKeyEntry(d)}else b==Closure.UPCALL_CONTENT_BAD&&console.log("In KeyFetchClosure.upcall: signature verification failed")};
if(d.signedInfo&&d.signedInfo.locator&&d.signature){3<LOG&&console.log("Key verification...");var g=DataUtils.toHex(d.signature.signature).toLowerCase(),k=null;null!=d.signature.Witness&&(k=new Witness,k.decode(d.signature.Witness));var l=d.signedInfo.locator;if(l.type==KeyLocatorType.KEYNAME)if(3<LOG&&console.log("KeyLocator contains KEYNAME"),l.keyName.contentName.match(d.name))3<LOG&&console.log("Content is key itself"),j=decodeSubjectPublicKeyInfo(d.content),g=j.verifyByteArray(d.rawSignatureData,
-k,g),g=!0==g?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,f.upcall(g,new UpcallInfo(a,null,0,d));else{var p=NDN.getKeyByName(l.keyName);p?(3<LOG&&console.log("Local key cache hit"),j=p.rsaKey,g=j.verifyByteArray(d.rawSignatureData,k,g),g=!0==g?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,f.upcall(g,new UpcallInfo(a,null,0,d))):(3<LOG&&console.log("Fetch key according to keylocator"),f=new j(d,f,l.keyName,g,k),d=new Interest(l.keyName.contentName.getPrefix(4)),d.interestLifetime=4,b.expressInterest(a,
+k,g),g=!0==g?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,f.upcall(g,new UpcallInfo(a,null,0,d));else{var p=NDN.getKeyByName(l.keyName);p?(3<LOG&&console.log("Local key cache hit"),j=p.rsaKey,g=j.verifyByteArray(d.rawSignatureData,k,g),g=!0==g?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,f.upcall(g,new UpcallInfo(a,null,0,d))):(3<LOG&&console.log("Fetch key according to keylocator"),f=new j(d,f,l.keyName,g,k),d=new Interest(l.keyName.contentName.getPrefix(4)),d.interestLifetime=4E3,b.expressInterest(a,
d,f))}else l.type==KeyLocatorType.KEY?(3<LOG&&console.log("Keylocator contains KEY"),j=decodeSubjectPublicKeyInfo(d.signedInfo.locator.publicKey),g=j.verifyByteArray(d.rawSignatureData,k,g),g=!0==g?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,f.upcall(Closure.UPCALL_CONTENT,new UpcallInfo(a,null,0,d))):(d=l.certificate,console.log("KeyLocator contains CERT"),console.log(d))}}}else console.log("Incoming packet is not Interest or ContentObject. Discard now.");delete c;delete b.structureDecoder;
delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);b.bufferOffset=0}};this.ws.onopen=function(a){3<LOG&&console.log(a);3<LOG&&console.log("ws.onopen: WebSocket connection opened.");3<LOG&&console.log("ws.onopen: ReadyState: "+this.readyState);a=new Interest(NDN.ccndIdFetcher);a.interestLifetime=4E3;var a=encodeToBinaryInterest(a),d=new Uint8Array(a.length);d.set(a);b.ws.send(d.buffer)};this.ws.onerror=function(a){console.log("ws.onerror: ReadyState: "+
this.readyState);console.log(a);console.log("ws.onerror: WebSocket error: "+a.data)};this.ws.onclose=function(){console.log("ws.onclose: WebSocket connection closed.");b.ws=null;a.readyStatus=NDN.CLOSED;a.onclose()}};
-WebSocketTransport.prototype.expressInterest=function(a,b,c){if(null!=this.ws){var d=encodeToBinaryInterest(b),e=new Uint8Array(d.length);e.set(d);var f=new PITEntry(b,c);NDN.PITTable.push(f);this.ws.send(e.buffer);3<LOG&&console.log("ws.send() returned.");c.timerID=setTimeout(function(){3<LOG&&console.log("Interest time out.");var d=NDN.PITTable.indexOf(f);0<=d&&NDN.PITTable.splice(d,1);c.upcall(Closure.UPCALL_INTEREST_TIMED_OUT,new UpcallInfo(a,b,0,null))},b.interestLifetime)}else console.log("WebSocket connection is not established.")};
+WebSocketTransport.prototype.expressInterest=function(a,b,c){if(null!=this.ws){var d=encodeToBinaryInterest(b),e=new Uint8Array(d.length);e.set(d);if(null!=c){var f=new PITEntry(b,c);NDN.PITTable.push(f)}this.ws.send(e.buffer);3<LOG&&console.log("ws.send() returned.");null!=c&&(c.timerID=setTimeout(function(){3<LOG&&console.log("Interest time out.");var d=NDN.PITTable.indexOf(f);0<=d&&NDN.PITTable.splice(d,1);c.upcall(Closure.UPCALL_INTEREST_TIMED_OUT,new UpcallInfo(a,b,0,null))},b.interestLifetime))}else console.log("WebSocket connection is not established.")};
var CSTable=[],CSEntry=function(a,b){this.name=a;this.closure=b};function getEntryForRegisteredPrefix(a){for(var b=0;b<CSTable.length;b++)if(null!=CSTable[b].name.match(a))return CSTable[b];return null}
WebSocketTransport.prototype.registerPrefix=function(a,b,c){if(null!=this.ws){if(null==this.ccndid)return console.log("ccnd node ID unkonwn. Cannot register prefix."),-1;var a=new ForwardingEntry("selfreg",b,null,null,3,2147483647),a=encodeForwardingEntry(a),d=new SignedInfo;d.setFields();a=new ContentObject(new Name,d,a,new Signature);a.sign();a=encodeToBinaryContentObject(a);a=new Name(["ccnx",this.ccndid,"selfreg",a]);a=new Interest(a);a.scope=1;d=encodeToBinaryInterest(a);a=new Uint8Array(d.length);
a.set(d);3<LOG&&console.log("Send Interest registration packet.");b=new CSEntry(b.getName(),c);CSTable.push(b);this.ws.send(a.buffer);return 0}console.log("WebSocket connection is not established.");return-1};