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