SyncUtil.c File Reference

Part of CCNx Sync. More...

Go to the source code of this file.

Defines

#define SET_ERR(d)   SyncSetDecodeErr(d, -__LINE__)

Functions

void SyncNoteErr (const char *msg)
int SyncSetDecodeErr (struct ccn_buf_decoder *d, int val)
int SyncCheckDecodeErr (struct ccn_buf_decoder *d)
sync_time SyncCurrentTime (void)
int64_t SyncDeltaTime (sync_time mt1, sync_time mt2)
struct ccn_buf_decoderSyncInitDecoderFromCharbufRange (struct ccn_buf_decoder *d, const struct ccn_charbuf *cb, ssize_t start, ssize_t stop)
struct ccn_buf_decoderSyncInitDecoderFromCharbuf (struct ccn_buf_decoder *d, const struct ccn_charbuf *cb, ssize_t start)
int SyncDecodeHexDigit (char c)
int SyncDecodeUriChar (char c)
char * SyncHexStr (const unsigned char *cp, size_t sz)
int SyncNoteFailed (struct SyncRootStruct *root, char *where, char *why, int line)
void SyncNoteSimple (struct SyncRootStruct *root, char *where, char *s1)
void SyncNoteSimple2 (struct SyncRootStruct *root, char *where, char *s1, char *s2)
void SyncNoteSimple3 (struct SyncRootStruct *root, char *where, char *s1, char *s2, char *s3)
void SyncNoteUri (struct SyncRootStruct *root, char *where, char *why, struct ccn_charbuf *name)
void SyncNoteUriBase (struct SyncBaseStruct *base, char *where, char *why, struct ccn_charbuf *name)
int SyncCmpNamesInner (struct ccn_buf_decoder *xx, struct ccn_buf_decoder *yy)
 compare two names advances both decoders, but early exit may leave them not fully over the names decoder error flags may be useful, though, if any errors occur
int SyncCmpNames (const struct ccn_charbuf *cbx, const struct ccn_charbuf *cby)
int SyncIsName (const struct ccn_charbuf *cb)
 tests to see if charbuf refers to a name
int SyncComponentCount (const struct ccn_charbuf *name)
int SyncPatternMatch (const struct ccn_charbuf *pattern, const struct ccn_charbuf *name, int start)
 simple pattern matching, where the pattern may contain components with a single 255 byte to match a single name component
int SyncPrefixMatch (const struct ccn_charbuf *prefix, const struct ccn_charbuf *name, int start)
int SyncComponentMatch (const struct ccn_charbuf *x, const struct ccn_charbuf *y)
int SyncGetComponentPtr (const struct ccn_charbuf *src, int comp, const unsigned char **xp, ssize_t *xs)
 finds the bytes for a component (not including the tag) src must be a name, comp the component index
int SyncAppendAllComponents (struct ccn_charbuf *dst, const struct ccn_charbuf *src)
 appends components from src to dst (both must be names)
struct ccn_charbufSyncNameForIndexbuf (const unsigned char *buf, struct ccn_indexbuf *comps)
 Convenience routine to make a name from a ccn_indexbuf.
struct ccn_charbufSyncUriForName (struct ccn_charbuf *name)
 Convenience routine to make a uri for a name.
void SyncGetHashPtr (const struct ccn_buf_decoder *hd, const unsigned char **xp, ssize_t *xs)
 finds the hash code, storing the pointer to *xp and the length to *xs if the hash is valid (test for *xs != 0 to be sure) a hash code may be a ContentHash, or the last component of a Name (for convenience, a Component may also be used) non-destructive to the decoder no error codes, but a pointer is set only for valid cases
