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