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 };
00147
00148
00149
00150
00151
00152
00153
00154
00155 #define FACESLOTBITS 18
00156 #define MAXFACES ((1U << FACESLOTBITS) - 1)
00157
00158 struct content_queue {
00159 unsigned burst_nsec;
00160 unsigned min_usec;
00161 unsigned rand_usec;
00162 unsigned ready;
00163 unsigned nrun;
00164 struct ccn_indexbuf *send_queue;
00165 struct ccn_scheduled_event *sender;
00166 };
00167
00168 enum cq_delay_class {
00169 CCN_CQ_ASAP,
00170 CCN_CQ_NORMAL,
00171 CCN_CQ_SLOW,
00172 CCN_CQ_N
00173 };
00174
00175
00176
00177
00178 enum ccnd_face_meter_index {
00179 FM_BYTI,
00180 FM_BYTO,
00181 FM_DATI,
00182 FM_INTO,
00183 FM_DATO,
00184 FM_INTI,
00185 CCND_FACE_METER_N
00186 };
00187
00188
00189
00190
00191 struct face {
00192 int recv_fd;
00193 unsigned sendface;
00194 int flags;
00195 int surplus;
00196 unsigned faceid;
00197 unsigned recvcount;
00198 struct content_queue *q[CCN_CQ_N];
00199 struct ccn_charbuf *inbuf;
00200 struct ccn_skeleton_decoder decoder;
00201 size_t outbufindex;
00202 struct ccn_charbuf *outbuf;
00203 const struct sockaddr *addr;
00204 socklen_t addrlen;
00205 int pending_interests;
00206 unsigned rrun;
00207 uintmax_t rseq;
00208 struct ccnd_meter *meter[CCND_FACE_METER_N];
00209 unsigned short pktseq;
00210 };
00211
00212
00213 #define CCN_FACE_LINK (1 << 0)
00214 #define CCN_FACE_DGRAM (1 << 1)
00215 #define CCN_FACE_GG (1 << 2)
00216 #define CCN_FACE_LOCAL (1 << 3)
00217 #define CCN_FACE_INET (1 << 4)
00218 #define CCN_FACE_MCAST (1 << 5)
00219 #define CCN_FACE_INET6 (1 << 6)
00220 #define CCN_FACE_DC (1 << 7)
00221 #define CCN_FACE_NOSEND (1 << 8)
00222 #define CCN_FACE_UNDECIDED (1 << 9)
00223 #define CCN_FACE_PERMANENT (1 << 10)
00224 #define CCN_FACE_CONNECTING (1 << 11)
00225 #define CCN_FACE_LOOPBACK (1 << 12)
00226 #define CCN_FACE_CLOSING (1 << 13)
00227 #define CCN_FACE_PASSIVE (1 << 14)
00228 #define CCN_FACE_NORECV (1 << 15)
00229 #define CCN_FACE_REGOK (1 << 16)
00230 #define CCN_FACE_SEQOK (1 << 17)
00231 #define CCN_FACE_SEQPROBE (1 << 18)
00232 #define CCN_FACE_LC (1 << 19)
00233 #define CCN_NOFACEID (~0U)
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 struct content_entry {
00246 ccn_accession_t accession;
00247 unsigned short *comps;
00248 int ncomps;
00249 int flags;
00250 const unsigned char *key;
00251 int key_size;
00252 int size;
00253 struct ccn_indexbuf *skiplinks;
00254 };
00255
00256
00257
00258
00259 #define CCN_CONTENT_ENTRY_SLOWSEND 1
00260 #define CCN_CONTENT_ENTRY_STALE 2
00261 #define CCN_CONTENT_ENTRY_PRECIOUS 4
00262
00263
00264
00265
00266
00267 struct sparse_straggler_entry {
00268 struct content_entry *content;
00269 };
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 struct propagating_entry {
00283 struct propagating_entry *next;
00284 struct propagating_entry *prev;
00285 unsigned flags;
00286 unsigned faceid;
00287 int usec;
00288 int sent;
00289 struct ccn_indexbuf *outbound;
00290 unsigned char *interest_msg;
00291 unsigned size;
00292 int fgen;
00293 };
00294
00295 #define CCN_PR_UNSENT 0x01
00296 #define CCN_PR_WAIT1 0x02
00297 #define CCN_PR_STUFFED1 0x04
00298 #define CCN_PR_TAP 0x08
00299 #define CCN_PR_EQV 0x10
00300 #define CCN_PR_SCOPE0 0x20
00301 #define CCN_PR_SCOPE1 0x40
00302 #define CCN_PR_SCOPE2 0x80
00303
00304
00305
00306
00307
00308 struct nameprefix_entry {
00309 struct propagating_entry pe_head;
00310 struct ccn_indexbuf *forward_to;
00311 struct ccn_indexbuf *tap;
00312 struct ccn_forwarding *forwarding;
00313 struct nameprefix_entry *parent;
00314 int children;
00315 unsigned flags;
00316 int fgen;
00317 unsigned src;
00318 unsigned osrc;
00319 unsigned usec;
00320 };
00321
00322
00323
00324
00325
00326 struct ccn_forwarding {
00327 unsigned faceid;
00328 unsigned flags;
00329 int expires;
00330 struct ccn_forwarding *next;
00331 };
00332
00333
00334 struct ccnd_meter *ccnd_meter_create(struct ccnd_handle *h, const char *what);
00335 void ccnd_meter_destroy(struct ccnd_meter **);
00336
00337
00338 void ccnd_meter_init(struct ccnd_handle *h, struct ccnd_meter *m, const char *what);
00339
00340
00341 void ccnd_meter_bump(struct ccnd_handle *h, struct ccnd_meter *m, unsigned amt);
00342
00343 unsigned ccnd_meter_rate(struct ccnd_handle *h, struct ccnd_meter *m);
00344 uintmax_t ccnd_meter_total(struct ccnd_meter *m);
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 #define CCN_FORW_PFXO (CCN_FORW_ADVERTISE | CCN_FORW_CAPTURE | CCN_FORW_LOCAL)
00360 #define CCN_FORW_REFRESHED (1 << 16)
00361
00362
00363
00364
00365
00366 #define CCN_FWU_SECS 5
00367
00368
00369
00370
00371
00372
00373 int ccnd_init_internal_keystore(struct ccnd_handle *);
00374 int ccnd_internal_client_start(struct ccnd_handle *);
00375 void ccnd_internal_client_stop(struct ccnd_handle *);
00376
00377
00378
00379
00380
00381 int ccnd_req_newface(struct ccnd_handle *h,
00382 const unsigned char *msg, size_t size,
00383 struct ccn_charbuf *reply_body);
00384
00385
00386
00387
00388
00389 int ccnd_req_destroyface(struct ccnd_handle *h,
00390 const unsigned char *msg, size_t size,
00391 struct ccn_charbuf *reply_body);
00392
00393
00394
00395
00396
00397 int ccnd_req_prefixreg(struct ccnd_handle *h,
00398 const unsigned char *msg, size_t size,
00399 struct ccn_charbuf *reply_body);
00400
00401
00402
00403
00404
00405 int ccnd_req_selfreg(struct ccnd_handle *h,
00406 const unsigned char *msg, size_t size,
00407 struct ccn_charbuf *reply_body);
00408
00409
00410
00411
00412 #define CCNDID_LOCAL_URI "ccnx:/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY"
00413 #define CCNDID_NEIGHBOR_URI "ccnx:/%C1.M.S.neighborhood/%C1.M.SRV/ccnd/KEY"
00414
00415
00416
00417
00418
00419 int ccnd_req_unreg(struct ccnd_handle *h,
00420 const unsigned char *msg, size_t size,
00421 struct ccn_charbuf *reply_body);
00422
00423 int ccnd_reg_uri(struct ccnd_handle *h,
00424 const char *uri,
00425 unsigned faceid,
00426 int flags,
00427 int expires);
00428
00429 struct face *ccnd_face_from_faceid(struct ccnd_handle *, unsigned);
00430 void ccnd_face_status_change(struct ccnd_handle *, unsigned);
00431 int ccnd_destroy_face(struct ccnd_handle *h, unsigned faceid);
00432 void ccnd_send(struct ccnd_handle *h, struct face *face,
00433 const void *data, size_t size);
00434
00435
00436 int ccnd_stats_handle_http_connection(struct ccnd_handle *, struct face *);
00437 void ccnd_msg(struct ccnd_handle *, const char *, ...);
00438 void ccnd_debug_ccnb(struct ccnd_handle *h,
00439 int lineno,
00440 const char *msg,
00441 struct face *face,
00442 const unsigned char *ccnb,
00443 size_t ccnb_size);
00444
00445 struct ccnd_handle *ccnd_create(const char *, ccnd_logger, void *);
00446 void ccnd_run(struct ccnd_handle *h);
00447 void ccnd_destroy(struct ccnd_handle **);
00448 extern const char *ccnd_usage_message;
00449
00450 #endif