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