ssize_t SyncCmpHashesRaw (const unsigned char *xp, ssize_t xs, const unsigned char *yp, ssize_t ys)
void SyncAccumHashRaw (struct SyncLongHashStruct *hp, const unsigned char *xp, size_t xs)
void SyncAccumHashInner (struct SyncLongHashStruct *hp, const struct ccn_buf_decoder *d)
void SyncAccumHash (struct SyncLongHashStruct *hp, const struct ccn_charbuf *cb)
struct ccn_charbufSyncLongHashToBuf (const struct SyncLongHashStruct *hp)
uint32_t SyncSmallHash (const unsigned char *xp, ssize_t xs)
int SyncAppendTaggedNumber (struct ccn_charbuf *cb, enum ccn_dtag dtag, unsigned val)
int SyncAppendRandomBytes (struct ccn_charbuf *cb, int n)
int SyncAppendRandomHash (struct ccn_charbuf *cb, int n)
int SyncAppendRandomName (struct ccn_charbuf *cb, int nComp, int maxCompLen)
int SyncAppendElementInner (struct ccn_charbuf *cb, struct ccn_buf_decoder *d)
int SyncAppendElement (struct ccn_charbuf *dst, const struct ccn_charbuf *src)
struct ccn_charbufSyncExtractName (struct ccn_buf_decoder *d)
struct ccn_charbufSyncCopyName (const struct ccn_charbuf *name)
unsigned SyncParseUnsigned (struct ccn_buf_decoder *d, enum ccn_dtag dtag)
ssize_t SyncParseHash (struct ccn_buf_decoder *d)
ssize_t SyncParseName (struct ccn_buf_decoder *d)
struct SyncNameAccumSyncAllocNameAccum (int lim)
struct SyncNameAccumSyncFreeNameAccum (struct SyncNameAccum *na)
 frees the name accum, but not the names
struct SyncNameAccumSyncFreeNameAccumAndNames (struct SyncNameAccum *na)
 frees the name accum and all of the names
int SyncNameAccumSorter (IndexSorter_Base base, IndexSorter_Index x, IndexSorter_Index y)
 default sorter callback for a name accum uses CCN standard name order
int SyncNameAccumAppend (struct SyncNameAccum *na, struct ccn_charbuf *name, intmax_t data)
 appends a new name with associated data important: the name is not copied!
struct ccn_charbufSyncNameAccumCanon (struct SyncNameAccum *na, const struct ccn_charbuf *name)
 canonicalizes a name with respect to the given name accum should be used for relatively small canon sets
struct SyncNodeAccumSyncAllocNodeAccum (int lim)
struct SyncNodeAccumSyncFreeNodeAccum (struct SyncNodeAccum *na)
void SyncAccumNode (struct SyncNodeAccum *na, struct SyncNodeComposite *nc)
static int appendLifetime (struct ccn_charbuf *cb, int lifetime)
static int appendExclusions (struct ccn_charbuf *cb, struct SyncNameAccum *excl)
struct ccn_charbufSyncGenInterest (struct ccn_charbuf *name, int scope, int lifetime, int maxSuffix, int childPref, struct SyncNameAccum *excl)
 given a spec for the desired fields (scope, lifetime, maxSuffix, child are omitted if negative)
struct ccn_charbufSyncNameForLocalNode (struct SyncRootStruct *root, struct ccn_charbuf *hash)
 given a sync node hash,
int SyncPointerToContent (struct ccn_charbuf *cb, struct ccn_parsed_ContentObject *pco, const unsigned char **xp, size_t *xs)
 given a charbuf cb for a content object, with optional parsing offsets in pco, sets *xp and *xs with the pointer and length of the actual content bytes
struct ccn_charbufSyncSignBuf (struct SyncBaseStruct *base, struct ccn_charbuf *cb, struct ccn_charbuf *name, long fresh, int flags)
 given a charbuf cb and name for a content object, signs the bytes and
int SyncLocalRepoStore (struct SyncBaseStruct *base, struct ccn_charbuf *name, struct ccn_charbuf *content, int flags)
 given a sync node hash,
int SyncLocalRepoFetch (struct SyncBaseStruct *base, struct ccn_charbuf *name, struct ccn_charbuf *cb, struct ccn_parsed_ContentObject *pco)
 given a local repo name and a buffer to fill, fills cb with the content object (note: not the content itself) pco is filled as a useful side effect, but may be NULL

Variables

static int freshLimit = 30


Detailed Description

Part of CCNx Sync.

Copyright (C) 2011 Palo Alto Research Center, Inc.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Definition in file SyncUtil.c.


