コード例 #1
0
ファイル: athena_LRUContentStore.c プロジェクト: PARC/Athena
static bool
_athenaLRUContentStore_PutContentObject(AthenaContentStoreImplementation *store, const CCNxContentObject *content)
{
    AthenaLRUContentStore *impl = (AthenaLRUContentStore *) store;

    // If there's no capacity at all, just return now.
    if (impl->maxSizeInBytes <= 0) {
        return false;
    }

    // Check to see if the ContentObject is expired. If so, don't bother to cache it.
    if (ccnxContentObject_HasExpiryTime(content)) {
        if (ccnxContentObject_GetExpiryTime(content) <= parcClock_GetTime(impl->wallClock)) {
            // the expiration time is now or earlier, so don't bother adding it.
            return false;
        }
    }

    _AthenaLRUContentStoreEntry *newEntry = _athenaLRUContentStoreEntry_Create(content);

    bool result = _athenaLRUContentStore_PutLRUContentStoreEntry(store, newEntry);

    if (result == false) {
        // We didn't have enough room in the store to add the new item.
    }

    _athenaLRUContentStoreEntry_Release(&newEntry);

    return result;
}
コード例 #2
0
ファイル: athena_LRUContentStore.c プロジェクト: PARC/Athena
static _AthenaLRUContentStoreEntry *
_athenaLRUContentStoreEntry_Create(const CCNxContentObject *contentObject)
{
    _AthenaLRUContentStoreEntry *result = parcObject_CreateAndClearInstance(_AthenaLRUContentStoreEntry);

    if (result != NULL) {
        result->contentObject = ccnxContentObject_Acquire(contentObject);
        result->next = NULL;
        result->prev = NULL;
        result->sizeInBytes = _calculateSizeOfContentObject(contentObject);
        result->hasExpiryTime = false;
        result->hasRecommendedCacheTime = false;

        if (ccnxContentObject_HasExpiryTime(contentObject)) {
            result->hasExpiryTime = true;
            result->expiryTime = ccnxContentObject_GetExpiryTime(contentObject);
        }

        // TODO:
        // Check if the CO has an RCT and set the flags and init the values appropriately.
        result->hasRecommendedCacheTime = false;

        // TODO:
        // Check if the CO has a KeyId and set the fields appropriately.
        result->hasKeyId = false;

        // TODO:
        // Calculate the CO's contentObjectHash and set the fields appropriately
        result->hasContentObjectHash = false;
    }
    return result;
}
コード例 #3
0
LONGBOW_TEST_CASE(Global, ccnxContentObject_SetGetExpiryTime)
{
    CCNxName *name = ccnxName_CreateFromCString("lci:/hello/dolly");
    PARCBuffer *payload = parcBuffer_WrapCString("hello");

    // Use a V1 ContentObject, as V0 doesn't support ExpiryTime
    CCNxContentObject *contentObject =
        ccnxContentObject_CreateWithImplAndPayload(&CCNxContentObjectFacadeV1_Implementation,
                                                   name, CCNxPayloadType_DATA, payload);

    assertFalse(ccnxContentObject_HasExpiryTime(contentObject), "Expected no expiration time by default");

    uint64_t expiryTime = 1010101ULL;
    ccnxContentObject_SetExpiryTime(contentObject, expiryTime);

    assertTrue(ccnxContentObject_HasExpiryTime(contentObject), "Expected the expiryTime to be set");
    uint64_t retrievedTime = ccnxContentObject_GetExpiryTime(contentObject);
    assertTrue(expiryTime == retrievedTime, "Did not retrieve expected expiryTime from ContentObject");

    parcBuffer_Release(&payload);
    ccnxName_Release(&name);
    ccnxContentObject_Release(&contentObject);
}
コード例 #4
0
LONGBOW_TEST_CASE(Global, ccnxContentObject_HasExpiryTime)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/hello/dolly");
    PARCBuffer *payload = parcBuffer_WrapCString("hello");

    // Use a V1 ContentObject, as V0 doesn't support ExpiryTime
    CCNxContentObject *contentObject =
        ccnxContentObject_CreateWithImplAndPayload(&CCNxContentObjectFacadeV1_Implementation,
                                                   name, CCNxPayloadType_DATA, payload);


    assertFalse(ccnxContentObject_HasExpiryTime(contentObject), "Expected no expiration time by default");

    parcBuffer_Release(&payload);
    ccnxName_Release(&name);
    ccnxContentObject_Release(&contentObject);
}