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 start_write_scope_limit;
00229 unsigned short seed[3];
00230 int running;
00231 int debug;
00232 int syncdebug;
00233 ccnr_logger logger;
00234 void *loggerdata;
00235 int logbreak;
00236 unsigned long logtime;
00237 int logpid;
00238 int flood;
00239 unsigned interest_faceid;
00240 const char *progname;
00241 struct ccn *direct_client;
00242 struct ccn *internal_client;
00243 struct fdholder *face0;
00244 struct ccn_charbuf *service_ccnb;
00245 struct ccn_charbuf *neighbor_ccnb;
00246 struct ccnr_parsed_policy *parsed_policy;
00247 struct ccn_charbuf *policy_name;
00248 struct ccn_charbuf *policy_link_cob;
00249 struct ccn_seqwriter *notice;
00250 struct ccn_indexbuf *chface;
00251 struct ccn_scheduled_event *internal_client_refresh;
00252 struct ccn_scheduled_event *direct_client_refresh;
00253 struct ccn_scheduled_event *notice_push;
00254
00255 struct SyncBaseStruct *sync_handle;
00256 ccnr_accession notify_after;
00257 ccnr_accession active_enum[CCNR_MAX_ENUM];
00258
00259 const char *directory;
00260 };
00261
00262 struct content_queue {
00263 unsigned burst_nsec;
00264 unsigned min_usec;
00265 unsigned rand_usec;
00266 unsigned ready;
00267 unsigned nrun;
00268 struct ccn_indexbuf *send_queue;
00269 struct ccn_scheduled_event *sender;
00270 };
00271
00272 enum cq_delay_class {
00273 CCN_CQ_ASAP,
00274 CCN_CQ_NORMAL,
00275 CCN_CQ_SLOW,
00276 CCN_CQ_N
00277 };
00278
00279
00280
00281
00282 enum ccnr_face_meter_index {
00283 FM_BYTI,
00284 FM_BYTO,
00285 FM_DATI,
00286 FM_INTO,
00287 FM_DATO,
00288 FM_INTI,
00289 CCNR_FACE_METER_N
00290 };
00291
00292
00293
00294
00295 struct fdholder {
00296 unsigned filedesc;
00297 int flags;
00298 unsigned recvcount;
00299 struct content_queue *q[CCN_CQ_N];
00300 off_t bufoffset;
00301 struct ccn_charbuf *inbuf;
00302 struct ccn_skeleton_decoder decoder;
00303 size_t outbufindex;
00304 struct ccn_charbuf *outbuf;
00305 struct ccn_charbuf *name;
00306 int pending_interests;
00307 struct ccnr_meter *meter[CCNR_FACE_METER_N];
00308 };
00309
00310
00311
00312 #define CCNR_FACE_DGRAM (1 << 1)
00313 #define CCNR_FACE_GG (1 << 2)
00314 #define CCNR_FACE_LOCAL (1 << 3)
00315 #define CCNR_FACE_INET (1 << 4)
00316 #define CCNR_FACE_INET6 (1 << 6)
00317 #define CCNR_FACE_NOSEND (1 << 8)
00318 #define CCNR_FACE_UNDECIDED (1 << 9)
00319 #define CCNR_FACE_PERMANENT (1 << 10)
00320 #define CCNR_FACE_CONNECTING (1 << 11)
00321 #define CCNR_FACE_LOOPBACK (1 << 12)
00322 #define CCNR_FACE_CLOSING (1 << 13)
00323 #define CCNR_FACE_PASSIVE (1 << 14)
00324 #define CCNR_FACE_NORECV (1 << 15)
00325 #define CCNR_FACE_REPODATA (1 << 19)
00326 #define CCNR_FACE_CCND (1 << 20)
00327 #define CCNR_FACE_SOCKMASK (CCNR_FACE_DGRAM | CCNR_FACE_INET | CCNR_FACE_INET6 | CCNR_FACE_LOCAL)
00328
00329 #define CCN_NOFACEID (-1)
00330
00331
00332
00333
00334
00335 struct content_entry;
00336
00337
00338
00339
00340 #define CCN_CONTENT_ENTRY_SLOWSEND 1
00341 #define CCN_CONTENT_ENTRY_STALE 2
00342 #define CCN_CONTENT_ENTRY_PRECIOUS 4
00343 #define CCN_CONTENT_ENTRY_STABLE 8
00344
00345
00346
00347
00348
00349 struct content_by_accession_entry {
00350 struct content_entry *content;
00351 };
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 struct propagating_entry {
00365 struct propagating_entry *next;
00366 struct propagating_entry *prev;
00367 unsigned flags;
00368 unsigned filedesc;
00369 int usec;
00370 int sent;
00371 struct ccn_indexbuf *outbound;
00372 unsigned char *interest_msg;
00373 unsigned size;
00374 int fgen;
00375 };
00376
00377 #define CCN_PR_UNSENT 0x01
00378 #define CCN_PR_WAIT1 0x02
00379 #define CCN_PR_STUFFED1 0x04
00380 #define CCN_PR_TAP 0x08
00381 #define CCN_PR_EQV 0x10
00382 #define CCN_PR_SCOPE0 0x20
00383 #define CCN_PR_SCOPE1 0x40
00384 #define CCN_PR_SCOPE2 0x80
00385
00386
00387
00388
00389
00390 struct nameprefix_entry {
00391 struct propagating_entry pe_head;
00392 struct ccn_indexbuf *forward_to;
00393 struct ccn_indexbuf *tap;
00394 struct ccn_forwarding *forwarding;
00395 struct nameprefix_entry *parent;
00396 int children;
00397 unsigned flags;
00398 int fgen;
00399 unsigned src;
00400 unsigned osrc;
00401 unsigned usec;
00402 };
00403
00404
00405
00406
00407
00408 struct ccn_forwarding {
00409 unsigned filedesc;
00410 unsigned flags;
00411 int expires;
00412 struct ccn_forwarding *next;
00413 };
00414
00415
00416
00417
00418
00419 enum es_active_state {
00420 ES_PENDING = -1,
00421 ES_INACTIVE = 0,
00422 ES_ACTIVE = 1
00423 };
00424 #define ENUM_N_COBS 9
00425 struct enum_state {
00426 struct ccn_charbuf *name;
00427 struct content_entry *content;
00428 struct ccn_charbuf *reply_body;
00429 struct ccn_charbuf *interest;
00430 struct ccn_indexbuf *interest_comps;
00431 struct ccn_charbuf *cob[ENUM_N_COBS];
00432 intmax_t next_segment;
00433 ccnr_cookie starting_cookie;
00434 enum es_active_state active;
00435 long lifetime;
00436 long lastuse_sec;
00437 unsigned lastuse_usec;
00438 };
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 #define CCN_FORW_PFXO (CCN_FORW_ADVERTISE | CCN_FORW_CAPTURE | CCN_FORW_LOCAL)
00449 #define CCN_FORW_REFRESHED (1 << 16)
00450
00451
00452
00453
00454
00455 #define CCN_FWU_SECS 5
00456
00457
00458
00459
00460 #define CCNRID_LOCAL_URI "ccnx:/%C1.M.S.localhost/%C1.M.SRV/repository/KEY"
00461 #define CCNRID_NEIGHBOR_URI "ccnx:/%C1.M.S.neighborhood/%C1.M.SRV/repository/KEY"
00462 #define CCNRID_POLICY_URI "ccnx:/%C1.M.S.localhost/%C1.M.SRV/repository/POLICY"
00463
00464 #define PUBLIC
00465
00466 struct ccnr_handle *r_init_create(const char *, ccnr_logger, void *);
00467 void r_init_run(struct ccnr_handle *h);
00468 void r_init_destroy(struct ccnr_handle **);
00469
00470 #endif