akmhoque | 03004e6 | 2012-09-06 01:12:28 -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_npl.h" |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 22 | #include "utility.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 23 | |
| 24 | |
| 25 | void |
| 26 | add_name_to_npl(struct name_prefix *np) |
| 27 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 28 | struct name_prefix_list_entry *npe=(struct name_prefix_list_entry *)malloc(sizeof(struct name_prefix_list_entry)); |
| 29 | //struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 30 | |
| 31 | struct hashtb_enumerator ee; |
| 32 | struct hashtb_enumerator *e = ⅇ |
| 33 | int res; |
| 34 | |
| 35 | hashtb_start(nlsr->npl, e); |
| 36 | res = hashtb_seek(e, np->name, np->length, 0); |
| 37 | |
| 38 | if(res == HT_NEW_ENTRY) |
| 39 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 40 | npe=e->data; |
| 41 | npe->np=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 42 | npe->np->length=np->length; |
| 43 | npe->np->name=(char *)malloc(np->length); |
| 44 | memcpy(npe->np->name,np->name,np->length); |
| 45 | npe->name_lsa_id=0; |
| 46 | //hnp = e->data; |
| 47 | //hnp->length=np->length; |
| 48 | //hnp->name=(char *)malloc(np->length); //free |
| 49 | //memcpy(hnp->name,np->name,np->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | hashtb_end(e); |
| 53 | |
| 54 | } |
| 55 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 56 | int |
| 57 | does_name_exist_in_npl(struct name_prefix *np) |
| 58 | { |
| 59 | int ret=0; |
| 60 | |
| 61 | //struct name_prefix_entry *npe; |
| 62 | |
| 63 | struct hashtb_enumerator ee; |
| 64 | struct hashtb_enumerator *e = ⅇ |
| 65 | int res; |
| 66 | |
| 67 | hashtb_start(nlsr->npl, e); |
| 68 | res = hashtb_seek(e, np->name, np->length, 0); |
| 69 | |
| 70 | if(res == HT_NEW_ENTRY) |
| 71 | { |
| 72 | hashtb_delete(e); |
| 73 | ret=0; |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | ret=1; |
| 78 | } |
| 79 | hashtb_end(e); |
| 80 | |
| 81 | return ret; |
| 82 | |
| 83 | } |
| 84 | |
| 85 | |
| 86 | long int |
| 87 | get_lsa_id_from_npl(struct name_prefix *np) |
| 88 | { |
| 89 | int ret=0; |
| 90 | |
| 91 | struct name_prefix_list_entry *npe; |
| 92 | |
| 93 | struct hashtb_enumerator ee; |
| 94 | struct hashtb_enumerator *e = ⅇ |
| 95 | int res; |
| 96 | |
| 97 | hashtb_start(nlsr->npl, e); |
| 98 | res = hashtb_seek(e, np->name, np->length, 0); |
| 99 | |
| 100 | if(res == HT_NEW_ENTRY) |
| 101 | { |
| 102 | hashtb_delete(e); |
| 103 | ret=0; |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | npe=e->data; |
| 108 | ret=npe->name_lsa_id; |
| 109 | } |
| 110 | hashtb_end(e); |
| 111 | |
| 112 | return ret; |
| 113 | |
| 114 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 115 | |
| 116 | void |
| 117 | print_name_prefix_from_npl(void) |
| 118 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 119 | if ( nlsr->debugging ) |
| 120 | printf("print_name_prefix_from_npl called \n"); |
| 121 | if ( nlsr->detailed_logging ) |
| 122 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_name_prefix_from_npl called\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 123 | int i, npl_element; |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 124 | //struct name_prefix *np; |
| 125 | struct name_prefix_list_entry *npe; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 126 | |
| 127 | struct hashtb_enumerator ee; |
| 128 | struct hashtb_enumerator *e = ⅇ |
| 129 | |
| 130 | hashtb_start(nlsr->npl, e); |
| 131 | npl_element=hashtb_n(nlsr->npl); |
| 132 | |
| 133 | for(i=0;i<npl_element;i++) |
| 134 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 135 | npe=e->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 136 | if ( nlsr->debugging ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 137 | printf("Name Prefix: %s and Length: %d and LSA Id: %ld\n",npe->np->name,npe->np->length,npe->name_lsa_id); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 138 | if ( nlsr->detailed_logging ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 139 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s and Length: %d \n",npe->np->name,npe->np->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 140 | hashtb_next(e); |
| 141 | } |
| 142 | |
| 143 | hashtb_end(e); |
| 144 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 145 | if ( nlsr->debugging ) |
| 146 | printf("\n"); |
| 147 | if ( nlsr->detailed_logging ) |
| 148 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | update_nlsa_id_for_name_in_npl(struct name_prefix *np, long int nlsa_id) |
| 153 | { |
| 154 | struct name_prefix_list_entry *npe; |
| 155 | struct hashtb_enumerator ee; |
| 156 | struct hashtb_enumerator *e = ⅇ |
| 157 | int res; |
| 158 | |
| 159 | hashtb_start(nlsr->npl, e); |
| 160 | res = hashtb_seek(e, np->name, np->length, 0); |
| 161 | |
| 162 | if(res == HT_OLD_ENTRY) |
| 163 | { |
| 164 | npe=e->data; |
| 165 | npe->name_lsa_id=nlsa_id; |
| 166 | } |
| 167 | else |
| 168 | { |
| 169 | hashtb_delete(e); |
| 170 | } |
| 171 | |
| 172 | hashtb_end(e); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 173 | } |
| 174 | |