Move timerID to pit entry; implement basic pipeline code
diff --git a/js/Closure.js b/js/Closure.js
index 2482e2b..7a1e9de 100644
--- a/js/Closure.js
+++ b/js/Closure.js
@@ -19,7 +19,6 @@
this.ndn_data = null; // this holds the ndn_closure
this.ndn_data_dirty = false;
- this.timerID = -1; // Store the interest timer; used to cancel the timer upon receiving interest
};
// Upcall result
diff --git a/js/NDN.js b/js/NDN.js
index 31e4cd0..0410425 100644
--- a/js/NDN.js
+++ b/js/NDN.js
@@ -81,6 +81,7 @@
var PITEntry = function PITEntry(interest, closure) {
this.interest = interest; // Interest
this.closure = closure; // Closure
+ this.timerID = -1; // Timer ID
};
// Return the longest entry from NDN.PITTable that matches name.
diff --git a/js/WebSocketTransport.js b/js/WebSocketTransport.js
index b40176e..594aff4 100644
--- a/js/WebSocketTransport.js
+++ b/js/WebSocketTransport.js
@@ -143,7 +143,7 @@
var currentClosure = pitEntry.closure;
// Cancel interest timer
- clearTimeout(currentClosure.timerID);
+ clearTimeout(pitEntry.timerID);
//console.log("Clear interest timer");
//console.log(currentClosure.timerID);
@@ -316,6 +316,7 @@
if (closure != null) {
var pitEntry = new PITEntry(interest, closure);
NDN.PITTable.push(pitEntry);
+ closure.pitEntry = pitEntry;
}
this.ws.send(bytearray.buffer);
@@ -323,7 +324,7 @@
// Set interest timer
if (closure != null) {
- closure.timerID = setTimeout(function() {
+ pitEntry.timerID = setTimeout(function() {
if (LOG > 3) console.log("Interest time out.");
// Remove PIT entry from NDN.PITTable
@@ -332,6 +333,8 @@
if (index >= 0)
NDN.PITTable.splice(index, 1);
//console.log(NDN.PITTable);
+ //console.log(pitEntry.interest.name.getName());
+
// Raise closure callback
closure.upcall(Closure.UPCALL_INTEREST_TIMED_OUT, new UpcallInfo(ndn, interest, 0, null));
}, interest.interestLifetime); // interestLifetime is in milliseconds.
diff --git a/js/testing/test-throughput-ws-pipeline.html b/js/testing/test-throughput-ws-pipeline.html
new file mode 100644
index 0000000..f741fb0
--- /dev/null
+++ b/js/testing/test-throughput-ws-pipeline.html
@@ -0,0 +1,332 @@
+<?xml version = "1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"DTD/xhtml1-strict.dtd">
+<html xmlns = "http://www.w3.org/1999/xhtml">
+<meta charset="UTF-8">
+
+<head>
+ <title>NDN Get File via WebSocket</title>
+
+ <script type="text/javascript" src="../tools/build/ndn-js.js"></script>
+
+ <script type="text/javascript">
+ //hostip = "131.179.196.232";
+ hostip = "localhost";
+ var ndncon = new NDN({port:9696,host:hostip});
+ ndncon.transport.connectWebSocket(ndncon);
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+ /*
+ * Closure for calling expressInterest to fetch big file.
+ */
+ var ContentClosure = function ContentClosure(ndn, T0) {
+ // Inherit from Closure.
+ Closure.call(this);
+
+ this.T0 = T0; // start time
+ this.ndn = ndn;
+ this.totalBlocks = 0; // total # of segments delivered to usr;
+ // TODO: in this test script we simply discard the content after it is received
+ // should consider some way to buffer the whole data in future refactor --- SWT
+
+ // We should always start with the first element so the first content object cannot be ooo data
+ //this.firstReceivedSegmentNumber = null;
+ //this.firstReceivedContentObject = null;
+
+ // statistic counters
+ this.ooo_count = 0; // out-of-order content object counter;
+ // when this counter reaches 3, apply fast retransmission alg.
+ this.pkt_recved = 0; // total # of content object received
+ this.timed_out = 0; // totle # of timed out interest
+ this.interest_sent = 1; // there is an initial interest before calling the closure upcall
+ this.dups = 0; // total # of dup content segments
+
+ this.max_window = 32; // max window size
+ this.max_retrans = 5; // max # of trial before give up; if we fail on one segment, the entire process is aborted
+
+ this.snd_una = 0; // pointer to unacked segments
+ this.snd_wnd = 1; // current window size
+ this.snd_nxt = 1; // pointer to next interest to be sent
+
+ this.ooo_table_size = 128;
+ this.ooo_table = []; // hash table to mark ooo segments
+
+ this.terminated = false; // Set this flag after we receive all the segments;
+ };
+
+ ContentClosure.prototype.upcall = function(kind, upcallInfo) {
+ this.pkt_recved++;
+
+ if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
+ if (this.terminated == false) {
+ this.timed_out++;
+
+ // Reduce window size to 1
+ this.snd_wnd = 1;
+
+ // Retransmit interest for this segment
+ this.ndn.expressInterest(upcallInfo.interest.name, this);
+ //console.log("Resend interest sent for " + upcallInfo.interest.name.getName());
+ document.getElementById('content').innerHTML += "<p>Resend interest sent for "
+ + upcallInfo.interest.name.getName() + "</p>";
+ this.interest_sent++;
+
+ document.getElementById('content').innerHTML += "<p>Interest " + upcallInfo.interest.name.getName() + " time out.</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of blocks: " + this.totalBlocks + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of packets: " + this.pkt_recved + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of dup segments: " + this.dups + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of interest sent: " + this.interest_sent + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of time-out interest: " + this.timed_out + "</p>";
+
+ document.getElementById('content').innerHTML += "<p>SND_UNA: " + this.snd_una + "</p>";
+ document.getElementById('content').innerHTML += "<p>SND_WND: " + this.snd_wnd + "</p>";
+ document.getElementById('content').innerHTML += "<p>SND_NXT: " + this.snd_nxt + "</p>";
+ }
+ return Closure.RESULT_OK;
+ }
+
+ if (kind == Closure.UPCALL_CONTENT_BAD) {
+ console.log("NdnProtocol.ContentClosure: signature verification failed");
+ console.log(upcallInfo.contentObject.name.getName());
+ console.log(DataUtils.toHex(upcallInfo.contentObject.signature.Witness).toLowerCase());
+ return Closure.RESULT_OK;
+ }
+
+ if (!(kind == Closure.UPCALL_CONTENT ||
+ kind == Closure.UPCALL_CONTENT_UNVERIFIED))
+ // The upcall is not for us.
+ return Closure.RESULT_ERR;
+
+ var contentObject = upcallInfo.contentObject;
+ if (contentObject.content == null) {
+ console.log("NdnProtocol.ContentClosure: contentObject.content is null");
+ return Closure.RESULT_ERR;
+ }
+
+ // Use the segmentNumber to load multiple segments.
+ var segmentNumber = DataUtils.bigEndianToUnsignedInt
+ (contentObject.name.components[contentObject.name.components.length - 1]);
+ //console.log("Seg # " + segmentNumber + " received");
+ //console.log("Seg name " + contentObject.name.getName());
+
+ /*
+ if (this.firstReceivedSegmentNumber == null) {
+ // This is the first call.
+ this.firstReceivedSegmentNumber = segmentNumber;
+ if (segmentNumber != 0) {
+ // Special case: Save this content object for later and request segment zero.
+ // SWT: this should not happen in normal case;
+ // ccnd should always return the first segment if no seg# is specified
+ this.firstReceivedContentObject = contentObject;
+ var componentsForZero = contentObject.name.components.slice
+ (0, contentObject.name.components.length - 1);
+ componentsForZero.push([0]);
+ this.ndn.expressInterest(new Name(componentsForZero), this);
+ return Closure.RESULT_OK;
+ }
+ }
+ */
+
+ // Process received data here...
+ // Count content length
+ //nameStr = escape(contentObject.name.getName());
+ //document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
+ //document.getElementById('content').innerHTML += "<p>Content buffer length: " + contentObject.content.length + "</p>";
+
+ /*
+ // Check for the special case if the saved content is for the next segment that we need.
+ if (this.firstReceivedContentObject != null &&
+ this.firstReceivedSegmentNumber == segmentNumber + 1) {
+ // Substitute the saved contentObject send its content and keep going.
+ contentObject = this.firstReceivedContentObject;
+ segmentNumber = segmentNumber + 1;
+ // Clear firstReceivedContentObject to save memory.
+ this.firstReceivedContentObject = null;
+
+ // Process received data here...
+ // Count content length
+ //nameStr = escape(contentObject.name.getName());
+ //document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
+ //document.getElementById('content').innerHTML += "<p>Content buffer length: " + contentObject.content.length + "</p>";
+ this.totalBlocks++;
+ }
+ */
+
+ // Record final seg# if present
+ var finalSegmentNumber = null;
+ if (contentObject.signedInfo != null && contentObject.signedInfo.finalBlockID != null)
+ finalSegmentNumber = DataUtils.bigEndianToUnsignedInt(contentObject.signedInfo.finalBlockID);
+
+ // Check for out-of-order segment
+ if (segmentNumber != this.snd_una) {
+ //console.log("Out-of-order segment #" + segmentNumber + " received.");
+ document.getElementById('content').innerHTML += "<p>Out-of-order segment #" + segmentNumber + " received.</p>";
+ this.ooo_count++;
+
+ if (segmentNumber >= this.snd_nxt || segmentNumber < this.snd_una) {
+ // Discard segment that is out of window
+ //console.log("Out-of-window segment #" + segmentNumber);
+ document.getElementById('content').innerHTML += "<p>Out-of-window segment #" + segmentNumber + "</p>";
+ return Closure.RESULT_OK;
+ }
+ // Mark this segment in hash table
+ var slot = segmentNumber % this.ooo_table_size;
+ this.ooo_table[slot] = segmentNumber;
+
+ if (this.ooo_count == 3) {
+ // Fast retransmit
+ // TODO: expressInterest for seg# = this.snd_una
+ //this.snd_wnd = Math.floor(this.snd_wnd / 2) + 3;
+ } else if (this.ooo_count > 3) {
+ //this.snd_wnd++;
+ // TODO: send a new interest if allowed by snd_wnd
+ // SWT: what if we never receive the first unacked segment???
+ }
+
+ return Closure.RESULT_OK;
+ }
+
+ // In-order segment; slide window forward
+ this.snd_una++
+ this.totalBlocks++;
+ var slot = this.snd_una % this.ooo_table_size;
+ while (this.ooo_table[slot] != undefined) {
+ // continue to move forward until we reach a hole in the seg# sequence
+ this.ooo_table[slot] = undefined;
+ this.snd_una++;
+ this.totalBlocks++;
+ slot = this.snd_una % this.ooo_table_size;
+ }
+
+ if (finalSegmentNumber != null && this.snd_una == finalSegmentNumber + 1) {
+ // All blocks before final block, including final block, is received. Mission complete.
+ // Record stop time and print statistic result
+ this.terminated = true;
+ var T1 = new Date();
+ document.getElementById('content').innerHTML += "<p>Final block received.</p>";
+ document.getElementById('content').innerHTML += "<p>Time elapsed: " + (T1 - this.T0) + " ms</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of blocks: " + this.totalBlocks + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of packets: " + this.pkt_recved + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of dup segments: " + this.dups + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of interest sent: " + this.interest_sent + "</p>";
+ document.getElementById('content').innerHTML += "<p>Total number of time-out interest: " + this.timed_out + "</p>";
+ return Closure.RESULT_OK;
+ }
+
+ // Adjust window size
+ if (this.snd_wnd < this.max_window) {
+ this.snd_wnd++;
+ //console.log("Window size after adjust: " + this.snd_wnd);
+ }
+
+ // Send the next interest if allowed by snd_wnd
+ var nextNameComponents = contentObject.name.components.slice(0, contentObject.name.components.length - 1);
+ //console.log("SND_UNA: " + this.snd_una);
+ //console.log("SND_NXT: " + this.snd_nxt);
+ while (this.snd_nxt - this.snd_una < this.snd_wnd) {
+ // Make a name for the next segment and get it.
+ var segmentNumberPlus1 = DataUtils.nonNegativeIntToBigEndian(this.snd_nxt);
+ // Put a 0 byte in front.
+ var nextSegmentNumber = new Uint8Array(segmentNumberPlus1.length + 1);
+ nextSegmentNumber.set(segmentNumberPlus1, 1);
+
+ nextNameComponents.push(nextSegmentNumber);
+
+ var nextName = new Name(nextNameComponents);
+ this.ndn.expressInterest(nextName, this);
+ //console.log("Interest sent for seg # " + this.snd_nxt + " name " + nextName.getName());
+ this.interest_sent++;
+
+ this.snd_nxt++;
+ nextNameComponents.pop(); // Remove segment number from components
+ }
+
+ return Closure.RESULT_OK;
+ };
+
+ /*
+ * Convert the big endian Uint8Array to an unsigned int.
+ * Don't check for overflow.
+ */
+ function ArrayToNum(bytes) {
+ var result = 0;
+ for (var i = 0; i < bytes.length; ++i) {
+ result = result * 10;
+ result += (bytes[i] - 48);
+ }
+ return result;
+ }
+
+ /*
+ * Convert the int value to a new big endian Uint8Array and return.
+ * If value is 0 or negative, return Uint8Array(0).
+ */
+ function NumToArray(value) {
+ value = Math.round(value);
+ if (value <= 0)
+ return new Uint8Array(0);
+
+ numString = value.toString();
+ var size = numString.length;
+ var result = new Uint8Array(size);
+ for (i = 0; i < size; i++) {
+ result[i] = numString.charCodeAt(i);
+ }
+ return result;
+ }
+///////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ /*
+ var AsyncGetClosure = function AsyncGetClosure(T0) {
+ this.T0 = T0; // Start time
+ // Inherit from Closure.
+ Closure.call(this);
+ };
+
+ AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
+ //console.log("Closure.upcall() executed.");
+ if (kind == Closure.UPCALL_FINAL) {
+ // Do nothing.
+ } else if (kind == Closure.UPCALL_CONTENT) {
+ var T1 = new Date();
+
+ var content = upcallInfo.contentObject;
+ nameStr = escape(content.name.getName());
+ document.getElementById('content').innerHTML += "<p>Time elapsed: " + (T1 - this.T0) + " ms</p>";
+ document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
+ document.getElementById('content').innerHTML += "<p>Content buffer length: " + content.content.length + "</p>";
+ //console.log("In callback, nameStr: " + nameStr);
+ //console.log("In callback, content: ");
+ //console.log(content.content.length);
+ //document.getElementById('content').innerHTML += contentObjectToHtml(content);
+ } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
+ console.log("Closure.upcall called with interest time out.");
+ }
+ return Closure.RESULT_OK;
+ };
+ */
+
+ function run() {
+ document.getElementById('content').innerHTML += "<p>Started...</p>";
+ //ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure( new Date() ));
+ var name = new Name(document.getElementById('interest').value);
+ ndncon.expressInterest( name,
+ new ContentClosure( ndncon, new Date() ));
+ }
+
+ </script>
+
+</head>
+<body >
+
+ <form>
+ Please Enter an Interest:<br />
+ <input id="interest" type="text" name="INTEREST" size="50" value="/wentao.shang/mars/%00" />
+ </form>
+
+ <button onclick="run()">Fetch Content</button>
+
+ <p id="content">Result: <br/></p>
+
+</body>
+</html>
diff --git a/js/tools/build/ndn-js-uncomp.js b/js/tools/build/ndn-js-uncomp.js
index 8469498..6f1bc95 100644
--- a/js/tools/build/ndn-js-uncomp.js
+++ b/js/tools/build/ndn-js-uncomp.js
@@ -19,7 +19,7 @@
this.ndn_data = null; // this holds the ndn_closure
this.ndn_data_dirty = false;
- this.timerID = -1; // Store the interest timer; used to cancel the timer upon receiving interest
+ //this.timerID = -1; // Store the interest timer; used to cancel the timer upon receiving interest
};
// Upcall result
@@ -209,7 +209,7 @@
var currentClosure = pitEntry.closure;
// Cancel interest timer
- clearTimeout(currentClosure.timerID);
+ clearTimeout(pitEntry.timerID);
//console.log("Clear interest timer");
//console.log(currentClosure.timerID);
@@ -382,6 +382,7 @@
if (closure != null) {
var pitEntry = new PITEntry(interest, closure);
NDN.PITTable.push(pitEntry);
+ closure.pitEntry = pitEntry;
}
this.ws.send(bytearray.buffer);
@@ -389,7 +390,7 @@
// Set interest timer
if (closure != null) {
- closure.timerID = setTimeout(function() {
+ pitEntry.timerID = setTimeout(function() {
if (LOG > 3) console.log("Interest time out.");
// Remove PIT entry from NDN.PITTable
@@ -398,6 +399,8 @@
if (index >= 0)
NDN.PITTable.splice(index, 1);
//console.log(NDN.PITTable);
+ //console.log(pitEntry.interest.name.getName());
+
// Raise closure callback
closure.upcall(Closure.UPCALL_INTEREST_TIMED_OUT, new UpcallInfo(ndn, interest, 0, null));
}, interest.interestLifetime); // interestLifetime is in milliseconds.
@@ -7856,6 +7859,7 @@
var PITEntry = function PITEntry(interest, closure) {
this.interest = interest; // Interest
this.closure = closure; // Closure
+ this.timerID = -1; // Timer ID
};
// Return the longest entry from NDN.PITTable that matches name.
diff --git a/js/tools/build/ndn-js.js b/js/tools/build/ndn-js.js
index 4c17018..43075ff 100644
--- a/js/tools/build/ndn-js.js
+++ b/js/tools/build/ndn-js.js
@@ -1,18 +1,18 @@
-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 Closure=function(){this.ndn_data=null;this.ndn_data_dirty=!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 WebSocketTransport=function(){this.ccndid=this.ws=null;this.maxBufferSize=1E4;this.buffer=new Uint8Array(this.maxBufferSize);this.bufferOffset=0;this.structureDecoder=new BinaryXMLStructureDecoder;this.defaultGetHostAndPort=NDN.makeShuffledGetHostAndPort(["A.ws.ndn.ucla.edu","B.ws.ndn.ucla.edu","C.ws.ndn.ucla.edu","D.ws.ndn.ucla.edu","E.ws.ndn.ucla.edu"],9696)};
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){var d=new Uint8Array(c);3<LOG&&console.log("BINARY RESPONSE IS "+DataUtils.toHex(d));try{if(d.length+b.bufferOffset>=b.buffer.byteLength){3<LOG&&
console.log("NDN.ws.onmessage: buffer overflow. Accumulate received length: "+b.bufferOffset+". Current packet length: "+d.length+".");delete b.structureDecoder;delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);b.bufferOffset=0;return}b.buffer.set(d,b.bufferOffset);b.bufferOffset+=d.length;if(!b.structureDecoder.findElementEnd(b.buffer.subarray(0,b.bufferOffset))){3<LOG&&console.log("Incomplete packet received. Length "+d.length+". Wait for more input.");
return}3<LOG&&console.log("Complete packet received. Length "+d.length+". Start decoding.")}catch(e){console.log("NDN.ws.onmessage exception: "+e);return}c=new BinaryXMLDecoder(b.buffer);if(c.peekStartElement(CCNProtocolDTags.Interest)){3<LOG&&console.log("Interest packet received.");d=new Interest;d.from_ccnb(c);3<LOG&&console.log(d);var f=escape(d.name.getName());3<LOG&&console.log(f);f=getEntryForRegisteredPrefix(f);null!=f&&(d=new UpcallInfo(a,d,0,null),f.closure.upcall(Closure.UPCALL_INTEREST,
d)==Closure.RESULT_INTEREST_CONSUMED&&null!=d.contentObject&&(f=encodeToBinaryContentObject(d.contentObject),d=new Uint8Array(f.length),d.set(f),b.ws.send(d.buffer)))}else if(c.peekStartElement(CCNProtocolDTags.ContentObject))if(3<LOG&&console.log("ContentObject packet received."),d=new ContentObject,d.from_ccnb(c),null==b.ccndid&&NDN.ccndIdFetcher.match(d.name))!d.signedInfo||!d.signedInfo.publisher||!d.signedInfo.publisher.publisherPublicKeyDigest?(console.log("Cannot contact router, close NDN now."),
-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."),
+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{var g=NDN.getEntryForExpressedInterest(d.name);if(null!=g){f=NDN.PITTable.indexOf(g);0<=f&&NDN.PITTable.splice(f,1);f=g.closure;clearTimeout(g.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=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);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.")};
+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);c.pitEntry=f}this.ws.send(e.buffer);3<LOG&&console.log("ws.send() returned.");null!=c&&(f.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};
@@ -263,7 +263,7 @@
BigInteger.prototype.multiply=bnMultiply;BigInteger.prototype.divide=bnDivide;BigInteger.prototype.remainder=bnRemainder;BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder;BigInteger.prototype.modPow=bnModPow;BigInteger.prototype.modInverse=bnModInverse;BigInteger.prototype.pow=bnPow;BigInteger.prototype.gcd=bnGCD;BigInteger.prototype.isProbablePrime=bnIsProbablePrime;
var LOG=0,NDN=function NDN(b){b=b||{};this.transport=(b.getTransport||function(){return new WebSocketTransport})();this.getHostAndPort=b.getHostAndPort||this.transport.defaultGetHostAndPort;this.host=void 0!==b.host?b.host:"localhost";this.port=b.port||9696;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.ccndIdFetcher=new Name("/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY");NDN.prototype.createRoute=function(a,b){this.host=a;this.port=b};NDN.KeyStore=[];var KeyStoreEntry=function(a,b,c){this.keyName=a;this.rsaKey=b;this.timeStamp=c};NDN.addKeyEntry=function(a){null==NDN.getKeyByName(a.keyName)&&NDN.KeyStore.push(a)};
-NDN.getKeyByName=function(a){for(var b=null,c=0;c<NDN.KeyStore.length;c++)if(NDN.KeyStore[c].keyName.contentName.match(a.contentName)&&(null==b||NDN.KeyStore[c].keyName.contentName.components.length>b.keyName.contentName.components.length))b=NDN.KeyStore[c];return b};NDN.PITTable=[];var PITEntry=function(a,b){this.interest=a;this.closure=b};
+NDN.getKeyByName=function(a){for(var b=null,c=0;c<NDN.KeyStore.length;c++)if(NDN.KeyStore[c].keyName.contentName.match(a.contentName)&&(null==b||NDN.KeyStore[c].keyName.contentName.components.length>b.keyName.contentName.components.length))b=NDN.KeyStore[c];return b};NDN.PITTable=[];var PITEntry=function(a,b){this.interest=a;this.closure=b;this.timerID=-1};
NDN.getEntryForExpressedInterest=function(a){for(var b=null,c=0;c<NDN.PITTable.length;c++)if(NDN.PITTable[c].interest.matches_name(a)&&(null==b||NDN.PITTable[c].interest.name.components.length>b.interest.name.components.length))b=NDN.PITTable[c];return b};NDN.makeShuffledGetHostAndPort=function(a,b){a=a.slice(0,a.length);DataUtils.shuffle(a);return function(){return 0==a.length?null:{host:a.splice(0,1)[0],port:b}}};
NDN.prototype.expressInterest=function(a,b,c){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=4E3;null==this.host||null==this.port?null==this.getHostAndPort?console.log("ERROR: host OR port NOT SET"):this.connectAndExpressInterest(a,
b):this.transport.expressInterest(this,a,b)};NDN.prototype.registerPrefix=function(a,b,c){return this.transport.registerPrefix(this,a,b,c)};