Example #1
0
extern struct SyncHashCacheEntry *
SyncHashEnter(struct SyncHashCacheHead *head,
              const unsigned char *xp, ssize_t xs,
              enum SyncHashState set) {
    if (xp == NULL || xs <= 0) return NULL;
    uint32_t h = SyncSmallHash(xp, xs);
    uint32_t hx = h % head->mod;
    struct SyncHashCacheEntry *old = head->ents[hx];
    struct SyncHashCacheEntry *ent = old;
    head->probes = head->probes + 1;
    while (ent != NULL) {
        if (h == ent->small) {
            // probably equal, but we have to check
            ssize_t cmp = SyncCmpHashesRaw(xp, xs, ent->hash->buf, ent->hash->length);
            if (cmp == 0) {
                ent->state |= set;
                return ent;
            }
        }
        ent = ent->next;
    }
    head->misses = head->misses + 1;
    if (ent == NULL) {
        uintmax_t index = head->lastIndex + 1;
        head->lastIndex = index;
        head->probes = head->probes + 1;
        head->misses = head->misses + 1;
        ent = NEW_STRUCT(1, SyncHashCacheEntry);
        ent->lastUsed = SyncCurrentTime();
        ent->head = head;
        ent->next = old;
        ent->small = h;
        ent->hash = ccn_charbuf_create();
        ent->index = index;
        ccn_charbuf_append(ent->hash, xp, xs);
        head->ents[hx] = ent;
        head->len++;
    }
    ent->state |= set;
    return ent;
}
Example #2
0
extern struct SyncBaseStruct *
SyncNewBase(struct ccnr_handle *ccnr,
            struct ccn *ccn,
            struct ccn_schedule *sched) {
    sync_time now = SyncCurrentTime();
    struct SyncBaseStruct *base = NEW_STRUCT(1, SyncBaseStruct);
    base->ccnr = ccnr;
    base->ccn = ccn;
    base->sched = sched;
    struct SyncPrivate *priv = NEW_STRUCT(1, SyncPrivate);
    base->priv = priv;
    priv->topoAccum = SyncAllocNameAccum(4);
    priv->prefixAccum = SyncAllocNameAccum(4);
    priv->sliceCmdPrefix = ccn_charbuf_create();
    priv->localHostPrefix = ccn_charbuf_create();
    priv->comps = ccn_indexbuf_create();
    priv->stableTarget = CCNR_NULL_HWM;
    priv->stableStored = CCNR_NULL_HWM;
    priv->lastStable = now;
    priv->lastCacheClean = now;
    ccn_name_from_uri(priv->localHostPrefix, "/%C1.M.S.localhost");
    ccn_name_from_uri(priv->sliceCmdPrefix, "/%C1.M.S.localhost/%C1.S.cs");
    return base;
}
Example #3
0
     res |= ccn_name_append(prefix, ce->hash->buf, ce->hash->length);
 } else {
     // append an empty component
     res |= ccn_name_append(prefix, "", 0);
 }
 struct SyncNameAccum *excl = SyncExclusionsFromHashList(root, NULL, ch->hashSeen);
 struct ccn_charbuf *template = SyncGenInterest(NULL,
                                                base->priv->syncScope,
                                                base->priv->fetchLifetime,
                                                -1, -1, excl);
 SyncFreeNameAccumAndNames(excl);
 struct ccn_closure *action = calloc(1, sizeof(*action));
 struct sync_diff_fetch_data *fetch_data = calloc(1, sizeof(*fetch_data));
 fetch_data->diff_data = diff_data;
 fetch_data->action = action;
 fetch_data->startTime = SyncCurrentTime();
 // note: no ce available yet
 action->data = fetch_data;
 action->intdata = LF_ADVISE;
 action->p = &my_response;
 fetch_data->next = ch->fetch_data;
 ch->fetch_data = fetch_data;
 res |= ccn_express_interest(ccn, prefix, action, template);
 ccn_charbuf_destroy(&template);
 if (ch->debug >= CCNL_FINE) {
     SyncNoteUri(diff_data->root, here, "start_interest", prefix);
 }
 ccn_charbuf_destroy(&prefix);
 if (res < 0) {
     SyncNoteFailed(root, here, "ccn_express_interest failed", __LINE__);
     // return the resources, must free fd first!