ccnd_private.h

Go to the documentation of this file.
00001 /**
00002  * @file ccnd_private.h
00003  *
00004  * Private definitions for ccnd - the CCNx daemon.
00005  * Data structures are described here so that logging and status
00006  * routines can be compiled separately.
00007  *
00008  * Part of ccnd - the CCNx Daemon.
00009  *
00010  * Copyright (C) 2008-2011 Palo Alto Research Center, Inc.
00011  *
00012  * This work is free software; you can redistribute it and/or modify it under
00013  * the terms of the GNU General Public License version 2 as published by the
00014  * Free Software Foundation.
00015  * This work is distributed in the hope that it will be useful, but WITHOUT ANY
00016  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00017  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00018  * for more details. You should have received a copy of the GNU General Public
00019  * License along with this program; if not, write to the
00020  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
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  * These are defined in other ccn headers, but the incomplete types suffice
00042  * for the purposes of this header.
00043  */
00044 struct ccn_charbuf;
00045 struct ccn_indexbuf;
00046 struct hashtb;
00047 struct ccnd_meter;
00048 
00049 /*
00050  * These are defined in this header.
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 //typedef uint_least64_t ccn_accession_t;
00061 typedef unsigned ccn_accession_t;
00062 
00063 typedef int (*ccnd_logger)(void *loggerdata, const char *format, va_list ap);
00064 
00065 /**
00066  * We pass this handle almost everywhere within ccnd
00067  */
00068 struct ccnd_handle {
00069     unsigned char ccnd_id[32];      /**< sha256 digest of our public key */
00070     struct hashtb *faces_by_fd;     /**< keyed by fd */
00071     struct hashtb *dgram_faces;     /**< keyed by sockaddr */
00072     struct hashtb *content_tab;     /**< keyed by portion of ContentObject */
00073     struct hashtb *nameprefix_tab;  /**< keyed by name prefix components */
00074     struct hashtb *propagating_tab; /**< keyed by nonce */
00075     struct ccn_indexbuf *skiplinks; /**< skiplist for content-ordered ops */
00076     unsigned forward_to_gen;        /**< for forward_to updates */
00077     unsigned face_gen;              /**< faceid generation number */
00078     unsigned face_rover;            /**< for faceid allocation */
00079     unsigned face_limit;            /**< current number of face slots */
00080     struct face **faces_by_faceid;  /**< array with face_limit elements */
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;            /**< "main" port number */
00086     unsigned ipv4_faceid;           /**< wildcard IPv4, bound to port */
00087     unsigned ipv6_faceid;           /**< wildcard IPv6, bound to port */
00088     nfds_t nfds;                    /**< number of entries in fds array */
00089     struct pollfd *fds;             /**< used for poll system call */
00090     struct ccn_gettime ticktock;    /**< our time generator */
00091     long sec;                       /**< cached gettime seconds */
00092     unsigned usec;                  /**< cached gettime microseconds */
00093     long starttime;                 /**< ccnd start time, in seconds */
00094     unsigned starttime_usec;        /**< ccnd start time fractional part */
00095     struct ccn_schedule *sched;     /**< our schedule */
00096     struct ccn_charbuf *scratch_charbuf; /**< one-slot scratch cache */
00097     struct ccn_indexbuf *scratch_indexbuf; /**< one-slot scratch cache */
00098     /** Next three fields are used for direct accession-to-content table */
00099     ccn_accession_t accession_base;
00100     unsigned content_by_accession_window;
00101     struct content_entry **content_by_accession;
00102     /** The following holds stragglers that would otherwise bloat the above */
00103     struct hashtb *sparse_straggler_tab; /* keyed by accession */
00104     ccn_accession_t accession;      /**< newest used accession number */
00105     ccn_accession_t min_stale;      /**< smallest accession of stale content */
00106     ccn_accession_t max_stale;      /**< largest accession of stale content */
00107     unsigned long capacity;         /**< may toss content if there more than
00108                                      this many content objects in the store */
00109     unsigned long n_stale;          /**< Number of stale content objects */
00110     struct ccn_indexbuf *unsol;     /**< unsolicited content */
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];         /**< for PRNG */
00122     int running;                    /**< true while should be running */
00123     int debug;                      /**< For controlling debug output */
00124     ccnd_logger logger;             /**< For debug output */
00125     void *loggerdata;               /**< Passed to logger */
00126     int logbreak;                   /**< see ccn_msg() */
00127     unsigned long logtime;          /**< see ccn_msg() */
00128     int logpid;                     /**< see ccn_msg() */
00129     int mtu;                        /**< Target size for stuffing interests */
00130     int flood;                      /**< Internal control for auto-reg */
00131     struct ccn_charbuf *autoreg;    /**< URIs to auto-register */
00132     int force_zero_freshness;       /**< Simulate freshness=0 on all content */
00133     unsigned interest_faceid;       /**< for self_reg internal client */
00134     const char *progname;           /**< our name, for locating helpers */
00135     struct ccn *internal_client;    /**< internal client */
00136     struct face *face0;             /**< special face for internal client */
00137     struct ccn_charbuf *service_ccnb; /**< for local service discovery */
00138     struct ccn_charbuf *neighbor_ccnb; /**< for neighbor service discovery */
00139     struct ccn_seqwriter *notice;   /**< for notices of status changes */
00140     struct ccn_indexbuf *chface;    /**< faceids w/ recent status changes */
00141     struct ccn_scheduled_event *internal_client_refresh;
00142     struct ccn_scheduled_event *notice_push;
00143     unsigned data_pause_microsec;   /**< tunable, see choose_face_delay() */
00144     void (*appnonce)(struct ccnd_handle *, struct face *, struct ccn_charbuf *);
00145                                     /**< pluggable nonce generation */
00146 };
00147 
00148 /**
00149  * Each face is referenced by a number, the faceid.  The low-order
00150  * bits (under the MAXFACES) constitute a slot number that is
00151  * unique (for this ccnd) among the faces that are alive at a given time.
00152  * The rest of the bits form a generation number that make the
00153  * entire faceid unique over time, even for faces that are defunct.
00154  */
00155 #define FACESLOTBITS 18
00156 #define MAXFACES ((1U << FACESLOTBITS) - 1)
00157 
00158 struct content_queue {
00159     unsigned burst_nsec;             /**< nsec per KByte, limits burst rate */
00160     unsigned min_usec;               /**< minimum delay for this queue */
00161     unsigned rand_usec;              /**< randomization range */
00162     unsigned ready;                  /**< # that have waited enough */
00163     unsigned nrun;                   /**< # sent since last randomized delay */
00164     struct ccn_indexbuf *send_queue; /**< accession numbers of pending content */
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  * Face meter index
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  * One of our active faces
00190  */
00191 struct face {
00192     int recv_fd;                /**< socket for receiving */
00193     unsigned sendface;          /**< faceid for sending (maybe == faceid) */
00194     int flags;                  /**< CCN_FACE_* face flags */
00195     int surplus;                /**< sends since last successful recv */
00196     unsigned faceid;            /**< internal face id */
00197     unsigned recvcount;         /**< for activity level monitoring */
00198     struct content_queue *q[CCN_CQ_N]; /**< outgoing content, per delay class */
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;     /**< sequence number for sent packets */
00210 };
00211 
00212 /** face flags */
00213 #define CCN_FACE_LINK   (1 << 0) /**< Elements wrapped by CCNProtocolDataUnit */
00214 #define CCN_FACE_DGRAM  (1 << 1) /**< Datagram interface, respect packets */
00215 #define CCN_FACE_GG     (1 << 2) /**< Considered friendly */
00216 #define CCN_FACE_LOCAL  (1 << 3) /**< PF_UNIX socket */
00217 #define CCN_FACE_INET   (1 << 4) /**< IPv4 */
00218 #define CCN_FACE_MCAST  (1 << 5) /**< a party line (e.g. multicast) */
00219 #define CCN_FACE_INET6  (1 << 6) /**< IPv6 */
00220 #define CCN_FACE_DC     (1 << 7) /**< Direct control face */
00221 #define CCN_FACE_NOSEND (1 << 8) /**< Don't send anymore */
00222 #define CCN_FACE_UNDECIDED (1 << 9) /**< Might not be talking ccn */
00223 #define CCN_FACE_PERMANENT (1 << 10) /**< No timeout for inactivity */
00224 #define CCN_FACE_CONNECTING (1 << 11) /**< Connect in progress */
00225 #define CCN_FACE_LOOPBACK (1 << 12) /**< v4 or v6 loopback address */
00226 #define CCN_FACE_CLOSING (1 << 13) /**< close stream when output is done */
00227 #define CCN_FACE_PASSIVE (1 << 14) /**< a listener or a bound dgram socket */
00228 #define CCN_FACE_NORECV (1 << 15) /**< use for sending only */
00229 #define CCN_FACE_REGOK (1 << 16) /**< Allowed to do prefix registration */
00230 #define CCN_FACE_SEQOK (1 << 17) /** OK to send SequenceNumber link messages */
00231 #define CCN_FACE_SEQPROBE (1 << 18) /** SequenceNumber probe */
00232 #define CCN_FACE_LC    (1 << 19) /** A link check has been issued recently */
00233 #define CCN_NOFACEID    (~0U)    /** denotes no face */
00234 
00235 /**
00236  *  The content hash table is keyed by the initial portion of the ContentObject
00237  *  that contains all the parts of the complete name.  The extdata of the hash
00238  *  table holds the rest of the object, so that the whole ContentObject is
00239  *  stored contiguously.  The internal form differs from the on-wire form in
00240  *  that the final content-digest name component is represented explicitly,
00241  *  which simplifies the matching logic.
00242  *  The original ContentObject may be reconstructed simply by excising this
00243  *  last name component, which is easily located via the comps array.
00244  */
00245 struct content_entry {
00246     ccn_accession_t accession;  /**< assigned in arrival order */
00247     unsigned short *comps;      /**< Name Component byte boundary offsets */
00248     int ncomps;                 /**< Number of name components plus one */
00249     int flags;                  /**< see below */
00250     const unsigned char *key;   /**< ccnb-encoded ContentObject */
00251     int key_size;               /**< Size of fragment prior to Content */
00252     int size;                   /**< Size of ContentObject */
00253     struct ccn_indexbuf *skiplinks; /**< skiplist for name-ordered ops */
00254 };
00255 
00256 /**
00257  * content_entry flags
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  * The sparse_straggler hash table, keyed by accession, holds scattered
00265  * entries that would otherwise bloat the direct content_by_accession table.
00266  */
00267 struct sparse_straggler_entry {
00268     struct content_entry *content;
00269 };
00270 
00271 /**
00272  * The propagating interest hash table is keyed by Nonce.
00273  *
00274  * While the interest is pending, the pe is also kept in a doubly-linked
00275  * list off of a nameprefix_entry.
00276  *
00277  * When the interest is consumed, the pe is removed from the doubly-linked
00278  * list and is cleaned up by freeing unnecessary bits (including the interest
00279  * message itself).  It remains in the hash table for a time, in order to catch
00280  * duplicate nonces.
00281  */
00282 struct propagating_entry {
00283     struct propagating_entry *next; /**< next (in arrival order) */
00284     struct propagating_entry *prev; /**< previous (older) */
00285     unsigned flags;             /**< CCN_PR_xxx */
00286     unsigned faceid;            /**< origin of the interest, dest for matches */
00287     int usec;                   /**< usec until timeout */
00288     int sent;                   /**< leading faceids of outbound processed */
00289     struct ccn_indexbuf *outbound; /**< in order of use */
00290     unsigned char *interest_msg; /**< pending interest message */
00291     unsigned size;              /**< size in bytes of interest_msg */
00292     int fgen;                   /**< decide if outbound is stale */
00293 };
00294 // XXX - with new outbound/sent repr, some of these flags may not be needed.
00295 #define CCN_PR_UNSENT   0x01 /**< interest has not been sent anywhere yet */
00296 #define CCN_PR_WAIT1    0x02 /**< interest has been sent to one place */
00297 #define CCN_PR_STUFFED1 0x04 /**< was stuffed before sent anywhere else */
00298 #define CCN_PR_TAP      0x08 /**< at least one tap face is present */
00299 #define CCN_PR_EQV      0x10 /**< a younger similar interest exists */
00300 #define CCN_PR_SCOPE0   0x20 /**< interest scope is 0 */
00301 #define CCN_PR_SCOPE1   0x40 /**< interest scope is 1 (this host) */
00302 #define CCN_PR_SCOPE2   0x80 /**< interest scope is 2 (immediate neighborhood) */
00303 
00304 /**
00305  * The nameprefix hash table is keyed by the Component elements of
00306  * the Name prefix.
00307  */
00308 struct nameprefix_entry {
00309     struct propagating_entry pe_head; /**< list head for propagating entries */
00310     struct ccn_indexbuf *forward_to; /**< faceids to forward to */
00311     struct ccn_indexbuf *tap;    /**< faceids to forward to as tap*/
00312     struct ccn_forwarding *forwarding; /**< detailed forwarding info */
00313     struct nameprefix_entry *parent; /**< link to next-shorter prefix */
00314     int children;                /**< number of children */
00315     unsigned flags;              /**< CCN_FORW_* flags about namespace */
00316     int fgen;                    /**< used to decide when forward_to is stale */
00317     unsigned src;                /**< faceid of recent content source */
00318     unsigned osrc;               /**< and of older matching content */
00319     unsigned usec;               /**< response-time prediction */
00320 };
00321 
00322 /**
00323  * Keeps track of the faces that interests matching a given name prefix may be
00324  * forwarded to.
00325  */
00326 struct ccn_forwarding {
00327     unsigned faceid;             /**< locally unique number identifying face */
00328     unsigned flags;              /**< CCN_FORW_* - c.f. <ccn/reg_mgnt.h> */
00329     int expires;                 /**< time remaining, in seconds */
00330     struct ccn_forwarding *next;
00331 };
00332 
00333 /* create and destroy procs for separately allocated meters */
00334 struct ccnd_meter *ccnd_meter_create(struct ccnd_handle *h, const char *what);
00335 void ccnd_meter_destroy(struct ccnd_meter **);
00336 
00337 /* for meters kept within other structures */
00338 void ccnd_meter_init(struct ccnd_handle *h, struct ccnd_meter *m, const char *what);
00339 
00340 /* count something (messages, packets, bytes), getting time info from h */
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  * Refer to doc/technical/Registration.txt for the meaning of these flags.
00349  *
00350  * @def CCN_FORW_ACTIVE         1
00351  * @def CCN_FORW_CHILD_INHERIT  2
00352  * @def CCN_FORW_ADVERTISE      4
00353  * @def CCN_FORW_LAST           8
00354  * @def CCN_FORW_CAPTURE       16
00355  * @def CCN_FORW_LOCAL         32
00356  * @def CCN_FORW_TAP           64
00357  * @def CCN_FORW_CAPTURE_OK   128
00358  */
00359 #define CCN_FORW_PFXO (CCN_FORW_ADVERTISE | CCN_FORW_CAPTURE | CCN_FORW_LOCAL)
00360 #define CCN_FORW_REFRESHED      (1 << 16) /**< private to ccnd */
00361 
00362  
00363 /**
00364  * Determines how frequently we age our forwarding entries
00365  */
00366 #define CCN_FWU_SECS 5
00367 
00368 /*
00369  * Internal client
00370  * The internal client is for communication between the ccnd and other
00371  * components, using (of course) ccn protocols.
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  * The internal client calls this with the argument portion ARG of
00379  * a face-creation request (/ccnx/CCNDID/newface/ARG)
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  * The internal client calls this with the argument portion ARG of
00387  * a face-destroy request (/ccnx/CCNDID/destroyface/ARG)
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  * The internal client calls this with the argument portion ARG of
00395  * a prefix-registration request (/ccnx/CCNDID/prefixreg/ARG)
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  * The internal client calls this with the argument portion ARG of
00403  * a prefix-registration request for self (/ccnx/CCNDID/selfreg/ARG)
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  * URIs for prefixes served by the internal client
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  * The internal client calls this with the argument portion ARG of
00417  * a prefix-unregistration request (/ccnx/CCNDID/unreg/ARG)
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 /* Consider a separate header for these */
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

Generated on Thu Feb 16 00:43:58 2012 for Content-Centric Networking in C by  doxygen 1.5.6