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){ |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 242 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame^] | 243 | int res_verify=verify_key(ptr,&pcobuf1,1); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 244 | |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame^] | 245 | if ( res_verify != 0 ){ |
| 246 | printf("Error in verfiying keys !! :( \n"); |
| 247 | } |
| 248 | else{ |
| 249 | printf("Key verification is successful :)\n"); |
| 250 | ptr_in=ptr; |
| 251 | length_in=length; |
| 252 | ccn_content_get_value(ptr_in, length_in, &pcobuf1, |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 253 | &ptr_in, &length_in); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame^] | 254 | *content_data = (unsigned char *) calloc(length_in, |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 255 | sizeof(char *)); |
akmhoque | b795818 | 2013-03-11 12:03:54 -0500 | [diff] [blame^] | 256 | memcpy (*content_data, ptr_in, length_in); |
| 257 | ret=0; |
| 258 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 259 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 260 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 261 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 262 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 263 | ccn_charbuf_destroy(&resultbuf); |
| 264 | ccn_charbuf_destroy(&templ); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 265 | ccn_charbuf_destroy(&name); |
| 266 | |
| 267 | return ret; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 268 | } |
| 269 | |
akmhoque | edb68d9 | 2013-03-05 10:18:16 -0600 | [diff] [blame] | 270 | void |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 271 | process_incoming_sync_content_lsa( unsigned char *content_data) |
| 272 | { |
| 273 | |
| 274 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 275 | if ( nlsr->debugging ) |
| 276 | printf("process_incoming_sync_content_lsa called \n"); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 277 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 278 | char *sep="|"; |
| 279 | char *rem; |
| 280 | char *orig_router; |
| 281 | char *orl; |
| 282 | int orig_router_length; |
| 283 | char *lst; |
| 284 | int ls_type; |
| 285 | char *lsid; |
| 286 | long int ls_id; |
| 287 | char *isvld; |
| 288 | int isValid; |
| 289 | char *num_link; |
| 290 | int no_link; |
| 291 | char *np; |
| 292 | char *np_length; |
| 293 | int name_length; |
| 294 | char *data; |
| 295 | char *orig_time; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 296 | |
| 297 | |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 298 | if ( nlsr->debugging ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 299 | printf("LSA Data \n"); |
| 300 | |
| 301 | if( strlen((char *)content_data ) > 0 ) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 302 | { |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 303 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 304 | orig_router=strtok_r((char *)content_data,sep,&rem); |
| 305 | orl=strtok_r(NULL,sep,&rem); |
| 306 | orig_router_length=atoi(orl); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 307 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 308 | if ( nlsr->debugging ) |
| 309 | { |
| 310 | printf(" Orig Router Name : %s\n",orig_router); |
| 311 | printf(" Orig Router Length: %d\n",orig_router_length); |
| 312 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 313 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 314 | lst=strtok_r(NULL,sep,&rem); |
| 315 | ls_type=atoi(lst); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 316 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 317 | if ( nlsr->debugging ) |
| 318 | printf(" LS Type : %d\n",ls_type); |
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 | if ( ls_type == LS_TYPE_NAME ) |
| 321 | { |
| 322 | lsid=strtok_r(NULL,sep,&rem); |
| 323 | ls_id=atoi(lsid); |
| 324 | orig_time=strtok_r(NULL,sep,&rem); |
| 325 | isvld=strtok_r(NULL,sep,&rem); |
| 326 | isValid=atoi(isvld); |
| 327 | np=strtok_r(NULL,sep,&rem); |
| 328 | np_length=strtok_r(NULL,sep,&rem); |
| 329 | name_length=atoi(np_length); |
| 330 | if ( nlsr->debugging ) |
| 331 | { |
| 332 | printf(" LS ID : %ld\n",ls_id); |
| 333 | printf(" isValid : %d\n",isValid); |
| 334 | printf(" Name Prefix : %s\n",np); |
| 335 | printf(" Orig Time : %s\n",orig_time); |
| 336 | printf(" Name Prefix length: %d\n",name_length); |
| 337 | } |
| 338 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 339 | build_and_install_others_name_lsa(orig_router,ls_type,ls_id, |
| 340 | orig_time,isValid,np); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 341 | |
| 342 | print_name_lsdb(); |
| 343 | |
| 344 | } |
| 345 | else if ( ls_type == LS_TYPE_ADJ ) |
| 346 | { |
| 347 | orig_time=strtok_r(NULL,sep,&rem); |
| 348 | num_link=strtok_r(NULL,sep,&rem); |
| 349 | no_link=atoi(num_link); |
| 350 | data=rem; |
| 351 | |
| 352 | if ( nlsr->debugging ) |
| 353 | { |
| 354 | printf(" Orig Time : %s\n",orig_time); |
| 355 | printf(" No Link : %d\n",no_link); |
| 356 | printf(" Data : %s\n",data); |
| 357 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 358 | build_and_install_others_adj_lsa(orig_router,ls_type,orig_time, |
| 359 | no_link,data); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 360 | } |
| 361 | else if ( ls_type == LS_TYPE_COR ) |
| 362 | { |
| 363 | orig_time=strtok_r(NULL,sep,&rem); |
| 364 | char *cor_r=strtok_r(NULL,sep,&rem); |
| 365 | char *cor_theta=strtok_r(NULL,sep,&rem); |
| 366 | |
| 367 | double r, theta; |
akmhoque | 8034d50 | 2013-02-24 11:53:24 -0600 | [diff] [blame] | 368 | r=strtod(cor_r,NULL); |
| 369 | theta=strtod(cor_theta,NULL); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 370 | |
| 371 | if ( nlsr->debugging ) |
| 372 | { |
| 373 | printf(" Orig Time : %s\n",orig_time); |
| 374 | printf(" Cor R : %f\n",r); |
| 375 | printf(" Cor Theta : %f\n",theta); |
| 376 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 377 | build_and_install_others_cor_lsa(orig_router,ls_type,orig_time, |
| 378 | (double)r, (double)theta); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 379 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 380 | |
| 381 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 382 | } |
| 383 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 384 | void |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 385 | process_content_from_sync (struct ccn_charbuf *content_name, |
| 386 | struct ccn_indexbuf *components) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 387 | { |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 388 | if (nlsr->debugging) |
| 389 | printf("process_content_from_sync called \n"); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 390 | size_t comp_size; |
| 391 | char *lst; |
| 392 | char *lsid; |
| 393 | const unsigned char *second_last_comp; |
| 394 | const unsigned char *third_last_comp; |
| 395 | const unsigned char *origtime; |
| 396 | char *sep="."; |
| 397 | char *rem; |
| 398 | char *second_comp_type; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 399 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 400 | int ls_type; |
| 401 | long int ls_id=0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 402 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 403 | unsigned char *content_data = NULL; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 404 | |
akmhoque | b31caa1 | 2013-02-22 08:42:09 -0600 | [diff] [blame] | 405 | char *time_stamp=get_current_timestamp_micro_v2(); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 406 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 407 | struct ccn_charbuf *uri = ccn_charbuf_create(); |
| 408 | ccn_uri_append(uri, content_name->buf, content_name->length, 0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 409 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 410 | struct name_prefix *orig_router=(struct name_prefix *) |
| 411 | calloc( 1, sizeof(struct name_prefix)); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 412 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 413 | ccn_name_comp_get( content_name->buf, components, |
| 414 | components->n-1-2, &second_last_comp, &comp_size); |
| 415 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 416 | if (nlsr->debugging) |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 417 | printf("2nd Last Component: %s \n", second_last_comp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 418 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 419 | second_comp_type=strtok_r((char *)second_last_comp, sep, &rem); |
| 420 | if (second_comp_type == NULL || rem == NULL) |
| 421 | { |
| 422 | printf ("Error: unable to tokenize the string: %s, calling exit()\n", |
| 423 | (char *)second_last_comp); |
| 424 | exit(0); |
| 425 | } |
| 426 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 427 | if ( strcmp( second_comp_type, "lsId" ) == 0 ) |
| 428 | { |
| 429 | lsid=rem; |
| 430 | ls_id=atoi(rem); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 431 | ccn_name_comp_get(content_name->buf, components,components->n-2-2, |
| 432 | &third_last_comp, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 433 | lst=strtok_r((char *)third_last_comp,sep,&rem); |
| 434 | lst=rem; |
| 435 | ls_type=atoi(lst); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 436 | ccn_name_comp_get(content_name->buf, components,components->n-2, |
| 437 | &origtime, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 438 | ccn_name_chop(content_name,components,-3); |
| 439 | get_name_part(orig_router,content_name,components,0); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 440 | |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 441 | if ( nlsr->debugging ) |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 442 | printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n", |
| 443 | orig_router->name,ls_type,ls_id,origtime); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 444 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 445 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 446 | if ( nlsr->debugging ) |
| 447 | printf("LSA Life time: %d\n",lsa_life_time); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 448 | |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 449 | if ( strcmp(orig_router->name,nlsr->router_name) != 0 |
| 450 | && (lsa_life_time < nlsr->router_dead_interval) ) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 451 | { |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 452 | int is_new_name_lsa=check_is_new_name_lsa(orig_router->name, |
| 453 | (char *)lst,(char *)lsid,(char *)origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 454 | if ( is_new_name_lsa == 1 ) |
| 455 | { |
| 456 | if ( nlsr->debugging ) |
| 457 | printf("New NAME LSA.....\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 458 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 459 | &content_data,orig_router->name); |
| 460 | if ( chk_con == 0 ){ |
| 461 | if ( nlsr->debugging ) |
| 462 | printf("Content Data: %s \n",content_data); |
| 463 | process_incoming_sync_content_lsa(content_data); |
| 464 | } |
| 465 | else{ |
| 466 | if ( nlsr->debugging ) |
| 467 | printf("Verification failed. No content given back\n"); |
| 468 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 469 | } |
| 470 | else |
| 471 | { |
| 472 | if ( nlsr->debugging ) |
| 473 | printf("Name LSA / Newer Name LSA already xists in LSDB\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); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 476 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 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 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 487 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 488 | else |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 489 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 490 | if ( nlsr->debugging ) |
| 491 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 492 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 493 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 494 | else |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 495 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 496 | ls_type=atoi(rem); |
| 497 | lst=rem; |
| 498 | if(ls_type == LS_TYPE_ADJ) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 499 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 500 | ccn_name_comp_get(content_name->buf, components,components->n-2, |
| 501 | &origtime, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 502 | ccn_name_chop(content_name,components,-2); |
| 503 | get_name_part(orig_router,content_name,components,0); |
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 | if ( nlsr->debugging ) |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 506 | printf("Orig Router: %s Ls Type: %d Orig Time: %s\n", |
| 507 | orig_router->name,ls_type,origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 508 | |
| 509 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 510 | if ( nlsr->debugging ) |
| 511 | printf("LSA Life time: %d\n",lsa_life_time); |
| 512 | |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 513 | if ( strcmp(orig_router->name,nlsr->router_name) != 0 |
| 514 | && (lsa_life_time < nlsr->router_dead_interval) ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 515 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 516 | int is_new_adj_lsa = check_is_new_adj_lsa( orig_router->name, |
| 517 | (char *)lst, (char *)origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 518 | if ( is_new_adj_lsa == 1 ) |
| 519 | { |
| 520 | if ( nlsr->debugging ) |
| 521 | printf("New Adj LSA.....\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 522 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 523 | &content_data,orig_router->name); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 524 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 525 | if ( chk_con == 0 ){ |
| 526 | if ( nlsr->debugging ) |
| 527 | printf("Content Data: %s \n",content_data); |
| 528 | process_incoming_sync_content_lsa(content_data); |
| 529 | } |
| 530 | else{ |
| 531 | if ( nlsr->debugging ) |
| 532 | printf("Verification failed. No content given back\n"); |
| 533 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 534 | } |
| 535 | else |
| 536 | { |
| 537 | if ( nlsr->debugging ) |
| 538 | printf("Adj LSA / Newer Adj LSA already exists in LSDB\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 539 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 540 | &content_data,orig_router->name); |
| 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 | } |
| 552 | else |
| 553 | { |
| 554 | if ( nlsr->debugging ) |
| 555 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
| 556 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 557 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 558 | else if(ls_type == LS_TYPE_COR) |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 559 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 560 | ccn_name_comp_get(content_name->buf, components, components->n-2, |
| 561 | &origtime, &comp_size); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 562 | ccn_name_chop(content_name,components,-2); |
| 563 | get_name_part(orig_router,content_name,components,0); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 564 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 565 | if ( nlsr->debugging ) |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 566 | printf("Orig Router: %s Ls Type: %d Orig Time: %s\n", |
| 567 | orig_router->name,ls_type,origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 568 | |
| 569 | int lsa_life_time=get_time_diff(time_stamp,(char *)origtime); |
akmhoque | 8c5e266 | 2013-02-24 06:37:14 -0600 | [diff] [blame] | 570 | if ( nlsr->debugging ) |
| 571 | printf("LSA Life time: %d\n",lsa_life_time); |
| 572 | |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 573 | if ( strcmp(orig_router->name,nlsr->router_name) != 0 |
| 574 | && (lsa_life_time < nlsr->router_dead_interval) ) |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 575 | { |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 576 | int is_new_cor_lsa=check_is_new_cor_lsa( orig_router->name, |
| 577 | (char *)lst,(char *) origtime); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 578 | if ( is_new_cor_lsa == 1 ) |
| 579 | { |
| 580 | if ( nlsr->debugging ) |
| 581 | printf("New Cor LSA.....\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 582 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 583 | &content_data, |
| 584 | orig_router->name); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 585 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 586 | if ( chk_con == 0 ){ |
| 587 | if ( nlsr->debugging ) |
| 588 | printf("Content Data: %s \n",content_data); |
| 589 | process_incoming_sync_content_lsa(content_data); |
| 590 | } |
| 591 | else{ |
| 592 | if ( nlsr->debugging ) |
| 593 | printf("Verification failed. No content given back\n"); |
| 594 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 595 | } |
| 596 | else |
| 597 | { |
| 598 | if ( nlsr->debugging ) |
| 599 | printf("Cor LSA / Newer Cor LSA already exists in LSDB\n"); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 600 | int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), |
| 601 | &content_data,orig_router->name); |
| 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 | } |
| 613 | else |
| 614 | { |
| 615 | if ( nlsr->debugging ) |
| 616 | printf("Lsa is older than Router LSA refresh time/ Dead Interval\n"); |
| 617 | } |
| 618 | |
| 619 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 620 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 621 | |
akmhoque | f677361 | 2013-02-23 09:53:00 -0600 | [diff] [blame] | 622 | if (orig_router->name) |
| 623 | free(orig_router->name); |
Obaid Amin | 0530089 | 2013-02-21 13:45:25 -0600 | [diff] [blame] | 624 | if (orig_router) |
| 625 | free(orig_router); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 626 | ccn_charbuf_destroy(&uri); |
| 627 | //01/31/2013 |
| 628 | free(time_stamp); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 629 | } |
| 630 | |
Obaid Amin | 7793ba7 | 2013-02-22 00:43:58 -0600 | [diff] [blame] | 631 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 632 | sync_monitor(char *topo_prefix, char *slice_prefix) |
| 633 | { |
| 634 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 635 | struct ccn_charbuf *prefix = ccn_charbuf_create(); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 636 | struct ccn_charbuf *topo = ccn_charbuf_create(); |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 637 | |
| 638 | nlsr->closure=(struct ccns_name_closure *) |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 639 | calloc(1,sizeof(struct ccns_name_closure)); // leak |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 640 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 641 | nlsr->slice = ccns_slice_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 642 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 643 | ccn_charbuf_reset(prefix); |
| 644 | ccn_name_from_uri(prefix, slice_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 645 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 646 | ccn_charbuf_reset(topo); |
| 647 | ccn_name_from_uri(topo, topo_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 648 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 649 | ccns_slice_set_topo_prefix(nlsr->slice, topo, prefix); |
| 650 | nlsr->closure->callback = &sync_cb; |
akmhoque | 54d8611 | 2013-02-21 16:42:34 -0600 | [diff] [blame] | 651 | nlsr->ccns = ccns_open(nlsr->ccn, nlsr->slice, nlsr->closure, NULL, NULL); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 652 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 653 | ccn_charbuf_destroy(&prefix); |
| 654 | ccn_charbuf_destroy(&topo); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 655 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 656 | } |
| 657 | |
Obaid Amin | 7793ba7 | 2013-02-22 00:43:58 -0600 | [diff] [blame] | 658 | struct ccn_charbuf * |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 659 | make_template(int scope) |
| 660 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 661 | struct ccn_charbuf *templ = NULL; |
| 662 | templ = ccn_charbuf_create(); |
| 663 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 664 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 665 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 666 | if (0 <= scope && scope <= 2) |
| 667 | ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 668 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 669 | return(templ); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 670 | } |
| 671 | |
Obaid Amin | 7793ba7 | 2013-02-22 00:43:58 -0600 | [diff] [blame] | 672 | int |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 673 | write_data_to_repo(char *data, char *name_prefix) |
| 674 | { |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 675 | |
| 676 | nlsr_lock(); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 677 | if ( nlsr->debugging ) |
| 678 | { |
| 679 | printf("write_data_to_repo called\n"); |
| 680 | printf("Content Name: %s \n",name_prefix); |
| 681 | printf("Content Data: %s \n",data); |
| 682 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 683 | |
Obaid Amin | f210a32 | 2013-02-22 02:04:52 -0600 | [diff] [blame] | 684 | struct ccn *temp_ccn; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 685 | temp_ccn=ccn_create(); |
| 686 | int ccn_fd=ccn_connect(temp_ccn, NULL); |
| 687 | if(ccn_fd == -1) |
| 688 | { |
| 689 | fprintf(stderr,"Could not connect to ccnd for Data Writing\n"); |
Obaid Amin | 4b0e4ec | 2013-02-24 22:15:01 -0600 | [diff] [blame] | 690 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
| 691 | "Could not connect to ccnd for Data Writing\n"); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 692 | return -1; |
| 693 | } |
Obaid Amin | f210a32 | 2013-02-22 02:04:52 -0600 | [diff] [blame] | 694 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 695 | struct ccn_charbuf *name = NULL; |
| 696 | struct ccn_seqwriter *w = NULL; |
| 697 | int blocksize = 4096; |
| 698 | int freshness = -1; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 699 | int scope = 1; |
| 700 | int res; |
| 701 | size_t blockread; |
| 702 | struct ccn_charbuf *templ; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 703 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 704 | name = ccn_charbuf_create(); |
| 705 | res = ccn_name_from_uri(name, name_prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 706 | if (res < 0) { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 707 | fprintf(stderr, "bad CCN URI: %s\n",name_prefix); |
| 708 | return -1; |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 709 | } |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 710 | |
Obaid Amin | f210a32 | 2013-02-22 02:04:52 -0600 | [diff] [blame] | 711 | w = ccn_seqw_create(temp_ccn, name); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 712 | if (w == NULL) { |
| 713 | fprintf(stderr, "ccn_seqw_create failed\n"); |
| 714 | return -1; |
| 715 | } |
| 716 | ccn_seqw_set_block_limits(w, blocksize, blocksize); |
| 717 | if (freshness > -1) |
| 718 | ccn_seqw_set_freshness(w, freshness); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 719 | |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 720 | struct ccn_charbuf *name_v = ccn_charbuf_create(); |
| 721 | ccn_seqw_get_name(w, name_v); |
| 722 | ccn_name_from_uri(name_v, "%C1.R.sw"); |
| 723 | ccn_name_append_nonce(name_v); |
| 724 | templ = make_template(scope); |
| 725 | res = ccn_get(temp_ccn, name_v, templ, 60000, NULL, NULL, NULL, 0); |
| 726 | ccn_charbuf_destroy(&templ); |
| 727 | ccn_charbuf_destroy(&name_v); |
| 728 | if (res < 0) { |
| 729 | fprintf(stderr, "No response from repository\n"); |
| 730 | return -1; |
| 731 | } |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 732 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 733 | struct ccn_charbuf *resultbuf=ccn_charbuf_create(); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 734 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 735 | sign_content_with_user_defined_keystore(name, |
| 736 | resultbuf, |
| 737 | data, |
| 738 | strlen(data), |
| 739 | nlsr->keystore_path, |
| 740 | nlsr->keystore_passphrase, |
| 741 | nlsr->root_key_prefix, |
| 742 | nlsr->site_name, |
| 743 | nlsr->router_name); |
| 744 | |
| 745 | |
| 746 | //blockread = 0; |
| 747 | //blockread=strlen(data)+1; |
| 748 | blockread=resultbuf->length; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 749 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 750 | if (blockread > 0) { |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 751 | //res = ccn_seqw_write(w, data, blockread); |
| 752 | res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 753 | while (res == -1) { |
akmhoque | 8034d50 | 2013-02-24 11:53:24 -0600 | [diff] [blame] | 754 | ccn_run(temp_ccn,100); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 755 | //res = ccn_seqw_write(w, data, blockread); |
| 756 | res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
akmhoque | 8034d50 | 2013-02-24 11:53:24 -0600 | [diff] [blame] | 760 | ccn_seqw_close(w); |
| 761 | ccn_run(temp_ccn, 100); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 762 | ccn_charbuf_destroy(&name); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 763 | ccn_destroy(&temp_ccn); |
akmhoque | 6e2ba84 | 2013-03-05 19:35:26 -0600 | [diff] [blame] | 764 | ccn_charbuf_destroy(&resultbuf); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 765 | |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 766 | nlsr_unlock(); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 767 | return 0; |
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 | int |
Obaid Amin | 7997ad8 | 2013-02-22 16:41:56 -0600 | [diff] [blame] | 770 | create_sync_slice(char *topo_prefix, char *slice_prefix) |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 771 | { |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 772 | int res; |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 773 | struct ccn *handle; |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 774 | struct ccns_slice *slice; |
| 775 | struct ccn_charbuf *prefix = ccn_charbuf_create(); |
| 776 | struct ccn_charbuf *topo = ccn_charbuf_create(); |
| 777 | struct ccn_charbuf *clause = ccn_charbuf_create(); |
| 778 | struct ccn_charbuf *slice_name = ccn_charbuf_create(); |
| 779 | struct ccn_charbuf *slice_uri = ccn_charbuf_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 780 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 781 | if (prefix == NULL || topo == NULL || clause == NULL || |
| 782 | slice_name == NULL || slice_uri == NULL) { |
| 783 | fprintf(stderr, "Unable to allocate required memory.\n"); |
| 784 | return -1; |
| 785 | } |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 786 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 787 | handle = ccn_create(); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 788 | res = ccn_connect(handle, NULL); |
| 789 | if (0 > res) { |
| 790 | fprintf(stderr, "Unable to connect to ccnd.\n"); |
| 791 | return -1; |
| 792 | } |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 793 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 794 | slice = ccns_slice_create(); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 795 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 796 | ccn_charbuf_reset(topo); |
| 797 | ccn_name_from_uri(topo, topo_prefix); |
| 798 | ccn_charbuf_reset(prefix); |
| 799 | ccn_name_from_uri(prefix,slice_prefix ); |
| 800 | ccns_slice_set_topo_prefix(slice, topo, prefix); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 801 | |
| 802 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 803 | res = ccns_write_slice(handle, slice, slice_name); |
Obaid Amin | bb8ac42 | 2013-02-20 17:08:48 -0600 | [diff] [blame] | 804 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 805 | //01/31/2013 |
| 806 | ccns_slice_destroy(&slice); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 807 | ccn_destroy(&handle); |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 808 | ccn_charbuf_destroy(&prefix); |
| 809 | ccn_charbuf_destroy(&topo); |
| 810 | ccn_charbuf_destroy(&clause); |
| 811 | ccn_charbuf_destroy(&slice_name); |
| 812 | ccn_charbuf_destroy(&slice_uri); |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 813 | |
Obaid Amin | 806df81 | 2013-02-21 13:30:26 -0600 | [diff] [blame] | 814 | return 0; |
akmhoque | a0e7115 | 2013-02-11 09:47:59 -0600 | [diff] [blame] | 815 | } |
| 816 | |
akmhoque | 0eb8de2 | 2013-02-24 14:08:19 -0600 | [diff] [blame] | 817 | |