Initial update of comments to JSDoc format.
diff --git a/js/Closure.js b/js/Closure.js
index 7a1e9de..24fdedb 100644
--- a/js/Closure.js
+++ b/js/Closure.js
@@ -7,8 +7,9 @@
* Jeff Burke <jburke@ucla.edu>
*/
-/*
- * Create a subclass of Closure and pass an object to async calls.
+/**
+ * You should create a subclass of Closure and pass an object to async calls.
+ * @constructor
*/
var Closure = function Closure() {
// I don't think storing NDN's closure is needed
@@ -39,7 +40,7 @@
Closure.UPCALL_CONTENT_UNVERIFIED = 5; // content that has not been verified
Closure.UPCALL_CONTENT_BAD = 6; // verification failed
-/*
+/**
* Override this in your subclass.
* If you're getting strange errors in upcall()
* check your code whether you're returning a value.
@@ -49,6 +50,10 @@
return Closure.RESULT_OK;
};
+/**
+ * An UpcallInfo is passed to Closure.upcall.
+ * @constructor
+ */
var UpcallInfo = function UpcallInfo(ndn, interest, matchedComps, contentObject) {
this.ndn = ndn; // NDN object (not used)
this.interest = interest; // Interest object
diff --git a/js/ContentObject.js b/js/ContentObject.js
index 7c66f3c..38c8066 100644
--- a/js/ContentObject.js
+++ b/js/ContentObject.js
@@ -3,31 +3,35 @@
* See COPYING for copyright and distribution information.
* This class represents ContentObject Objects
*/
-var ContentObject = function ContentObject(_name,_signedInfo,_content,_signature){
-
-
- if (typeof _name == 'string') {
- this.name = new Name(_name);
- }
- else{
- //TODO Check the class of _name
- this.name = _name;
- }
- this.signedInfo = _signedInfo;
-
- if (typeof _content == 'string') {
- this.content = DataUtils.toNumbersFromString(_content);
- } else {
- this.content = _content;
- }
-
- this.signature = _signature;
+/**
+ * Create a new ContentObject with the optional values.
+ *
+ * @constructor
+ * @param {Name} name
+ * @param {SignedInfo} signedInfo
+ * @param {Uint8Array} content
+ * @param {Signature} signature
+ */
+var ContentObject = function ContentObject(name, signedInfo, content, signature) {
+ if (typeof name == 'string')
+ this.name = new Name(name);
+ else
+ //TODO Check the class of name
+ this.name = name;
+
+ this.signedInfo = signedInfo;
+
+ if (typeof content == 'string')
+ this.content = DataUtils.toNumbersFromString(content);
+ else
+ this.content = content;
+
+ this.signature = signature;
this.startSIG = null;
this.endSIG = null;
- //this.startSignedInfo = null;
this.endContent = null;
this.rawSignatureData = null;
@@ -114,12 +118,16 @@
this.rawSignatureData = sigBits;
};
-// Deprecated. Use BinaryXMLWireFormat.decodeContentObject.
+/**
+ * @deprecated Use BinaryXMLWireFormat.decodeContentObject.
+ */
ContentObject.prototype.from_ccnb = function(/*XMLDecoder*/ decoder) {
BinaryXMLWireFormat.decodeContentObject(this, decoder);
};
-// Deprecated. Use BinaryXMLWireFormat.encodeContentObject.
+/**
+ * @deprecated Use BinaryXMLWireFormat.encodeContentObject.
+ */
ContentObject.prototype.to_ccnb = function(/*XMLEncoder*/ encoder) {
BinaryXMLWireFormat.encodeContentObject(this, encoder);
};
@@ -147,13 +155,13 @@
ContentObject.prototype.getElementLabel= function(){return CCNProtocolDTags.ContentObject;};
/**
- * Signature
+ * Create a new Signature with the optional values.
+ * @constructor
*/
-var Signature = function Signature(_witness,_signature,_digestAlgorithm) {
-
- this.Witness = _witness;//byte [] _witness;
- this.signature = _signature;//byte [] _signature;
- this.digestAlgorithm = _digestAlgorithm//String _digestAlgorithm;
+var Signature = function Signature(witness, signature, digestAlgorithm) {
+ this.Witness = witness;
+ this.signature = signature;
+ this.digestAlgorithm = digestAlgorithm
};
Signature.prototype.from_ccnb =function( decoder) {
@@ -210,27 +218,23 @@
};
-/**
- * SignedInfo
- */
var ContentType = {DATA:0, ENCR:1, GONE:2, KEY:3, LINK:4, NACK:5};
var ContentTypeValue = {0:0x0C04C0, 1:0x10D091,2:0x18E344,3:0x28463F,4:0x2C834A,5:0x34008A};
var ContentTypeValueReverse = {0x0C04C0:0, 0x10D091:1,0x18E344:2,0x28463F:3,0x2C834A:4,0x34008A:5};
-var SignedInfo = function SignedInfo(_publisher,_timestamp,_type,_locator,_freshnessSeconds,_finalBlockID){
-
- //TODO, Check types
-
- this.publisher = _publisher; //publisherPublicKeyDigest
- this.timestamp=_timestamp; // CCN Time
- this.type=_type; // ContentType
- this.locator =_locator;//KeyLocator
- this.freshnessSeconds =_freshnessSeconds; // Integer
- this.finalBlockID=_finalBlockID; //byte array
+/**
+ * Create a new SignedInfo with the optional values.
+ * @constructor
+ */
+var SignedInfo = function SignedInfo(publisher, timestamp, type, locator, freshnessSeconds, finalBlockID) {
+ this.publisher = publisher; //publisherPublicKeyDigest
+ this.timestamp=timestamp; // CCN Time
+ this.type=type; // ContentType
+ this.locator =locator;//KeyLocator
+ this.freshnessSeconds =freshnessSeconds; // Integer
+ this.finalBlockID=finalBlockID; //byte array
- // SWT: merge setFields() method into constructor
- this.setFields();
-
+ this.setFields();
};
SignedInfo.prototype.setFields = function(){
diff --git a/js/FaceInstance.js b/js/FaceInstance.js
index 91b8780..621e5ec 100644
--- a/js/FaceInstance.js
+++ b/js/FaceInstance.js
@@ -6,38 +6,20 @@
var NetworkProtocol = { TCP:6, UDP:17};
-var FaceInstance = function FaceInstance(
- _action,
- _publisherPublicKeyDigest,
- _faceID,
- _ipProto,
- _host,
- _port,
- _multicastInterface,
- _multicastTTL,
- _freshnessSeconds){
-
-
- this.action = _action;
- this.publisherPublicKeyDigest = _publisherPublicKeyDigest;
- this.faceID = _faceID;
- this.ipProto = _ipProto;
- this.host = _host;
- this.Port = _port;
- this.multicastInterface =_multicastInterface;
- this.multicastTTL =_multicastTTL;
- this.freshnessSeconds = _freshnessSeconds;
-
- //action ::= ("newface" | "destroyface" | "queryface")
- //publisherPublicKeyDigest ::= SHA-256 digest
- //faceID ::= nonNegativeInteger
- //ipProto ::= nonNegativeInteger [IANA protocol number, 6=TCP, 17=UDP]
- //Host ::= textual representation of numeric IPv4 or IPv6 address
- //Port ::= nonNegativeInteger [1..65535]
- //MulticastInterface ::= textual representation of numeric IPv4 or IPv6 address
- //MulticastTTL ::= nonNegativeInteger [1..255]
- //freshnessSeconds ::= nonNegativeInteger
-
+/**
+ * @constructor
+ */
+var FaceInstance = function FaceInstance(action, publisherPublicKeyDigest, faceID, ipProto, host, port, multicastInterface,
+ multicastTTL, freshnessSeconds) {
+ this.action = action;
+ this.publisherPublicKeyDigest = publisherPublicKeyDigest;
+ this.faceID = faceID;
+ this.ipProto = ipProto;
+ this.host = host;
+ this.Port = port;
+ this.multicastInterface =multicastInterface;
+ this.multicastTTL =multicastTTL;
+ this.freshnessSeconds = freshnessSeconds;
};
/**
@@ -155,5 +137,7 @@
}
-FaceInstance.prototype.getElementLabel= function(){return CCNProtocolDTags.FaceInstance;};
+FaceInstance.prototype.getElementLabel = function() {
+ return CCNProtocolDTags.FaceInstance;
+};
diff --git a/js/ForwardingEntry.js b/js/ForwardingEntry.js
index baf00cb..185f784 100644
--- a/js/ForwardingEntry.js
+++ b/js/ForwardingEntry.js
@@ -4,35 +4,23 @@
* This class represents Forwarding Entries
*/
-var ForwardingEntry = function ForwardingEntry(
- //ActionType
- _action,
- //Name
- _prefixName,
- //PublisherPublicKeyDigest
- _ccndId,
- //Integer
- _faceID,
- //Integer
- _flags,
- //Integer
- _lifetime){
-
-
-
- //String
- this.action = _action;
- //Name\
- this.prefixName = _prefixName;
- //PublisherPublicKeyDigest
- this.ccndID = _ccndId;
- //Integer
- this.faceID = _faceID;
- //Integer
- this.flags = _flags;
- //Integer
- this.lifetime = _lifetime; // in seconds
-
+/**
+ * Create a new ForwardingEntry with the optional arguments.
+ * @constructor
+ * @param {String} action
+ * @param {Name} prefixName
+ * @param {PublisherPublicKeyDigest} ccndId
+ * @param {number} faceID
+ * @param {number} flags
+ * @param {number} lifetime in seconds
+ */
+var ForwardingEntry = function ForwardingEntry(action, prefixName, ccndId, faceID, flags, lifetime) {
+ this.action = action;
+ this.prefixName = prefixName;
+ this.ccndID = ccndId;
+ this.faceID = faceID;
+ this.flags = flags;
+ this.lifetime = lifetime;
};
ForwardingEntry.prototype.from_ccnb =function(
@@ -64,9 +52,6 @@
decoder.readEndElement();
};
- /**
- * Used by NetworkObject to encode the object to a network stream.
- */
ForwardingEntry.prototype.to_ccnb =function(
//XMLEncoder
encoder)
diff --git a/js/Interest.js b/js/Interest.js
index 692b90c..c3d771f 100644
--- a/js/Interest.js
+++ b/js/Interest.js
@@ -4,23 +4,38 @@
* This class represents Interest Objects
*/
-// _interestLifetime is in milliseconds.
+/**
+ * Create a new Interest with the optional values.
+ *
+ * @constructor
+ * @param {Name} name
+ * @param {FaceInstance} faceInstance
+ * @param {number} minSuffixComponents
+ * @param {number} maxSuffixComponents
+ * @param {Uint8Array} publisherPublicKeyDigest
+ * @param {Exclude} exclude
+ * @param {number} childSelector
+ * @param {number} answerOriginKind
+ * @param {number} scope
+ * @param {number} interestLifetime in milliseconds
+ * @param {Uint8Array} nonce
+ */
var Interest = function Interest
- (_name, _faceInstance, _minSuffixComponents, _maxSuffixComponents, _publisherPublicKeyDigest, _exclude,
- _childSelector, _answerOriginKind, _scope, _interestLifetime, _nonce) {
+ (name, faceInstance, minSuffixComponents, maxSuffixComponents, publisherPublicKeyDigest, exclude,
+ childSelector, answerOriginKind, scope, interestLifetime, nonce) {
- this.name = _name;
- this.faceInstance = _faceInstance;
- this.maxSuffixComponents = _maxSuffixComponents;
- this.minSuffixComponents = _minSuffixComponents;
+ this.name = name;
+ this.faceInstance = faceInstance;
+ this.maxSuffixComponents = maxSuffixComponents;
+ this.minSuffixComponents = minSuffixComponents;
- this.publisherPublicKeyDigest = _publisherPublicKeyDigest;
- this.exclude = _exclude;
- this.childSelector = _childSelector;
- this.answerOriginKind = _answerOriginKind;
- this.scope = _scope;
- this.interestLifetime = _interestLifetime; // milli seconds
- this.nonce = _nonce;
+ this.publisherPublicKeyDigest = publisherPublicKeyDigest;
+ this.exclude = exclude;
+ this.childSelector = childSelector;
+ this.answerOriginKind = answerOriginKind;
+ this.scope = scope;
+ this.interestLifetime = interestLifetime; // milli seconds
+ this.nonce = nonce;
};
Interest.RECURSIVE_POSTFIX = "*";
@@ -34,12 +49,16 @@
Interest.DEFAULT_ANSWER_ORIGIN_KIND = Interest.ANSWER_CONTENT_STORE | Interest.ANSWER_GENERATED;
-// Deprecated. Use BinaryXMLWireFormat.decodeInterest.
+/**
+ * @deprecated Use BinaryXMLWireFormat.decodeInterest.
+ */
Interest.prototype.from_ccnb = function(/*XMLDecoder*/ decoder) {
BinaryXMLWireFormat.decodeInterest(this, decoder);
};
-// Deprecated. Use BinaryXMLWireFormat.encodeInterest.
+/**
+ * @deprecated Use BinaryXMLWireFormat.encodeInterest.
+ */
Interest.prototype.to_ccnb = function(/*XMLEncoder*/ encoder){
BinaryXMLWireFormat.encodeInterest(this, encoder);
};
@@ -64,7 +83,7 @@
wireFormat.decodeInterest(this, input);
};
-/*
+/**
* Return true if this.name.match(name) and the name conforms to the interest selectors.
*/
Interest.prototype.matches_name = function(/*Name*/ name) {
@@ -86,7 +105,7 @@
return true;
};
-/*
+/**
* Return a new Interest with the same fields as this Interest.
* Note: This does NOT make a deep clone of the name, exclue or other objects.
*/
@@ -99,10 +118,16 @@
/*
* Handle the interest Exclude element.
- * _values is an array where each element is either Uint8Array component or Exclude.ANY.
+ * values is
*/
-var Exclude = function Exclude(_values) {
- this.values = (_values || []);
+
+/**
+ *
+ * @constructor
+ * @param {Array<Uint8Array|Exclude.ANY>} values an array where each element is either Uint8Array component or Exclude.ANY.
+ */
+var Exclude = function Exclude(values) {
+ this.values = (values || []);
}
Exclude.ANY = "*";
@@ -149,7 +174,7 @@
encoder.writeEndElement();
};
-/*
+/**
* Return a string with elements separated by "," and Exclude.ANY shown as "*".
*/
Exclude.prototype.to_uri = function() {
@@ -169,7 +194,7 @@
return result;
};
-/*
+/**
* Return true if the component matches any of the exclude criteria.
*/
Exclude.prototype.matches = function(/*Uint8Array*/ component) {
@@ -224,7 +249,7 @@
return false;
};
-/*
+/**
* Return -1 if component1 is less than component2, 1 if greater or 0 if equal.
* A component is less if it is shorter, otherwise if equal length do a byte comparison.
*/
diff --git a/js/Key.js b/js/Key.js
index 35b0428..20b3e41 100644
--- a/js/Key.js
+++ b/js/Key.js
@@ -4,6 +4,9 @@
* This class represents Key Objects
*/
+/**
+ * @constructor
+ */
var Key = function Key(){
/* TODO: Port from PyCCN:
generateRSA()
@@ -25,23 +28,24 @@
KEYNAME:3
};
-var KeyLocator = function KeyLocator(_input,_type){
-
- this.type = _type;
+/**
+ * @constructor
+ */
+var KeyLocator = function KeyLocator(input,type) {
+ this.type = type;
- if (_type == KeyLocatorType.KEYNAME){
- if (LOG>3) console.log('KeyLocator: SET KEYNAME');
- this.keyName = _input;
- }
- else if (_type == KeyLocatorType.KEY){
- if (LOG>3) console.log('KeyLocator: SET KEY');
- this.publicKey = _input;
- }
- else if (_type == KeyLocatorType.CERTIFICATE){
- if (LOG>3) console.log('KeyLocator: SET CERTIFICATE');
- this.certificate = _input;
- }
-
+ if (type == KeyLocatorType.KEYNAME){
+ if (LOG>3) console.log('KeyLocator: SET KEYNAME');
+ this.keyName = input;
+ }
+ else if (type == KeyLocatorType.KEY){
+ if (LOG>3) console.log('KeyLocator: SET KEY');
+ this.publicKey = input;
+ }
+ else if (type == KeyLocatorType.CERTIFICATE){
+ if (LOG>3) console.log('KeyLocator: SET CERTIFICATE');
+ this.certificate = input;
+ }
};
KeyLocator.prototype.from_ccnb = function(decoder) {
@@ -146,6 +150,7 @@
/**
* KeyName is only used by KeyLocator.
+ * @constructor
*/
var KeyName = function KeyName() {
this.contentName = this.contentName; //contentName
diff --git a/js/NDN.js b/js/NDN.js
index f6d51a2..d0fdb81 100644
--- a/js/NDN.js
+++ b/js/NDN.js
@@ -4,40 +4,42 @@
* This class represents the top-level object for communicating with an NDN host.
*/
+/**
+ * Set this to a higher number to dump more debugging log messages.
+ * @type Number
+ */
var LOG = 0;
/**
- * settings is an associative array with the following defaults:
+ * Create a new NDN with the given settings.
+ * This throws an exception if NDN.supported is false.
+ * @constructor
+ * @param {Object} settings if not null, an associative array with the following defaults:
* {
* getTransport: function() { return new WebSocketTransport(); },
- * getHostAndPort: transport.defaultGetHostAndPort,
+ * getHostAndPort: transport.defaultGetHostAndPort, // a function, on each call it returns a new { host: host, port: port } or null if there are no more hosts.
* host: null, // If null, use getHostAndPort when connecting.
* port: 9696,
* onopen: function() { if (LOG > 3) console.log("NDN connection established."); },
* onclose: function() { if (LOG > 3) console.log("NDN connection closed."); },
* verify: true // If false, don't verify and call upcall with Closure.UPCALL_CONTENT_UNVERIFIED.
* }
- *
- * getHostAndPort is a function, on each call it returns a new { host: host, port: port } or
- * null if there are no more hosts.
- *
- * This throws an exception if NDN.supported is false.
*/
var NDN = function NDN(settings) {
- if (!NDN.supported)
- throw new Error("The necessary JavaScript support is not available on this platform.");
+ if (!NDN.supported)
+ throw new Error("The necessary JavaScript support is not available on this platform.");
- settings = (settings || {});
- var getTransport = (settings.getTransport || function() { return new WebSocketTransport(); });
- this.transport = getTransport();
- this.getHostAndPort = (settings.getHostAndPort || this.transport.defaultGetHostAndPort);
+ settings = (settings || {});
+ var getTransport = (settings.getTransport || function() { return new WebSocketTransport(); });
+ this.transport = getTransport();
+ this.getHostAndPort = (settings.getHostAndPort || this.transport.defaultGetHostAndPort);
this.host = (settings.host !== undefined ? settings.host : null);
this.port = (settings.port || 9696);
- this.readyStatus = NDN.UNOPEN;
- this.verify = (settings.verify !== undefined ? settings.verify : true);
- // Event handler
- this.onopen = (settings.onopen || function() { if (LOG > 3) console.log("NDN connection established."); });
- this.onclose = (settings.onclose || function() { if (LOG > 3) console.log("NDN connection closed."); });
+ this.readyStatus = NDN.UNOPEN;
+ this.verify = (settings.verify !== undefined ? settings.verify : true);
+ // Event handler
+ this.onopen = (settings.onopen || function() { if (LOG > 3) console.log("NDN connection established."); });
+ this.onclose = (settings.onclose || function() { if (LOG > 3) console.log("NDN connection closed."); });
this.ccndid = null;
};
@@ -45,7 +47,7 @@
NDN.OPENED = 1; // connection to ccnd opened
NDN.CLOSED = 2; // connection to ccnd closed
-/*
+/**
* Return true if necessary JavaScript support is available, else log an error and return false.
*/
NDN.getSupported = function() {
@@ -102,13 +104,16 @@
// For fetching data
NDN.PITTable = new Array();
+/**
+ * @constructor
+ */
var PITEntry = function PITEntry(interest, closure) {
this.interest = interest; // Interest
this.closure = closure; // Closure
this.timerID = -1; // Timer ID
};
-/*
+/**
* Return the entry from NDN.PITTable where the name conforms to the interest selectors, and
* the interest name is the longest that matches name.
*/
@@ -129,6 +134,9 @@
// For publishing data
NDN.CSTable = new Array();
+/**
+ * @constructor
+ */
var CSEntry = function CSEntry(name, closure) {
this.name = name; // String
this.closure = closure; // Closure
@@ -142,7 +150,7 @@
return null;
}
-/*
+/**
* Return a function that selects a host at random from hostList and returns { host: host, port: port }.
* If no more hosts remain, return null.
*/
@@ -159,20 +167,17 @@
};
};
-/** Encode name as an Interest. If template is not null, use its attributes.
- * Send the interest to host:port, read the entire response and call
+/**
+ * Encode name as an Interest and send the it to host:port, read the entire response and call
* closure.upcall(Closure.UPCALL_CONTENT (or Closure.UPCALL_CONTENT_UNVERIFIED),
- * new UpcallInfo(this, interest, 0, contentObject)).
+ * new UpcallInfo(this, interest, 0, contentObject)).
+ * @param {Name} name
+ * @param {Closure} closure
+ * @param {Interest} template if not null, use its attributes
*/
-NDN.prototype.expressInterest = function(
- // Name
- name,
- // Closure
- closure,
- // Interest
- template) {
+NDN.prototype.expressInterest = function (name, closure, template) {
var interest = new Interest(name);
- if (template != null) {
+ if (template != null) {
interest.minSuffixComponents = template.minSuffixComponents;
interest.maxSuffixComponents = template.maxSuffixComponents;
interest.publisherPublicKeyDigest = template.publisherPublicKeyDigest;
@@ -181,9 +186,9 @@
interest.answerOriginKind = template.answerOriginKind;
interest.scope = template.scope;
interest.interestLifetime = template.interestLifetime;
- }
- else
- interest.interestLifetime = 4000; // default interest timeout value in milliseconds.
+ }
+ else
+ interest.interestLifetime = 4000; // default interest timeout value in milliseconds.
if (this.host == null || this.port == null) {
if (this.getHostAndPort == null)
@@ -198,7 +203,7 @@
this.reconnectAndExpressInterest(interest, closure);
};
-/*
+/**
* If the host and port are different than the ones in this.transport, then call
* this.transport.connect to change the connection (or connect for the first time).
* Then call expressInterestHelper.
@@ -212,7 +217,7 @@
this.expressInterestHelper(interest, closure);
};
-/*
+/**
* Do the work of reconnectAndExpressInterest once we know we are connected. Set the PITTable and call
* this.transport.send to send the interest.
*/
@@ -253,6 +258,12 @@
this.transport.send(binaryInterest);
};
+/**
+ * Register name with the connected NDN hub and receive interests with closure.upcall.
+ * @param {Name} name
+ * @param {Closure} closure
+ * @param {number} flag
+ */
NDN.prototype.registerPrefix = function(name, closure, flag) {
var thisNDN = this;
var onConnected = function() {
@@ -278,7 +289,7 @@
onConnected();
};
-/*
+/**
* This is a closure to receive the ContentObject for NDN.ccndIdFetcher and call
* registerPrefixHelper(name, callerClosure, flag).
*/
@@ -320,7 +331,7 @@
return Closure.RESULT_OK;
};
-/*
+/**
* Do the work of registerPrefix once we know we are connected with a ccndid.
*/
NDN.prototype.registerPrefixHelper = function(name, closure, flag) {
@@ -348,7 +359,7 @@
this.transport.send(encodeToBinaryInterest(interest));
};
-/*
+/**
* This is called when an entire binary XML element is received, such as a ContentObject or Interest.
* Look up in the PITTable and call the closure callback.
*/
@@ -509,7 +520,7 @@
console.log('Incoming packet is not Interest or ContentObject. Discard now.');
};
-/*
+/**
* Assume this.getHostAndPort is not null. This is called when this.host is null or its host
* is not alive. Get a host and port, connect, then execute onConnected().
*/
@@ -574,16 +585,18 @@
return Closure.RESULT_OK;
};
-/*
+/**
* A BinaryXmlElementReader lets you call onReceivedData multiple times which uses a
- * BinaryXMLStructureDecoder to detect the end of a binary XML element and calls
- * elementListener.onReceivedElement(element) with the element.
+ * BinaryXMLStructureDecoder to detect the end of a binary XML element and calls
+ * elementListener.onReceivedElement(element) with the element.
* This handles the case where a single call to onReceivedData may contain multiple elements.
+ * @constructor
+ * @param {{onReceivedElement:function}} elementListener
*/
var BinaryXmlElementReader = function BinaryXmlElementReader(elementListener) {
- this.elementListener = elementListener;
+ this.elementListener = elementListener;
this.dataParts = [];
- this.structureDecoder = new BinaryXMLStructureDecoder();
+ this.structureDecoder = new BinaryXMLStructureDecoder();
};
BinaryXmlElementReader.prototype.onReceivedData = function(/* Uint8Array */ data) {
diff --git a/js/Name.js b/js/Name.js
index 605f110..cda44bb 100644
--- a/js/Name.js
+++ b/js/Name.js
@@ -4,30 +4,29 @@
* This class represents a Name as an array of components where each is a byte array.
*/
-/*
- * Create a new Name from _components.
- * If _components is a string, parse it as a URI.
- * If _components is a Name, add a deep copy of its components.
- * Otherwise it is an array of components where each is a string, byte array, ArrayBuffer, Uint8Array
- * or Name.
- * Convert and store as an array of Uint8Array.
- * If a component is a string, encode as utf8.
+/**
+ * Create a new Name from components.
+ *
+ * @constructor
+ * @param {String|Name|Array<String|Array<number>|ArrayBuffer|Uint8Array|Name>} components if a string, parse it as a URI. If a Name, add a deep copy of its components.
+ * Otherwise it is an array of components where each is a string, byte array, ArrayBuffer, Uint8Array or Name.
+ * Convert each and store as an array of Uint8Array. If a component is a string, encode as utf8.
*/
-var Name = function Name(_components){
- if( typeof _components == 'string') {
- if(LOG>3)console.log('Content Name String '+_components);
- this.components = Name.createNameArray(_components);
+var Name = function Name(components) {
+ if( typeof components == 'string') {
+ if(LOG>3)console.log('Content Name String '+components);
+ this.components = Name.createNameArray(components);
}
- else if(typeof _components === 'object'){
+ else if(typeof components === 'object'){
this.components = [];
- if (_components instanceof Name)
- this.add(_components);
- else {
- for (var i = 0; i < _components.length; ++i)
- this.add(_components[i]);
- }
+ if (components instanceof Name)
+ this.add(components);
+ else {
+ for (var i = 0; i < components.length; ++i)
+ this.add(components[i]);
+ }
}
- else if(_components==null)
+ else if(components==null)
this.components =[];
else
if(LOG>1)console.log("NO CONTENT NAME GIVEN");
@@ -37,8 +36,7 @@
return this.to_uri();
};
-/* Parse uri as a URI and return an array of Uint8Array components.
- *
+/** Parse uri as a URI and return an array of Uint8Array components.
*/
Name.createNameArray = function(uri) {
uri = uri.trim();
@@ -118,11 +116,11 @@
return CCNProtocolDTags.Name;
};
-/*
- * component is a string, byte array, ArrayBuffer, Uint8Array or Name.
- * Convert to Uint8Array and add to this Name.
- * If a component is a string, encode as utf8.
+/**
+ * Convert the component to a Uint8Array and add to this Name.
* Return this Name object to allow chaining calls to add.
+ * @param {String|Array<number>|ArrayBuffer|Uint8Array|Name} component If a component is a string, encode as utf8.
+ * @returns {Name}
*/
Name.prototype.add = function(component){
var result;
@@ -160,39 +158,9 @@
};
/**
- * @brief Add component that represents a segment number
- *
- * @param number Segment number (integer is expected)
- *
- * This component has a special format handling:
- * - if number is zero, then %00 is added
- * - if number is between 1 and 255, %00%01 .. %00%FF is added
- * - ...
+ * Return the escaped name string according to "NDNx URI Scheme".
+ * @returns {String}
*/
-Name.prototype.addSegment = function(number) {
- // step 1: figure out how many bytes will be needed
- var bytes = 1; // at least 1 byte
- var test_number = number;
- while (test_number > 0) {
- bytes ++;
- test_number >>= 8;
- }
-
- var result = new Uint8Array (bytes);
- var index = 0;
- result[index] = 0;
- index ++;
- while (number > 0) {
- result[index] = number & 0xFF;
- number >>= 8;
- index ++;
- }
-
- this.components.push(result);
- return this;
-}
-
-// Return the escaped name string according to "CCNx URI Scheme".
Name.prototype.to_uri = function() {
if (this.components.length == 0)
return "/";
@@ -206,15 +174,15 @@
};
/**
-* @brief Add component that represents a segment number
-*
-* @param number Segment number (integer is expected)
-*
-* This component has a special format handling:
-* - if number is zero, then %00 is added
-* - if number is between 1 and 255, %00%01 .. %00%FF is added
-* - ...
-*/
+ * Add a component that represents a segment number
+ *
+ * This component has a special format handling:
+ * - if number is zero, then %00 is added
+ * - if number is between 1 and 255, %00%01 .. %00%FF is added
+ * - ...
+ * @param {number} number the segment number (integer is expected)
+ * @returns {Name}
+ */
Name.prototype.addSegment = function(number) {
var segmentNumberBigEndian = DataUtils.nonNegativeIntToBigEndian(number);
// Put a 0 byte in front.
@@ -225,7 +193,7 @@
return this;
};
-/*
+/**
* Return a new Name with the first nComponents components of this Name.
*/
Name.prototype.getPrefix = function(nComponents) {
@@ -240,7 +208,7 @@
return new Name(this.components.slice(0, this.components.length-1));
}
-/*
+/**
* Return a new ArrayBuffer of the component at i.
*/
Name.prototype.getComponent = function(i) {
@@ -249,7 +217,7 @@
return result;
}
-/*
+/**
* The "file name" in a name is the last component that isn't blank and doesn't start with one of the
* special marker octets (for version, etc.). Return the index in this.components of
* the file name, or -1 if not found.
@@ -270,7 +238,7 @@
return -1;
}
-/*
+/**
* Return true if this Name has the same components as name.
*/
Name.prototype.equalsName = function(name) {
@@ -286,7 +254,7 @@
return true;
}
-/*
+/**
* Find the last component in name that has a ContentDigest and return the digest value as Uint8Array,
* or null if not found. See Name.getComponentContentDigestValue.
*/
@@ -300,7 +268,7 @@
return null;
}
-/*
+/**
* If component is a ContentDigest, return the digest value as a Uint8Array subarray (don't modify!).
* If not a ContentDigest, return null.
* A ContentDigest component is Name.ContentDigestPrefix + 32 bytes + Name.ContentDigestSuffix.
@@ -323,7 +291,7 @@
Name.ContentDigestPrefix = new Uint8Array([0xc1, 0x2e, 0x4d, 0x2e, 0x47, 0xc1, 0x01, 0xaa, 0x02, 0x85]);
Name.ContentDigestSuffix = new Uint8Array([0x00]);
-/*
+/**
* Return component as an escaped string according to "CCNx URI Scheme".
* We can't use encodeURIComponent because that doesn't encode all the characters we want to.
*/
@@ -357,7 +325,7 @@
return result;
};
-/*
+/**
* Return component as a Uint8Array by decoding the escapedString according to "CCNx URI Scheme".
* If escapedString is "", "." or ".." then return null, which means to skip the component in the name.
*/
diff --git a/js/PublisherID.js b/js/PublisherID.js
index cea6f83..fb83879 100644
--- a/js/PublisherID.js
+++ b/js/PublisherID.js
@@ -4,14 +4,16 @@
* This class represents Publisher and PublisherType Objects
*/
-
-var PublisherType = function PublisherType(_tag){
+/**
+ * @constructor
+ */
+var PublisherType = function PublisherType(tag){
this.KEY =(CCNProtocolDTags.PublisherPublicKeyDigest);
this.CERTIFICATE= (CCNProtocolDTags.PublisherCertificateDigest);
this.ISSUER_KEY= (CCNProtocolDTags.PublisherIssuerKeyDigest);
this.ISSUER_CERTIFICATE =(CCNProtocolDTags.PublisherIssuerCertificateDigest);
- this.Tag = _tag;
+ this.Tag = tag;
};
var isTypeTagVal = function(tagVal) {
@@ -24,9 +26,9 @@
return false;
};
-
-
-
+/**
+ * @constructor
+ */
var PublisherID = function PublisherID() {
this.PUBLISHER_ID_DIGEST_ALGORITHM = "SHA-256";
diff --git a/js/PublisherPublicKeyDigest.js b/js/PublisherPublicKeyDigest.js
index 2079f19..5f83ea8 100644
--- a/js/PublisherPublicKeyDigest.js
+++ b/js/PublisherPublicKeyDigest.js
@@ -3,13 +3,17 @@
* See COPYING for copyright and distribution information.
* This class represents PublisherPublicKeyDigest Objects
*/
-var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){
+
+/**
+ * @constructor
+ */
+var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(pkd){
//this.PUBLISHER_ID_LEN = 256/8;
this.PUBLISHER_ID_LEN = 512/8;
- this.publisherPublicKeyDigest = _pkd;
+ this.publisherPublicKeyDigest = pkd;
//if( typeof _pkd == "object") this.publisherPublicKeyDigest = _pkd; // Byte Array
//else if( typeof _pkd == "PublicKey") ;//TODO...
diff --git a/js/WebSocketTransport.js b/js/WebSocketTransport.js
index bc2a3e7..6365bcb 100644
--- a/js/WebSocketTransport.js
+++ b/js/WebSocketTransport.js
@@ -3,6 +3,9 @@
* See COPYING for copyright and distribution information.
*/
+/**
+ * @constructor
+ */
var WebSocketTransport = function WebSocketTransport() {
if (!WebSocket)
throw new Error("WebSocket support is not available on this platform.");
@@ -17,7 +20,7 @@
9696);
};
-/*
+/**
* Connect to the host and port in ndn. This replaces a previous connection and sets connectedHost
* and connectedPort. Once connected, call onopenCallback().
* Listen on the port to read an entire binary XML encoded element and call
@@ -83,7 +86,7 @@
}
};
-/*
+/**
* Send the Uint8Array data.
*/
WebSocketTransport.prototype.send = function(data) {
diff --git a/js/XpcomTransport.js b/js/XpcomTransport.js
index 973ed77..2d89f74 100644
--- a/js/XpcomTransport.js
+++ b/js/XpcomTransport.js
@@ -9,6 +9,9 @@
// Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
// Components.utils.import("resource://gre/modules/NetUtil.jsm");
+/**
+ * @constructor
+ */
var XpcomTransport = function XpcomTransport() {
this.elementListener = null;
this.socket = null; // nsISocketTransport
@@ -22,7 +25,7 @@
9695);
};
-/*
+/**
* Connect to the host and port in ndn. This replaces a previous connection and sets connectedHost
* and connectedPort. Once connected, call onopenCallback().
* Listen on the port to read an entire binary XML encoded element and call
@@ -35,7 +38,7 @@
onopenCallback();
};
-/*
+/**
* Do the work to connect to host and port. This replaces a previous connection and sets connectedHost
* and connectedPort.
* Listen on the port to read an entire binary XML encoded element and call
@@ -85,7 +88,7 @@
pump.asyncRead(dataListener, null);
};
-/*
+/**
* Send the data over the connection created by connect.
*/
XpcomTransport.prototype.send = function(/* Uint8Array */ data) {
diff --git a/js/encoding/BinaryXMLDecoder.js b/js/encoding/BinaryXMLDecoder.js
index bf8597b..675a876 100644
--- a/js/encoding/BinaryXMLDecoder.js
+++ b/js/encoding/BinaryXMLDecoder.js
@@ -65,7 +65,9 @@
return null;
};
-//console.log(stringToTag(64));
+/**
+ * @constructor
+ */
var BinaryXMLDecoder = function BinaryXMLDecoder(input){
var MARK_LEN=512;
var DEBUG_MAX_LEN = 32768;
@@ -380,7 +382,7 @@
};
-/*
+/**
* 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.
@@ -564,9 +566,6 @@
return this.v;
};
-
-
-
BinaryXMLDecoder.prototype.readIntegerElement =function(
//String
startTag) {
@@ -580,7 +579,6 @@
return parseInt(strVal);
};
-
BinaryXMLDecoder.prototype.readUTF8Element =function(
//String
startTag,
@@ -594,8 +592,7 @@
return strElementText;
};
-
-/*
+/**
* Set the offset into the input, used for the next read.
*/
BinaryXMLDecoder.prototype.seek = function(
diff --git a/js/encoding/BinaryXMLEncoder.js b/js/encoding/BinaryXMLEncoder.js
index 99a1ad2..517abca 100644
--- a/js/encoding/BinaryXMLEncoder.js
+++ b/js/encoding/BinaryXMLEncoder.js
@@ -39,14 +39,16 @@
var bits_18 = 0x00003FFFF;
var bits_32 = 0x0FFFFFFFF;
-
+/**
+ * @constructor
+ */
var BinaryXMLEncoder = function BinaryXMLEncoder(){
this.ostream = new DynamicUint8Array(100);
this.offset =0;
this.CODEC_NAME = "Binary";
};
-/*
+/**
* Encode utf8Content as utf8.
*/
BinaryXMLEncoder.prototype.writeUString = function(/*String*/ utf8Content) {
@@ -142,7 +144,7 @@
return null;
};
-/*
+/**
* If Content is a string, then encode as utf8 and write UDATA.
*/
BinaryXMLEncoder.prototype.writeElement = function(
@@ -234,7 +236,7 @@
return numEncodingBytes;
};
-/*
+/**
* Encode ustring as utf8.
*/
BinaryXMLEncoder.prototype.encodeUString = function(
diff --git a/js/encoding/BinaryXMLStructureDecoder.js b/js/encoding/BinaryXMLStructureDecoder.js
index 9b99fd5..19f7ceb 100644
--- a/js/encoding/BinaryXMLStructureDecoder.js
+++ b/js/encoding/BinaryXMLStructureDecoder.js
@@ -6,6 +6,9 @@
* See COPYING for copyright and distribution information.
*/
+/**
+ * @constructor
+ */
var BinaryXMLStructureDecoder = function BinaryXMLDecoder() {
this.gotElementEnd = false;
this.offset = 0;
@@ -20,7 +23,7 @@
BinaryXMLStructureDecoder.READ_HEADER_OR_CLOSE = 0;
BinaryXMLStructureDecoder.READ_BYTES = 1;
-/*
+/**
* Continue scanning input starting from this.offset. If found the end of the element
* which started at offset 0 then return true, else false.
* If this returns false, you should read more into input and call again.
@@ -148,20 +151,18 @@
}
};
-/*
+/**
* Set the state to READ_HEADER_OR_CLOSE and set up to start reading the header
*/
BinaryXMLStructureDecoder.prototype.startHeader = function() {
- this.headerLength = 0;
- this.useHeaderBuffer = false;
- this.state = BinaryXMLStructureDecoder.READ_HEADER_OR_CLOSE;
+ this.headerLength = 0;
+ this.useHeaderBuffer = false;
+ this.state = BinaryXMLStructureDecoder.READ_HEADER_OR_CLOSE;
}
-/*
+/**
* Set the offset into the input, used for the next read.
*/
-BinaryXMLStructureDecoder.prototype.seek = function(
- //int
- offset) {
- this.offset = offset;
+BinaryXMLStructureDecoder.prototype.seek = function(offset) {
+ this.offset = offset;
}
diff --git a/js/encoding/BinaryXMLWireFormat.js b/js/encoding/BinaryXMLWireFormat.js
index 8dbe3a2..b4859a0 100644
--- a/js/encoding/BinaryXMLWireFormat.js
+++ b/js/encoding/BinaryXMLWireFormat.js
@@ -6,6 +6,7 @@
/**
* A BinaryXMLWireFormat implements the WireFormat interface for encoding and decoding in binary XML.
+ * @constructor
*/
var BinaryXMLWireFormat = function BinaryXMLWireFormat() {
};
diff --git a/js/encoding/DynamicUint8Array.js b/js/encoding/DynamicUint8Array.js
index 5bf0080..802b5c2 100644
--- a/js/encoding/DynamicUint8Array.js
+++ b/js/encoding/DynamicUint8Array.js
@@ -4,11 +4,12 @@
* Encapsulate an Uint8Array and support dynamic reallocation.
*/
-/*
+/**
* Create a DynamicUint8Array where this.array is a Uint8Array of size length.
- * If length is not supplied, use a default initial length.
* The methods will update this.length.
* To access the array, use this.array or call subarray.
+ * @constructor
+ * @param {number} length the initial length of the array. If null, use a default.
*/
var DynamicUint8Array = function DynamicUint8Array(length) {
if (!length)
@@ -18,7 +19,7 @@
this.length = length;
};
-/*
+/**
* Ensure that this.array has the length, reallocate and copy if necessary.
* Update this.length which may be greater than length.
*/
@@ -38,7 +39,7 @@
this.length = newLength;
};
-/*
+/**
* Call this.array.set(value, offset), reallocating if necessary.
*/
DynamicUint8Array.prototype.set = function(value, offset) {
@@ -46,9 +47,9 @@
this.array.set(value, offset);
};
-/*
+/**
* Return this.array.subarray(begin, end);
*/
DynamicUint8Array.prototype.subarray = function(begin, end) {
return this.array.subarray(begin, end);
-}
+};
diff --git a/js/encoding/EncodingUtils.js b/js/encoding/EncodingUtils.js
index 02f0b3a..0715f27 100644
--- a/js/encoding/EncodingUtils.js
+++ b/js/encoding/EncodingUtils.js
@@ -8,7 +8,9 @@
return DataUtils.toHex(interest.encode());
}
-// Deprecated: Use interest.encode().
+/**
+ * @deprecated Use interest.encode().
+ */
function encodeToBinaryInterest(interest) {
return interest.encode();
}
@@ -17,7 +19,9 @@
return DataUtils.toHex(contentObject.encode());
}
-// Deprecated: Use contentObject.encode().
+/**
+ * @deprecated Use contentObject.encode().
+ */
function encodeToBinaryContentObject(contentObject) {
contentObject.encode();
}
@@ -80,7 +84,7 @@
}
-/*
+/**
* Decode the Uint8Array which holds SubjectPublicKeyInfo and return an RSAKey.
*/
function decodeSubjectPublicKeyInfo(array) {
@@ -91,8 +95,9 @@
return rsaKey;
}
-/* Return a user friendly HTML string with the contents of co.
- This also outputs to console.log.
+/**
+ * Return a user friendly HTML string with the contents of co.
+ * This also outputs to console.log.
*/
function contentObjectToHtml(/* ContentObject */ co) {
var output ="";
diff --git a/js/encoding/MimeTypes.js b/js/encoding/MimeTypes.js
index 9689355..ef17849 100644
--- a/js/encoding/MimeTypes.js
+++ b/js/encoding/MimeTypes.js
@@ -4,8 +4,11 @@
* See COPYING for copyright and distribution information.
*/
+/**
+ * MimeTypes contains a mapping of filename extension to MIME type, and a function getContentTypeAndCharset to select it.
+ */
var MimeTypes = {
- /*
+ /**
* Based on filename, return an object with properties contentType and charset.
*/
getContentTypeAndCharset: function(filename) {
diff --git a/js/security/KeyManager.js b/js/security/KeyManager.js
index 32a7f42..d3e70cd 100644
--- a/js/security/KeyManager.js
+++ b/js/security/KeyManager.js
@@ -3,6 +3,9 @@
* See COPYING for copyright and distribution information.
*/
+/**
+ * @constructor
+ */
var KeyManager = function KeyManager(){
diff --git a/js/security/Witness.js b/js/security/Witness.js
index 59f4fe1..04d9acf 100644
--- a/js/security/Witness.js
+++ b/js/security/Witness.js
@@ -3,11 +3,17 @@
* See COPYING for copyright and distribution information.
*/
+/**
+ * @constructor
+ */
var MerklePath = function MerkelPath() {
this.index = null; // int
this.digestList = []; // array of hex string
};
+/**
+ * @constructor
+ */
var Witness = function Witness() {
this.oid = null; // string
this.path = new MerklePath(); // MerklePath
diff --git a/js/util/CCNTime.js b/js/util/CCNTime.js
index e4c8afd..bb1222e 100644
--- a/js/util/CCNTime.js
+++ b/js/util/CCNTime.js
@@ -4,24 +4,14 @@
* This class represents CCNTime Objects
*/
-var CCNTime = function CCNTime(
-
- input) {
-
-
-
-
+/**
+ * @constructor
+ */
+var CCNTime = function CCNTime(input) {
this.NANOS_MAX = 999877929;
- /*if(typeof input =='object'){
- this.longDate = DataUtils.byteArrayToUnsignedLong(input);
- this.binaryDate = input;
- }*/
- if(typeof input =='number'){
+ if(typeof input =='number')
this.msec = input;
- //this.binaryDate = DataUtils.unsignedLongToByteArray(input);
-
- }
else{
if(LOG>1) console.log('UNRECOGNIZED TYPE FOR TIME');
}
diff --git a/js/util/ExponentialReExpressClosure.js b/js/util/ExponentialReExpressClosure.js
index 1057f60..3b0fd85 100644
--- a/js/util/ExponentialReExpressClosure.js
+++ b/js/util/ExponentialReExpressClosure.js
@@ -4,13 +4,14 @@
* This is the closure class for use in expressInterest to re express with exponential falloff.
*/
-/*
+/**
* Create a new ExponentialReExpressClosure where upcall responds to UPCALL_INTEREST_TIMED_OUT
* by expressing the interest again with double the interestLifetime. If the interesLifetime goes
* over maxInterestLifetime, then call callerClosure.upcall with UPCALL_INTEREST_TIMED_OUT.
* When upcall is not UPCALL_INTEREST_TIMED_OUT, just call callerClosure.upcall.
- *
- * settings is an associative array with the following defaults:
+ * @constructor
+ * @param {Closure} callerClosure
+ * @param {Object} settings if not null, an associative array with the following defaults:
* {
* maxInterestLifetime: 16000 // milliseconds
* }
@@ -25,6 +26,10 @@
this.maxInterestLifetime = (settings.maxInterestLifetime || 16000);
};
+/**
+ * Wrap this.callerClosure to responds to UPCALL_INTEREST_TIMED_OUT
+ * by expressing the interest again as described in the constructor.
+ */
ExponentialReExpressClosure.prototype.upcall = function(kind, upcallInfo) {
try {
if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {