ccnr_private.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef CCNR_PRIVATE_DEFINED
00025 #define CCNR_PRIVATE_DEFINED
00026
00027 #include <poll.h>
00028 #include <stdarg.h>
00029 #include <stddef.h>
00030 #include <stdint.h>
00031 #include <sys/socket.h>
00032 #include <sys/types.h>
00033
00034 #include <ccn/ccn_private.h>
00035 #include <ccn/coding.h>
00036 #include <ccn/reg_mgmt.h>
00037 #include <ccn/schedule.h>
00038 #include <ccn/seqwriter.h>
00039
00040
00041
00042
00043
00044 struct ccn_charbuf;
00045 struct ccn_indexbuf;
00046 struct hashtb;
00047 struct ccnr_meter;
00048 struct ccn_btree;
00049
00050 struct SyncBaseStruct;
00051
00052
00053
00054 struct ccnr_handle;
00055 struct fdholder;
00056 struct content_entry;
00057 struct nameprefix_entry;
00058 struct propagating_entry;
00059 struct content_tree_node;
00060 struct ccn_forwarding;
00061 struct enum_state;
00062 struct ccnr_parsed_policy;
00063
00064
00065
00066 #if (defined(CCNLINT) && (CCNLINT == 1))
00067
00068 typedef uint_least64_t ccnr_accession;
00069 #define CCNR_NULL_ACCESSION ((ccnr_accession)(0))
00070 #define CCNR_MIN_ACCESSION ((ccnr_accession)(1))
00071 #define CCNR_MAX_ACCESSION ((ccnr_accession)(~CCNR_NULL_ACCESSION))
00072 #elif (defined(CCNLINT) && (CCNLINT == 2))
00073 #error "Not expected to work - this is for detecting illegitimate comparisons"
00074 struct intentionally_incomplete;
00075 typedef struct intentionally_incomplete *ccnr_accession;
00076 #define CCNR_NULL_ACCESSION ((ccnr_accession)(0))
00077 #define CCNR_MIN_ACCESSION ((ccnr_accession)(0x10000000))
00078 #define CCNR_MAX_ACCESSION ((ccnr_accession)(0x7fffffff))
00079 #elif (defined(CCNLINT) && (CCNLINT == 3))
00080 #error "Not expected to work - this is for detecting illegitimate casts"
00081 typedef struct ccnr_accession_rep {unsigned a; unsigned b;} ccnr_accession;
00082 struct ccnr_accession_rep ccnr_null_accession;
00083 struct ccnr_accession_rep ccnr_min_accession;
00084 struct ccnr_accession_rep ccnr_max_accession;
00085 #define CCNR_NULL_ACCESSION ccnr_null_accession
00086 #define CCNR_MIN_ACCESSION ccnr_min_accession
00087 #define CCNR_MAX_ACCESSION ccnr_max_accession
00088 #else
00089 typedef uint_least64_t ccnr_accession;
00090 #define CCNR_NULL_ACCESSION ((ccnr_accession)(0))
00091 #define CCNR_MIN_ACCESSION ((ccnr_accession)(1))
00092 #define CCNR_MAX_ACCESSION ((ccnr_accession)(~CCNR_NULL_ACCESSION))
00093 #endif
00094
00095 #define CCNR_NOT_COMPARABLE (-2)
00096
00097
00098 uintmax_t ccnr_accession_encode(struct ccnr_handle *, ccnr_accession);
00099 ccnr_accession ccnr_accession_decode(struct ccnr_handle *, uintmax_t);
00100
00101
00102
00103
00104 int ccnr_accession_compare(struct ccnr_handle *ccnr, ccnr_accession x, ccnr_accession y);
00105
00106
00107
00108
00109 typedef uintmax_t ccnr_hwm;
00110 #define CCNR_NULL_HWM ((ccnr_hwm)(0))
00111
00112
00113 uintmax_t ccnr_hwm_encode(struct ccnr_handle *, ccnr_hwm);
00114 ccnr_hwm ccnr_hwm_decode(struct ccnr_handle *, uintmax_t);
00115
00116
00117 int ccnr_acc_in_hwm(struct ccnr_handle *, ccnr_accession a, ccnr_hwm hwm);
00118
00119
00120 ccnr_hwm ccnr_hwm_update(struct ccnr_handle *, ccnr_hwm, ccnr_accession);
00121 ccnr_hwm ccnr_hwm_merge(struct ccnr_handle *, ccnr_hwm, ccnr_hwm);
00122
00123
00124
00125
00126 int ccnr_hwm_compare(struct ccnr_handle *ccnr, ccnr_hwm x, ccnr_hwm y);
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 typedef unsigned ccnr_cookie;
00140
00141
00142
00143 typedef int (*ccnr_logger)(void *loggerdata, const char *format, va_list ap);
00144
00145
00146
00147
00148
00149 #define CCNSHOULDLOG(h, who, level) (((h)->debug >= (level)) != 0)
00150
00151
00152 #define LM_2 2
00153 #define LM_4 4
00154 #define LM_8 8
00155 #define LM_16 16
00156 #define LM_32 32
00157 #define LM_64 64
00158 #define LM_128 128
00159
00160
00161
00162
00163 #define CCNR_MAX_ENUM 64
00164
00165
00166
00167
00168 struct ccnr_handle {
00169 unsigned char ccnr_id[32];
00170 struct ccn_charbuf *ccnr_keyid;
00171 struct hashtb *nameprefix_tab;
00172 struct hashtb *propagating_tab;
00173 struct hashtb *enum_state_tab;
00174 struct ccn_indexbuf *skiplinks;
00175 struct ccn_btree *btree;
00176 unsigned forward_to_gen;
00177 unsigned face_gen;
00178 unsigned face_rover;
00179 unsigned face_limit;
00180 struct fdholder **fdholder_by_fd;
00181 int active_in_fd;
00182 int active_out_fd;
00183 int repofile1_fd;
00184 off_t startupbytes;
00185 off_t stable;
00186 struct ccn_scheduled_event *reaper;
00187 struct ccn_scheduled_event *age;
00188 struct ccn_scheduled_event *clean;
00189 struct ccn_scheduled_event *age_forwarding;
00190 struct ccn_scheduled_event *reap_enumerations;
00191 struct ccn_scheduled_event *index_cleaner;
00192 struct ccn_indexbuf *toclean;
00193 const char *portstr;
00194 nfds_t nfds;
00195 struct pollfd *fds;
00196 struct ccn_gettime ticktock;
00197 long sec;
00198 unsigned usec;
00199 long starttime;
00200 unsigned starttime_usec;
00201 struct ccn_schedule *sched;
00202 struct ccn_charbuf *scratch_charbuf;
00203 struct ccn_indexbuf *scratch_indexbuf;
00204
00205 unsigned cookie_limit;
00206 struct content_entry **content_by_cookie;
00207 struct hashtb *content_by_accession_tab;
00208 ccnr_cookie cookie;
00209 ccnr_cookie min_stale;
00210 ccnr_cookie max_stale;
00211 ccnr_cookie trim_rover;
00212 unsigned long n_stale;
00213 struct ccn_indexbuf *unsol;
00214 unsigned long cob_count;
00215 unsigned long cob_limit;
00216 unsigned long oldformatcontent;
00217 unsigned long oldformatcontentgrumble;
00218 unsigned long oldformatinterests;
00219 unsigned long oldformatinterestgrumble;
00220 unsigned long content_dups_recvd;
00221 unsigned long content_items_sent;
00222 unsigned long interests_accepted;
00223 unsigned long interests_dropped;
00224 unsigned long interests_sent;
00225 unsigned long interests_stuffed;
00226 unsigned long content_from_accession_hits;
00227 unsigned long content_from_accession_misses;
00228 unsigned long count_lmc_found;
00229 unsigned long count_lmc_found_iters;
00230 unsigned long count_lmc_notfound;
00231 unsigned long count_lmc_notfound_iters;
00232 unsigned long count_rmc_found;
00233 unsigned long count_rmc_found_iters;
00234 unsigned long count_rmc_notfound;
00235 unsigned long count_rmc_notfound_iters;
00236
00237 unsigned start_write_scope_limit;
00238 unsigned short seed[3];
00239 int running;
00240 int debug;
00241 int syncdebug;
00242 ccnr_logger logger;
00243 void *loggerdata;
00244 int logbreak;
00245 unsigned long logtime;
00246 int logpid;
00247 int flood;
00248 unsigned interest_faceid;
00249 const char *progname;
00250 struct ccn *direct_client;
00251 struct ccn *internal_client;
00252 struct fdholder *face0;
00253 struct ccn_charbuf *service_ccnb;
00254 struct ccn_charbuf *neighbor_ccnb;
00255 struct ccnr_parsed_policy *parsed_policy;
00256 struct ccn_charbuf *policy_name;
00257 struct ccn_charbuf *policy_link_cob;
00258 struct ccn_seqwriter *notice;
00259 struct ccn_indexbuf *chface;
00260 struct ccn_scheduled_event *internal_client_refresh;
00261 struct ccn_scheduled_event *direct_client_refresh;
00262 struct ccn_scheduled_event *notice_push;
00263
00264 struct SyncBaseStruct *sync_handle;
00265 ccnr_accession notify_after;
00266 ccnr_accession active_enum[CCNR_MAX_ENUM];
00267
00268 const char *directory;
00269 };
00270
00271 struct content_queue {
00272 unsigned burst_nsec;
00273 unsigned min_usec;
00274 unsigned rand_usec;
00275 unsigned ready;
00276 unsigned nrun;
00277 struct ccn_indexbuf *send_queue;
00278 struct ccn_scheduled_event *sender;
00279 };
00280
00281 enum cq_delay_class {
00282 CCN_CQ_ASAP,
00283 CCN_CQ_NORMAL,
00284 CCN_CQ_SLOW,
00285 CCN_CQ_N
00286 };
00287
00288
00289
00290
00291 enum ccnr_face_meter_index {
00292 FM_BYTI,
00293 FM_BYTO,
00294 FM_DATI,
00295 FM_INTO,
00296 FM_DATO,
00297 FM_INTI,
00298 CCNR_FACE_METER_N
00299 };
00300
00301
00302
00303
00304 struct fdholder {
00305 unsigned filedesc;
00306 int flags;
00307 unsigned recvcount;
00308 struct content_queue *q[CCN_CQ_N];
00309 off_t bufoffset;
00310 struct ccn_charbuf *inbuf;
00311 struct ccn_skeleton_decoder decoder;
00312 size_t outbufindex;
00313 struct ccn_charbuf *outbuf;
00314 struct ccn_charbuf *name;
00315 int pending_interests;
00316 struct ccnr_meter *meter[CCNR_FACE_METER_N];
00317 };
00318
00319
00320
00321 #define CCNR_FACE_DGRAM (1 << 1)
00322 #define CCNR_FACE_GG (1 << 2)
00323 #define CCNR_FACE_LOCAL (1 << 3)
00324 #define CCNR_FACE_INET (1 << 4)
00325 #define CCNR_FACE_INET6 (1 << 6)
00326 #define CCNR_FACE_NOSEND (1 << 8)
00327 #define CCNR_FACE_UNDECIDED (1 << 9)
00328 #define CCNR_FACE_PERMANENT (1 << 10)
00329 #define CCNR_FACE_CONNECTING (1 << 11)
00330 #define CCNR_FACE_LOOPBACK (1 << 12)
00331 #define CCNR_FACE_CLOSING (1 << 13)
00332 #define CCNR_FACE_PASSIVE (1 << 14)
00333 #define CCNR_FACE_NORECV (1 << 15)
00334 #define CCNR_FACE_REPODATA (1 << 19)
00335 #define CCNR_FACE_CCND (1 << 20)
00336 #define CCNR_FACE_SOCKMASK (CCNR_FACE_DGRAM | CCNR_FACE_INET | CCNR_FACE_INET6 | CCNR_FACE_LOCAL)
00337
00338 #define CCN_NOFACEID (-1)
00339
00340
00341
00342
00343
00344 struct content_entry;
00345
00346
00347
00348
00349 #define CCN_CONTENT_ENTRY_SLOWSEND 1
00350 #define CCN_CONTENT_ENTRY_STALE 2
00351 #define CCN_CONTENT_ENTRY_PRECIOUS 4
00352 #define CCN_CONTENT_ENTRY_STABLE 8
00353
00354
00355
00356
00357
00358 struct content_by_accession_entry {
00359 struct content_entry *content;
00360 };
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 struct propagating_entry {
00374 struct propagating_entry *next;
00375 struct propagating_entry *prev;
00376 unsigned flags;
00377 unsigned filedesc;
00378 int usec;
00379 int sent;
00380 struct ccn_indexbuf *outbound;
00381 unsigned char *interest_msg;
00382 unsigned size;
00383 int fgen;
00384 };
00385
00386 #define CCN_PR_UNSENT 0x01
00387 #define CCN_PR_WAIT1 0x02
00388 #define CCN_PR_STUFFED1 0x04
00389 #define CCN_PR_TAP 0x08
00390 #define CCN_PR_EQV 0x10
00391 #define CCN_PR_SCOPE0 0x20
00392 #define CCN_PR_SCOPE1 0x40
00393 #define CCN_PR_SCOPE2 0x80
00394
00395
00396
00397
00398
00399 struct nameprefix_entry {
00400 struct propagating_entry pe_head;
00401 struct ccn_indexbuf *forward_to;
00402 struct ccn_indexbuf *tap;
00403 struct ccn_forwarding *forwarding;
00404 struct nameprefix_entry *parent;
00405 int children;
00406 unsigned flags;
00407 int fgen;
00408 unsigned src;
00409 unsigned osrc;
00410 unsigned usec;
00411 };
00412
00413
00414
00415
00416
00417 struct ccn_forwarding {
00418 unsigned filedesc;
00419 unsigned flags;
00420 int expires;
00421 struct ccn_forwarding *next;
00422 };
00423
00424
00425
00426
00427
00428 enum es_active_state {
00429 ES_PENDING = -1,
00430 ES_INACTIVE = 0,
00431 ES_ACTIVE = 1,
00432 ES_ACTIVE_PENDING_INACTIVE = 2
00433 };
00434 #define ENUM_N_COBS 9
00435 struct enum_state {
00436 struct ccn_charbuf *name;
00437 struct content_entry *content;
00438 struct ccn_charbuf *reply_body;
00439 struct ccn_charbuf *interest;
00440 struct ccn_indexbuf *interest_comps;
00441 struct ccn_charbuf *cob[ENUM_N_COBS];
00442 int cob_deferred[ENUM_N_COBS];
00443 intmax_t next_segment;
00444 ccnr_cookie starting_cookie;
00445 enum es_active_state active;
00446 long lifetime;
00447 long lastuse_sec;
00448 unsigned lastuse_usec;
00449 };
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 #define CCN_FORW_PFXO (CCN_FORW_ADVERTISE | CCN_FORW_CAPTURE | CCN_FORW_LOCAL)
00460 #define CCN_FORW_REFRESHED (1 << 16)
00461
00462
00463
00464
00465
00466 #define CCN_FWU_SECS 5
00467
00468
00469
00470
00471 #define CCNRID_LOCAL_URI "ccnx:/%C1.M.S.localhost/%C1.M.SRV/repository/KEY"
00472 #define CCNRID_NEIGHBOR_URI "ccnx:/%C1.M.S.neighborhood/%C1.M.SRV/repository/KEY"
00473 #define CCNRID_POLICY_URI "ccnx:/%C1.M.S.localhost/%C1.M.SRV/repository/POLICY"
00474
00475 #define PUBLIC
00476
00477 struct ccnr_handle *r_init_create(const char *, ccnr_logger, void *);
00478 void r_init_run(struct ccnr_handle *h);
00479 void r_init_destroy(struct ccnr_handle **);
00480
00481 #endif