コード例 #1
0
/**
 * Wait for a response to a previously issued Interest. This function reads from the specified Portal
 * until the requested content is fully received. It's not very clever, as it ignores all incoming
 * portal message types except those that are CCNxContentObjects.
 *
 * @param portal An instance of CCNxPortal to read from.
 *
 * @return true If the requested content has been fully received, false otherwise.
 */
static bool
_receiveResponseToIssuedInterest(CCNxPortal *portal, const CCNxName *domainPrefix)
{
    bool isTransferComplete = false;

    while (isTransferComplete == false && ccnxPortal_IsError(portal) == false) {
        CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);

        if (response != NULL) {
            if (ccnxMetaMessage_IsContentObject(response)) {
                CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response);

                // Receive the content message. This returns the number of blocks remaining
                // in the transfer. If it returns 0, it was the final block of the content
                // and we're done.

                if (_receiveContentObject(contentObject, domainPrefix) == 0) {
                    isTransferComplete = true;
                }
            }
            ccnxMetaMessage_Release(&response);
        }
    }

    return isTransferComplete;
}
コード例 #2
0
LONGBOW_TEST_CASE(Local, _athenaLRUContentStore_ProcessMessage_StatHits)
{
    AthenaLRUContentStore *impl = _createLRUContentStore();

    CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthena_ContentStore "/stat/hits");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);
    ccnxInterest_Release(&interest);

    CCNxMetaMessage *response = _athenaLRUContentStore_ProcessMessage(impl, message);

    assertNotNull(response, "Expected a response to ProcessMessage()");
    assertTrue(ccnxMetaMessage_IsContentObject(response), "Expected a content object");

    CCNxContentObject *content = ccnxMetaMessage_GetContentObject(response);

    PARCBuffer *payload = ccnxContentObject_GetPayload(content);
    parcBuffer_Display(payload, 0);

    ccnxMetaMessage_Release(&message);
    ccnxMetaMessage_Release(&response);
    _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl);
}
コード例 #3
0
ファイル: athena.c プロジェクト: chris-wood/ghost
void
athena_ProcessMessage(Athena *athena, CCNxMetaMessage *ccnxMessage, PARCBitVector *ingressVector)
{
    if (ccnxMetaMessage_IsInterest(ccnxMessage)) {
        const char *name = ccnxName_ToString(ccnxInterest_GetName(ccnxMessage));
        parcLog_Debug(athena->log, "Processing Interest Message: %s", name);
        parcMemory_Deallocate(&name);

        CCNxInterest *interest = ccnxMetaMessage_GetInterest(ccnxMessage);
        _processInterest(athena, interest, ingressVector);
        athena->stats.numProcessedInterests++;
    } else if (ccnxMetaMessage_IsContentObject(ccnxMessage)) {
        const char *name = ccnxName_ToString(ccnxContentObject_GetName(ccnxMessage));
        parcLog_Debug(athena->log, "Processing Content Object Message: %s", name);
        parcMemory_Deallocate(&name);

        CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(ccnxMessage);
        _processContentObject(athena, contentObject, ingressVector);
        athena->stats.numProcessedContentObjects++;
    } else if (ccnxMetaMessage_IsControl(ccnxMessage)) {
        parcLog_Debug(athena->log, "Processing Control Message");

        CCNxControl *control = ccnxMetaMessage_GetControl(ccnxMessage);
        _processControl(athena, control, ingressVector);
        athena->stats.numProcessedControlMessages++;
    } else if (ccnxMetaMessage_IsInterestReturn(ccnxMessage)) {
        parcLog_Debug(athena->log, "Processing Interest Return Message");

        CCNxInterestReturn *interestReturn = ccnxMetaMessage_GetInterestReturn(ccnxMessage);
        _processInterestReturn(athena, interestReturn, ingressVector);
        athena->stats.numProcessedInterestReturns++;
    } else {
        trapUnexpectedState("Invalid CCNxMetaMessage type");
    }
}
コード例 #4
0
int
consumer(void)
{
    parcSecurity_Init();
    
    CCNxPortalFactory *factory = setupConsumerFactory();
   
    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);

    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    CCNxName *name = ccnxName_CreateFromCString("lci:/Hello/World");

    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);
    
    if (ccnxPortal_Send(portal, message,CCNxStackTimeout_Never)) {
        while (ccnxPortal_IsError(portal) == false) {
            CCNxMetaMessage *response = ccnxPortal_Receive(portal,CCNxStackTimeout_Never);
            if (response != NULL) {
                if (ccnxMetaMessage_IsContentObject(response)) {
                    CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response);

                    PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject);

                    char *string = parcBuffer_ToString(payload);
                    printf("%s\n", string);
                    parcMemory_Deallocate((void **)&string);

                    break;
                }
            }
            ccnxMetaMessage_Release(&response);
        }
    }

    ccnxPortal_Release(&portal);

    ccnxPortalFactory_Release(&factory);
    
    parcSecurity_Fini();
    return 0;
}
コード例 #5
0
int
ccnGet(PARCIdentity *identity, CCNxName *name)
{
    CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);

    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);

    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);

    if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) {
        while (ccnxPortal_IsError(portal) == false) {
            CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);
            if (response != NULL) {
                if (ccnxMetaMessage_IsContentObject(response)) {
                    CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response);

                    PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject);

                    size_t length = parcBuffer_Remaining(payload);
                    ssize_t nwritten = write(1, parcBuffer_Overlay(payload, length), length);
                    assertTrue(nwritten == length, "Did not write whole buffer, got %zd expected %zu", nwritten, length);

                    break;
                }
                ccnxMetaMessage_Release(&response);
            }
        }
    }

    ccnxPortal_Release(&portal);

    ccnxPortalFactory_Release(&factory);

    return 0;
}
コード例 #6
0
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_GetContentObject)
{
    CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
    PARCBuffer *payload = parcBuffer_WrapCString("This is some data. It's not good data, but it is data.");
    CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload);

    CCNxMetaMessage *portalMessage = ccnxMetaMessage_CreateFromContentObject(contentObject);

    CCNxContentObject *reference = ccnxMetaMessage_GetContentObject(portalMessage);

