akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 11 | |
| 12 | |
| 13 | #include <ccn/ccn.h> |
| 14 | #include <ccn/uri.h> |
| 15 | #include <ccn/keystore.h> |
| 16 | #include <ccn/signing.h> |
| 17 | #include <ccn/schedule.h> |
| 18 | #include <ccn/hashtb.h> |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 19 | #include <ccn/bloom.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 20 | |
| 21 | #include "nlsr.h" |
| 22 | #include "nlsr_ndn.h" |
| 23 | #include "utility.h" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 24 | #include "nlsr_adl.h" |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 25 | |
| 26 | enum ccn_upcall_res |
| 27 | incoming_interest(struct ccn_closure *selfp, |
| 28 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 29 | { |
| 30 | |
| 31 | switch (kind) { |
| 32 | case CCN_UPCALL_FINAL: |
| 33 | break; |
| 34 | case CCN_UPCALL_INTEREST: |
| 35 | // printing the name prefix for which it received interest |
| 36 | printf("Interest Received for name: "); |
| 37 | struct ccn_charbuf*c; |
| 38 | c=ccn_charbuf_create(); |
| 39 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 40 | //ccn_name_chop(c,NULL,-1); |
| 41 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 42 | ccn_charbuf_destroy(&c); |
| 43 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 44 | process_incoming_interest(selfp, info); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 48 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 49 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 50 | |
| 51 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name], |
| 52 | info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 53 | |
| 54 | sp.template_ccnb=ccn_charbuf_create(); |
| 55 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 56 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010); |
| 57 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 58 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 59 | |
| 60 | res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello")); |
| 61 | res=ccn_put(ospfndn->ccn,data->buf,data->length); |
| 62 | ccn_charbuf_destroy(&data); |
| 63 | |
| 64 | */ |
| 65 | break; |
| 66 | |
| 67 | default: |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | return CCN_UPCALL_RESULT_OK; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 76 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
| 77 | { |
| 78 | |
| 79 | |
| 80 | switch(kind) { |
| 81 | case CCN_UPCALL_FINAL: |
| 82 | break; |
| 83 | case CCN_UPCALL_CONTENT: |
| 84 | printf("Content Received for name: "); |
| 85 | struct ccn_charbuf*c; |
| 86 | c=ccn_charbuf_create(); |
| 87 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 88 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 89 | ccn_charbuf_destroy(&c); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 90 | |
| 91 | process_incoming_content(selfp, info); |
| 92 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 93 | break; |
| 94 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 95 | printf("Interest timed out \n"); |
| 96 | struct ccn_charbuf*ic; |
| 97 | ic=ccn_charbuf_create(); |
| 98 | ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 99 | printf("%s\n",ccn_charbuf_as_string(ic)); |
| 100 | ccn_charbuf_destroy(&ic); |
| 101 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 102 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 103 | break; |
| 104 | default: |
| 105 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
| 106 | return CCN_UPCALL_RESULT_ERR; |
| 107 | } |
| 108 | |
| 109 | return CCN_UPCALL_RESULT_OK; |
| 110 | } |
akmhoque | 61fe447 | 2012-08-10 10:13:34 -0500 | [diff] [blame] | 111 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 112 | |
| 113 | void |
| 114 | process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 115 | { |
| 116 | printf("process_incoming_content called \n"); |
| 117 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 118 | struct ccn_charbuf*c; |
| 119 | c=ccn_charbuf_create(); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 120 | //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 121 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 122 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 123 | ccn_charbuf_destroy(&c); |
| 124 | |
| 125 | const unsigned char *comp_ptr1; |
| 126 | size_t comp_size; |
| 127 | int res,i; |
| 128 | int nlsr_position=0; |
| 129 | int name_comps=(int)info->interest_comps->n; |
| 130 | |
| 131 | for(i=0;i<name_comps;i++) |
| 132 | { |
| 133 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 134 | if( res == 0) |
| 135 | { |
| 136 | nlsr_position=i; |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 142 | |
| 143 | |
| 144 | printf("Det= %s \n",comp_ptr1); |
| 145 | |
| 146 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 147 | { |
| 148 | process_incoming_content_lsdb(selfp,info); |
| 149 | } |
| 150 | |
| 151 | } |
| 152 | |
| 153 | |
| 154 | void |
| 155 | process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 156 | { |
| 157 | printf("process_incoming_content_lsdb called \n"); |
| 158 | |
| 159 | const unsigned char *content_data; |
| 160 | size_t length; |
| 161 | ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length); |
| 162 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 163 | |
| 164 | if ( !strcmp((char *)content_data,"NACK")) |
| 165 | { |
| 166 | printf("NACK received for LSDB request. Do nothing \n"); |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | // Do the LSDB processing here |
| 171 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 172 | const unsigned char *comp_ptr1; |
| 173 | size_t comp_size; |
| 174 | int res; |
| 175 | |
| 176 | res=ccn_name_comp_get(info->content_ccnb, info->content_comps,info->interest_comps->n-1,&comp_ptr1, &comp_size); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 177 | if ( res >=0) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 178 | printf("Received Database Version: %s \n",(char *)comp_ptr1); |
| 179 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 180 | } |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 181 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 182 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 183 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | |
| 187 | void |
| 188 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 189 | { |
| 190 | printf("process_incoming_timed_out_interest called \n"); |
| 191 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 192 | struct ccn_charbuf*c; |
| 193 | c=ccn_charbuf_create(); |
| 194 | //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 195 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 196 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 197 | ccn_charbuf_destroy(&c); |
| 198 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 199 | //const unsigned char *comp_ptr1; |
| 200 | //size_t comp_size; |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 201 | int res,i; |
| 202 | int nlsr_position=0; |
| 203 | int name_comps=(int)info->interest_comps->n; |
| 204 | |
| 205 | for(i=0;i<name_comps;i++) |
| 206 | { |
| 207 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 208 | if( res == 0) |
| 209 | { |
| 210 | nlsr_position=i; |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 215 | //res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 216 | |
| 217 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 218 | //printf("Det= %s \n",comp_ptr1); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 219 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 220 | //if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 221 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0) |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 222 | { |
| 223 | process_incoming_timed_out_interest_lsdb(selfp,info); |
| 224 | } |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 228 | void |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 229 | process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 230 | { |
| 231 | printf("process_incoming_timed_out_interest_lsdb called \n"); |
| 232 | |
| 233 | |
| 234 | int res,i; |
| 235 | int nlsr_position=0; |
| 236 | int name_comps=(int)info->interest_comps->n; |
| 237 | |
| 238 | //const unsigned char *comp_ptr1; |
| 239 | //size_t comp_size; |
| 240 | |
| 241 | for(i=0;i<name_comps;i++) |
| 242 | { |
| 243 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 244 | if( res == 0) |
| 245 | { |
| 246 | nlsr_position=i; |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 252 | struct ccn_charbuf *nbr; |
| 253 | nbr=ccn_charbuf_create(); |
| 254 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 255 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 256 | const unsigned char *comp_ptr1; |
| 257 | size_t comp_size; |
| 258 | for(i=0;i<nlsr_position;i++) |
| 259 | { |
| 260 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 261 | //printf("%s \n",comp_ptr1); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 262 | ccn_charbuf_append_string(nbr,"/"); |
| 263 | ccn_charbuf_append_string(nbr,(const char *)comp_ptr1); |
| 264 | } |
| 265 | |
akmhoque | 71b552d | 2012-08-21 11:44:34 -0400 | [diff] [blame] | 266 | ccn_charbuf_append_string(nbr,"\0"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 267 | printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr)); |
| 268 | |
| 269 | update_adjacent_status_to_adl(nbr,1); |
| 270 | |
| 271 | ccn_charbuf_destroy(&nbr); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 275 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 276 | { |
| 277 | printf("process_incoming_interest called \n"); |
| 278 | |
| 279 | |
| 280 | struct ccn_charbuf*c; |
| 281 | c=ccn_charbuf_create(); |
| 282 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 283 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 284 | ccn_charbuf_destroy(&c); |
| 285 | |
| 286 | const unsigned char *comp_ptr1; |
| 287 | size_t comp_size; |
| 288 | int res,i; |
| 289 | int nlsr_position=0; |
| 290 | int name_comps=(int)info->interest_comps->n; |
| 291 | |
| 292 | for(i=0;i<name_comps;i++) |
| 293 | { |
| 294 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 295 | if( res == 0) |
| 296 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 297 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 298 | break; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | e078986 | 2012-08-16 14:23:32 -0500 | [diff] [blame] | 303 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 304 | printf("Det= %s \n",comp_ptr1); |
| 305 | |
| 306 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 307 | { |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 308 | process_incoming_interest_lsdb(selfp,info); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 309 | } |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 310 | |
| 311 | |
| 312 | } |
| 313 | |
| 314 | |
| 315 | void |
| 316 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 317 | { |
| 318 | printf("process_incoming_interest_lsdb called \n"); |
| 319 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 320 | int l, res; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 321 | const unsigned char *exclbase; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 322 | size_t size; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 323 | struct ccn_buf_decoder decoder; |
| 324 | struct ccn_buf_decoder *d; |
| 325 | const unsigned char *comp; |
| 326 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 327 | |
| 328 | l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude]; |
| 329 | if (l > 0) |
| 330 | { |
| 331 | comp = NULL; |
| 332 | size = 0; |
| 333 | exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude]; |
| 334 | d = ccn_buf_decoder_start(&decoder, exclbase, l); |
| 335 | if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) |
| 336 | { |
| 337 | ccn_buf_advance(d); |
| 338 | if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) |
| 339 | ccn_buf_advance_past_element(d); |
| 340 | if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) |
| 341 | { |
| 342 | ccn_buf_advance(d); |
| 343 | ccn_buf_match_blob(d, &comp, &size); |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 344 | ccn_buf_check_close(d); |
| 345 | |
| 346 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 347 | } |
| 348 | ccn_buf_check_close(d); |
| 349 | } |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 350 | //if (d->decoder.state < 0) |
| 351 | //printf("Parse Failed\n"); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 352 | if (comp != NULL) |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 353 | printf("Number in Exclusion Filter is %s\n",comp); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 354 | |
| 355 | /* Now comp points to the start of your potential number, and size is its length */ |
| 356 | } |
| 357 | |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 358 | int excl_db_version=atoi((char *)comp); |
| 359 | int dbcmp=nlsr->lsdb->version-excl_db_version; |
| 360 | //int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16); |
| 361 | |
| 362 | |
akmhoque | 898d4aa | 2012-08-16 10:26:15 -0500 | [diff] [blame] | 363 | |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 364 | printf (" dbcmp = %d \n",dbcmp); |
akmhoque | 898d4aa | 2012-08-16 10:26:15 -0500 | [diff] [blame] | 365 | |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 366 | if(dbcmp > 0) |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 367 | { |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 368 | printf("Has Updated database (Older: %s New: %ld)\n",comp,nlsr->lsdb->version); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 369 | } |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 370 | else |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 371 | { |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 372 | printf("Data base is not updated than the older one (Older: %s New: %ld)\n",comp,nlsr->lsdb->version); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 373 | printf("Sending NACK Content back.....\n"); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 374 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 375 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 376 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 377 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 378 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 379 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 380 | //ccn_name_append_str(name,"0000000000000001"); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 381 | |
| 382 | sp.template_ccnb=ccn_charbuf_create(); |
| 383 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 384 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 385 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 386 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 387 | |
| 388 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 389 | if(res >= 0) |
| 390 | printf("Signing Content is successful \n"); |
| 391 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 392 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
akmhoque | bf11b1d | 2012-08-16 11:11:17 -0500 | [diff] [blame] | 393 | |
| 394 | if(res >= 0) |
| 395 | printf("Sending NACK Content is successful \n"); |
| 396 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 397 | ccn_charbuf_destroy(&data); |
| 398 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 399 | |
| 400 | } |
| 401 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | int |
| 405 | send_lsdb_interest(struct ccn_schedule *sched, void *clienth, |
| 406 | struct ccn_scheduled_event *ev, int flags) |
| 407 | { |
| 408 | |
| 409 | struct ccn_charbuf *name; |
| 410 | long int rnum; |
| 411 | char rnumstr[20]; |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 412 | char lsdb_str[5]; |
| 413 | char nlsr_str[5]; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 414 | |
| 415 | int res,i; |
| 416 | int adl_element; |
| 417 | |
| 418 | rnum=random(); |
| 419 | memset(&rnumstr,0,20); |
| 420 | sprintf(rnumstr,"%ld",rnum); |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 421 | memset(&nlsr_str,0,5); |
| 422 | sprintf(nlsr_str,"nlsr"); |
| 423 | memset(&lsdb_str,0,5); |
| 424 | sprintf(lsdb_str,"lsdb"); |
| 425 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 426 | |
| 427 | struct ndn_neighbor *nbr; |
| 428 | |
| 429 | struct hashtb_enumerator ee; |
| 430 | struct hashtb_enumerator *e = ⅇ |
| 431 | |
| 432 | hashtb_start(nlsr->adl, e); |
| 433 | adl_element=hashtb_n(nlsr->adl); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 434 | //int mynumber=15; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 435 | |
| 436 | for(i=0;i<adl_element;i++) |
| 437 | { |
| 438 | nbr=e->data; |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame^] | 439 | printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,lsdb_str); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 440 | name=ccn_charbuf_create(); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame^] | 441 | res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor)); |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 442 | ccn_name_append_str(name,nlsr_str); |
| 443 | ccn_name_append_str(name,lsdb_str); |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 444 | //ccn_name_append_str(name,rnumstr); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 445 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 446 | /* adding Exclusion filter */ |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 447 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 448 | struct ccn_charbuf *templ; |
| 449 | templ = ccn_charbuf_create(); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 450 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 451 | struct ccn_charbuf *c; |
| 452 | c = ccn_charbuf_create(); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 453 | |
| 454 | |
| 455 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 456 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 457 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 458 | ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 459 | ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 460 | ccn_charbuf_reset(c); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 461 | //ccn_charbuf_putf(c, "%u", (unsigned)mynumber); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame^] | 462 | //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version); |
| 463 | ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 464 | ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 465 | ccn_charbuf_append_closer(templ); /* </Exclude> */ |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 466 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 467 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 468 | |
| 469 | /* Adding Exclusion filter done */ |
| 470 | |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 471 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 472 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 473 | if ( res >= 0 ) |
| 474 | printf("Interest sending Successfull .... \n"); |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 475 | ccn_charbuf_destroy(&c); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 476 | ccn_charbuf_destroy(&templ); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 477 | ccn_charbuf_destroy(&name); |
| 478 | |
akmhoque | 1d7343f | 2012-08-21 10:46:35 -0400 | [diff] [blame] | 479 | hashtb_next(e); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | hashtb_end(e); |
| 483 | |
akmhoque | bf11b1d | 2012-08-16 11:11:17 -0500 | [diff] [blame] | 484 | nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 485 | |
| 486 | return 0; |
| 487 | |
| 488 | } |
| 489 | |