Define Documentation

#define SET_ERR (  )     SyncSetDecodeErr(d, -__LINE__)


Function Documentation

static int appendExclusions ( struct ccn_charbuf cb,
struct SyncNameAccum excl 
) [static]

Definition at line 990 of file SyncUtil.c.

Referenced by SyncGenInterest().

static int appendLifetime ( struct ccn_charbuf cb,
int  lifetime 
) [static]

Definition at line 974 of file SyncUtil.c.

Referenced by SyncGenInterest().

void SyncAccumHash ( struct SyncLongHashStruct hp,
const struct ccn_charbuf cb 
)

Definition at line 619 of file SyncUtil.c.

Referenced by MakeNodeFromNames(), SyncNodeAddName(), and testReadBuilder().

void SyncAccumHashInner ( struct SyncLongHashStruct hp,
const struct ccn_buf_decoder d 
)

Definition at line 606 of file SyncUtil.c.

Referenced by SyncAccumHash(), and SyncNodeAddNode().

void SyncAccumHashRaw ( struct SyncLongHashStruct hp,
const unsigned char *  xp,
size_t  xs 
)

Definition at line 574 of file SyncUtil.c.

Referenced by SyncAccumHashInner().

void SyncAccumNode ( struct SyncNodeAccum na,
struct SyncNodeComposite nc 
)

Definition at line 951 of file SyncUtil.c.

Referenced by MakeNodeFromNames(), and newNodeCommon().

struct SyncNameAccum* SyncAllocNameAccum ( int  lim  )  [read]

Returns:
a new name accum with at least lim space for names

Definition at line 831 of file SyncUtil.c.

Referenced by addNameFromCompare(), copyFilter(), exclusionsFromHashList(), readAndAccumNames(), sortNames(), SyncAddRoot(), SyncNewBase(), SyncRootDecodeAndAdd(), SyncUpdateRoot(), testRootBasic(), and UpdateAction().

struct SyncNodeAccum* SyncAllocNodeAccum ( int  lim  )  [read]

Definition at line 933 of file SyncUtil.c.

Referenced by nodeFromNodes(), and UpdateAction().

int SyncAppendAllComponents ( struct ccn_charbuf dst,
const struct ccn_charbuf src 
)

appends components from src to dst (both must be names)

Returns:
< 0 for an error

the number of components copied otherwise

Definition at line 466 of file SyncUtil.c.

Referenced by constructCommandPrefix(), and existingRootOp().

int SyncAppendElement ( struct ccn_charbuf dst,
const struct ccn_charbuf src 
)

Definition at line 755 of file SyncUtil.c.

Referenced by SyncEndComposite(), and SyncNodeAddName().

int SyncAppendElementInner ( struct ccn_charbuf cb,
struct ccn_buf_decoder d 
)

int SyncAppendRandomBytes ( struct ccn_charbuf cb,
int  n 
)

Definition at line 664 of file SyncUtil.c.

Referenced by SyncAppendRandomHash(), and SyncAppendRandomName().

int SyncAppendRandomHash ( struct ccn_charbuf cb,
int  n 
)

Definition at line 680 of file SyncUtil.c.

int SyncAppendRandomName ( struct ccn_charbuf cb,
int  nComp,
int  maxCompLen 
)

Definition at line 690 of file SyncUtil.c.

Referenced by testGenComposite().

int SyncAppendTaggedNumber ( struct ccn_charbuf cb,
enum ccn_dtag  dtag,
unsigned  val 
)

int SyncCheckDecodeErr ( struct ccn_buf_decoder d  ) 

ssize_t SyncCmpHashesRaw ( const unsigned char *  xp,
ssize_t  xs,
const unsigned char *  yp,
ssize_t  ys 
)

Definition at line 562 of file SyncUtil.c.

Referenced by SyncHashEnter(), and SyncHashLookup().

int SyncCmpNames ( const struct ccn_charbuf cbx,
const struct ccn_charbuf cby 
)

int SyncCmpNamesInner ( struct ccn_buf_decoder xx,
struct ccn_buf_decoder yy 
)

