akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [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 <sys/stat.h> |
| 8 | #include <assert.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <signal.h> |
| 11 | #include <sys/socket.h> |
| 12 | #include <sys/un.h> |
| 13 | #include <fcntl.h> |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <netinet/in.h> |
| 16 | #include <netdb.h> |
| 17 | #include <arpa/inet.h> |
| 18 | |
| 19 | #include <ccn/ccn.h> |
| 20 | #include <ccn/uri.h> |
| 21 | #include <ccn/keystore.h> |
| 22 | #include <ccn/signing.h> |
| 23 | #include <ccn/schedule.h> |
| 24 | #include <ccn/hashtb.h> |
| 25 | #include <ccn/sync.h> |
| 26 | #include <ccn/seqwriter.h> |
| 27 | |
| 28 | #include "nlsr.h" |
| 29 | #include "nlsr_sync.h" |
| 30 | #include "nlsr_lsdb.h" |
| 31 | #include "utility.h" |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 32 | #include "nlsr_km.h" |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 33 | #include "nlsr_km_util.h" |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 34 | |
| 35 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 36 | char * |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 37 | hex_string(unsigned char *s, size_t l) |
| 38 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 39 | const char *hex_digits = "0123456789abcdef"; |
| 40 | char *r; |
| 41 | int i; |
| 42 | r = calloc(1, 1 + 2 * l); |
| 43 | for (i = 0; i < l; i++) { |
| 44 | r[2*i] = hex_digits[(s[i]>>4) & 0xf]; |
| 45 | r[1+2*i] = hex_digits[s[i] & 0xf]; |
| 46 | } |
| 47 | return(r); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 48 | } |
| 49 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 50 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 51 | sync_cb(struct ccns_name_closure *nc, |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 52 | struct ccn_charbuf *lhash, |
| 53 | struct ccn_charbuf *rhash, |
| 54 | struct ccn_charbuf *name) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 55 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 56 | int res; |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 57 | struct ccn_charbuf *content_name; |
| 58 | struct ccn_indexbuf *content_comps; |
| 59 | struct ccn_indexbuf *name_comps; |
| 60 | |
| 61 | content_comps = ccn_indexbuf_create(); |
| 62 | res = ccn_name_split(name, content_comps); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 63 | if ( res < 0 ) |
| 64 | return 0; |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 65 | |
| 66 | if (content_comps->n < 2) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 67 | return 0; |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 68 | |
| 69 | content_name = ccn_charbuf_create(); |
| 70 | ccn_name_init(content_name); |
| 71 | |
| 72 | res = ccn_name_append_components( content_name, name->buf, |
| 73 | content_comps->buf[0], content_comps->buf[content_comps->n - 1]); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 74 | |
| 75 | if ( res < 0) |
| 76 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 77 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 78 | // for debugging |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 79 | struct ccn_charbuf *temp=ccn_charbuf_create(); |
| 80 | ccn_uri_append(temp, content_name->buf, content_name->length, 0); |
| 81 | if ( nlsr->debugging ) |
| 82 | printf("Name before chopping: %s \n",ccn_charbuf_as_string(temp)); |
| 83 | ccn_charbuf_destroy(&temp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 84 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 85 | name_comps = ccn_indexbuf_create(); |
| 86 | res=ccn_name_split (content_name, name_comps); |
| 87 | if (res < 0) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 88 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 89 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 90 | if ( nlsr->debugging ) |
| 91 | { |
| 92 | printf("Number of components in name = %d \n",res); |
| 93 | printf("Number of components in name as indexbuf->n = %d \n", |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 94 | (int)name_comps->n); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 95 | } |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 96 | |
| 97 | ccn_name_chop(content_name, name_comps, -3); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 98 | if ( nlsr->debugging ) |
| 99 | printf("Number of components in name as indexbuf->n after chopping= %d \n" |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 100 | , (int)name_comps->n); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 101 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 102 | //for debugging |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 103 | struct ccn_charbuf *temp1=ccn_charbuf_create(); |
| 104 | ccn_uri_append(temp1, content_name->buf, content_name->length, 0); |
| 105 | if ( nlsr->debugging ) |
| 106 | printf("Name after chopping: %s \n",ccn_charbuf_as_string(temp1)); |
| 107 | ccn_charbuf_destroy(&temp1); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 108 | |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 109 | //main method that processes contents from the sync |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 110 | process_content_from_sync(content_name, name_comps); |
| 111 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 112 | ccn_charbuf_destroy(&content_name); |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 113 | ccn_indexbuf_destroy(&content_comps); |
| 114 | ccn_indexbuf_destroy(&name_comps); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 115 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 116 | return(0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | |
akmhoque | ccb33e9 | 2013-02-20 11:44:28 -0600 | [diff] [blame] | 120 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 121 | void |
akmhoque | ccb33e9 | 2013-02-20 11:44:28 -0600 | [diff] [blame] | 122 | get_name_part(struct name_prefix *name_part,struct ccn_charbuf * interest_ccnb, |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 123 | struct ccn_indexbuf *interest_comps, int offset) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 124 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 125 | int lsa_position=0; |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 126 | |
akmhoque | 0b60ba9 | 2013-02-25 17:55:35 -0600 | [diff] [blame] | 127 | struct ccn_indexbuf *components=ccn_indexbuf_create(); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 128 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 129 | ccn_name_from_uri(name,nlsr->slice_prefix); |
| 130 | ccn_name_split (name, components); |
| 131 | lsa_position=components->n-2; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 132 | ccn_charbuf_destroy(&name); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 133 | |
akmhoque | f677361 | 2013-02-23 09:53:00 -0600 | [diff] [blame] | 134 | struct ccn_charbuf *temp=ccn_charbuf_create(); |
| 135 | ccn_name_init(temp); |
| 136 | ccn_name_append_components( temp, interest_ccnb->buf, |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 137 | interest_comps->buf[lsa_position+1], |
| 138 | interest_comps->buf[interest_comps->n - 1]); |
akmhoque | f677361 | 2013-02-23 09:53:00 -0600 | [diff] [blame] | 139 | |
| 140 | struct ccn_charbuf *temp1=ccn_charbuf_create(); |
| 141 | ccn_uri_append(temp1, temp->buf, temp->length, 0); |
| 142 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 143 | name_part->name=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1, |
| 144 | sizeof(char)); |
| 145 | memcpy(name_part->name,ccn_charbuf_as_string(temp1), |
| 146 | strlen(ccn_charbuf_as_string(temp1))); |
akmhoque | f677361 | 2013-02-23 09:53:00 -0600 | [diff] [blame] | 147 | name_part->name[strlen(ccn_charbuf_as_string(temp1))]='\0'; |
| 148 | name_part->length=strlen(ccn_charbuf_as_string(temp1))+1; |
| 149 | |
| 150 | ccn_charbuf_destroy(&temp1); |
| 151 | ccn_charbuf_destroy(&temp); |
akmhoque | 0b60ba9 | 2013-02-25 17:55:35 -0600 | [diff] [blame] | 152 | ccn_indexbuf_destroy(&components); |
akmhoque | f677361 | 2013-02-23 09:53:00 -0600 | [diff] [blame] | 153 | |
| 154 | if ( nlsr->debugging ) |
| 155 | printf("Name Part: %s \n",name_part->name); |
| 156 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 157 | } |
| 158 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 159 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 160 | |
| 161 | |
| 162 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 163 | int |
| 164 | get_content_by_content_name(char *content_name, unsigned char **content_data, |
| 165 | char *orig_router) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 166 | { |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 167 | |
| 168 | int ret=-1; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 169 | struct ccn_charbuf *name = NULL; |
| 170 | struct ccn_charbuf *templ = NULL; |
| 171 | struct ccn_charbuf *resultbuf = NULL; |
| 172 | struct ccn_parsed_ContentObject pcobuf = { 0 }; |
| 173 | int res; |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 174 | int allow_stale = 1; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 175 | int content_only = 1; |
| 176 | int scope = -1; |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 177 | const unsigned char *ptr,*ptr_in; |
| 178 | size_t length,length_in; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 179 | int resolve_version = CCN_V_HIGHEST; |
| 180 | int timeout_ms = 3000; |
| 181 | const unsigned lifetime_default = CCN_INTEREST_LIFETIME_SEC << 12; |
| 182 | unsigned lifetime_l12 = lifetime_default; |
| 183 | int get_flags = 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 184 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 185 | name = ccn_charbuf_create(); |
| 186 | res = ccn_name_from_uri(name,content_name); |
| 187 | if (res < 0) { |
| 188 | fprintf(stderr, "Bad ccn URI: %s\n", content_name); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 189 | ccn_charbuf_destroy(&name); |
| 190 | return ret; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 191 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 192 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 193 | if (allow_stale || lifetime_l12 != lifetime_default || scope != -1) { |
| 194 | templ = ccn_charbuf_create(); |
| 195 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 196 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 197 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 198 | if (allow_stale) { |
| 199 | ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG); |
| 200 | ccnb_append_number(templ, |
| 201 | CCN_AOK_DEFAULT | CCN_AOK_STALE); |
| 202 | ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */ |
| 203 | } |
| 204 | if (scope != -1) { |
| 205 | ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 206 | } |
| 207 | if (lifetime_l12 != lifetime_default) { |
| 208 | /* |
| 209 | * Choose the interest lifetime so there are at least 3 |
| 210 | * expressions (in the unsatisfied case). |
| 211 | */ |
| 212 | unsigned char buf[3] = { 0 }; |
| 213 | int i; |
| 214 | for (i = sizeof(buf) - 1; i >= 0; i--, lifetime_l12 >>= 8) |
| 215 | buf[i] = lifetime_l12 & 0xff; |
| 216 | ccnb_append_tagged_blob(templ, CCN_DTAG_InterestLifetime, buf, |
| 217 | sizeof(buf)); |
| 218 | } |
| 219 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 220 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 221 | resultbuf = ccn_charbuf_create(); |
| 222 | if (resolve_version != 0) { |
| 223 | res = ccn_resolve_version(nlsr->ccn, name, resolve_version, 500); |
| 224 | if (res >= 0) { |
| 225 | ccn_uri_append(resultbuf, name->buf, name->length, 1); |
| 226 | resultbuf->length = 0; |
| 227 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 228 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 229 | res = ccn_get(nlsr->ccn, name, templ, timeout_ms, resultbuf, &pcobuf, NULL, |
| 230 | get_flags); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 231 | if (res >= 0) { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 232 | ptr = resultbuf->buf; |
| 233 | length = resultbuf->length; |
| 234 | if (content_only){ |
| 235 | ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 236 | struct ccn_parsed_ContentObject pcobuf1 = { 0 }; |
| 237 | int chk_cont=ccn_parse_ContentObject(ptr,length,&pcobuf1,NULL); |
| 238 | printf("Content Parsing result: %d\n",chk_cont); |
| 239 | if ( contain_key_name(ptr, &pcobuf1) == 1){ |
| 240 | struct ccn_charbuf *key_name=get_key_name(ptr, &pcobuf1); |
| 241 | struct ccn_charbuf *orig_router_kn=ccn_charbuf_create(); |
| 242 | res=get_orig_router_from_key_name(orig_router_kn,key_name); |
| 243 | if( res == 0){ |
| 244 | struct ccn_charbuf *rtr_uri = ccn_charbuf_create(); |
| 245 | ccn_uri_append(rtr_uri, orig_router_kn->buf, |
| 246 | orig_router_kn->length, 0); |
| 247 | printf("Orig Router from Key name: %s\n", |
| 248 | ccn_charbuf_as_string(rtr_uri)); |
| 249 | |
| 250 | if( strcmp(orig_router,ccn_charbuf_as_string(rtr_uri)) == 0){ |
| 251 | |
| 252 | int res_verify=verify_key(ptr,pcobuf1.offset[CCN_PCO_E], |
| 253 | &pcobuf1); |
| 254 | |
| 255 | if ( res_verify != 0 ){ |
| 256 | printf("Error in verfiying keys !! :( \n"); |
| 257 | } |
| 258 | else{ |
| 259 | printf("Key verification is successful :)\n"); |
| 260 | ptr_in=ptr; |
| 261 | length_in=length; |
| 262 | ccn_content_get_value(ptr_in, length_in, &pcobuf1, |
| 263 | &ptr_in, &length_in); |
| 264 | *content_data = (unsigned char *) calloc(length_in, |
| 265 | sizeof(char *)); |
| 266 | memcpy (*content_data, ptr_in, length_in); |
| 267 | ret=0; |
| 268 | } |
| 269 | } |
| 270 | ccn_charbuf_destroy(&rtr_uri); |
| 271 | } |
| 272 | ccn_charbuf_destroy(&key_name); |
| 273 | ccn_charbuf_destroy(&orig_router_kn); |
| 274 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 275 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 276 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 277 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 278 | ccn_charbuf_destroy(&resultbuf); |
| 279 | ccn_charbuf_destroy(&templ); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 280 | ccn_charbuf_destroy(&name); |
| 281 | |
| 282 | return ret; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 283 | } |
| 284 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 285 | void |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 286 | process_incoming_sync_content_lsa( unsigned char *content_data) |
| 287 | { |
| 288 | |
| 289 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 290 | if ( nlsr->debugging ) |
| 291 | printf("process_incoming_sync_content_lsa called \n"); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 292 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 293 | char *sep="|"; |
| 294 | char *rem; |
| 295 | char *orig_router; |
| 296 | char *orl; |
| 297 | int orig_router_length; |
| 298 | char *lst; |
| 299 | int ls_type; |
| 300 | char *lsid; |
| 301 | long int ls_id; |
| 302 | char *isvld; |
| 303 | int isValid; |
| 304 | char *num_link; |
| 305 | int no_link; |
| 306 | char *np; |
| 307 | char *np_length; |
| 308 | int name_length; |
| 309 | char *data; |
| 310 | char *orig_time; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 311 | |
| 312 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 313 | if ( nlsr->debugging ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 314 | printf("LSA Data \n"); |
| 315 | |
| 316 | if( strlen((char *)content_data ) > 0 ) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 317 | { |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 318 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 319 | orig_router=strtok_r((char *)content_data,sep,&rem); |
| 320 | orl=strtok_r(NULL,sep,&rem); |
| 321 | orig_router_length=atoi(orl); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 322 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 323 | if ( nlsr->debugging ) |
| 324 | { |
| 325 | printf(" Orig Router Name : %s\n",orig_router); |
| 326 | printf(" Orig Router Length: %d\n",orig_router_length); |
| 327 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 328 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 329 | lst=strtok_r(NULL,sep,&rem); |
| 330 | ls_type=atoi(lst); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 331 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 332 | if ( nlsr->debugging ) |
| 333 | printf(" LS Type : %d\n",ls_type); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 334 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 335 | if ( ls_type == LS_TYPE_NAME ) |
| 336 | { |
| 337 | lsid=strtok_r(NULL,sep,&rem); |
| 338 | ls_id=atoi(lsid); |
| 339 | orig_time=strtok_r(NULL,sep,&rem); |
| 340 | isvld=strtok_r(NULL,sep,&rem); |
| 341 | isValid=atoi(isvld); |
| 342 | np=strtok_r(NULL,sep,&rem); |
| 343 | np_length=strtok_r(NULL,sep,&rem); |
| 344 | name_length=atoi(np_length); |
| 345 | if ( nlsr->debugging ) |
| 346 | { |
| 347 | printf(" LS ID : %ld\n",ls_id); |
| 348 | printf(" isValid : %d\n",isValid); |
| 349 | printf(" Name Prefix : %s\n",np); |
| 350 | printf(" Orig Time : %s\n",orig_time); |
| 351 | printf(" Name Prefix length: %d\n",name_length); |
| 352 | } |
| 353 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 354 | build_and_install_others_name_lsa(orig_router,ls_type,ls_id, |
| 355 | orig_time,isValid,np); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 356 | |
| 357 | print_name_lsdb(); |
| 358 | |
| 359 | } |
| 360 | else if ( ls_type == LS_TYPE_ADJ ) |
| 361 | { |
| 362 | orig_time=strtok_r(NULL,sep,&rem); |
| 363 | num_link=strtok_r(NULL,sep,&rem); |
| 364 | no_link=atoi(num_link); |
| 365 | data=rem; |
| 366 | |
| 367 | if ( nlsr->debugging ) |
| 368 | { |
| 369 | printf(" Orig Time : %s\n",orig_time); |
| 370 | printf(" No Link : %d\n",no_link); |
| 371 | printf(" Data : %s\n",data); |
| 372 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 373 | build_and_install_others_adj_lsa(orig_router,ls_type,orig_time, |
| 374 | no_link,data); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 375 | } |
| 376 | else if ( ls_type == LS_TYPE_COR ) |
| 377 | { |
| 378 | orig_time=strtok_r(NULL,sep,&rem); |
| 379 | char *cor_r=strtok_r(NULL,sep,&rem); |
| 380 | char *cor_theta=strtok_r(NULL,sep,&rem); |
| 381 | |
| 382 | double r, theta; |
akmhoque | 8034d50 | 2013-02-24 11:53:24 -0600 | [diff] [blame] | 383 | r=strtod(cor_r,NULL); |
| 384 | theta=strtod(cor_theta,NULL); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 385 | |
| 386 | if ( nlsr->debugging ) |
| 387 | { |
| 388 | printf(" Orig Time : %s\n",orig_time); |
| 389 | printf(" Cor R : %f\n",r); |
| 390 | printf(" Cor Theta : %f\n",theta); |
| 391 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 392 | build_and_install_others_cor_lsa(orig_router,ls_type,orig_time, |
| 393 | (double)r, (double)theta); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 394 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 395 | |
| 396 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 397 | } |
| 398 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 399 | void |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 400 | process_content_from_sync (struct ccn_charbuf *content_name, |
| 401 | struct ccn_indexbuf *components) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 402 | { |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 403 | if (nlsr->debugging) |
| 404 | printf("process_content_from_sync called \n"); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 405 | size_t comp_size; |
| 406 | char *lst; |
| 407 | char *lsid; |
| 408 | const unsigned char *second_last_comp; |
| 409 | const unsigned char *third_last_comp; |
| 410 | const unsigned char *origtime; |
| 411 | char *sep="."; |
| 412 | char *rem; |
| 413 | char *second_comp_type; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 414 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 415 | int ls_type; |
| 416 | long int ls_id=0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 417 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 418 | unsigned char *content_data = NULL; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 419 | |
akmhoque | b31caa1 | 2013-02-22 08:42:09 -0600 | [diff] [blame] | 420 | char *time_stamp=get_current_timestamp_micro_v2(); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 421 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 422 | struct ccn_charbuf *uri = ccn_charbuf_create(); |
| 423 | ccn_uri_append(uri, content_name->buf, content_name->length, 0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 424 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 425 | struct name_prefix *orig_router=(struct name_prefix *) |
| 426 | calloc( 1, sizeof(struct name_prefix)); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 427 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 428 | ccn_name_comp_get( content_name->buf, components, |
| 429 | components->n-1-2, &second_last_comp, &comp_size); |
| 430 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 431 | if (nlsr->debugging) |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 432 | printf("2nd Last Component: %s \n", second_last_comp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 433 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 434 | second_comp_type=strtok_r((char *)second_last_comp, sep, &rem); |
| 435 | if (second_comp_type == NULL || rem == NULL) |
| 436 | { |
| 437 | printf ("Error: unable to tokenize the string: %s, calling exit()\n", |
| 438 | (char *)second_last_comp); |
| 439 | exit(0); |
| 440 | } |
| 441 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 442 | if ( strcmp( second_comp_type, "lsId" ) == 0 ) |
| 443 | { |
| 444 | lsid=rem; |
| 445 | ls_id=atoi(rem); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 446 | ccn_name_comp_get(content_name->buf, components,components->n-2-2, |
| 447 | &third_last_comp, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 448 | lst=strtok_r((char *)third_last_comp,sep,&rem); |
| 449 | lst=rem; |
| 450 | ls_type=atoi(lst); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 451 | ccn_name_comp_get(content_name->buf, components,components->n-2, |
| 452 | &origtime, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 453 | ccn_name_chop(content_name,components,-3); |
| 454 | get_name_part(orig_router,content_name,components,0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 455 | |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 456 | if ( nlsr->debugging ) |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 457 | printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n", |
| 458 | orig_router->name,ls_type,ls_id,origtime); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 459 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 460 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 461 | if ( nlsr->debugging ) |
| 462 | printf("LSA Life time: %d\n",lsa_life_time); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 463 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 464 | if ( (strcmp(orig_router->name,nlsr->router_name) == 0 && |
| 465 | lsa_life_time < nlsr->lsa_refresh_time) |
| 466 | || (strcmp(orig_router->name,nlsr->router_name) != 0 |
| 467 | && lsa_life_time < nlsr->router_dead_interval) ) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 468 | { |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 469 | int is_new_name_lsa=check_is_new_name_lsa(orig_router->name, |
| 470 | (char *)lst,(char *)lsid,(char *)origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 471 | if ( is_new_name_lsa == 1 ) |
| 472 | { |
| 473 | if ( nlsr->debugging ) |
| 474 | printf("New NAME LSA.....\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 475 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 476 | &content_data,orig_router->name); |
| 477 | if ( chk_con == 0 ){ |
| 478 | if ( nlsr->debugging ) |
| 479 | printf("Content Data: %s \n",content_data); |
| 480 | process_incoming_sync_content_lsa(content_data); |
| 481 | } |
| 482 | else{ |
| 483 | if ( nlsr->debugging ) |
| 484 | printf("Verification failed. No content given back\n"); |
| 485 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 486 | } |
| 487 | else |
| 488 | { |
| 489 | if ( nlsr->debugging ) |
| 490 | printf("Name LSA / Newer Name LSA already xists in LSDB\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 491 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri) |
| 492 | , &content_data,orig_router->name); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 493 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 494 | if ( chk_con == 0 ){ |
| 495 | if ( nlsr->debugging ) |
| 496 | printf("Content Data: %s \n",content_data); |
| 497 | process_incoming_sync_content_lsa(content_data); |
| 498 | } |
| 499 | else{ |
| 500 | if ( nlsr->debugging ) |
| 501 | printf("Verification failed. No content given back\n"); |
| 502 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 503 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 504 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 505 | else |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 506 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 507 | if ( nlsr->debugging ) |
| 508 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 509 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 510 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 511 | else |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 512 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 513 | ls_type=atoi(rem); |
| 514 | lst=rem; |
| 515 | if(ls_type == LS_TYPE_ADJ) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 516 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 517 | ccn_name_comp_get(content_name->buf, components,components->n-2, |
| 518 | &origtime, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 519 | ccn_name_chop(content_name,components,-2); |
| 520 | get_name_part(orig_router,content_name,components,0); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 521 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 522 | if ( nlsr->debugging ) |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 523 | printf("Orig Router: %s Ls Type: %d Orig Time: %s\n", |
| 524 | orig_router->name,ls_type,origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 525 | |
| 526 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 527 | if ( nlsr->debugging ) |
| 528 | printf("LSA Life time: %d\n",lsa_life_time); |
| 529 | |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 530 | if ( (strcmp(orig_router->name,nlsr->router_name) == 0 && |
| 531 | lsa_life_time < nlsr->lsa_refresh_time) || |
| 532 | (strcmp(orig_router->name,nlsr->router_name) != 0 && |
| 533 | lsa_life_time < nlsr->router_dead_interval) ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 534 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 535 | int is_new_adj_lsa = check_is_new_adj_lsa( orig_router->name, |
| 536 | (char *)lst, (char *)origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 537 | if ( is_new_adj_lsa == 1 ) |
| 538 | { |
| 539 | if ( nlsr->debugging ) |
| 540 | printf("New Adj LSA.....\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 541 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 542 | &content_data,orig_router->name); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 543 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 544 | if ( chk_con == 0 ){ |
| 545 | if ( nlsr->debugging ) |
| 546 | printf("Content Data: %s \n",content_data); |
| 547 | process_incoming_sync_content_lsa(content_data); |
| 548 | } |
| 549 | else{ |
| 550 | if ( nlsr->debugging ) |
| 551 | printf("Verification failed. No content given back\n"); |
| 552 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 553 | } |
| 554 | else |
| 555 | { |
| 556 | if ( nlsr->debugging ) |
| 557 | printf("Adj LSA / Newer Adj LSA already exists in LSDB\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 558 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 559 | &content_data,orig_router->name); |
| 560 | if ( chk_con == 0 ){ |
| 561 | if ( nlsr->debugging ) |
| 562 | printf("Content Data: %s \n",content_data); |
| 563 | process_incoming_sync_content_lsa(content_data); |
| 564 | } |
| 565 | else{ |
| 566 | if ( nlsr->debugging ) |
| 567 | printf("Verification failed. No content given back\n"); |
| 568 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | else |
| 572 | { |
| 573 | if ( nlsr->debugging ) |
| 574 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
| 575 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 576 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 577 | else if(ls_type == LS_TYPE_COR) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 578 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 579 | ccn_name_comp_get(content_name->buf, components, components->n-2, |
| 580 | &origtime, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 581 | ccn_name_chop(content_name,components,-2); |
| 582 | get_name_part(orig_router,content_name,components,0); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 583 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 584 | if ( nlsr->debugging ) |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 585 | printf("Orig Router: %s Ls Type: %d Orig Time: %s\n", |
| 586 | orig_router->name,ls_type,origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 587 | |
| 588 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 589 | if ( nlsr->debugging ) |
| 590 | printf("LSA Life time: %d\n",lsa_life_time); |
| 591 | |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 592 | if ( (strcmp(orig_router->name,nlsr->router_name) == 0 && |
| 593 | lsa_life_time < nlsr->lsa_refresh_time) || |
| 594 | (strcmp(orig_router->name,nlsr->router_name) != 0 && |
| 595 | lsa_life_time < nlsr->router_dead_interval) ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 596 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 597 | int is_new_cor_lsa=check_is_new_cor_lsa( orig_router->name, |
| 598 | (char *)lst,(char *) origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 599 | if ( is_new_cor_lsa == 1 ) |
| 600 | { |
| 601 | if ( nlsr->debugging ) |
| 602 | printf("New Cor LSA.....\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 603 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 604 | &content_data, |
| 605 | orig_router->name); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 606 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 607 | if ( chk_con == 0 ){ |
| 608 | if ( nlsr->debugging ) |
| 609 | printf("Content Data: %s \n",content_data); |
| 610 | process_incoming_sync_content_lsa(content_data); |
| 611 | } |
| 612 | else{ |
| 613 | if ( nlsr->debugging ) |
| 614 | printf("Verification failed. No content given back\n"); |
| 615 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 616 | } |
| 617 | else |
| 618 | { |
| 619 | if ( nlsr->debugging ) |
| 620 | printf("Cor LSA / Newer Cor LSA already exists in LSDB\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 621 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 622 | &content_data,orig_router->name); |
| 623 | if ( chk_con == 0 ){ |
| 624 | if ( nlsr->debugging ) |
| 625 | printf("Content Data: %s \n",content_data); |
| 626 | process_incoming_sync_content_lsa(content_data); |
| 627 | } |
| 628 | else{ |
| 629 | if ( nlsr->debugging ) |
| 630 | printf("Verification failed. No content given back\n"); |
| 631 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | else |
| 635 | { |
| 636 | if ( nlsr->debugging ) |
| 637 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
| 638 | } |
| 639 | |
| 640 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 641 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 642 | |
akmhoque | f677361 | 2013-02-23 09:53:00 -0600 | [diff] [blame] | 643 | if (orig_router->name) |
| 644 | free(orig_router->name); |
Obaid Amin | 0530089 | 2013-02-21 13:45:25 -0600 | [diff] [blame] | 645 | if (orig_router) |
| 646 | free(orig_router); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 647 | ccn_charbuf_destroy(&uri); |
| 648 | //01/31/2013 |
| 649 | free(time_stamp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 650 | } |
| 651 | |
Obaid Amin | 7793ba7 | 2013-02-22 00:43:58 -0600 | [diff] [blame] | 652 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 653 | sync_monitor(char *topo_prefix, char *slice_prefix) |
| 654 | { |
| 655 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 656 | struct ccn_charbuf *prefix = ccn_charbuf_create(); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 657 | struct ccn_charbuf *topo = ccn_charbuf_create(); |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 658 | |
| 659 | nlsr->closure=(struct ccns_name_closure *) |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 660 | calloc(1,sizeof(struct ccns_name_closure)); // leak |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 661 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 662 | nlsr->slice = ccns_slice_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 663 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 664 | ccn_charbuf_reset(prefix); |
| 665 | ccn_name_from_uri(prefix, slice_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 666 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 667 | ccn_charbuf_reset(topo); |
| 668 | ccn_name_from_uri(topo, topo_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 669 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 670 | ccns_slice_set_topo_prefix(nlsr->slice, topo, prefix); |
| 671 | nlsr->closure->callback = &sync_cb; |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame] | 672 | nlsr->ccns = ccns_open(nlsr->ccn, nlsr->slice, nlsr->closure, NULL, NULL); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 673 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 674 | ccn_charbuf_destroy(&prefix); |
| 675 | ccn_charbuf_destroy(&topo); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 676 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 677 | } |
| 678 | |
Obaid Amin | 7793ba7 | 2013-02-22 00:43:58 -0600 | [diff] [blame] | 679 | struct ccn_charbuf * |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 680 | make_template(int scope) |
| 681 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 682 | struct ccn_charbuf *templ = NULL; |
| 683 | templ = ccn_charbuf_create(); |
| 684 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 685 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 686 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 687 | if (0 <= scope && scope <= 2) |
| 688 | ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 689 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 690 | return(templ); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 691 | } |
| 692 | |
Obaid Amin | 7793ba7 | 2013-02-22 00:43:58 -0600 | [diff] [blame] | 693 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 694 | write_data_to_repo(char *data, char *name_prefix) |
| 695 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 696 | if ( nlsr->debugging ) |
| 697 | { |
| 698 | printf("write_data_to_repo called\n"); |
| 699 | printf("Content Name: %s \n",name_prefix); |
| 700 | printf("Content Data: %s \n",data); |
| 701 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 702 | |
Obaid Amin | f210a32 | 2013-02-22 02:04:52 -0600 | [diff] [blame] | 703 | struct ccn *temp_ccn; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 704 | temp_ccn=ccn_create(); |
| 705 | int ccn_fd=ccn_connect(temp_ccn, NULL); |
| 706 | if(ccn_fd == -1) |
| 707 | { |
| 708 | fprintf(stderr,"Could not connect to ccnd for Data Writing\n"); |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 709 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
| 710 | "Could not connect to ccnd for Data Writing\n"); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 711 | return -1; |
| 712 | } |
Obaid Amin | f210a32 | 2013-02-22 02:04:52 -0600 | [diff] [blame] | 713 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 714 | struct ccn_charbuf *name = NULL; |
| 715 | struct ccn_seqwriter *w = NULL; |
| 716 | int blocksize = 4096; |
| 717 | int freshness = -1; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 718 | int scope = 1; |
| 719 | int res; |
| 720 | size_t blockread; |
| 721 | struct ccn_charbuf *templ; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 722 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 723 | name = ccn_charbuf_create(); |
| 724 | res = ccn_name_from_uri(name, name_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 725 | if (res < 0) { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 726 | fprintf(stderr, "bad CCN URI: %s\n",name_prefix); |
| 727 | return -1; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 728 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 729 | |
Obaid Amin | f210a32 | 2013-02-22 02:04:52 -0600 | [diff] [blame] | 730 | w = ccn_seqw_create(temp_ccn, name); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 731 | if (w == NULL) { |
| 732 | fprintf(stderr, "ccn_seqw_create failed\n"); |
| 733 | return -1; |
| 734 | } |
| 735 | ccn_seqw_set_block_limits(w, blocksize, blocksize); |
| 736 | if (freshness > -1) |
| 737 | ccn_seqw_set_freshness(w, freshness); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 738 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 739 | struct ccn_charbuf *name_v = ccn_charbuf_create(); |
| 740 | ccn_seqw_get_name(w, name_v); |
| 741 | ccn_name_from_uri(name_v, "%C1.R.sw"); |
| 742 | ccn_name_append_nonce(name_v); |
| 743 | templ = make_template(scope); |
| 744 | res = ccn_get(temp_ccn, name_v, templ, 60000, NULL, NULL, NULL, 0); |
| 745 | ccn_charbuf_destroy(&templ); |
| 746 | ccn_charbuf_destroy(&name_v); |
| 747 | if (res < 0) { |
| 748 | fprintf(stderr, "No response from repository\n"); |
| 749 | return -1; |
| 750 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 751 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 752 | struct ccn_charbuf *resultbuf=ccn_charbuf_create(); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 753 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 754 | sign_content_with_user_defined_keystore(name, |
| 755 | resultbuf, |
| 756 | data, |
| 757 | strlen(data), |
| 758 | nlsr->keystore_path, |
| 759 | nlsr->keystore_passphrase, |
| 760 | nlsr->root_key_prefix, |
| 761 | nlsr->site_name, |
| 762 | nlsr->router_name); |
| 763 | |
| 764 | |
| 765 | //blockread = 0; |
| 766 | //blockread=strlen(data)+1; |
| 767 | blockread=resultbuf->length; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 768 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 769 | if (blockread > 0) { |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 770 | //res = ccn_seqw_write(w, data, blockread); |
| 771 | res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 772 | while (res == -1) { |
akmhoque | 8034d50 | 2013-02-24 11:53:24 -0600 | [diff] [blame] | 773 | ccn_run(temp_ccn,100); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 774 | //res = ccn_seqw_write(w, data, blockread); |
| 775 | res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
akmhoque | 8034d50 | 2013-02-24 11:53:24 -0600 | [diff] [blame] | 779 | ccn_seqw_close(w); |
| 780 | ccn_run(temp_ccn, 100); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 781 | ccn_charbuf_destroy(&name); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 782 | ccn_destroy(&temp_ccn); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 783 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 784 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 785 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 786 | int |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 787 | create_sync_slice(char *topo_prefix, char *slice_prefix) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 788 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 789 | int res; |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame^] | 790 | struct ccn *handle; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 791 | struct ccns_slice *slice; |
| 792 | struct ccn_charbuf *prefix = ccn_charbuf_create(); |
| 793 | struct ccn_charbuf *topo = ccn_charbuf_create(); |
| 794 | struct ccn_charbuf *clause = ccn_charbuf_create(); |
| 795 | struct ccn_charbuf *slice_name = ccn_charbuf_create(); |
| 796 | struct ccn_charbuf *slice_uri = ccn_charbuf_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 797 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 798 | if (prefix == NULL || topo == NULL || clause == NULL || |
| 799 | slice_name == NULL || slice_uri == NULL) { |
| 800 | fprintf(stderr, "Unable to allocate required memory.\n"); |
| 801 | return -1; |
| 802 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 803 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 804 | handle = ccn_create(); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 805 | res = ccn_connect(handle, NULL); |
| 806 | if (0 > res) { |
| 807 | fprintf(stderr, "Unable to connect to ccnd.\n"); |
| 808 | return -1; |
| 809 | } |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 810 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 811 | slice = ccns_slice_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 812 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 813 | ccn_charbuf_reset(topo); |
| 814 | ccn_name_from_uri(topo, topo_prefix); |
| 815 | ccn_charbuf_reset(prefix); |
| 816 | ccn_name_from_uri(prefix,slice_prefix ); |
| 817 | ccns_slice_set_topo_prefix(slice, topo, prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 818 | |
| 819 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 820 | res = ccns_write_slice(handle, slice, slice_name); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 821 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 822 | //01/31/2013 |
| 823 | ccns_slice_destroy(&slice); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 824 | ccn_destroy(&handle); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 825 | ccn_charbuf_destroy(&prefix); |
| 826 | ccn_charbuf_destroy(&topo); |
| 827 | ccn_charbuf_destroy(&clause); |
| 828 | ccn_charbuf_destroy(&slice_name); |
| 829 | ccn_charbuf_destroy(&slice_uri); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 830 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 831 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 832 | } |
| 833 | |
akmhoque | 0eb8de2 | 2013-02-24 14:08:19 -0600 | [diff] [blame] | 834 | |