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 CCND_PRIVATE_DEFINED
00025 #define CCND_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 ccnd_meter;
00048
00049
00050
00051
00052 struct ccnd_handle;
00053 struct face;
00054 struct content_entry;
00055 struct nameprefix_entry;
00056 struct interest_entry;
00057 struct pit_face_item;
00058 struct content_tree_node;
00059 struct ccn_forwarding;
00060 struct ccn_strategy;
00061
00062
00063 typedef unsigned ccn_accession_t;
00064
00065
00066
00067
00068
00069
00070 typedef uint32_t ccn_wrappedtime;
00071
00072 typedef int (*ccnd_logger)(void *loggerdata, const char *format, va_list ap);
00073
00074
00075
00076
00077 struct ccnd_handle {
00078 unsigned char ccnd_id[32];
00079 struct hashtb *faces_by_fd;
00080 struct hashtb *dgram_faces;
00081 struct hashtb *content_tab;
00082 struct hashtb *nameprefix_tab;
00083 struct hashtb *interest_tab;
00084 struct ccn_indexbuf *skiplinks;
00085 unsigned forward_to_gen;
00086 unsigned face_gen;
00087 unsigned face_rover;
00088 unsigned face_limit;
00089 struct face **faces_by_faceid;
00090 struct ccn_scheduled_event *reaper;
00091 struct ccn_scheduled_event *age;
00092 struct ccn_scheduled_event *clean;
00093 struct ccn_scheduled_event *age_forwarding;
00094 const char *portstr;
00095 unsigned ipv4_faceid;
00096 unsigned ipv6_faceid;
00097 nfds_t nfds;
00098 struct pollfd *fds;
00099 struct ccn_gettime ticktock;
00100 long sec;
00101 unsigned usec;
00102 ccn_wrappedtime wtnow;
00103 long
00104 int sliver;
00105 long starttime;
00106 unsigned starttime_usec;
00107 unsigned iserial;
00108 struct ccn_schedule *sched;
00109 struct ccn_charbuf *send_interest_scratch;
00110 struct ccn_charbuf *scratch_charbuf;
00111 struct ccn_indexbuf *scratch_indexbuf;
00112
00113 ccn_accession_t accession_base;
00114 unsigned content_by_accession_window;
00115 struct content_entry **content_by_accession;
00116
00117 struct hashtb *sparse_straggler_tab;
00118 ccn_accession_t accession;
00119 ccn_accession_t min_stale;
00120 ccn_accession_t max_stale;
00121 unsigned long capacity;
00122
00123 unsigned long n_stale;
00124 struct ccn_indexbuf *unsol;
00125 unsigned long oldformatcontent;
00126 unsigned long oldformatcontentgrumble;
00127 unsigned long oldformatinterests;
00128 unsigned long oldformatinterestgrumble;
00129 unsigned long content_dups_recvd;
00130 unsigned long content_items_sent;
00131 unsigned long interests_accepted;
00132 unsigned long interests_dropped;
00133 unsigned long interests_sent;
00134 unsigned long interests_stuffed;
00135 unsigned short seed[3];
00136 int running;
00137 int debug;
00138 ccnd_logger logger;
00139 void *loggerdata;
00140 int logbreak;
00141 unsigned long logtime;
00142 int logpid;
00143 int mtu;
00144 int flood;
00145 struct ccn_charbuf *autoreg;
00146 int force_zero_freshness;
00147 unsigned interest_faceid;
00148 const char *progname;
00149 struct ccn *internal_client;
00150 struct face *face0;
00151 struct ccn_charbuf *service_ccnb;
00152 struct ccn_charbuf *neighbor_ccnb;
00153 struct ccn_seqwriter *notice;
00154 struct ccn_indexbuf *chface;
00155 struct ccn_scheduled_event *internal_client_refresh;
00156 struct ccn_scheduled_event *notice_push;
00157 unsigned data_pause_microsec;
00158 int (*noncegen)(struct ccnd_handle *, struct face *, unsigned char *);
00159
00160 int tts_default;
00161 int tts_limit;
00162 };
00163
00164
00165
00166
00167
00168
00169
00170
00171 #define FACESLOTBITS 18
00172 #define MAXFACES ((1U << FACESLOTBITS) - 1)
00173
00174 struct content_queue {
00175 unsigned burst_nsec;
00176 unsigned min_usec;
00177 unsigned rand_usec;
00178 unsigned ready;
00179 unsigned nrun;
00180 struct ccn_indexbuf *send_queue;
00181 struct ccn_scheduled_event *sender;
00182 };
00183
00184 enum cq_delay_class {
00185 CCN_CQ_ASAP,
00186 CCN_CQ_NORMAL,
00187 CCN_CQ_SLOW,
00188 CCN_CQ_N
00189 };
00190
00191
00192
00193
00194 enum ccnd_face_meter_index {
00195 FM_BYTI,
00196 FM_BYTO,
00197 FM_DATI,
00198 FM_INTO,
00199 FM_DATO,
00200 FM_INTI,
00201 CCND_FACE_METER_N
00202 };
00203
00204
00205
00206
00207 struct face {
00208 int recv_fd;
00209 unsigned sendface;
00210 int flags;
00211 int surplus;
00212 unsigned faceid;
00213 unsigned recvcount;
00214 struct content_queue *q[CCN_CQ_N];
00215 struct ccn_charbuf *inbuf;
00216 struct ccn_skeleton_decoder decoder;
00217 size_t outbufindex;
00218 struct ccn_charbuf *outbuf;
00219 const struct sockaddr *addr;
00220 socklen_t addrlen;
00221 int pending_interests;
00222 unsigned rrun;
00223 uintmax_t rseq;
00224 struct ccnd_meter *meter[CCND_FACE_METER_N];
00225 unsigned short pktseq;
00226 };
00227
00228
00229 #define CCN_FACE_LINK (1 << 0)
00230 #define CCN_FACE_DGRAM (1 << 1)
00231 #define CCN_FACE_GG (1 << 2)
00232 #define CCN_FACE_LOCAL (1 << 3)
00233 #define CCN_FACE_INET (1 << 4)
00234 #define CCN_FACE_MCAST (1 << 5)
00235 #define CCN_FACE_INET6 (1 << 6)
00236 #define CCN_FACE_DC (1 << 7)
00237 #define CCN_FACE_NOSEND (1 << 8)
00238 #define CCN_FACE_UNDECIDED (1 << 9)
00239 #define CCN_FACE_PERMANENT (1 << 10)
00240 #define CCN_FACE_CONNECTING (1 << 11)
00241 #define CCN_FACE_LOOPBACK (1 << 12)
00242 #define CCN_FACE_CLOSING (1 << 13)
00243 #define CCN_FACE_PASSIVE (1 << 14)
00244 #define CCN_FACE_NORECV (1 << 15)
00245 #define CCN_FACE_REGOK (1 << 16)
00246 #define CCN_FACE_SEQOK (1 << 17)
00247 #define CCN_FACE_SEQPROBE (1 << 18)
00248 #define CCN_FACE_LC (1 << 19)
00249 #define CCN_NOFACEID (~0U)
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 struct content_entry {
00262 ccn_accession_t accession;
00263 unsigned short *comps;
00264 int ncomps;
00265 int flags;
00266 const unsigned char *key;
00267 int key_size;
00268 int size;
00269 struct ccn_indexbuf *skiplinks;
00270 };
00271
00272
00273
00274
00275 #define CCN_CONTENT_ENTRY_SLOWSEND 1
00276 #define CCN_CONTENT_ENTRY_STALE 2
00277 #define CCN_CONTENT_ENTRY_PRECIOUS 4
00278
00279
00280
00281
00282
00283 struct sparse_straggler_entry {
00284 struct content_entry *content;
00285 };
00286
00287
00288
00289
00290
00291
00292 struct ccn_strategy {
00293 struct ccn_scheduled_event *ev;
00294 int state;
00295 ccn_wrappedtime birth;
00296 ccn_wrappedtime renewed;
00297 unsigned renewals;
00298 };
00299
00300 struct ielinks;
00301 struct ielinks {
00302 struct ielinks *next;
00303 struct ielinks *prev;
00304 struct nameprefix_entry *npe;
00305 };
00306
00307
00308
00309
00310
00311
00312
00313
00314 struct interest_entry {
00315 struct ielinks ll;
00316 struct ccn_strategy strategy;
00317 struct pit_face_item *pfl;
00318 struct ccn_scheduled_event *ev;
00319 const unsigned char *interest_msg;
00320 unsigned size;
00321 unsigned serial;
00322 };
00323
00324 #define TYPICAL_NONCE_SIZE 12
00325
00326
00327
00328
00329
00330
00331
00332
00333 struct pit_face_item {
00334 struct pit_face_item *next;
00335 unsigned faceid;
00336 ccn_wrappedtime renewed;
00337 ccn_wrappedtime expiry;
00338 unsigned pfi_flags;
00339 unsigned char nonce[TYPICAL_NONCE_SIZE];
00340 };
00341 #define CCND_PFI_NONCESZ 0x00FF
00342 #define CCND_PFI_UPSTREAM 0x0100
00343 #define CCND_PFI_UPENDING 0x0200
00344 #define CCND_PFI_SENDUPST 0x0400
00345 #define CCND_PFI_UPHUNGRY 0x0800
00346 #define CCND_PFI_DNSTREAM 0x1000
00347 #define CCND_PFI_PENDING 0x2000
00348 #define CCND_PFI_SUPDATA 0x4000
00349 #define CCND_PFI_DCFACE 0x10000
00350
00351
00352
00353
00354
00355 struct nameprefix_entry {
00356 struct ielinks ie_head;
00357 struct ccn_indexbuf *forward_to;
00358 struct ccn_indexbuf *tap;
00359 struct ccn_forwarding *forwarding;
00360 struct nameprefix_entry *parent;
00361 int children;
00362 unsigned flags;
00363 int fgen;
00364 unsigned src;
00365 unsigned osrc;
00366 unsigned usec;
00367 };
00368
00369
00370
00371
00372
00373 struct ccn_forwarding {
00374 unsigned faceid;
00375 unsigned flags;
00376 int expires;
00377 struct ccn_forwarding *next;
00378 };
00379
00380
00381 struct ccnd_meter *ccnd_meter_create(struct ccnd_handle *h, const char *what);
00382 void ccnd_meter_destroy(struct ccnd_meter **);
00383
00384
00385 void ccnd_meter_init(struct ccnd_handle *h, struct ccnd_meter *m, const char *what);
00386
00387
00388 void ccnd_meter_bump(struct ccnd_handle *h, struct ccnd_meter *m, unsigned amt);
00389
00390 unsigned ccnd_meter_rate(struct ccnd_handle *h, struct ccnd_meter *m);
00391 uintmax_t ccnd_meter_total(struct ccnd_meter *m);
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 #define CCN_FORW_PFXO (CCN_FORW_ADVERTISE | CCN_FORW_CAPTURE | CCN_FORW_LOCAL)
00407 #define CCN_FORW_REFRESHED (1 << 16)
00408
00409
00410
00411
00412
00413 #define CCN_FWU_SECS 5
00414
00415
00416
00417
00418
00419
00420 int ccnd_init_internal_keystore(struct ccnd_handle *);
00421 int ccnd_internal_client_start(struct ccnd_handle *);
00422 void ccnd_internal_client_stop(struct ccnd_handle *);
00423
00424
00425
00426
00427
00428 int ccnd_req_newface(struct ccnd_handle *h,
00429 const unsigned char *msg, size_t size,
00430 struct ccn_charbuf *reply_body);
00431
00432
00433
00434
00435
00436 int ccnd_req_destroyface(struct ccnd_handle *h,
00437 const unsigned char *msg, size_t size,
00438 struct ccn_charbuf *reply_body);
00439
00440
00441
00442
00443
00444 int ccnd_req_prefixreg(struct ccnd_handle *h,
00445 const unsigned char *msg, size_t size,
00446 struct ccn_charbuf *reply_body);
00447
00448
00449
00450
00451
00452 int ccnd_req_selfreg(struct ccnd_handle *h,
00453 const unsigned char *msg, size_t size,
00454 struct ccn_charbuf *reply_body);
00455
00456
00457
00458
00459 #define CCNDID_LOCAL_URI "ccnx:/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY"
00460 #define CCNDID_NEIGHBOR_URI "ccnx:/%C1.M.S.neighborhood/%C1.M.SRV/ccnd/KEY"
00461
00462
00463
00464
00465
00466 int ccnd_req_unreg(struct ccnd_handle *h,
00467 const unsigned char *msg, size_t size,
00468 struct ccn_charbuf *reply_body);
00469
00470 int ccnd_reg_uri(struct ccnd_handle *h,
00471 const char *uri,
00472 unsigned faceid,
00473 int flags,
00474 int expires);
00475
00476 struct face *ccnd_face_from_faceid(struct ccnd_handle *, unsigned);
00477 void ccnd_face_status_change(struct ccnd_handle *, unsigned);
00478 int ccnd_destroy_face(struct ccnd_handle *h, unsigned faceid);
00479 void ccnd_send(struct ccnd_handle *h, struct face *face,
00480 const void *data, size_t size);
00481
00482
00483 int ccnd_stats_handle_http_connection(struct ccnd_handle *, struct face *);
00484 void ccnd_msg(struct ccnd_handle *, const char *, ...);
00485 void ccnd_debug_ccnb(struct ccnd_handle *h,
00486 int lineno,
00487 const char *msg,
00488 struct face *face,
00489 const unsigned char *ccnb,
00490 size_t ccnb_size);
00491
00492 struct ccnd_handle *ccnd_create(const char *, ccnd_logger, void *);
00493 void ccnd_run(struct ccnd_handle *h);
00494 void ccnd_destroy(struct ccnd_handle **);
00495 extern const char *ccnd_usage_message;
00496
00497 #endif