compare two names advances both decoders, but early exit may leave them not fully over the names decoder error flags may be useful, though, if any errors occur

Definition at line 183 of file SyncUtil.c.

Referenced by SyncCmpNames(), and SyncNodeCompareLeaf().

int SyncComponentCount ( const struct ccn_charbuf name  ) 

Returns:
number of components in the name

Definition at line 247 of file SyncUtil.c.

Referenced by SyncRegisterInterest(), SyncRootLookupName(), SyncSendRootAdviseInterest(), and SyncStartNodeFetch().

int SyncComponentMatch ( const struct ccn_charbuf x,
const struct ccn_charbuf y 
)

Returns:
number of components in the longest prefix of both x and y

-1 if there is a parsing error

Definition at line 405 of file SyncUtil.c.

Referenced by TryNodeSplit().

struct ccn_charbuf* SyncCopyName ( const struct ccn_charbuf name  )  [read]

sync_time SyncCurrentTime ( void   ) 

int SyncDecodeHexDigit ( char  c  ) 

Definition at line 103 of file SyncUtil.c.

Referenced by parseAndAccumName().

int SyncDecodeUriChar ( char  c  ) 

Definition at line 111 of file SyncUtil.c.

Referenced by parseAndAccumName().

int64_t SyncDeltaTime ( sync_time  mt1,
sync_time  mt2 
)

struct ccn_charbuf* SyncExtractName ( struct ccn_buf_decoder d  )  [read]

Definition at line 763 of file SyncUtil.c.

Referenced by SyncParseComposite(), and SyncRootDecodeAndAdd().

struct SyncNameAccum* SyncFreeNameAccum ( struct SyncNameAccum na  )  [read]

frees the name accum, but not the names

Returns:
NULL

Definition at line 840 of file SyncUtil.c.

Referenced by exclusionsFromHashList(), testReadBuilder(), testReader(), and testRootBasic().

struct SyncNameAccum* SyncFreeNameAccumAndNames ( struct SyncNameAccum na  )  [read]

frees the name accum and all of the names

Returns:
NULL

Definition at line 849 of file SyncUtil.c.

Referenced by destroyCompareData(), SyncFreeBase(), SyncRemRoot(), SyncRootDecodeAndAdd(), SyncSendRootAdviseInterest(), SyncStartCompareAction(), and UpdateAction().

struct SyncNodeAccum* SyncFreeNodeAccum ( struct SyncNodeAccum na  )  [read]

Definition at line 942 of file SyncUtil.c.

Referenced by nodeFromNodes(), and UpdateAction().

struct ccn_charbuf* SyncGenInterest ( struct ccn_charbuf name,
int  scope,
int  lifetime,
int  maxSuffix,
int  childPref,
struct SyncNameAccum excl 
) [read]

given a spec for the desired fields (scope, lifetime, maxSuffix, child are omitted if negative)

Returns:
the encoding for an interest

Definition at line 1020 of file SyncUtil.c.

Referenced by existingRootOp(), fetchStablePoint(), getFile(), putFile(), SyncHandleSlice(), SyncLocalRepoFetch(), SyncSendRootAdviseInterest(), SyncStartContentFetch(), SyncStartHeartbeat(), SyncStartNodeFetch(), and SyncStartSliceEnum().

int SyncGetComponentPtr ( const struct ccn_charbuf src,
int  comp,
const unsigned char **  xp,
ssize_t *  xs 
)

finds the bytes for a component (not including the tag) src must be a name, comp the component index

Returns:
< 0 for an error, 0 otherwise

Definition at line 442 of file SyncUtil.c.

Referenced by SyncHandleSlice().

void SyncGetHashPtr ( const struct ccn_buf_decoder hd,
const unsigned char **  xp,
ssize_t *  xs 
)

finds the hash code, storing the pointer to *xp and the length to *xs if the hash is valid (test for *xs != 0 to be sure) a hash code may be a ContentHash, or the last component of a Name (for convenience, a Component may also be used) non-destructive to the decoder no error codes, but a pointer is set only for valid cases

Definition at line 529 of file SyncUtil.c.

