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> |
| 19 | |
| 20 | #include "nlsr.h" |
| 21 | #include "nlsr_ndn.h" |
| 22 | #include "utility.h" |
| 23 | |
| 24 | enum ccn_upcall_res |
| 25 | incoming_interest(struct ccn_closure *selfp, |
| 26 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 27 | { |
| 28 | |
| 29 | switch (kind) { |
| 30 | case CCN_UPCALL_FINAL: |
| 31 | break; |
| 32 | case CCN_UPCALL_INTEREST: |
| 33 | // printing the name prefix for which it received interest |
| 34 | printf("Interest Received for name: "); |
| 35 | struct ccn_charbuf*c; |
| 36 | c=ccn_charbuf_create(); |
| 37 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 38 | //ccn_name_chop(c,NULL,-1); |
| 39 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 40 | ccn_charbuf_destroy(&c); |
| 41 | |
| 42 | //process_incoming_interest(selfp, info); |
| 43 | |
| 44 | /* |
| 45 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 46 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 47 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 48 | |
| 49 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name], |
| 50 | info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 51 | |
| 52 | sp.template_ccnb=ccn_charbuf_create(); |
| 53 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 54 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010); |
| 55 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 56 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 57 | |
| 58 | res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello")); |
| 59 | res=ccn_put(ospfndn->ccn,data->buf,data->length); |
| 60 | ccn_charbuf_destroy(&data); |
| 61 | |
| 62 | */ |
| 63 | break; |
| 64 | |
| 65 | default: |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | return CCN_UPCALL_RESULT_OK; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 74 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
| 75 | { |
| 76 | |
| 77 | |
| 78 | switch(kind) { |
| 79 | case CCN_UPCALL_FINAL: |
| 80 | break; |
| 81 | case CCN_UPCALL_CONTENT: |
| 82 | printf("Content Received for name: "); |
| 83 | struct ccn_charbuf*c; |
| 84 | c=ccn_charbuf_create(); |
| 85 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 86 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 87 | ccn_charbuf_destroy(&c); |
| 88 | |
| 89 | //process_incoming_content(selfp, info); |
| 90 | break; |
| 91 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
| 92 | /* printf("Interest timed out \n"); |
| 93 | |
| 94 | const unsigned char *comp_ptr; |
| 95 | size_t comp_size; |
| 96 | int res; |
| 97 | |
| 98 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,2,&comp_ptr, &comp_size); |
| 99 | |
| 100 | printf("Parsed Interest: %s size: %d Size of name prefix: %d\n",comp_ptr,(int)comp_size,(int)info->interest_comps->n); |
| 101 | */ |
| 102 | |
| 103 | //process_timed_out_interest(selfp,info); |
| 104 | break; |
| 105 | default: |
| 106 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
| 107 | return CCN_UPCALL_RESULT_ERR; |
| 108 | } |
| 109 | |
| 110 | return CCN_UPCALL_RESULT_OK; |
| 111 | } |
akmhoque | 61fe447 | 2012-08-10 10:13:34 -0500 | [diff] [blame] | 112 | |
| 113 | /* --- */ |