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