SyncRoot.h

Go to the documentation of this file.
00001 /**
00002  * @file sync/SyncRoot.h
00003  *  
00004  * Copyright (C) 2011 Palo Alto Research Center, Inc.
00005  *
00006  * Part of CCNx Sync.
00007  *
00008  * This library is free software; you can redistribute it and/or modify it
00009  * under the terms of the GNU Lesser General Public License version 2.1
00010  * as published by the Free Software Foundation.
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014  * Lesser General Public License for more details. You should have received
00015  * a copy of the GNU Lesser General Public License along with this library;
00016  * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
00017  * Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef CCN_SyncRoot
00021 #define CCN_SyncRoot
00022 
00023 #include <ccn/charbuf.h>
00024 #include "SyncBase.h"
00025 
00026 struct SyncHashCacheHead;  // defined in SyncHashCache.h
00027 struct SyncNameAccum;      // defined in SyncUtil.h
00028 struct SyncActionData;     // defined in SyncActions.h
00029 struct SyncCompareData;    // defined in SyncActions.c
00030 struct SyncUpdateData;     // defined in SyncActions.c
00031 struct SyncRootPrivate;    // private to SyncRoot.c
00032 
00033 /**
00034  * A SyncRootStruct object holds the necessary data for a root sync tree.
00035  */
00036 struct SyncRootStruct {
00037     unsigned rootId;                      /**< root Id for reporting */
00038     struct SyncBaseStruct *base;          /**< Sync Agent base */
00039     struct SyncRootStruct *next;          /**< next root in our list */
00040     struct SyncRootPrivate *priv;         /**< private to SyncRoot */
00041     struct SyncHashCacheHead *ch;         /**< cache head */
00042     struct ccn_charbuf *topoPrefix;       /**< Sync Protocol topo prefix */
00043     struct ccn_charbuf *namingPrefix;     /**< Sync Protocol naming prefix */
00044     struct SyncNameAccum *filter;         /**< filter clauses */
00045     struct ccn_charbuf *currentHash;      /**< current top-level cache hash */
00046     struct SyncNameAccum *namesToAdd;     /**< names needing addition to root */
00047     struct SyncNameAccum *namesToFetch;   /**< names needing contents fetch */
00048     struct SyncActionData *actions;       /**< data for pending interests */
00049     struct SyncCompareData *compare;      /**< data for doing sync tree comparison */
00050     struct SyncUpdateData *update;        /**< data for doing sync tree updates */
00051     struct ccn_charbuf *sliceCoding;      /**< ccnb encoding for the description */
00052     struct ccn_charbuf *sliceHash;        /**< the raw hash of the sliceCoding */
00053 };
00054 
00055 /**
00056  * namesToAdd has the names where content is known to be present.  These names
00057  * should come from SyncNotifyContent.
00058  * The name storage belongs to the root.
00059  *
00060  * namesToFetch has the names where content should be fetched.  Once content is
00061  * fetched and stored to the repo the names should be appended to namesToAdd.
00062  * The name storage belongs to the root.
00063  */
00064 
00065 ///////////////////////////////////////////////////////
00066 // Routines for working with sync tree roots
00067 ///////////////////////////////////////////////////////
00068 
00069 /**
00070  * Creates a new root structure and adds it to the base.
00071  * The topoPrefix and namingPrefix will be copied and canonicalized.
00072  * The filter (and the names in it) will also be copied and canonicalized.
00073  * Canonicalized data is owned by the base.
00074  * @returns the new root object
00075  */
00076 struct SyncRootStruct *
00077 SyncAddRoot(struct SyncBaseStruct *base,
00078             const struct ccn_charbuf *topoPrefix,
00079             const struct ccn_charbuf *namingPrefix,
00080             struct SyncNameAccum *filter);
00081 
00082 /**
00083  * Removes the root from the base, and frees up associated storage.
00084  * Requires that there are no active comparisons.
00085  * Deactivates all pending interests.
00086  * @returns NULL if the root was removed, the root itself if not removed.
00087  */
00088 struct SyncRootStruct *
00089 SyncRemRoot(struct SyncRootStruct *root);
00090 
00091 /**
00092  * Parse a content object representing a config slice,
00093  * and if successful add it to the base.
00094  * @returns the new root if successful, NULL otherwise.
00095  */
00096 struct SyncRootStruct *
00097 SyncRootDecodeAndAdd(struct SyncBaseStruct *base,
00098                      struct ccn_buf_decoder *d);
00099 
00100 /**
00101  * Appends the ccnb encoding for a config slice to the provided cb.
00102  * @returns -1 for failure, 0 for success.
00103  */
00104 int
00105 SyncRootAppendSlice(struct ccn_charbuf *cd, struct SyncRootStruct *root);
00106 
00107 enum SyncRootLookupCode {
00108     SyncRootLookupCode_none,        /**< not covered by this root */
00109     SyncRootLookupCode_covered,     /**< covered by this root */
00110     SyncRootLookupCode_error        /**< error in the name or the state */
00111 };
00112     
00113 /**
00114  * @returns the top entry, if the root hash has been established for this root,
00115  * otherwise returns NULL.
00116  */
00117 struct SyncHashCacheEntry *
00118 SyncRootTopEntry(struct SyncRootStruct *root);
00119 
00120 /**
00121  * Tests to see if the name is covered by this root.
00122  * Useful for testing full names given by the Repo.
00123  * The topoPrefix does not participate, but the filter does.
00124  * @returns a code indicating the result
00125  */
00126 enum SyncRootLookupCode
00127 SyncRootLookupName(struct SyncRootStruct *root,
00128                     const struct ccn_charbuf *name);
00129 
00130 #endif

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