blob: cb9e8fc6306221dd398ecc1d9ac7d2803f0d039f [file] [log] [blame]
Meki Cherkaoui8f173612012-06-06 01:05:40 -07001
2
3var lwNDN = function lwNDN(host,port){
4 this.host = host;
5 this.port = port;
6};
7
8lwNDN.prototype.createRoute = function(host,port){
9 this.host=host;
10 this.port=port;
11}
12
13lwNDN.prototype.get = function(message){
14 if(this.host!=null && this.port!=null){
15 var output ='';
16 message = message.trim();
17 if(message==null || message =="" ){
18 console.log('INVALID INPUT TO GET');
19 return null;
20 }
21
22
23 //var array = ContentName.createNameArray(message);
24
25 int = new Interest(new ContentName(message));
26
27 int.InterestLifetime = 4200;
28
29 var hex = encodeToHexInterest(int);
30
31 //var result = get_java_socket_bridge().connectAndStart(ndnurl,ndnport,hex);
32
33 var result = get(this.host,this.port, hex);
34
35
36 if(LOG>0)console.log('BINARY RESPONSE IS ' +result);
37
38 if(result==null || result==undefined || result =="" ){
39 /*if(result[0] != '0'||result[1]!='4') {
40 if(LOG>2)console.log('INVALID ANSWER');
41 }*/
42 return null;
43 }
44
45 else{
46
47 co = decodeHexContentObject(result);
48
49 if(LOG>2) {
50 console.log('DECODED CONTENT OBJECT');
51 console.log(co);
52 }
53 return co;
54 }
55 }
56 else{
57
58 console.log('ERROR URL OR PORT NOT SET');
59
60 return null;
61
62 }
63
64
65}
66
67
68lwNDN.prototype.put = function(name,content){
69 if(this.host!=null && this.port!=null){
70
71
72 name = name.trim();
73
74 var fe = new ForwardingEntry('selfreg',new ContentName(name),null, null, 3,2147483647);
75
76 var bytes = encodeForwardingEntry(fe);
77
78
79 var si = new SignedInfo();
80 si.setFields();
81
82 var co = new ContentObject(new ContentName(),si,bytes,new Signature());
83 co.sign();
84
85 var coBinary = encodeToBinaryContentObject(co);
86
87 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');
88
89 var interestName = new ContentName(['ccnx',ccnxnodename,'prefixreg',coBinary]);
90
91 int = new Interest(interestName);
92 int.Scope = 1;
93
94 var hex = encodeToHexInterest(int);
95
96 console.log('GOING TO PUT INTEREST OBJECT');
97
98 console.log(hex);
99
100 var result = put(this.host,this.port, hex,name);
101
102 return result;
103
104 }
105 else{
106
107 console.log('ERROR URL OR PORT NOT SET');
108
109 return null;
110
111 }
112
113
114}