#ifndef BUGZID_712
    // TODO: We need a ccnxContentObject_Equals()!
    // assertTrue(ccnxContentObject_Equals(contentObject, reference), "Expected reference to equal original contentObject");
#endif // !BUGZID_712
    ccnxContentObject_AssertValid(reference);

    ccnxMetaMessage_Release(&portalMessage);

    ccnxContentObject_Release(&contentObject);
    parcBuffer_Release(&payload);
    ccnxName_Release(&name);
}
コード例 #7
0
LONGBOW_TEST_CASE(Global, Hello)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);
   
    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(data->factory, TEST_STACK);
    CCNxPortal *portalIn = ccnxPortalFactory_CreatePortal(data->factory, TEST_STACK);

    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    CCNxName *name = ccnxName_CreateFromCString("lci:/Hello/World");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);

    CCNxMetaMessage *interestMessage = ccnxMetaMessage_CreateFromInterest(interest);

    if (ccnxPortal_Send(portal, interestMessage, CCNxStackTimeout_Never)) {
        for (int responses = 0; responses == 0; ) {
            CCNxMetaMessage *message = ccnxPortal_Receive(portalIn, CCNxStackTimeout_Never);
            if (message != NULL) {
                if (ccnxMetaMessage_IsContentObject(message)) {
                    CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(message);

                    PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject);
                    if (parcBuffer_HasRemaining(payload) == false) {
                        fprintf(stderr, "**************** Content object has arrived WITH EMPTY CONTENT\n");
                    } else {
                        char *string = parcBuffer_ToString(payload);
                        fprintf(stderr, "**************** Content object has arrived: %s\n", string);
                        parcMemory_Deallocate((void **)&string);
                    }
                    responses++;
                }
                ccnxMetaMessage_Release(&message);
            }
        }
    }

    ccnxMetaMessage_Release(&interestMessage);
    ccnxPortal_Release(&portal);
}
コード例 #8
0
ファイル: athenactl.c プロジェクト: chris-wood/ghost
static const char *
_athenactl_SendInterestControl(PARCIdentity *identity, CCNxMetaMessage *message)
{
    const char *result = NULL;
    CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);

    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);

    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    athenactl_EncodeMessage(message);

    if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) {
        while (ccnxPortal_IsError(portal) == false) {
            CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);
            if (response != NULL) {
                if (ccnxMetaMessage_IsContentObject(response)) {
                    CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response);

                    PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject);

                    if (payload) {
                        result = parcBuffer_ToString(payload);
                    }
                }
                ccnxMetaMessage_Release(&response);
                break;
            }
        }
    }

    ccnxPortal_Release(&portal);

    ccnxPortalFactory_Release(&factory);
    return result;
}
コード例 #9
0
/**
 * Run the consumer to fetch the specified file. Save it to disk once transferred.
 *
 * @param [in] target Name of the content to request.
 * @param [in] outFile Name of the file to which the buffer will be written.
 */
