LONGBOW_TEST_CASE(Global, ccnxInterest_SetContentObjectHashRestriction) { CCNxName *name = ccnxName_CreateFromURI("lci:/name"); PARCBuffer *coh = parcBuffer_Allocate(8); parcBuffer_PutUint64(coh, 77573L); CCNxInterest *interest = ccnxInterest_Create(name, CCNxInterestDefault_LifetimeMilliseconds, NULL, NULL); PARCBuffer *actual = ccnxInterest_GetContentObjectHashRestriction(interest); assertNull(actual, "Expected retrieved ContentObjectHash to be initially NULL"); ccnxInterest_SetContentObjectHashRestriction(interest, coh); actual = ccnxInterest_GetContentObjectHashRestriction(interest); assertTrue(actual == coh, "Expected retrieved ContentObjectHash to be the same as assigned"); // Re-setting is not yet supported. At the moment, you can only put the COHR once. // Now change it, and validate. //PARCBuffer *coh2 = parcBuffer_Allocate(8); //parcBuffer_PutUint64(coh2, 3262L); //ccnxInterest_SetContentObjectHashRestriction(interest, coh2); //actual = ccnxInterest_GetContentObjectHashRestriction(interest); //assertTrue(actual == coh2, "Expected retrieved ContentObjectHash to be the same as assigned"); ccnxName_Release(&name); ccnxInterest_Release(&interest); parcBuffer_Release(&coh); //parcBuffer_Release(&coh2); }
static CCNxContentObject * //_athenaLRUContentStore_GetMatch(AthenaContentStoreImplementation *store, const CCNxName *name, const PARCBuffer *keyIdRestriction, // const PARCBuffer *contentObjectHash) _athenaLRUContentStore_GetMatch(AthenaContentStoreImplementation *store, const CCNxInterest *interest) { CCNxContentObject *result = NULL; AthenaLRUContentStore *impl = (AthenaLRUContentStore *) store; _AthenaLRUContentStoreEntry *entry = NULL; CCNxName *name = ccnxInterest_GetName(interest); PARCBuffer *contentObjectHashRestriction = ccnxInterest_GetContentObjectHashRestriction(interest); PARCBuffer *keyIdRestriction = ccnxInterest_GetKeyIdRestriction(interest); if (contentObjectHashRestriction != NULL) { PARCObject *nameAndHashKey = _createHashableKey(name, NULL, contentObjectHashRestriction); entry = (_AthenaLRUContentStoreEntry *) parcHashMap_Get(impl->tableByNameAndObjectHash, nameAndHashKey); parcObject_Release((PARCObject **) &nameAndHashKey); } if ((entry == NULL) && (keyIdRestriction != NULL)) { PARCObject *nameAndKeyIdKey = _createHashableKey(name, keyIdRestriction, NULL); entry = (_AthenaLRUContentStoreEntry *) parcHashMap_Get(impl->tableByNameAndKeyId, nameAndKeyIdKey); parcObject_Release((PARCObject **) &nameAndKeyIdKey); } if (entry == NULL) { PARCObject *nameKey = _createHashableKey(name, NULL, NULL); entry = (_AthenaLRUContentStoreEntry *) parcHashMap_Get(impl->tableByName, nameKey); parcObject_Release((PARCObject **) &nameKey); } // Matching is done. Now check for validity, if necessary. if (entry != NULL) { // We found matching content. Now make sure it's not expired before returning it. If it is expired, // remove it from the store and don't return anything. if (entry->hasExpiryTime && (entry->expiryTime < parcClock_GetTime(impl->wallClock))) { _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry); entry = NULL; } // XXX: TODO: Check that the KeyId, if any, was verified. } // At this point, the cached content is considered valid for responding with. Return it. if (entry != NULL) { result = entry->contentObject; // Update LRU so that the matched entry is at the top of the list. _moveContentStoreEntryToLRUHead(impl, entry); impl->stats.numMatchHits++; } else { impl->stats.numMatchMisses++; } return result; }
LONGBOW_TEST_CASE(Global, ccnxInterest_GetContentObjectHashRestriction) { CCNxName *name = ccnxName_CreateFromURI("lci:/name"); PARCBuffer *coh = parcBuffer_Allocate(8); parcBuffer_PutUint64(coh, 1234L); CCNxInterest *interest = ccnxInterest_Create(name, CCNxInterestDefault_LifetimeMilliseconds, NULL, coh); PARCBuffer *actual = ccnxInterest_GetContentObjectHashRestriction(interest); assertTrue(actual == coh, "Expected retrieved ContentObjectHash to be the same as assigned"); ccnxName_Release(&name); ccnxInterest_Release(&interest); parcBuffer_Release(&coh); }