Referenced by cacheEntryForElem(), SyncAccumHashInner(), and SyncTreeWorkerPush().

char* SyncHexStr ( const unsigned char *  cp,
size_t  sz 
)

struct ccn_buf_decoder* SyncInitDecoderFromCharbuf ( struct ccn_buf_decoder d,
const struct ccn_charbuf cb,
ssize_t  start 
) [read]

struct ccn_buf_decoder* SyncInitDecoderFromCharbufRange ( struct ccn_buf_decoder d,
const struct ccn_charbuf cb,
ssize_t  start,
ssize_t  stop 
) [read]

int SyncIsName ( const struct ccn_charbuf cb  ) 

tests to see if charbuf refers to a name

Returns:
1 for a name, 0 otherwise

Definition at line 238 of file SyncUtil.c.

int SyncLocalRepoFetch ( struct SyncBaseStruct base,
struct ccn_charbuf name,
struct ccn_charbuf cb,
struct ccn_parsed_ContentObject pco 
)

given a local repo name and a buffer to fill, fills cb with the content object (note: not the content itself) pco is filled as a useful side effect, but may be NULL

Returns:
< 0 if the node fails

Definition at line 1154 of file SyncUtil.c.

Referenced by SyncCacheEntryFetch().

int SyncLocalRepoStore ( struct SyncBaseStruct base,
struct ccn_charbuf name,
struct ccn_charbuf content,
int  flags 
)

given a sync node hash,

Returns:
the local repo name for the node

Definition at line 1132 of file SyncUtil.c.

Referenced by SyncCacheEntryStore().

struct ccn_charbuf* SyncLongHashToBuf ( const struct SyncLongHashStruct hp  )  [read]

Definition at line 626 of file SyncUtil.c.

Referenced by SyncEndComposite(), SyncParseComposite(), testReadBuilder(), and UpdateAction().

int SyncNameAccumAppend ( struct SyncNameAccum na,
struct ccn_charbuf name,
intmax_t  data 
)

appends a new name with associated data important: the name is not copied!

Definition at line 884 of file SyncUtil.c.

Referenced by addNameFromCompare(), AddUpdateName(), exclusionsFromHashList(), parseAndAccumName(), sortNames(), SyncAddName(), SyncNameAccumCanon(), SyncRootDecodeAndAdd(), SyncTreeGenerateNames(), and testRootBasic().

struct ccn_charbuf* SyncNameAccumCanon ( struct SyncNameAccum na,
const struct ccn_charbuf name 
) [read]

canonicalizes a name with respect to the given name accum should be used for relatively small canon sets

Returns:
an equal name if it was in the accum

a copy of the name (and enters it) if no equal name was in the accum

Definition at line 909 of file SyncUtil.c.

Referenced by SyncAddRoot().

int SyncNameAccumSorter ( IndexSorter_Base  base,
IndexSorter_Index  x,
IndexSorter_Index  y 
)

default sorter callback for a name accum uses CCN standard name order

Definition at line 869 of file SyncUtil.c.

Referenced by sortNames(), SyncUpdateRoot(), and testReader().

struct ccn_charbuf* SyncNameForIndexbuf ( const unsigned char *  buf,
struct ccn_indexbuf comps 
) [read]

Convenience routine to make a name from a ccn_indexbuf.

The storage for the returned charbuf is owned by the caller.

Returns:
a charbuf for the name (NULL if an error)

Definition at line 495 of file SyncUtil.c.

Referenced by SyncRootAdviseResponse().

struct ccn_charbuf* SyncNameForLocalNode ( struct SyncRootStruct root,
struct ccn_charbuf hash 
) [read]

given a sync node hash,

Returns:
the local repo name for the node

Definition at line 1054 of file SyncUtil.c.

Referenced by SyncCacheEntryFetch(), and SyncCacheEntryStore().

void SyncNoteErr ( const char *  msg  ) 

int SyncNoteFailed ( struct SyncRootStruct root,
char *  where,
char *  why,
int  line 
)

void SyncNoteSimple ( struct SyncRootStruct root,
char *  where,
char *  s1 
)

