コード例 #1
0
ファイル: athena.c プロジェクト: chris-wood/ghost
Athena *
athena_Create(size_t contentStoreSizeInMB)
{
    Athena *athena = parcObject_CreateAndClearInstance(Athena);

    athena->athenaName = ccnxName_CreateFromURI(CCNxNameAthena_Forwarder);
    assertNotNull(athena->athenaName, "Failed to create forwarder name (%s)", CCNxNameAthena_Forwarder);

    athena->athenaFIB = athenaFIB_Create();
    assertNotNull(athena->athenaFIB, "Failed to create FIB");

    athena->athenaPIT = athenaPIT_Create();
    assertNotNull(athena->athenaPIT, "Failed to create PIT");

    AthenaLRUContentStoreConfig storeConfig;
    storeConfig.capacityInMB = contentStoreSizeInMB;

    athena->athenaContentStore = athenaContentStore_Create(&AthenaContentStore_LRUImplementation, &storeConfig);
    assertNotNull(athena->athenaContentStore, "Failed to create Content Store");

    athena->athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, athena);
    assertNotNull(athena->athenaTransportLinkAdapter, "Failed to create Transport Link Adapter");

    athena->log = _athena_logger_create();
    athena->athenaState = Athena_Running;

    return athena;
}
コード例 #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
static _DummyChunker *
_dummy_Create(int val)
{
    _DummyChunker *chunker = (_DummyChunker *) parcObject_CreateAndClearInstance(_DummyChunker);
    chunker->start = 0;
    chunker->end = val;
    chunker->released = false;
    return chunker;
}
コード例 #4
0
CCNxManifestHashGroupPointer *
ccnxManifestHashGroupPointer_Create(CCNxManifestHashGroupPointerType type, const PARCBuffer *digest)
{
    CCNxManifestHashGroupPointer *ptr = parcObject_CreateAndClearInstance(CCNxManifestHashGroupPointer);
    if (ptr != NULL) {
        ptr->pointerType = type;
        ptr->digest = parcBuffer_Acquire(digest);
    }
    return ptr;
}
コード例 #5
0
ファイル: parc_JSONValue.c プロジェクト: PARC/Libparc
static PARCJSONValue *
_createValue(_PARCJSONValueType type)
{
    PARCJSONValue *result = parcObject_CreateAndClearInstance(PARCJSONValue);

    if (result != NULL) {
        result->type = type;
    }
    return result;
}
コード例 #6
0
ファイル: metis_LRUContentStore.c プロジェクト: PARC/Metis
MetisContentStoreInterface *
metisLRUContentStore_Create(MetisContentStoreConfig *config, MetisLogger *logger)
{
    MetisContentStoreInterface *storeImpl = NULL;

    assertNotNull(logger, "MetisLRUContentStore requires a non-NULL logger");

    storeImpl = parcObject_CreateAndClearInstance(MetisContentStoreInterface);

    if (storeImpl != NULL) {
        storeImpl->_privateData = parcObject_CreateAndClearInstance(_MetisLRUContentStore);

        if (_metisLRUContentStore_Init(storeImpl->_privateData, config, logger)) {
            storeImpl->putContent = &_metisLRUContentStore_PutContent;
            storeImpl->removeContent = &_metisLRUContentStore_RemoveContent;

            storeImpl->matchInterest = &_metisLRUContentStore_MatchInterest;

            storeImpl->getObjectCount = &_metisLRUContentStore_GetObjectCount;
            storeImpl->getObjectCapacity = &_metisLRUContentStore_GetObjectCapacity;

            storeImpl->log = &_metisLRUContentStore_Log;

            storeImpl->acquire = &_metisLRUContentStore_Acquire;
            storeImpl->release = &_metisLRUContentStore_Release;

            // Initialize from the config passed to us.
            _metisLRUContentStore_SetObjectCapacity(storeImpl, config->objectCapacity);

            if (metisLogger_IsLoggable(logger, MetisLoggerFacility_Processor, PARCLogLevel_Info)) {
                metisLogger_Log(logger, MetisLoggerFacility_Processor, PARCLogLevel_Info, __func__,
                                "LRUContentStore %p created with capacity %zu",
                                (void *) storeImpl, metisContentStoreInterface_GetObjectCapacity(storeImpl));
            }
        }
    } else {
        parcObject_Release((void **) &storeImpl);
    }

    return storeImpl;
}
コード例 #7
0
ファイル: athena_Ethernet.c プロジェクト: chris-wood/ghost
AthenaEthernet *
athenaEthernet_Create(PARCLog *log, const char *interface, uint16_t etherType)
{
    AthenaEthernet *athenaEthernet = parcObject_CreateAndClearInstance(AthenaEthernet);
    athenaEthernet->log = parcLog_Acquire(log);
    athenaEthernet->etherType = etherType;

    athenaEthernet->fd = _open_socket(interface);
    if (athenaEthernet->fd == -1) {
        parcLog_Error(athenaEthernet->log, "socket: %s", strerror(errno));

        athenaEthernet_Release(&athenaEthernet);
        return NULL;
    }

    if (ioctl(athenaEthernet->fd, BIOCGBLEN, &(athenaEthernet->etherBufferLength))) {
        perror("error getting buffer length");
        return NULL;
    }

    // Populate the configured physical MAC and MTU by searching ifaddrs
    struct ifaddrs *ifaddr;
    int res = getifaddrs(&ifaddr);
    if (res == -1) {
        perror("getifaddrs");
        return 0;
    }

    struct ifaddrs *next;
    for (next = ifaddr; next != NULL; next = next->ifa_next) {
        if (strcmp(next->ifa_name, interface) == 0) {
            if (next->ifa_addr->sa_family == AF_LINK) {
                struct sockaddr_dl *addr_dl = (struct sockaddr_dl *) next->ifa_addr;

                // addr_dl->sdl_data[12] contains the interface name followed by the MAC address, so
                // need to offset in to the array past the interface name.
                memcpy(&(athenaEthernet->mac), &addr_dl->sdl_data[addr_dl->sdl_nlen], addr_dl->sdl_alen);

                struct if_data *ifdata = (struct if_data *) next->ifa_data;
                athenaEthernet->mtu = ifdata->ifi_mtu;

                // break out of loop and freeifaddrs
                break;
            }
        }
    }
    freeifaddrs(ifaddr);

    return athenaEthernet;
}
コード例 #8
0
ファイル: parc_AtomicUint32.c プロジェクト: isolis/Libparc
PARCAtomicUint32 *
parcAtomicUint32_Create(uint32_t value)
{
    PARCAtomicUint32 *result = parcObject_CreateAndClearInstance(PARCAtomicUint32);

#ifdef PARCLibrary_DISABLE_ATOMICS
    pthread_mutex_init(&result->mutex, NULL);
    result->value = value;
#else
    *result = value;
#endif

    return result;
}
コード例 #9
0
CCNxSimpleFileTransferChunkList *
ccnxSimpleFileTransferChunkList_Create(const char *fileName, size_t numChunks)
{

    CCNxSimpleFileTransferChunkList *result = parcObject_CreateAndClearInstance(CCNxSimpleFileTransferChunkList);

    if (fileName != NULL) {
        result->fileName = parcBuffer_WrapCString((char *) fileName);
    }

    size_t sizeNeeded = (numChunks * sizeof(CCNxContentObject *));
    result->chunkPointers = parcMemory_AllocateAndClear(sizeNeeded);

    result->numChunks = numChunks;

    return result;
}
コード例 #10
0
CCNxManifestHashGroup *
ccnxManifestHashGroup_Create(void)
{
    CCNxManifestHashGroup *section = parcObject_CreateAndClearInstance(CCNxManifestHashGroup);

    if (section != NULL) {
        section->pointers = parcLinkedList_Create();

        section->overallDataDigest = NULL;
        section->dataSize = 0;
        section->entrySize = 0;
        section->blockSize = 0;
        section->treeHeight = 0;
        section->locator = NULL;
    }

    return section;
}
コード例 #11
0
ファイル: athena_LRUContentStore.c プロジェクト: PARC/Athena
static AthenaContentStoreImplementation *
_athenaLRUContentStore_Create(AthenaContentStoreConfig *storeConfig)
{
    AthenaLRUContentStoreConfig *config = (AthenaLRUContentStoreConfig *) storeConfig;
    AthenaLRUContentStore *result = parcObject_CreateAndClearInstance(AthenaLRUContentStore);
    if (result != NULL) {
        result->wallClock = parcClock_Wallclock();

        if (config != NULL) {
            result->maxSizeInBytes = config->capacityInMB * (1024 * 1024); // MB to bytes
        } else {
            result->maxSizeInBytes = 10 * (1024 * 1024); // 10 MB default
        }

        _athenaLRUContentStore_initializeIndexes(result, result->maxSizeInBytes);
    }

    return (AthenaContentStoreImplementation *) result;
}
コード例 #12
0
PARCPkcs12KeyStore *
parcPkcs12KeyStore_Open(const char *filename, const char *password, PARCCryptoHashType hashType)
{
    PARCPkcs12KeyStore *keyStore = parcObject_CreateAndClearInstance(PARCPkcs12KeyStore);
    if (keyStore != NULL) {
        keyStore->hasher = parcCryptoHasher_Create(hashType);
        keyStore->public_key_digest = NULL;
        keyStore->certificate_digest = NULL;
        keyStore->public_key_der = NULL;
        keyStore->certificate_der = NULL;
        keyStore->hashType = hashType;

        if (_parcPkcs12KeyStore_ParseFile(keyStore, filename, password) != 0) {
            parcPkcs12KeyStore_Release(&keyStore);
        }
    }

    return keyStore;
}
コード例 #13
0
AthenaTransportLink *
athenaTransportLink_Create(const char *name,
                           AthenaTransportLink_SendMethod *sendMethod,
                           AthenaTransportLink_ReceiveMethod *receiveMethod,
                           AthenaTransportLink_CloseMethod *closeMethod)
{
    AthenaTransportLink *athenaTransportLink = parcObject_CreateAndClearInstance(AthenaTransportLink);

    if (athenaTransportLink != NULL) {
        athenaTransportLink->linkName = parcMemory_StringDuplicate(name, strlen(name));
        athenaTransportLink->sendMethod = sendMethod;
        athenaTransportLink->receiveMethod = receiveMethod;
        athenaTransportLink->closeMethod = closeMethod;
        athenaTransportLink->log = _parc_logger_create(name);
        athenaTransportLink->linkEvents = AthenaTransportLinkEvent_None;
        athenaTransportLink->linkFlags = AthenaTransportLinkFlag_None;
        athenaTransportLink->eventFd = -1;
    }

    return athenaTransportLink;
}
コード例 #14
0
static AthenaContentStoreImplementation *
_emptyImplCreate()
{
    EmptyImpl *result = parcObject_CreateAndClearInstance(EmptyImpl);
    return result;
}