Uncomitted stuff from the previous commit
diff --git a/js/CCNTime.js b/js/CCNTime.js
index 5aafca1..26e98df 100644
--- a/js/CCNTime.js
+++ b/js/CCNTime.js
@@ -4,15 +4,28 @@
*/
var CCNTime = function CCNTime(
- //long
-msec) {
+
+ msec) {
this.NANOS_MAX = 999877929;
- this.date = new Date(msec);
+ if(typeof msec =='object'){
+ this.setDateBinary(msec);
+ this.msec = msec;
+ this.msecHex = toHex(msec);
+ }
+ else if(typeof msec =='string'){
+
+ this.msec = toNumbers(msec);
+ this.setDateBinary(this.msec);
+ this.msecHex = msec;
+ }
+ else{
+ if(LOG>1) console.log('UNRECOGNIZED TYPE FOR TIME');
+ }
};
@@ -21,18 +34,7 @@
* @param timestamp source timestamp to initialize from, some precision will be lost
*/
- /**
- * Create a CCNTime
- * @param time source Date to initialize from, some precision will be lost
- * as CCNTime does not round to unitary milliseconds
- */
-CCNTime.prototype.setDate = function(
- //Date
- date) {
- this.date = date;
-};
-
/**
* Create a CCNTime from its binary encoding
* @param binaryTime12 the binary representation of a CCNTime
@@ -50,24 +52,22 @@
value = 0;
for(i = 0; i < binaryTime12.length; i++) {
value = value << 8;
- // Java will assume the byte is signed, so extend it and trim it.
b = (binaryTime12[i]) & 0xFF;
value |= b;
}
- this.date = new Date(value);
+ this.date = value;
+ //this.date = new Date(value);
};
//byte[]
CCNTime.prototype.toBinaryTime = function() {
-
-
- return unsignedLongToByteArray(this.date.getTime());
+ return this.msec; //unsignedLongToByteArray(this.date.getTime());
}
-
+/*
unsignedLongToByteArray= function( value) {
if( 0 == value )
return [0];
@@ -95,5 +95,5 @@
out[ offset - i ] = b;
}
return out;
-}
+}*/
diff --git a/js/ContentName.js b/js/ContentName.js
index bec8482..8c12188 100644
--- a/js/ContentName.js
+++ b/js/ContentName.js
@@ -15,23 +15,43 @@
this.ROOT = null;
if( typeof _Components == 'string') {
- this.Components = _Components;
-
+ if(LOG>3)console.log('Content Name String '+_Components);
+ this.Components = createNameArray(_Components);
}
else if(typeof _Components === 'object' && _Components instanceof Array ){
+ if(LOG>4)console.log('Content Name Array '+_Components);
this.Components = _Components;
}
+ else if(_Components==null){
+ this.Components =[];
+ }
else{
-
- console.log("TODO: This should be an array");
- this.Components==_Components;
+
+ if(LOG>1)console.log("NO CONTENT NAME GIVEN");
+
}
};
+function createNameArray(name){
+
+ //message = decodeURIComponent(message);
+ name = unescape(name);
+
+ var array = name.split('/');
+
+
+ if(name[0]=="/")
+ array=array.slice(1,array.length);
+
+ if(name[name.length-1]=="/")
+ array=array.slice(0,array.length-1);
+
+ return array;
+}
ContentName.prototype.decode = function(/*XMLDecoder*/ decoder) {
@@ -49,7 +69,8 @@
ContentName.prototype.encode = function(/*XMLEncoder*/ encoder) {
- //TODO Check if parameters are valid
+ if( this.Components ==null )
+ throw new Exception("CANNOT ENCODE EMPTY CONTENT NAME");
encoder.writeStartElement(this.getElementLabel());
var count = this.Components.length;
diff --git a/js/ContentObject.js b/js/ContentObject.js
index d05f7ba..e120a98 100644
--- a/js/ContentObject.js
+++ b/js/ContentObject.js
@@ -6,7 +6,7 @@
if (typeof _Name === 'string'){
- var n = new Name(_Name);
+ this.Name = new ContentName(_Name);
}
else{
//TODO Check the class of _Name
@@ -16,26 +16,115 @@
this.Content=_Content;
this.Signature = _Signature;
+
+ this.StartSIG = null;
+ this.EndSIG = null;
+
+ this.StartSignedInfo = null;
+ this.EndContent = null;
+
+ this.rawSignatureData = null;
};
+ContentObject.prototype.sign = function(){
+ var n1 = this.encodeObject(this.Name);
+ var n2 = this.encodeObject(this.SignedInfo);
+ var n3 = this.encodeContent();
+
+ var n = n1.concat(n2,n3);
+ if(LOG>2)console.log('Signature Data is (binary) '+n);
+
+ if(LOG>2)console.log('Signature Data is (RawString) '+ toString(n) );
+ if(LOG>2)console.log(toString(n) );
+
+
+ var rsa = new RSAKey();
+
+ rsa.readPrivateKeyFromPEMString(globalKeyManager.privateKey);
+
+ var hSig = rsa.signString(toString(n), "sha256");
+
+ if(LOG>2)console.log('SIGNATURE SAVED IS');
+
+ if(LOG>2)console.log(hSig);
+
+ if(LOG>2)console.log(toNumbers(hSig.trim()));
+
+ this.Signature.Signature = toNumbers(hSig.trim());
+};
+
+ContentObject.prototype.encodeObject = function encodeObject(obj){
+ var enc = new BinaryXMLEncoder();
+
+ obj.encode(enc);
+
+ var num = enc.getReducedOstream();
+
+ return num;
+
+
+};
+
+ContentObject.prototype.encodeContent = function encodeContent(obj){
+ var enc = new BinaryXMLEncoder();
+
+ enc.writeElement(CCNProtocolDTags.Content, this.Content);
+
+ var num = enc.getReducedOstream();
+
+ return num;
+
+
+};
+
+ContentObject.prototype.saveRawData = function(bytes){
+
+ var sigBits = bytes.slice(this.StartSIG, this.EndSIG );
+
+ //var sigIngoPlusContentBits = bytes.slice(this.StartSignedInfo, this.EndContent );
+
+ //var concat = sigBits.concat(sigIngoPlusContentBits);
+
+ //this.rawSignatureData = concat;
+
+ this.rawSignatureData = sigBits;
+};
ContentObject.prototype.decode = function(/*XMLDecoder*/ decoder) {
decoder.readStartElement(this.getElementLabel());
- this.Signature = new Signature();
- this.Signature.decode(decoder);
+
+ if( decoder.peekStartElement(CCNProtocolDTags.Signature) ){
+ this.Signature = new Signature();
+ this.Signature.decode(decoder);
+ }
+
+ //this.EndSIG = decoder.offset;
+
+ this.StartSIG = decoder.offset;
this.Name = new ContentName();
this.Name.decode(decoder);
-
- this.SignedInfo = new SignedInfo();
- this.SignedInfo.decode(decoder);
-
+
+ //this.StartSignedInfo = decoder.offset;
+
+
+ if( decoder.peekStartElement(CCNProtocolDTags.SignedInfo) ){
+ this.SignedInfo = new SignedInfo();
+ this.SignedInfo.decode(decoder);
+ }
+
this.Content = decoder.readBinaryElement(CCNProtocolDTags.Content);
- decoder.readEndElement();
+
+ //this.EndContent = decoder.offset;
+ this.EndSIG = decoder.offset;
+
+ decoder.readEndElement();
+
+ this.saveRawData(decoder.istream);
};
ContentObject.prototype.encode = function(/*XMLEncoder*/ encoder) {
@@ -45,14 +134,35 @@
encoder.writeStartElement(this.getElementLabel());
+
+
+
if(null!=this.Signature) this.Signature.encode(encoder);
+
+
+ this.StartSIG = encoder.offset;
+
+
if(null!=this.Name) this.Name.encode(encoder);
+
+ //this.EndSIG = encoder.offset;
+ //this.StartSignedInfo = encoder.offset;
+
+
if(null!=this.SignedInfo) this.SignedInfo.encode(encoder);
encoder.writeElement(CCNProtocolDTags.Content, this.Content);
- encoder.writeEndElement();
+
+ this.EndSIG = encoder.offset;
+
+ //this.EndContent = encoder.offset;
+
+ encoder.writeEndElement();
+
+ this.saveRawData(encoder.ostream);
+
};
ContentObject.prototype.getElementLabel= function(){return CCNProtocolDTags.ContentObject;};
diff --git a/js/FaceInstance.js b/js/FaceInstance.js
index 48d9e5f..9f32ade 100644
--- a/js/FaceInstance.js
+++ b/js/FaceInstance.js
@@ -1,4 +1,7 @@
-
+/*
+ * @author: ucla-cs
+ * This class represents Face Instances
+ */
var FaceInstance = function FaceInstance(
@@ -151,7 +154,5 @@
}
-
-
FaceInstance.prototype.getElementLabel= function(){return CCNProtocolDTags.FaceInstance;};
diff --git a/js/ForwardingEntry.js b/js/ForwardingEntry.js
index 6702f39..60fe750 100644
--- a/js/ForwardingEntry.js
+++ b/js/ForwardingEntry.js
@@ -1,4 +1,7 @@
-
+/*
+ * @author: ucla-cs
+ * This class represents Forwarding Entries
+ */
var ForwardingEntry = function ForwardingEntry(
//ActionType
diff --git a/js/KeyLocator.js b/js/KeyLocator.js
index 68adcba..d61ed12 100644
--- a/js/KeyLocator.js
+++ b/js/KeyLocator.js
@@ -18,6 +18,7 @@
this.KeyName = _Input;
}
else if(_Type==KeyLocatorType.KEY){
+ console.log('SET KEY');
this.PublicKey = _Input;
}
else if(_Type==KeyLocatorType.CERTIFICATE){
@@ -37,16 +38,19 @@
//TODO FIX THIS, This should create a Key Object instead of keeping bytes
- this.Key = encodedKey;//CryptoUtil.getPublicKey(encodedKey);
+ this.PublicKey = encodedKey;//CryptoUtil.getPublicKey(encodedKey);
- this.PublicKey = encodedKey;
+
+
+ if(LOG>4) console.log('PUBLIC KEY FOUND: '+ this.PublicKey);
+ //this.PublicKey = encodedKey;
} catch (e) {
throw new Exception("Cannot parse key: ", e);
}
- if (null == this.Key) {
+ if (null == this.PublicKey) {
throw new Exception("Cannot parse key: ");
}
@@ -61,13 +65,20 @@
//CertificateFactory factory = CertificateFactory.getInstance("X.509");
//this.Certificate = (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(encodedCert));
+
+ this.Certificate = encodedCert;
+
+ if(LOG>4) console.log('CERTIFICATE FOUND: '+ this.Certificate);
+
} catch ( e) {
throw new Exception("Cannot decode certificate: " + e);
}
if (null == this.Certificate) {
throw new Exception("Cannot parse certificate! ");
}
- } else {
+ } else {
+
+
this.KeyName = new KeyName();
this.KeyName.decode(decoder);
}
@@ -76,18 +87,19 @@
KeyLocator.prototype.encode = function( encoder) {
-
+
+ if(LOG>2) console.log('type is is ' + this.Type);
//TODO Check if Name is missing
- /*if (!validate()) {
+ if (!this.validate()) {
throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
- }*/
+ }
//TODO FIX THIS TOO
encoder.writeStartElement(this.getElementLabel());
- if (this._Type == KeyLocatorType.KEY) {
-
+ if (this.Type == KeyLocatorType.KEY) {
+ if(LOG>5)console.log('About to encode a public key' +this.PublicKey);
encoder.writeElement(CCNProtocolDTags.Key, this.PublicKey);
} else if (this.Type == KeyLocatorType.CERTIFICATE) {
@@ -99,7 +111,7 @@
}
} else if (this.Type == KeyLocatorType.NAME) {
- console.log('ACTUALLY HERE');
+
this.KeyName.encode(encoder);
}
encoder.writeEndElement();
@@ -111,6 +123,6 @@
};
KeyLocator.prototype.validate = function() {
- return ( (null != this.keyName) || (null != this.PublicKey) || (null != this.Certificate) );
+ return ( (null != this.KeyName) || (null != this.PublicKey) || (null != this.Certificate) );
};
\ No newline at end of file
diff --git a/js/KeyName.js b/js/KeyName.js
index 036a550..2c79bfc 100644
--- a/js/KeyName.js
+++ b/js/KeyName.js
@@ -20,6 +20,8 @@
this.ContentName = new ContentName();
this.ContentName.decode(decoder);
+ if(LOG>4) console.log('KEY NAME FOUND: ');
+
if ( peek(decoder) ) {
this.PublisherID = new PublisherID();
this.PublisherID.decode(decoder);
diff --git a/js/PublisherPublicKeyDigest.js b/js/PublisherPublicKeyDigest.js
index 92dec39..adbc25c 100644
--- a/js/PublisherPublicKeyDigest.js
+++ b/js/PublisherPublicKeyDigest.js
@@ -4,24 +4,39 @@
*/
var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){
- if( typeof _pkd == "ByteArray") this.PublisherPublicKeyDigest = _pkd; // Byte Array
- else if( typeof _pkd == "PublicKey") ;//TODO...
+
+ this.PUBLISHER_ID_LEN = 256/8;
+
+ this.PublisherPublicKeyDigest = _pkd;
+ //if( typeof _pkd == "object") this.PublisherPublicKeyDigest = _pkd; // Byte Array
+ //else if( typeof _pkd == "PublicKey") ;//TODO...
+
+
};
+
+
+
PublisherPublicKeyDigest.prototype.decode = function( decoder) {
this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel());
+
+ if(LOG>4)console.log('Publisher public key digest is ' + this.PublisherPublicKeyDigest);
+
if (null == this.PublisherPublicKeyDigest) {
throw new Exception("Cannot parse publisher key digest.");
}
//TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason)
- /*if (this.PublisherPublicKeyDigest.length != PublisherID.PUBLISHER_ID_LEN) {
- console.log('SHOULD NOT GO HERE !!!!!!!!!!!!!!!!!!');
- this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest;
- }*/
+ if (this.PublisherPublicKeyDigest.length != PublisherID.PUBLISHER_ID_LEN) {
+
+ console.log('LENGTH OF PUBLISHER ID IS WRONG!');
+
+ //this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest;
+
+ }
};
PublisherPublicKeyDigest.prototype.encode= function( encoder) {
@@ -29,8 +44,8 @@
/*if (!this.validate()) {
throw new Exception("Cannot encode : field values missing.");
}*/
-
- if (this.PublisherKeyDigest!=null)this.encoder.writeElement(this.getElementLabel(), this.PublisherKeyDigest);
+ if(LOG>3) console.log('PUBLISHER KEY DIGEST IS'+this.PublisherPublicKeyDigest);
+ encoder.writeElement(this.getElementLabel(), this.PublisherPublicKeyDigest);
};
PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; };
diff --git a/js/Signature.js b/js/Signature.js
index 763d9fe..f8f4d69 100644
--- a/js/Signature.js
+++ b/js/Signature.js
@@ -11,16 +11,49 @@
this.DigestAlgorithm = _DigestAlgorithm//String _digestAlgorithm;
};
+var generateSignature = function(contentName,content,signedinfo){
+
+ var enc = new BinaryXMLEncoder();
+ contentName.encode(enc);
+ var hex1 = toHex(enc.getReducedOstream());
+
+ var enc = new BinaryXMLEncoder();
+ content.encode(enc);
+ var hex2 = toHex(enc.getReducedOstream());
+
+ var enc = new BinaryXMLEncoder();
+ signedinfo.encode(enc);
+ var hex3 = toHex(enc.getReducedOstream());
+
+ var hex = hex1+hex2+hex3;
+
+ //globalKeyManager.sig
+
+};
Signature.prototype.decode =function( decoder) {
decoder.readStartElement(this.getElementLabel());
+
+ if(LOG>4)console.log('STARTED DECODING SIGNATURE ');
+
if (decoder.peekStartElement(CCNProtocolDTags.DigestAlgorithm)) {
+
+ if(LOG>4)console.log('DIGIEST ALGORITHM FOUND');
this.DigestAlgorithm = decoder.readUTF8Element(CCNProtocolDTags.DigestAlgorithm);
}
if (decoder.peekStartElement(CCNProtocolDTags.Witness)) {
+ if(LOG>4)console.log('WITNESS FOUND FOUND');
this.Witness = decoder.readBinaryElement(CCNProtocolDTags.Witness);
}
- this.Signature = decoder.readBinaryElement(CCNProtocolDTags.SignatureBits);
+
+ //FORCE TO READ A SIGNATURE
+
+ //if (decoder.peekStartElement(CCNProtocolDTags.SignatureBits)) {
+ //if(LOG>4)console.log('SIGNATURE FOUND ');
+ this.Signature = decoder.readBinaryElement(CCNProtocolDTags.SignatureBits);
+
+ //}
+
decoder.readEndElement();
};
diff --git a/js/SignedInfo.js b/js/SignedInfo.js
index 3d03f17..0b81201 100644
--- a/js/SignedInfo.js
+++ b/js/SignedInfo.js
@@ -13,7 +13,7 @@
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
@@ -23,18 +23,45 @@
};
+SignedInfo.prototype.setFields = function(){
+ //BASE64 -> RAW STRING
+
+ var stringCertificate = DataUtils.base64toString(globalKeyManager.certificate);
+
+ if(LOG>3)console.log('string Certificate is '+stringCertificate);
+
+ //HEX -> BYTE ARRAY
+ var publisherkey = toNumbers(hex_sha256(stringCertificate));
+
+ if(LOG>3)console.log('publisher key is ');
+ if(LOG>3)console.log(publisherkey);
+
+ this.Publisher = new PublisherPublicKeyDigest(publisherkey);
+
+
+ this.Timestamp = new CCNTime('FD0499602d2000');
+
+ this.Type = ContentType.DATA;
+
+ console.log('toNumbersFromString(stringCertificate) '+toNumbersFromString(stringCertificate));
+ this.Locator = new KeyLocator( toNumbersFromString(stringCertificate) ,KeyLocatorType.KEY );
+
+};
SignedInfo.prototype.decode = function( decoder){
decoder.readStartElement( this.getElementLabel() );
if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
+ if(LOG>3) console.log('DECODING PUBLISHER KEY');
this.Publisher = new PublisherPublicKeyDigest();
this.Publisher.decode(decoder);
}
if (decoder.peekStartElement(CCNProtocolDTags.Timestamp)) {
this.Timestamp = decoder.readDateTime(CCNProtocolDTags.Timestamp);
+ if(LOG>4)console.log('TIMESTAMP FOUND IS '+this.Timestamp);
+
}
if (decoder.peekStartElement(CCNProtocolDTags.Type)) {
@@ -43,22 +70,25 @@
//TODO Implement Type of Key Reading
- //this.Type = valueToType(binType);
+ if(LOG>4)console.log('TYPE IS'+bintype);
+
+ this.Type = this.valueToType(binType);
//TODO Implement Type of Key Reading
- /*
+
if (null == this.Type) {
throw new Exception("Cannot parse signedInfo type: bytes.");
}
} else {
- this.Type = ContentType.DATA; // default*/
+ this.Type = ContentType.DATA; // default
}
if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
this.FreshnessSeconds = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
+ if(LOG>4) console.log('FRESHNESS IN SECONDS IS '+ this.FreshnessSeconds);
}
if (decoder.peekStartElement(CCNProtocolDTags.FinalBlockID)) {
@@ -80,6 +110,8 @@
encoder.writeStartElement(this.getElementLabel());
if (null!=this.Publisher) {
+ if(LOG>3) console.log('ENCODING PUBLISHER KEY' + this.Publisher.PublisherPublicKeyDigest);
+
this.Publisher.encode(encoder);
}
@@ -107,6 +139,15 @@
encoder.writeEndElement();
};
+SignedInfo.prototype.valueToType = function(){
+ //for (Entry<byte [], ContentType> entry : ContentValueTypes.entrySet()) {
+ //if (Arrays.equals(value, entry.getKey()))
+ //return entry.getValue();
+ //}
+ return null;
+
+};
+
SignedInfo.prototype.getElementLabel = function() {
return CCNProtocolDTags.SignedInfo;
};
diff --git a/js/java_socket_bridge.js b/js/java_socket_bridge.js
index 5ed0c9d..5ecb343 100644
--- a/js/java_socket_bridge.js
+++ b/js/java_socket_bridge.js
@@ -3,7 +3,10 @@
* This class represents Interest Objects
*/
-var LOG = 5;
+//var ccndAddr = unescape(%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F);
+var ccndAddrHex = '%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F';
+
+var LOG = 5;
// Global variables
var java_socket_bridge_ready_flag = false;
@@ -22,6 +25,9 @@
java_socket_bridge_ready_flag = true;
}
+
+
+
//Sets the route to ccnx router
function createRoute(url, port){
ndnport = port;
@@ -30,11 +36,9 @@
console.log(new BinaryXMLDecoder());
//SEND INTERST TO CCNX NODE
- startRegisterPrefix();
+
//Now Start the receiving thread
- var result = get_java_socket_bridge().connectAndStartAndPublish();
-
}
@@ -55,17 +59,8 @@
}
//message = decodeURIComponent(message);
- message = unescape(message);
- var array = message.split('/');
-
-
- if(message[0]=="/")
- array=array.slice(1,array.length);
-
- if(message[message.length-1]=="/")
- array=array.slice(0,array.length-1);
-
+ var array = createNameArray(message);
//console.log('ARRAY IS '+ array);
@@ -80,8 +75,6 @@
//console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);
-
-
var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
@@ -106,8 +99,8 @@
co.decode(decoder);
- //console.log(co);
-
+ if(LOG>2) console.log(co);
+
return co;
@@ -116,6 +109,7 @@
}
+
else{
alert('ERROR URL OR PORT NOT SET');
@@ -126,8 +120,33 @@
}
+var registerStarted = false;
+function registerPrefix(name, content){
+
+ registeredPrefixes[name] = content ;
+
+ if(registerStarted == false){
+ var result = get_java_socket_bridge().connectAndStartAndPublish();
+
+ startRegisterPrefix();
+
+ registerStarted = true;
+ }
+ sendForwardingEntry(10);
+}
+
+
+function unRegisterPrefix(name){
+
+ delete registeredPrefixes[name];
+
+}
+
+
+
function on_socket_received_interest(IP, port, interestBinary){
+ console.log('WOOOO RECEIVED STUFF' );
var interest = decodeHexInterest(interestBinary);
console.log('WOOO received interest' + interest.Name.Components);
@@ -152,20 +171,6 @@
}
}
-function registerPrefix(name, content){
-
- registeredPrefixes[name] = content ;
-
-}
-
-
-function unRegisterPrefix(name){
-
- delete registeredPrefixes[name];
-
-}
-
-
@@ -194,26 +199,32 @@
var faceInstanceBinary = encoder1.getReducedOstream();
-
- var co = new ContentObject(null,null,faceInstanceBinary,null);
+ var si = new SignedInfo();
+ si.setFields();
+
+ var co = new ContentObject(new ContentName(),si,faceInstanceBinary,new Signature());
+ co.sign();
var encoder2 = new BinaryXMLEncoder();
-
+
co.encode(encoder2);
var coBinary = encoder2.getReducedOstream();
+
+ //if(LOG>3)console.log('ADDESS OF CCND IS'+unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F'));
+
+ //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);
+ var interestName = new ContentName(['ccnx',unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F'),'newface',coBinary]);
+ //var interestName = new ContentName(['ccnx','%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F','newface',coBinary]);
-
-
- var interestName = new ContentName(['ccnx','1234','newface',faceInstanceBinary]);
//var interestName = new ContentName(['ccnx','1234','newface',coBinary]);
-
+ //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);
int = new Interest(interestName,face);
var hex = encodeToHexInterest(int);
/////////////////
-
-
+
+
if(LOG>4)console.log('Interst name of Conntection Message is '+ interestName);
@@ -222,11 +233,9 @@
//console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);
var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
-
- console.log('BINARY RESPONSE IS ' +result);
+
//TODO MOVE THIS
- sendForwardingEntry(10);
//result[0] and result[1] should be 0 and 4 if there is a content object found
if(result==null || result==undefined || result =="" || result[0] != '0'||result[1]!='4'){
@@ -271,7 +280,7 @@
///////////////////////
- var face = new ForwardingEntry('prefixreg',new ContentName('helloworld'),null, faceID, 1,null);
+ var face = new ForwardingEntry('prefixreg',new ContentName(['helloworld']),null, faceID, 1,null);
var encoder1 = new BinaryXMLEncoder();
@@ -281,18 +290,26 @@
- var co = new ContentObject(null,null,faceInstanceBinary,null);
+ var si = new SignedInfo();
+ si.setFields();
+
+ var co = new ContentObject(new ContentName(),si,faceInstanceBinary,new Signature());
+ co.sign();
var encoder2 = new BinaryXMLEncoder();
-
+
co.encode(encoder2);
var coBinary = encoder2.getReducedOstream();
- var interestName = new ContentName(['ccnx','1234','prefixreg',faceInstanceBinary]);
+ var interestName = new ContentName(['ccnx',unescape('%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F'),'prefixreg',coBinary]);
+ //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);
+ //var interestName = new ContentName(['ccnx','%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F','newface',coBinary]);
+
//var interestName = new ContentName(['ccnx','1234','newface',coBinary]);
+ //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'prefixreg',coBinary]);
int = new Interest(interestName,face);
@@ -309,7 +326,7 @@
var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
- console.log('BINARY RESPONSE IS ' +result);
+ if(LOG>3)console.log('BINARY RESPONSE IS ' +result);
//result[0] and result[1] should be 0 and 4 if there is a content object found
@@ -340,25 +357,6 @@
-function createNameArray(name){
- if(name==null || name =="" || name=="/"){
- return -2;
- }
-
- //message = decodeURIComponent(message);
- name = unescape(name);
-
- var array = name.split('/');
-
-
- if(name[0]=="/")
- array=array.slice(1,array.length);
-
- if(name[name.length-1]=="/")
- array=array.slice(0,array.length-1);
-
- return array;
-}
function encodeToHexInterest(int){
@@ -391,9 +389,8 @@
decoder = new BinaryXMLDecoder(numbers);
- console.log('DECODED HEX INTERST \n'+numbers);
-
-
+ if(LOG>3)console.log('DECODED HEX INTERST \n'+numbers);
+
i = new Interest();
i.decode(decoder);
@@ -406,7 +403,7 @@
var numbers = toNumbers(result);
decoder = new BinaryXMLDecoder(numbers);
- console.log('DECODED HEX CONTENT OBJECT \n'+numbers);
+ if(LOG>3)console.log('DECODED HEX CONTENT OBJECT \n'+numbers);
co = new ContentObject();
@@ -417,30 +414,7 @@
}
-//http://ejohn.org/blog/numbers-hex-and-colors/
-function toHex(arguments){
- //console.log(arguments);
- var ret = "";
- for ( var i = 0; i < arguments.length; i++ )
- ret += (arguments[i] < 16 ? "0" : "") + arguments[i].toString(16);
- return ret.toUpperCase();
-}
-function toString(arguments){
- //console.log(arguments);
- var ret = "";
- for ( var i = 0; i < arguments.length; i++ )
- ret += String.fromCharCode(arguments[i]);
- return ret;
-}
-
-function toNumbers( str ){
- var ret = [];
- str.replace(/(..)/g, function(str){
- ret.push( parseInt( str, 16 ) );
- });
- return ret;
-}
// Get something from the socket
function on_socket_get(message){}