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