btree_content.h

Go to the documentation of this file.
00001 /**
00002  * @file ccn/btree_content.h
00003  *
00004  * Storage of a content index in a btree
00005  */
00006 /*
00007  * (Someday) Part of the CCNx C Library.
00008  *
00009  * Copyright (C) 2011 Palo Alto Research Center, Inc.
00010  *
00011  * This library is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU Lesser General Public License version 2.1
00013  * as published by the Free Software Foundation.
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details. You should have received
00018  * a copy of the GNU Lesser General Public License along with this library;
00019  * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Fifth Floor, Boston, MA 02110-1301 USA.
00021  */
00022  
00023  
00024 #ifndef CCN_BTREE_CONTENT_DEFINED
00025 #define CCN_BTREE_CONTENT_DEFINED
00026 
00027 #include <sys/types.h>
00028 #include <ccn/btree.h>
00029 #include <ccn/ccn.h>
00030 #include <ccn/charbuf.h>
00031 
00032 /**
00033  *  Structure of the entry payload within a leaf node.
00034  */
00035 struct ccn_btree_content_payload {
00036     unsigned char magic[1];     /**< CCN_BT_CONTENT_MAGIC */
00037     unsigned char ctype[3];     /**< Type */
00038     unsigned char cobsz[4];     /**< Size in bytes of ContentObject */
00039     unsigned char ncomp[2];     /**< number of name components */
00040     unsigned char flags[1];     /**< CCN_RCFLAG_* */
00041     unsigned char ttpad[1];     /**< Reserved until 20 Aug 4147 07:32:16 GMT */
00042     unsigned char timex[6];     /**< Timestamp from content object */
00043     unsigned char actim[6];     /**< Accession time, Timestamp format */
00044     unsigned char cobid[8];     /**< Where the actual ContentObject is */
00045     unsigned char ppkdg[32];    /**< PublisherPublicKeyDigest */
00046 };
00047 #define CCN_BT_CONTENT_MAGIC    0xC0
00048 #define CCN_RCFLAG_LASTBLOCK    0x80
00049 #define CCN_RCFLAG_STALE        0x01
00050 
00051 /**
00052  *  Logical structure of the entry within a leaf node.
00053  */
00054 struct ccn_btree_content_entry {
00055     struct ccn_btree_content_payload ce;
00056     struct ccn_btree_entry_trailer trailer;
00057 };
00058 
00059 /* Match an interest against a btree entry, assuming a prefix match. */
00060 int ccn_btree_match_interest(struct ccn_btree_node *node, int ndx,
00061                              const unsigned char *interest_msg,
00062                              const struct ccn_parsed_interest *pi,
00063                              struct ccn_charbuf *scratch);
00064 
00065 /* Insert a ContentObject into a btree node */
00066 int ccn_btree_insert_content(struct ccn_btree_node *node, int ndx,
00067                              uint_least64_t cobid,
00068                              const unsigned char *content_object,
00069                              struct ccn_parsed_ContentObject *pc,
00070                              struct ccn_charbuf *flatname);
00071 
00072 /* cobid accessor */
00073 uint_least64_t ccn_btree_content_cobid(struct ccn_btree_node *node, int ndx);
00074 int ccn_btree_content_set_cobid(struct ccn_btree_node *node, int ndx,
00075                                 uint_least64_t cobid);
00076 /* cobsz accessor */
00077 int ccn_btree_content_cobsz(struct ccn_btree_node *node, int ndx);
00078 
00079 
00080 /**
00081  * Flat name representation
00082  *
00083  * Within the btree-based index, the name is stored in a representation
00084  * different than the ccnb encoding that is used on the wire.
00085  * This encoding is designed so that simple lexical ordering on
00086  * flatname byte arrays corresponds precisely with ccn's CanonicalOrdering
00087  * of Names.
00088  *
00089  * In the flatname representation, the bytes that constitute each
00090  * Component are prepended by a length indicator that occupies one or
00091  * more bytes.  The high-order bit is used to mark the end of the length
00092  * indicator, with 0 marking the last byte. The low order 7 bits of each
00093  * of these bytes are concatenated together, in big endian order, to form
00094  * the length.
00095  *
00096  * For example:
00097  * 0x00                => the zero-length component
00098  * 0x01 0x41           => the component "A"
00099  * 0x7F 0xC1 ...       => a component 127 bytes long that starts with "%C1"
00100  * 0x81 0x00 0x39 ...  => a component 128 bytes long that starts with "9"
00101  * 0xff 0x3F 0x30 ...  => a component 16383 bytes long that starts with "0"
00102  *
00103  * Length indicators larger than this are possible in theory, but unlikely
00104  * to come up in practice. Nontheless, we do allow 3-byte length indicators.
00105  */
00106 
00107 /* Name flattening */
00108 int ccn_flatname_append_component(struct ccn_charbuf *dst,
00109                                   const unsigned char *comp, size_t size);
00110 int ccn_flatname_append_from_ccnb(struct ccn_charbuf *dst,
00111                                   const unsigned char *ccnb, size_t size,
00112                                   int skip, int count);
00113 int ccn_flatname_from_ccnb(struct ccn_charbuf *dst,
00114                            const unsigned char *ccnb, size_t size);
00115 
00116 /* Name unflattening */
00117 int ccn_name_append_flatname(struct ccn_charbuf *dst,
00118                              const unsigned char *flatname, size_t size,
00119                              int skip, int count);
00120 int ccn_uri_append_flatname(struct ccn_charbuf *uri,
00121                              const unsigned char *flatname, size_t size,
00122                              int includescheme);
00123 /* Flatname accessors */
00124 int ccn_flatname_ncomps(const unsigned char *flatname, size_t size);
00125 
00126 /* Flatname comparison */
00127 int ccn_flatname_charbuf_compare(struct ccn_charbuf *a, struct ccn_charbuf *b);
00128 int ccn_flatname_compare(const unsigned char *a, size_t al,
00129                          const unsigned char *b, size_t bl);
00130 
00131 /*
00132  * Parse the component delimiter from the start of a flatname
00133  * Returns -1 for error, 0 nothing left, or compsize * 4 + delimsize
00134  */
00135 int ccn_flatname_next_comp(const unsigned char *flatname, size_t size);
00136 /** Get delimiter size from return value of ccn_flatname_next_comp */
00137 #define CCNFLATDELIMSZ(rnc) ((rnc) & 3)
00138 /** Get data size from return value of ccn_flatname_next_comp */
00139 #define CCNFLATDATASZ(rnc) ((rnc) >> 2)
00140 /** Get total delimited size from return value of ccn_flatname_next_comp */
00141 #define CCNFLATSKIP(rnc) (CCNFLATDELIMSZ(rnc) + CCNFLATDATASZ(rnc))
00142 
00143 #endif

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