Commit 15bbd030 authored by Greg Williams's avatar Greg Williams
Browse files

Changed remaining asserts to use KINETIC_ASSERT so that they get logged to aid...

Changed remaining asserts to use KINETIC_ASSERT so that they get logged to aid debugging upon failure.
Added accessors to get termination status and get/set connection ID.
Added accessors to get status code/connection ID and protobuf/value lengths from responses.
parent 6305cbb2
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "kinetic_auth.h"
#include "kinetic_device_info.h"
#include "kinetic_acl.h"
#include "kinetic_logger.h"

#ifdef TEST
struct ACL *ACLs = NULL;
@@ -77,7 +78,7 @@ KineticStatus KineticAdminClient_SetErasePin(KineticSession * const session,
KineticStatus KineticAdminClient_SecureErase(KineticSession * const session,
    ByteArray pin)
{
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);

    KineticStatus status;
    status = KineticAuth_EnsureSslEnabled(&session->config);
@@ -98,7 +99,7 @@ KineticStatus KineticAdminClient_SecureErase(KineticSession * const session,
KineticStatus KineticAdminClient_InstantErase(KineticSession * const session,
    ByteArray pin)
{
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);

    KineticStatus status;
    status = KineticAuth_EnsureSslEnabled(&session->config);
@@ -140,7 +141,7 @@ KineticStatus KineticAdminClient_SetLockPin(KineticSession * const session,
KineticStatus KineticAdminClient_LockDevice(KineticSession * const session,
    ByteArray pin)
{
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);

    KineticStatus status;
    status = KineticAuth_EnsureSslEnabled(&session->config);
@@ -161,7 +162,7 @@ KineticStatus KineticAdminClient_LockDevice(KineticSession * const session,
KineticStatus KineticAdminClient_UnlockDevice(KineticSession * const session,
    ByteArray pin)
{
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);

    KineticStatus status;
    status = KineticAuth_EnsureSslEnabled(&session->config);
@@ -184,8 +185,8 @@ KineticStatus KineticAdminClient_GetLog(KineticSession * const session,
                                   KineticLogInfo** info,
                                   KineticCompletionClosure* closure)
{
    assert(session != NULL);
    assert(info != NULL);
    KINETIC_ASSERT(session != NULL);
    KINETIC_ASSERT(info != NULL);

    KineticProto_Command_GetLog_Type protoType =
        KineticLogInfo_Type_to_KineticProto_Command_GetLog_Type(type);
@@ -208,8 +209,8 @@ KineticStatus KineticAdminClient_GetDeviceSpecificLog(KineticSession * const ses
                                   KineticLogInfo** info,
                                   KineticCompletionClosure* closure)
{
    assert(session != NULL);
    assert(info != NULL);
    KINETIC_ASSERT(session != NULL);
    KINETIC_ASSERT(info != NULL);

    KineticOperation* operation = KineticAllocator_NewOperation(session);
    if (operation == NULL) {return KINETIC_STATUS_MEMORY_ERROR;}
@@ -224,7 +225,7 @@ KineticStatus KineticAdminClient_GetDeviceSpecificLog(KineticSession * const ses
void KineticClient_FreeLogInfo(KineticSession * const session,
                                  KineticLogInfo* info)
{
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);
    if (info) { KineticLogInfo_Free(info); }

    /* The session is not currently used, but part of the API to allow
@@ -235,7 +236,7 @@ void KineticClient_FreeLogInfo(KineticSession * const session,
KineticStatus KineticAdminClient_SetClusterVersion(KineticSession * const session,
    int64_t version)
{
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);

    KineticOperation* operation = KineticAllocator_NewOperation(session);
    if (operation == NULL) {return KINETIC_STATUS_MEMORY_ERROR;}
@@ -246,7 +247,7 @@ KineticStatus KineticAdminClient_SetClusterVersion(KineticSession * const sessio

KineticStatus KineticAdminClient_SetACL(KineticSession * const session,
        const char *ACLPath) {
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);
    if (ACLPath == NULL) {
        return KINETIC_STATUS_INVALID_REQUEST;
    }
@@ -277,7 +278,7 @@ KineticStatus KineticAdminClient_SetACL(KineticSession * const session,
KineticStatus KineticAdminClient_UpdateFirmware(KineticSession * const session,
    char const * const fw_path)
{
    assert(session != NULL);
    KINETIC_ASSERT(session != NULL);

    KineticOperation* operation = KineticAllocator_NewOperation(session);
    if (operation == NULL) {return KINETIC_STATUS_MEMORY_ERROR;}
+9 −9
Original line number Diff line number Diff line
@@ -25,15 +25,15 @@

KineticStatus KineticAuth_EnsureSslEnabled(KineticSessionConfig const * const config)
{
    assert(config);
    KINETIC_ASSERT(config);
    if (!config->useSsl) {return KINETIC_STATUS_SSL_REQUIRED;}
    return KINETIC_STATUS_SUCCESS;
}

KineticStatus KineticAuth_PopulateHmac(KineticSessionConfig const * const config, KineticRequest * const pdu)
{
    assert(config);
    assert(pdu);
    KINETIC_ASSERT(config);
    KINETIC_ASSERT(pdu);

    LOG3("Adding HMAC auth info");

@@ -51,8 +51,8 @@ KineticStatus KineticAuth_PopulateHmac(KineticSessionConfig const * const config

    // Configure HMAC support
    ByteArray const * const hmacKey = &config->hmacKey;
    assert(hmacKey->len <= KINETIC_HMAC_MAX_LEN);  // NOCOMMIT
    assert(hmacKey->data != NULL);
    KINETIC_ASSERT(hmacKey->len <= KINETIC_HMAC_MAX_LEN);  // NOCOMMIT
    KINETIC_ASSERT(hmacKey->data != NULL);

    msg->hmacAuth = &pdu->message.hmacAuth;

@@ -75,8 +75,8 @@ KineticStatus KineticAuth_PopulateHmac(KineticSessionConfig const * const config

KineticStatus KineticAuth_PopulatePin(KineticSessionConfig const * const config, KineticRequest * const pdu, ByteArray pin)
{
    assert(config);
    assert(pdu);
    KINETIC_ASSERT(config);
    KINETIC_ASSERT(pdu);

    LOG3("Adding PIN auth info");

@@ -93,8 +93,8 @@ KineticStatus KineticAuth_PopulatePin(KineticSessionConfig const * const config,
    msg->command.header = &msg->header;
    
    // Configure PIN support
    assert(pin.len <= KINETIC_PIN_MAX_LEN);
    if (pin.len > 0) { assert(pin.data != NULL); }
    KINETIC_ASSERT(pin.len <= KINETIC_PIN_MAX_LEN);
    if (pin.len > 0) { KINETIC_ASSERT(pin.data != NULL); }
    msg->message.pinAuth->pin = (ProtobufCBinaryData) {
        .data = pin.data,
        .len = pin.len,
+3 −3
Original line number Diff line number Diff line
@@ -72,8 +72,8 @@ STATIC bool unpack_header(uint8_t const * const read_buf, size_t const read_size
    uint8_t versionPrefix = buf_header->versionPrefix;

    if (protobufLength <= PDU_PROTO_MAX_LEN &&
        valueLength <= PDU_PROTO_MAX_LEN) {

        valueLength <= PDU_PROTO_MAX_LEN)
    {
        *header = (KineticPDUHeader){
            .versionPrefix = versionPrefix,
            .protobufLength = protobufLength,
@@ -226,7 +226,7 @@ STATIC bus_unpack_cb_res_t unpack_cb(void *msg, void *socket_udata) {
        {
            if (response->proto->has_authType &&
                response->proto->authType == KINETIC_PROTO_MESSAGE_AUTH_TYPE_UNSOLICITEDSTATUS
                && session->connectionID == 0)
                && KineticSession_GetConnectionID(session) == 0)
            {
                /* Ignore the unsolicited status message on connect. */
                seq_id = BUS_NO_SEQ_ID;
+13 −30
Original line number Diff line number Diff line
@@ -176,14 +176,12 @@ void KineticController_HandleUnexpectedResponse(void *msg,

    // Handle unsolicited status PDUs
    if (response->proto->authType == KINETIC_PROTO_MESSAGE_AUTH_TYPE_UNSOLICITEDSTATUS) {
        if (response->command != NULL &&
            response->command->header != NULL &&
            response->command->header->has_connectionID)
        int64_t connectionID = KineticResponse_GetConnectionID(response);
        if (connectionID != 0)
        {
            // Extract connectionID from unsolicited status message
            session->connectionID = response->command->header->connectionID;
            LOGF2("Extracted connection ID from unsolicited status PDU (id=%lld)",
                session->connectionID);
            // Store connectionID from unsolicited status message in the session for future requests
            KineticSession_SetConnectionID(session, connectionID);
            LOGF2("Extracted connection ID from unsolicited status PDU (id=%lld)", connectionID);
            connetionInfoReceived = true;
            logTag = statusTag;
            logAtLevel = 2;
@@ -194,16 +192,11 @@ void KineticController_HandleUnexpectedResponse(void *msg,
            logTag = statusTag;
            logAtLevel = 0; 
            protoLogAtLevel = 0;
            if (response && response->command &&
                response->command->status &&
                response->command->status->has_code)
            {
                session->terminationStatus =
                    KineticProtoStatusCode_to_KineticStatus(response->command->status->code);
            KineticStatus status = KineticResponse_GetStatus(response);
            KineticSession_SetTerminationStatus(session, status);
            KineticSession_Disconnect(session);
        }
    }
    }
    else {
        KineticLogger_LogTimestamp(0, "WARNING: Received unexpected response!");
        logTag = unexpectedTag;
@@ -217,7 +210,8 @@ void KineticController_HandleUnexpectedResponse(void *msg,
        (void*)response, (void*)session,
        (void*)session->messageBus,
        session->socket, (long long)seq_id,
        response->header.protobufLength, response->header.valueLength);
        KineticResponse_GetProtobufLength(response),
        KineticResponse_GetValueLength(response));
    KineticLogger_LogProtobuf(protoLogAtLevel, response->proto);

    KineticAllocator_FreeKineticResponse(response);
@@ -237,27 +231,16 @@ void KineticController_HandleResult(bus_msg_result_t *res, void *udata)

    if (status == KINETIC_STATUS_SUCCESS) {
        KineticResponse * response = res->u.response.opaque_msg;
        KINETIC_ASSERT(response);
        KINETIC_ASSERT(response->command);
        KINETIC_ASSERT(response->command->header);

        if (response->command != NULL &&
            response->command->status != NULL &&
            response->command->status->has_code)
        {
            status = KineticProtoStatusCode_to_KineticStatus(response->command->status->code);
            op->response = response;
        }
        else {
            status = KINETIC_STATUS_INVALID;
        }
        KineticStatus status = KineticResponse_GetStatus(response);

        LOGF2("[PDU RX] pdu: %p, session: %p, bus: %p, "
            "fd: %6d, seq: %8lld, protoLen: %8u, valueLen: %8u, op: %p, status: %s",
            (void*)response,
            (void*)op->session, (void*)op->session->messageBus,
            op->session->socket, response->command->header->ackSequence,
            response->header.protobufLength, response->header.valueLength,
            KineticResponse_GetProtobufLength(response),
            KineticResponse_GetValueLength(response),
            (void*)op,
            Kinetic_GetStatusDescription(status));
        KineticLogger_LogHeader(3, &response->header);
+4 −4
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ KineticCountingSemaphore * KineticCountingSemaphore_Create(uint32_t counts)

void KineticCountingSemaphore_Take(KineticCountingSemaphore * const sem) // WAIT
{
    assert(sem != NULL);
    KINETIC_ASSERT(sem != NULL);
    pthread_mutex_lock(&sem->mutex);

    sem->num_waiting++;
@@ -59,7 +59,7 @@ void KineticCountingSemaphore_Take(KineticCountingSemaphore * const sem) // WAIT

void KineticCountingSemaphore_Give(KineticCountingSemaphore * const sem) // SIGNAL
{
    assert(sem != NULL);
    KINETIC_ASSERT(sem != NULL);
    pthread_mutex_lock(&sem->mutex);
    
    if (sem->count == 0 && sem->num_waiting > 0) {
@@ -73,12 +73,12 @@ void KineticCountingSemaphore_Give(KineticCountingSemaphore * const sem) // SIGN
    pthread_mutex_unlock(&sem->mutex);
    
    LOGF3("Concurrent ops throttle -- GIVE: %u => %u (waiting=%u)", before, after, waiting);
    assert(sem->max >= after);
    KINETIC_ASSERT(sem->max >= after);
}

void KineticCountingSemaphore_Destroy(KineticCountingSemaphore * const sem)
{
    assert(sem != NULL);
    KINETIC_ASSERT(sem != NULL);
    pthread_mutex_destroy(&sem->mutex);
    pthread_cond_destroy(&sem->available);
    free(sem);
Loading