Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 1 | /*
|
| 2 | * @author: ucla-cs
|
| 3 | * This class represents Interest Objects
|
| 4 | */
|
| 5 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 6 | //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);
|
| 7 | 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';
|
| 8 |
|
Axel Colin de Verdiere | f049a76 | 2012-05-19 12:10:17 -0700 | [diff] [blame] | 9 | //var LOG = 5;
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 10 | var LOG = 5;
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 11 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 12 | // Global variables
|
| 13 | var java_socket_bridge_ready_flag = false;
|
| 14 |
|
| 15 | var ndnport =null;
|
| 16 | var ndnurl=null;
|
| 17 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 18 | var registeredPrefixes ={};
|
| 19 |
|
| 20 | String.prototype.trim = function() {
|
| 21 | return this.replace(/^\s+|\s+$/g, "");
|
| 22 | };
|
| 23 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 24 | // Applet reports it is ready to use
|
| 25 | function java_socket_bridge_ready(){
|
| 26 | java_socket_bridge_ready_flag = true;
|
| 27 | }
|
| 28 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 29 |
|
| 30 |
|
| 31 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 32 | //Sets the route to ccnx router
|
Axel Colin de Verdiere | e2991cd | 2012-05-18 16:49:27 -0700 | [diff] [blame] | 33 | /**
|
| 34 | * Setup the router to use
|
| 35 | * @url the url of the remote NDN router
|
| 36 | * @port the port of the remote NDN router
|
| 37 | */
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 38 | function createRoute(url, port){
|
| 39 | ndnport = port;
|
| 40 | ndnurl=url;
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 41 |
|
| 42 | console.log(new BinaryXMLDecoder());
|
| 43 |
|
| 44 | //SEND INTERST TO CCNX NODE
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 45 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 46 |
|
| 47 | //Now Start the receiving thread
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 48 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 49 | }
|
| 50 |
|
| 51 | // Connect to a given url and port
|
| 52 | //Error -1 No countent found
|
| 53 | //Error -2 Empty query
|
Axel Colin de Verdiere | f049a76 | 2012-05-19 12:10:17 -0700 | [diff] [blame] | 54 | /**
|
| 55 | * Sends an interest for the given prefix and returns the response (java_socket_bridge.js)
|
| 56 | * @message the prefix to query for
|
| 57 | * @return -1 if no content is found,-2 is the array is empty, the content otherwise
|
| 58 | */
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 59 | function queryPrefix(message){
|
| 60 | if(ndnport!=null && ndnurl!=null){
|
| 61 | var newMessage ='';
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 62 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 63 |
|
| 64 | message = message.trim();
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 | if(message==null || message =="" || message=="/"){
|
| 69 | return -2;
|
| 70 | }
|
| 71 |
|
| 72 | //message = decodeURIComponent(message);
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 73 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 74 | var array = createNameArray(message);
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 75 |
|
| 76 | //console.log('ARRAY IS '+ array);
|
| 77 |
|
| 78 | enc = new BinaryXMLEncoder();
|
| 79 |
|
| 80 | int = new Interest(new ContentName(array));
|
| 81 |
|
| 82 | int.encode(enc);
|
| 83 |
|
| 84 | var hex = toHex(enc.getReducedOstream());
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 | //console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 89 |
|
| 90 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 91 | var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
|
| 92 |
|
| 93 | console.log('BINARY RESPONSE IS ' +result);
|
| 94 |
|
| 95 |
|
| 96 | //result[0] and result[1] should be 0 and 4 if there is a content object found
|
| 97 | if(result==null || result==undefined || result =="" || result[0] != '0'||result[1]!='4'){
|
| 98 | return -1;
|
| 99 | }
|
| 100 |
|
| 101 | else{
|
| 102 |
|
| 103 | var numbers = toNumbers(result);
|
| 104 |
|
| 105 | console.log('HEX RESPONSE IS \n'+numbers);
|
| 106 | decoder = new BinaryXMLDecoder(numbers);
|
| 107 |
|
| 108 |
|
| 109 | co = new ContentObject();
|
| 110 |
|
| 111 | co.decode(decoder);
|
| 112 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 113 | if(LOG>2) console.log(co);
|
| 114 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 115 | return co;
|
| 116 |
|
| 117 |
|
| 118 | }
|
| 119 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 120 |
|
| 121 | }
|
| 122 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 123 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 124 | else{
|
| 125 |
|
| 126 | alert('ERROR URL OR PORT NOT SET');
|
| 127 |
|
| 128 | return -3;
|
| 129 |
|
| 130 | }
|
| 131 |
|
| 132 | }
|
| 133 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 134 | var registerStarted = false;
|
| 135 | function registerPrefix(name, content){
|
| 136 |
|
| 137 | registeredPrefixes[name] = content ;
|
| 138 |
|
| 139 | if(registerStarted == false){
|
| 140 | var result = get_java_socket_bridge().connectAndStartAndPublish();
|
| 141 |
|
| 142 | startRegisterPrefix();
|
| 143 |
|
| 144 | registerStarted = true;
|
| 145 | }
|
| 146 | sendForwardingEntry(10);
|
| 147 | }
|
| 148 |
|
| 149 |
|
| 150 | function unRegisterPrefix(name){
|
| 151 |
|
| 152 | delete registeredPrefixes[name];
|
| 153 |
|
| 154 | }
|
| 155 |
|
| 156 |
|
| 157 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 158 |
|
| 159 | function on_socket_received_interest(IP, port, interestBinary){
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 160 | console.log('WOOOO RECEIVED STUFF' );
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 161 | var interest = decodeHexInterest(interestBinary);
|
| 162 |
|
| 163 | console.log('WOOO received interest' + interest.Name.Components);
|
| 164 |
|
| 165 | var stringName = "";
|
| 166 |
|
| 167 | for(var i=0;i<interest.Name.Components.length;i++){
|
| 168 | stringName += "/"+ interest.Name.Components[i];
|
| 169 | }
|
| 170 |
|
| 171 | if(registeredPrefix[stringName]!=null){
|
| 172 | if(LOG>1)console.log("CANNOT FIND THE OBJECT OF NAME " + stringName );
|
| 173 | }
|
| 174 | else{
|
| 175 | var co = new ContentObject(interest.Name, null,registeredPrefix[stringName],null );
|
| 176 |
|
| 177 | var hex = encodeToHexContentObject(co);
|
| 178 |
|
| 179 | get_java_socket_bridge().sendContentObject(IP,port,hex);
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 180 |
|
| 181 |
|
| 182 | }
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 183 | }
|
| 184 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 185 |
|
| 186 |
|
| 187 |
|
| 188 | // Connect to a given url and port
|
| 189 | //Error -1 No countent found
|
| 190 | //Error -2 Empty query
|
| 191 | function startRegisterPrefix(){
|
| 192 | if(LOG>2) console.log('START REGISTER PREFIX');
|
| 193 |
|
| 194 | if(ndnport!=null && ndnurl!=null){
|
| 195 | var newMessage ='';
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 | name = name.trim();
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 | ///////////////////////
|
| 204 | var face = new FaceInstance('newface',null,null, 17, '127.0.0.1',9876,null,null,null);
|
| 205 |
|
| 206 | var encoder1 = new BinaryXMLEncoder();
|
| 207 |
|
| 208 | face.encode(encoder1);
|
| 209 |
|
| 210 | var faceInstanceBinary = encoder1.getReducedOstream();
|
| 211 |
|
| 212 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 213 | var si = new SignedInfo();
|
| 214 | si.setFields();
|
| 215 |
|
| 216 | var co = new ContentObject(new ContentName(),si,faceInstanceBinary,new Signature());
|
| 217 | co.sign();
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 218 |
|
| 219 | var encoder2 = new BinaryXMLEncoder();
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 220 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 221 | co.encode(encoder2);
|
| 222 |
|
| 223 | var coBinary = encoder2.getReducedOstream();
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 224 |
|
| 225 | //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'));
|
| 226 |
|
| 227 | //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);
|
| 228 | 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]);
|
| 229 | //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]);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 230 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 231 | //var interestName = new ContentName(['ccnx','1234','newface',coBinary]);
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 232 | //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 233 | int = new Interest(interestName,face);
|
| 234 |
|
| 235 | var hex = encodeToHexInterest(int);
|
| 236 | /////////////////
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 237 |
|
| 238 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 239 |
|
| 240 | if(LOG>4)console.log('Interst name of Conntection Message is '+ interestName);
|
| 241 |
|
| 242 |
|
| 243 | if(LOG>4) console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+hex);
|
| 244 | //console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);
|
| 245 |
|
| 246 | var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 247 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 248 |
|
| 249 | //TODO MOVE THIS
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 250 |
|
| 251 | //result[0] and result[1] should be 0 and 4 if there is a content object found
|
| 252 | if(result==null || result==undefined || result =="" || result[0] != '0'||result[1]!='4'){
|
| 253 | return -1;
|
| 254 | }
|
| 255 |
|
| 256 | if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);
|
| 257 |
|
| 258 | else{
|
| 259 |
|
| 260 | co = decodeHexContentObject(result);
|
| 261 |
|
| 262 | if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);
|
| 263 |
|
| 264 | return co;
|
| 265 | }
|
| 266 | }
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 267 | else{
|
| 268 |
|
| 269 | alert('ERROR URL OR PORT NOT SET');
|
| 270 |
|
| 271 | return -3;
|
| 272 |
|
| 273 | }
|
| 274 |
|
| 275 | }
|
| 276 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 277 |
|
| 278 | // Connect to a given url and port
|
| 279 | //Error -1 No countent found
|
| 280 | //Error -2 Empty query
|
| 281 | function sendForwardingEntry(faceID){
|
| 282 | if(LOG>2) console.log('START REGISTER PREFIX');
|
| 283 |
|
| 284 | if(ndnport!=null && ndnurl!=null){
|
| 285 | var newMessage ='';
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 | name = name.trim();
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 | ///////////////////////
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 294 | var face = new ForwardingEntry('prefixreg',new ContentName(['helloworld']),null, faceID, 1,null);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 295 |
|
| 296 | var encoder1 = new BinaryXMLEncoder();
|
| 297 |
|
| 298 | face.encode(encoder1);
|
| 299 |
|
| 300 | var faceInstanceBinary = encoder1.getReducedOstream();
|
| 301 |
|
| 302 |
|
| 303 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 304 | var si = new SignedInfo();
|
| 305 | si.setFields();
|
| 306 |
|
| 307 | var co = new ContentObject(new ContentName(),si,faceInstanceBinary,new Signature());
|
| 308 | co.sign();
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 309 |
|
| 310 | var encoder2 = new BinaryXMLEncoder();
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 311 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 312 | co.encode(encoder2);
|
| 313 |
|
| 314 | var coBinary = encoder2.getReducedOstream();
|
| 315 |
|
| 316 |
|
| 317 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 318 | 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]);
|
| 319 | //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'newface',coBinary]);
|
| 320 | //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]);
|
| 321 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 322 | //var interestName = new ContentName(['ccnx','1234','newface',coBinary]);
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 323 | //var interestName = new ContentName(['ccnx',co.SignedInfo.Publisher.PublisherPublicKeyDigest,'prefixreg',coBinary]);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 324 |
|
| 325 | int = new Interest(interestName,face);
|
| 326 |
|
| 327 | var hex = encodeToHexInterest(int);
|
| 328 | /////////////////
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 | if(LOG>4)console.log('Interst name of Conntection Message is '+ interestName);
|
| 333 |
|
| 334 |
|
| 335 | if(LOG>4) console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+hex);
|
| 336 | //console.log('Connecting and start '+ ndnurl +':'+ndnport+'-'+message);
|
| 337 |
|
| 338 | var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
|
| 339 |
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 340 | if(LOG>3)console.log('BINARY RESPONSE IS ' +result);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 341 |
|
| 342 |
|
| 343 | //result[0] and result[1] should be 0 and 4 if there is a content object found
|
| 344 | if(result==null || result==undefined || result =="" || result[0] != '0'||result[1]!='4'){
|
| 345 | return -1;
|
| 346 | }
|
| 347 |
|
| 348 | if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);
|
| 349 |
|
| 350 | else{
|
| 351 |
|
| 352 | co = decodeHexContentObject(result);
|
| 353 |
|
| 354 | if(LOG>4) console.log('RECEIVED THE FOLLOWING DATA: ' +co.Content);
|
| 355 |
|
| 356 | return co;
|
| 357 | }
|
| 358 | }
|
| 359 | else{
|
| 360 |
|
| 361 | alert('ERROR URL OR PORT NOT SET');
|
| 362 |
|
| 363 | return -3;
|
| 364 |
|
| 365 | }
|
| 366 |
|
| 367 | }
|
| 368 |
|
| 369 |
|
Axel Colin de Verdiere | e5e666f | 2012-05-22 23:32:00 -0700 | [diff] [blame^] | 370 | /**
|
| 371 | * Computes the size in bytes of the ContentObject once encoded
|
| 372 | * @param co the content object to encode
|
| 373 | * @returns the size in bytes of the encoded ContentObject
|
| 374 | */
|
| 375 | function getContentObjectSize(co){
|
| 376 | var enc = new BinaryXMLEncoder();
|
| 377 |
|
| 378 | co.encode(enc);
|
| 379 |
|
| 380 | return enc.getReducedOstream().length;
|
| 381 | }
|
| 382 |
|
| 383 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 384 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 385 |
|
| 386 | function encodeToHexInterest(int){
|
| 387 |
|
| 388 | var enc = new BinaryXMLEncoder();
|
| 389 |
|
| 390 | int.encode(enc);
|
| 391 |
|
| 392 | var hex = toHex(enc.getReducedOstream());
|
| 393 |
|
| 394 | return hex;
|
| 395 |
|
| 396 |
|
| 397 | }
|
| 398 |
|
| 399 |
|
| 400 | function encodeToHexContentObject(co){
|
| 401 | var enc = new BinaryXMLEncoder();
|
| 402 |
|
| 403 | co.encode(enc);
|
| 404 |
|
Axel Colin de Verdiere | e5e666f | 2012-05-22 23:32:00 -0700 | [diff] [blame^] | 405 | var reducedOstream = enc.getReducedOstream();
|
| 406 |
|
| 407 | if(LOG>3) console.log("In encodeToHexContentObject, reducedOstream: ", reducedOstream);
|
| 408 |
|
| 409 | var hex = toHex(reducedOstream);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 410 |
|
| 411 | return hex;
|
| 412 |
|
| 413 |
|
| 414 | }
|
| 415 |
|
| 416 | function decodeHexInterest(result){
|
| 417 | var numbers = toNumbers(result);
|
| 418 |
|
| 419 |
|
| 420 | decoder = new BinaryXMLDecoder(numbers);
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 421 | if(LOG>3)console.log('DECODED HEX INTERST \n'+numbers);
|
| 422 |
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 423 | i = new Interest();
|
| 424 |
|
| 425 | i.decode(decoder);
|
| 426 |
|
| 427 | return i;
|
| 428 |
|
| 429 | }
|
| 430 |
|
| 431 | function decodeHexContentObject(result){
|
| 432 | var numbers = toNumbers(result);
|
| 433 |
|
| 434 | decoder = new BinaryXMLDecoder(numbers);
|
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 435 | if(LOG>3)console.log('DECODED HEX CONTENT OBJECT \n'+numbers);
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 436 |
|
| 437 | co = new ContentObject();
|
| 438 |
|
| 439 | co.decode(decoder);
|
| 440 |
|
| 441 | return co;
|
| 442 |
|
| 443 | }
|
| 444 |
|
| 445 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 446 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 447 |
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 448 | // Get something from the socket
|
| 449 | function on_socket_get(message){}
|
| 450 |
|
| 451 | // Report an error
|
| 452 | function on_socket_error(message){
|
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 453 | alert('Received error message \n' +message);
|
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 454 | }
|
| 455 |
|
| 456 | // Get the applet object
|
| 457 | function get_java_socket_bridge(){
|
| 458 | return document.getElementById('JavaSocketBridge');
|
| 459 | } |