Set interest timeout with interest.interestLifetime
diff --git a/js/tools/build/ndn-js-uncomp.js b/js/tools/build/ndn-js-uncomp.js
index fa00a92..4b62da8 100644
--- a/js/tools/build/ndn-js-uncomp.js
+++ b/js/tools/build/ndn-js-uncomp.js
@@ -98,8 +98,6 @@
NDN.OPENED = 1; // connection to ccnd opened
NDN.CLOSED = 2; // connection to ccnd closed
-NDN.InterestTimeOut = 5000; // 5000 ms timeout for pending interest
-
/* Java Socket Bridge and XPCOM transport */
NDN.prototype.createRoute = function(host,port){
@@ -136,7 +134,7 @@
interest.interestLifetime = template.interestLifetime;
}
else
- interest.interestLifetime = 4200;
+ interest.interestLifetime = 4200; // default interest timeout value
this.transport.expressInterest(this, interest, closure);
};
@@ -266,6 +264,11 @@
clearTimeout(pitEntry.closure.timerID);
//console.log("Clear interest timer");
//console.log(pitEntry.closure.timerID);
+
+ // Remove PIT entry from PITTable
+ index = PITTable.indexOf(pitEntry);
+ PITTable.splice(index, 1);
+
// Raise callback
pitEntry.closure.upcall(Closure.UPCALL_CONTENT, new UpcallInfo(ndn, null, 0, co));
}
@@ -356,7 +359,7 @@
// Set interest timer
closure.timerID = setTimeout(function() {
- console.log("Interest time out.");
+ if (LOG > 3) console.log("Interest time out.");
// Remove PIT entry from PITTable
index = PITTable.indexOf(pitEntry);
@@ -365,7 +368,7 @@
//console.log(PITTable);
// Raise closure callback
closure.upcall(Closure.UPCALL_INTEREST_TIMED_OUT, new UpcallInfo(ndn, interest, 0, null));
- }, NDN.InterestTimeOut);
+ }, interest.interestLifetime);
//console.log(closure.timerID);
}
else
@@ -437,7 +440,7 @@
}
}
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class contains all CCNx tags
@@ -593,7 +596,7 @@
//TESTING
//console.log(exports.CCNProtocolDTagsStrings[17]);
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents CCNTime Objects
@@ -696,7 +699,7 @@
return out;
}*/
-/*
+/**
* @author: Meki Cheraoui, Jeff Thompson
* See COPYING for copyright and distribution information.
* This class represents a Name as an array of components where each is a byte array.
@@ -956,7 +959,7 @@
}
return result;
};
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents ContentObject Objects
@@ -1522,7 +1525,7 @@
Date.prototype.format = function (mask, utc) {
return dateFormat(this, mask, utc);
};
- /*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents Interest Objects
@@ -1746,7 +1749,7 @@
};
ExcludeComponent.prototype.getElementLabel = function() { return CCNProtocolDTags.Component; };
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents Key Objects
@@ -1941,7 +1944,7 @@
// null signedInfo ok
return (null != this.contentName);
};
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents Publisher and PublisherType Objects
@@ -2037,7 +2040,7 @@
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents PublisherPublicKeyDigest Objects
@@ -2088,7 +2091,7 @@
PublisherPublicKeyDigest.prototype.validate =function() {
return (null != this.publisherPublicKeyDigest);
};
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents Face Instances
@@ -2247,7 +2250,7 @@
FaceInstance.prototype.getElementLabel= function(){return CCNProtocolDTags.FaceInstance;};
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
* This class represents Forwarding Entries
@@ -2347,7 +2350,7 @@
};
ForwardingEntry.prototype.getElementLabel = function() { return CCNProtocolDTags.ForwardingEntry; }
-/*
+/**
* This class is used to encode ccnb binary elements (blob, type/value pairs).
*
* @author: Meki Cheraoui
@@ -2745,7 +2748,7 @@
return this.ostream.subarray(0, this.offset);
};
-/*
+/**
* This class is used to decode ccnb binary elements (blob, type/value pairs).
*
* @author: Meki Cheraoui
@@ -3474,7 +3477,7 @@
ContentDecodingException.prototype = new Error();
ContentDecodingException.prototype.name = "ContentDecodingException";
-/*
+/**
* This class uses BinaryXMLDecoder to follow the structure of a ccnb binary element to
* determine its end.
*
@@ -3652,7 +3655,7 @@
this.headerBuffer = newHeaderBuffer;
}
this.headerBuffer.set(subarray, bufferOffset);
-}/*
+}/**
* This class contains utilities to help parse the data
* author: Meki Cheraoui, Jeff Thompson
* See COPYING for copyright and distribution information.
@@ -4084,7 +4087,7 @@
}
return result.subarray(size - i, size);
};
-/*
+/**
* This file contains utilities to help encode and decode NDN objects.
* author: Meki Cheraoui
* See COPYING for copyright and distribution information.
@@ -4429,7 +4432,7 @@
return output;
}
-/*
+/**
* @author: Meki Cheraoui
* See COPYING for copyright and distribution information.
*/
diff --git a/js/tools/build/ndn-js.js b/js/tools/build/ndn-js.js
index 77ae081..5a409ed 100644
--- a/js/tools/build/ndn-js.js
+++ b/js/tools/build/ndn-js.js
@@ -1,16 +1,16 @@
var Closure=function(){this.ndn_data=null;this.ndn_data_dirty=!1;this.timerID=-1};Closure.RESULT_ERR=-1;Closure.RESULT_OK=0;Closure.RESULT_REEXPRESS=1;Closure.RESULT_INTEREST_CONSUMED=2;Closure.RESULT_VERIFY=3;Closure.RESULT_FETCHKEY=4;Closure.UPCALL_FINAL=0;Closure.UPCALL_INTEREST=1;Closure.UPCALL_CONSUMED_INTEREST=2;Closure.UPCALL_CONTENT=3;Closure.UPCALL_INTEREST_TIMED_OUT=4;Closure.UPCALL_CONTENT_UNVERIFIED=5;Closure.UPCALL_CONTENT_BAD=6;Closure.prototype.upcall=function(){return Closure.RESULT_OK};
var UpcallInfo=function(a,b,c,d){this.ndn=a;this.interest=b;this.matchedComps=c;this.contentObject=d};UpcallInfo.prototype.toString=function(){var a="ndn = "+this.ndn,a=a+("\nInterest = "+this.interest),a=a+("\nmatchedComps = "+this.matchedComps);return a+="\nContentObject: "+this.contentObject};
-var LOG=0,NDN=function NDN(b){b=b||{};this.host=b.host||"localhost";this.port=b.port||9696;this.transport=(b.getTransport||function(){return new WebSocketTransport})();this.readyStatus=NDN.UNOPEN;this.onopen=b.onopen||function(){3<LOG&&console.log("NDN connection established.")};this.onclose=b.onclose||function(){3<LOG&&console.log("NDN connection closed.")}};NDN.UNOPEN=0;NDN.OPENED=1;NDN.CLOSED=2;NDN.InterestTimeOut=5E3;NDN.prototype.createRoute=function(a,b){this.host=a;this.port=b};
+var LOG=0,NDN=function NDN(b){b=b||{};this.host=b.host||"localhost";this.port=b.port||9696;this.transport=(b.getTransport||function(){return new WebSocketTransport})();this.readyStatus=NDN.UNOPEN;this.onopen=b.onopen||function(){3<LOG&&console.log("NDN connection established.")};this.onclose=b.onclose||function(){3<LOG&&console.log("NDN connection closed.")}};NDN.UNOPEN=0;NDN.OPENED=1;NDN.CLOSED=2;NDN.prototype.createRoute=function(a,b){this.host=a;this.port=b};
NDN.prototype.expressInterest=function(a,b,c){null==this.host||null==this.port?dump("ERROR host OR port NOT SET\n"):(a=new Interest(a),null!=c?(a.minSuffixComponents=c.minSuffixComponents,a.maxSuffixComponents=c.maxSuffixComponents,a.publisherPublicKeyDigest=c.publisherPublicKeyDigest,a.exclude=c.exclude,a.childSelector=c.childSelector,a.answerOriginKind=c.answerOriginKind,a.scope=c.scope,a.interestLifetime=c.interestLifetime):a.interestLifetime=4200,this.transport.expressInterest(this,a,b))};
NDN.prototype.registerPrefix=function(a,b,c){return this.transport.registerPrefix(this,a,b,c)};var WebSocketTransport=function(){this.ccndid=this.ws=null;this.maxBufferSize=1E4;this.buffer=new Uint8Array(this.maxBufferSize);this.structureDecoder=new BinaryXMLStructureDecoder},ccndIdFetcher="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY";
WebSocketTransport.prototype.connectWebSocket=function(a){null!=this.ws&&delete this.ws;this.ws=new WebSocket("ws://"+a.host+":"+a.port);0<LOG&&console.log("ws connection created.");this.ws.binaryType="arraybuffer";var b=this;this.ws.onmessage=function(c){c=c.data;if(null==c||void 0==c||""==c)console.log("INVALID ANSWER");else if(c instanceof ArrayBuffer){c=new Uint8Array(c);3<LOG&&console.log("BINARY RESPONSE IS "+DataUtils.toHex(c));try{if(c.length+b.buffer.byteOffset>=b.buffer.byteLength){console.log("NDN.ws.onmessage: buffer overflow. Accumulate received length: "+
b.buffer.byteOffset+". Current packet length: "+c.length+".");delete b.structureDecoder;delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);return}b.buffer.set(c,b.buffer.byteOffset);if(!b.structureDecoder.findElementEnd(b.buffer)){console.log("Incomplete packet received. Length "+c.length+". Wait for more input.");console.log("self.buffer length: "+b.buffer.length);return}}catch(d){console.log("NDN.ws.onmessage exception: "+d);return}c=new BinaryXMLDecoder(b.buffer);
if(c.peekStartElement(CCNProtocolDTags.Interest)){3<LOG&&console.log("Interest packet received.");var e=new Interest;e.from_ccnb(c);3<LOG&&console.log(e);var f=escape(e.name.getName());3<LOG&&console.log(f);f=getEntryForRegisteredPrefix(f);null!=f&&f.closure.upcall(Closure.UPCALL_INTEREST,new UpcallInfo(a,e,0,null))}else c.peekStartElement(CCNProtocolDTags.ContentObject)?(3<LOG&&console.log("ContentObject packet received."),e=new ContentObject,e.from_ccnb(c),3<LOG&&console.log(e),f=e.name.getName(),
-3<LOG&&console.log(f),null==b.ccndid&&null!=f.match(ccndIdFetcher)?!e.signedInfo||!e.signedInfo.publisher||!e.signedInfo.publisher.publisherPublicKeyDigest?(console.log("Cannot contact router, close NDN now."),a.readyStatus=NDN.CLOSED,a.onclose()):(b.ccndid=e.signedInfo.publisher.publisherPublicKeyDigest,3<LOG&&console.log(b.ccndid),a.readyStatus=NDN.OPENED,a.onopen()):(f=getEntryForExpressedInterest(f),null!=f&&(clearTimeout(f.closure.timerID),f.closure.upcall(Closure.UPCALL_CONTENT,new UpcallInfo(a,
-null,0,e))))):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)}};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(new Name(ccndIdFetcher));a.InterestLifetime=4200;var a=encodeToBinaryInterest(a),
+3<LOG&&console.log(f),null==b.ccndid&&null!=f.match(ccndIdFetcher)?!e.signedInfo||!e.signedInfo.publisher||!e.signedInfo.publisher.publisherPublicKeyDigest?(console.log("Cannot contact router, close NDN now."),a.readyStatus=NDN.CLOSED,a.onclose()):(b.ccndid=e.signedInfo.publisher.publisherPublicKeyDigest,3<LOG&&console.log(b.ccndid),a.readyStatus=NDN.OPENED,a.onopen()):(f=getEntryForExpressedInterest(f),null!=f&&(clearTimeout(f.closure.timerID),index=PITTable.indexOf(f),PITTable.splice(index,1),f.closure.upcall(Closure.UPCALL_CONTENT,
+new UpcallInfo(a,null,0,e))))):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)}};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(new Name(ccndIdFetcher));a.InterestLifetime=4200;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()}};var PITTable=[],PITEntry=function(a,b){this.interest=a;this.closure=b};
function getEntryForExpressedInterest(a){for(var b=0;b<PITTable.length;b++)if(null!=a.match(PITTable[b].interest))return PITTable[b];return null}
-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.name.getName(),c);PITTable.push(f);this.ws.send(e.buffer);3<LOG&&console.log("ws.send() returned.");c.timerID=setTimeout(function(){console.log("Interest time out.");index=PITTable.indexOf(f);PITTable.splice(index,1);c.upcall(Closure.UPCALL_INTEREST_TIMED_OUT,new UpcallInfo(a,b,0,null))},NDN.InterestTimeOut)}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);var f=new PITEntry(b.name.getName(),c);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.");index=PITTable.indexOf(f);PITTable.splice(index,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};