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