static int
_ccnxFileRepoClient_Run(char *target, char *outFile)
{
    parcSecurity_Init();

    PARCLog *log = _ccnxFileRepoClient_CreateLogger();

    CCNxPortalFactory *factory = _setupConsumerPortalFactory();
    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);
    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    CCNxName *name = ccnxName_CreateFromCString(target);
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);

    if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) {
        while (ccnxPortal_IsError(portal) == false) {
            CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);
            if (response != NULL) {
                if (ccnxMetaMessage_IsManifest(response)) {
                    parcLog_Info(log, "Received root manifest. Beginning to retrieve the content.");

                    // Extract the manifest and instantiate a new fetcher for it
                    CCNxManifest *root = ccnxMetaMessage_GetManifest(response);
                    CCNxFileRepoManifestFetcher *fetcher = ccnxFileRepoManifestFetcher_Create(portal, root);

                    // Initialize the file offset and I/O buffer
                    size_t fileOffset = 0;
                    PARCBuffer *chunkBuffer = parcBuffer_Allocate(ccnxFileRepoCommon_ClientBufferSize);

                    // Start reading from the manifest until done
                    bool done = false;
                    while (!done) {
                        // Reset the buffer information
                        parcBuffer_SetPosition(chunkBuffer, 0);
                        parcBuffer_SetLimit(chunkBuffer, ccnxFileRepoCommon_ClientBufferSize);

                        // Fill the buffer with data from the manifest
                        done = ccnxFileRepoManifestFetcher_FillBuffer(fetcher, chunkBuffer);
                        parcBuffer_Flip(chunkBuffer);

                        // Write the buffer to the file
                        size_t totalSize = parcBuffer_Remaining(chunkBuffer);
                        _ccnxFileRepoClient_AppendBufferToFile(outFile, chunkBuffer, fileOffset);
                        fileOffset += totalSize;

                        // Flip the buffer back around for writing
                        parcBuffer_Flip(chunkBuffer);
                    }
                    parcBuffer_Release(&chunkBuffer);

                    break;
                } else if (ccnxMetaMessage_IsContentObject(response)) {
                    parcLog_Info(log, "Received a content object. Dump the payload and exit.");
                    CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response);
                    PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject);
                    _ccnxFileRepoClient_AppendBufferToFile(outFile, payload, 0);
                    break;
                }
            }
            ccnxMetaMessage_Release(&response);
        }
    }

    ccnxPortal_Release(&portal);
    ccnxPortalFactory_Release(&factory);

    parcSecurity_Fini();
    return 0;
}