/* | |
* @author: ucla-cs | |
* This class represents Interest Objects | |
*/ | |
//var ccnxnodename = 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 LOG = 0; | |
var java_socket_bridge_ready_flag = false; | |
var ndnport =null; | |
var ndnurl=null; | |
var registeredPrefixes ={}; | |
/** | |
* Add a trim funnction for Strings | |
*/ | |
String.prototype.trim = function() { | |
return this.replace(/^\s+|\s+$/g, ""); | |
}; | |
// Applet reports it is ready to use | |
function java_socket_bridge_ready(){ | |
console.log('APPLET LOADED'); | |
java_socket_bridge_ready_flag = true; | |
} | |
// Send Test Interest | |
function get(host,port,data){ | |
if(java_socket_bridge_ready_flag){ | |
return get_java_socket_bridge().get(host,port,data,1000); | |
} | |
else{ | |
on_socket_error("Java Socket Bridge send Interest until the applet has loaded"); | |
} | |
} | |
// Send Test Interest | |
function put(host,port,data,name,toReturn){ | |
if(java_socket_bridge_ready_flag){ | |
return get_java_socket_bridge().put(host,port,data,name,toReturn); | |
} | |
else{ | |
on_socket_error("Java Socket Bridge send Interest until the applet has loaded"); | |
} | |
} | |
function on_socket_received_interest(hex,name){ | |
if(LOG>3)console.log('received interest from host'+ host +':'+port+' with name '+name); | |
if(LOG>3)console.log('DATA '); | |
if(LOG>3)console.log(hex); | |
interest = decodeHexInterest(hex); | |
console.log('SUCCESSFULLY PARSED INTEREST'); | |
console.log('CREATING ANSWER'); | |
var si = new SignedInfo(); | |
si.setFields(); | |
var answer = toNumbersFromString('WORLD'); | |
var co = new ContentObject(new Name(name),si,answer,new Signature()); | |
co.sign(); | |
var outputHex = encodeToHexContentObject(co); | |
console.log('SENDING ANSWER'); | |
return get_java_socket_bridge().putAnswer(outputHex,name); | |
} | |
// Get something from the socket | |
function on_socket_get(message){} | |
// Report an error | |
function on_socket_error(message){ | |
alert('Received error message \n' +message); | |
} | |
// Get the applet object | |
function get_java_socket_bridge(){ | |
return document.getElementById('JavaSocketBridge'); | |
} |