void SyncNoteSimple2 ( struct SyncRootStruct root,
char *  where,
char *  s1,
char *  s2 
)

void SyncNoteSimple3 ( struct SyncRootStruct root,
char *  where,
char *  s1,
char *  s2,
char *  s3 
)

Definition at line 158 of file SyncUtil.c.

Referenced by SyncInterestArrived().

void SyncNoteUri ( struct SyncRootStruct root,
char *  where,
char *  why,
struct ccn_charbuf name 
)

void SyncNoteUriBase ( struct SyncBaseStruct base,
char *  where,
char *  why,
struct ccn_charbuf name 
)

Definition at line 171 of file SyncUtil.c.

Referenced by SyncLocalRepoFetch(), and SyncLocalRepoStore().

ssize_t SyncParseHash ( struct ccn_buf_decoder d  ) 

Definition at line 805 of file SyncUtil.c.

Referenced by SyncParseComposite().

ssize_t SyncParseName ( struct ccn_buf_decoder d  ) 

Definition at line 812 of file SyncUtil.c.

Referenced by SyncParseComposite().

unsigned SyncParseUnsigned ( struct ccn_buf_decoder d,
enum ccn_dtag  dtag 
)

Definition at line 790 of file SyncUtil.c.

Referenced by SyncParseComposite(), SyncRootDecodeAndAdd(), and testRootBasic().

int SyncPatternMatch ( const struct ccn_charbuf pattern,
const struct ccn_charbuf name,
int  start 
)

simple pattern matching, where the pattern may contain components with a single 255 byte to match a single name component

Returns:
number of matching components in the pattern if the name (starting at component index start) matches the prefix,

-1 if there is a parsing error or no match

Definition at line 269 of file SyncUtil.c.

Referenced by SyncRootLookupName().

int SyncPointerToContent ( struct ccn_charbuf cb,
struct ccn_parsed_ContentObject pco,
const unsigned char **  xp,
size_t *  xs 
)

given a charbuf cb for a content object, with optional parsing offsets in pco, sets *xp and *xs with the pointer and length of the actual content bytes

Returns:
< 0 for failure

Definition at line 1070 of file SyncUtil.c.

Referenced by existingRootOp(), fetchStablePoint(), and SyncHandleSlice().

int SyncPrefixMatch ( const struct ccn_charbuf prefix,
const struct ccn_charbuf name,
int  start 
)

Returns:
number of components in the prefix if the name (starting at component index start) matches the prefix,

-1 if there is a parsing error or no match

Definition at line 344 of file SyncUtil.c.

Referenced by SyncHandleSlice(), SyncNotifyContent(), and SyncRootLookupName().

int SyncSetDecodeErr ( struct ccn_buf_decoder d,
int  val 
)

Definition at line 57 of file SyncUtil.c.

Referenced by SyncExtractName(), and SyncGetHashPtr().

struct ccn_charbuf* SyncSignBuf ( struct SyncBaseStruct base,
struct ccn_charbuf cb,
struct ccn_charbuf name,
long  fresh,
int  flags 
) [read]

given a charbuf cb and name for a content object, signs the bytes and

Returns:
the signed buffer (NULL for failure)

Definition at line 1087 of file SyncUtil.c.

Referenced by storeStablePoint(), SyncInterestArrived(), and SyncLocalRepoStore().

uint32_t SyncSmallHash ( const unsigned char *  xp,
ssize_t  xs 
)

Definition at line 636 of file SyncUtil.c.

Referenced by SyncHashEnter(), and SyncHashLookup().

struct ccn_charbuf* SyncUriForName ( struct ccn_charbuf name  )  [read]

Convenience routine to make a uri for a name.

The storage for the returned charbuf is owned by the caller.

Returns:
the charbuf with the uri for the name (NULL if an error)

Definition at line 518 of file SyncUtil.c.

Referenced by existingRootOp(), sendSlice(), SyncNoteUri(), SyncNoteUriBase(), SyncNotifyContent(), and SyncRegisterInterests().


Variable Documentation

int freshLimit = 30 [static]

Definition at line 39 of file SyncUtil.c.

Referenced by SyncSignBuf().


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