Commit 61563acd authored by Greg Williams's avatar Greg Williams
Browse files

Added support to populate the and attributes of the KeyValue struct into PUT...

Added support to populate the  and  attributes of the KeyValue struct into PUT operation requests. Added KineticSynchronization public enum, and mapping to protobuf. Updated to latest list a status codes from ongoing dev work. Re-beautified code with KnR style.
parent 8851772e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ OPTIMIZE = -O3
WARN = -Wall -Wextra -pedantic
# This is necessary because the library depends on
# both C99 _and_ POSIX (for the BSD sockets API).
CDEFS += -D_POSIX_C_SOURCE=1
CDEFS += -D_POSIX_C_SOURCE=1 -D_C99_SOURCE=1
CFLAGS += -std=c99 -fPIC -g ${WARN} ${CDEFS} ${OPTIMIZE}

LIB_INCS = -I$(LIB_DIR) -I$(PUB_INC) -I$(PBC_INC) -I$(VND_INC)
+1 −1
Original line number Diff line number Diff line
#!/bin/sh
# Run astyle on all C files in all project source folders
astyle --style=allman --break-blocks=all --pad-oper --pad-header --unpad-paren --align-pointer=type --add-brackets --convert-tabs --lineend=linux --recursive ./src/*.c ./src/*.h ./include/*.h
astyle --suffix=none --style=kr --break-closing-brackets --pad-oper --pad-header --unpad-paren --convert-tabs --indent=spaces=4 --indent-col1-comments --min-conditional-indent=0 --align-pointer=type --align-reference=type --keep-one-line-statements --lineend=linux --recursive "src/*.h" --recursive "src/*.c" --recursive "test/*.c" --recursive "test/*.h"  --recursive "include/*.h"
+60 −39
Original line number Diff line number Diff line
@@ -94,8 +94,7 @@ typedef ProtobufCBinaryData ByteArray;
//     void        *allocator_data;
// } ProtobufCAllocator;

typedef struct
{
typedef struct {
    ByteArray   buffer;
    size_t      maxLen;
} ByteBuffer;
@@ -105,8 +104,7 @@ typedef struct


// Kinetic Device Client Connection
typedef struct _KineticConnection
{
typedef struct _KineticConnection {
    bool    connected;
    bool    nonBlocking;
    int     port;
@@ -150,8 +148,7 @@ typedef struct _KineticConnection


// Kinetic Message HMAC
typedef struct _KineticHMAC
{
typedef struct _KineticHMAC {
    KineticProto_Security_ACL_HMACAlgorithm algorithm;
    uint32_t len;
    uint8_t data[KINETIC_HMAC_MAX_LEN];
@@ -159,8 +156,7 @@ typedef struct _KineticHMAC


// Kinetic Device Message Request
typedef struct _KineticMessage
{
typedef struct _KineticMessage {
    // Kinetic Protocol Buffer Elements
    KineticProto                proto;
    KineticProto_Command        command;
@@ -204,24 +200,53 @@ typedef struct _KineticMessage


// Kinetic Status Codes
typedef enum
{
typedef enum {
    KINETIC_STATUS_INVALID = -1,        // Status not available (no reponse/status available)
    KINETIC_STATUS_SUCCESS = 0,         // Operation successful
    KINETIC_STATUS_SESSION_EMPTY,       // Session was NULL in request
    KINETIC_STATUS_SESSION_INVALID,     // Session configuration was invalid or NULL
    KINETIC_STATUS_HOST_EMPTY,          // Host was empty in request
    KINETIC_STATUS_HMAC_EMPTY,          // HMAC key is empty or NULL
    KINETIC_STATUS_NO_PDUS_AVAVILABLE,  // All PDUs for the session have been allocated
    KINETIC_STATUS_DEVICE_BUSY,         // Device busy (retry later)
    KINETIC_STATUS_CONNECTION_ERROR,    // No connection/disconnected
    KINETIC_STATUS_INVALID_REQUEST,     // Something about the request is invalid
    KINETIC_STATUS_OPERATION_INVALID,   // Operation was invalid
    KINETIC_STATUS_OPERATION_FAILED,    // Device reported an operation error
    KINETIC_STATUS_VERSION_FAILURE,     // Basically a VERSION_MISMATCH error for a PUT
    KINETIC_STATUS_DATA_ERROR,       // Device reported data error, no spaces, HMAC failure
    KINETIC_STATUS_DATA_ERROR,          // Device reported data error, no space or HMAC failure
    KINETIC_STATUS_COUNT                // Number of status codes in KineticStatusDescriptor
} KineticStatus;
extern const int KineticStatusDescriptorCount;
extern const char* KineticStatusDescriptor[];


// KeyValue meta-data
typedef struct _KineticKeyValue
{
/**
 * @brief Enumeration of encryption/checksum key algorithms
 */
typedef enum _KineticAlgorithm {
    KINETIC_ALGORITHM_INVALID = -1,
    KINETIC_ALGORITHM_SHA1 = 2,
    KINETIC_ALGORITHM_SHA2,
    KINETIC_ALGORITHM_SHA3,
    KINETIC_ALGORITHM_CRC32,
    KINETIC_ALGORITHM_CRC64
} KineticAlgorithm;


/**
 * @brief Enumeration of synchronization types for an operation.
 */
typedef enum _KineticSynchronization {
    KINETIC_SYNCHRONIZATION_INVALID = -1,
    KINETIC_SYNCHRONIZATION_WRITETHROUGH = 1,
    KINETIC_SYNCHRONIZATION_WRITEBACK = 2,
    KINETIC_SYNCHRONIZATION_FLUSH = 3
} KineticSynchronization;

/**
 * @brief KeyValue meta-data structure for Kinetic objects.
 */
typedef struct _KineticKeyValue {
    ByteArray key;
    ByteArray newVersion;
    ByteArray dbVersion;
@@ -229,7 +254,7 @@ typedef struct _KineticKeyValue
    bool force;
    KineticProto_Algorithm algorithm;
    bool metadataOnly;
    KineticProto_Synchronization synchronization;
    KineticSynchronization synchronization;
    ByteArray value;
} KineticKeyValue;

@@ -241,8 +266,7 @@ typedef struct _KineticKeyValue
#define PDU_VALUE_MAX_LEN           (1024 * 1024)
#define PDU_MAX_LEN                 (PDU_HEADER_LEN + \
                                    PDU_PROTO_MAX_LEN + PDU_VALUE_MAX_LEN)
typedef struct __attribute__ ((__packed__)) _KineticPDUHeader
{
typedef struct __attribute__((__packed__)) _KineticPDUHeader {
    uint8_t     versionPrefix;
    uint32_t    protobufLength;
    uint32_t    valueLength;
@@ -252,8 +276,7 @@ typedef struct __attribute__ ((__packed__)) _KineticPDUHeader


// Kinetic PDU
typedef struct _KineticPDU
{
typedef struct _KineticPDU {
    // Binary PDU header
    KineticPDUHeader header;    // Header struct in native byte order
    KineticPDUHeader headerNBO; // Header struct in network-byte-order
@@ -304,8 +327,7 @@ typedef struct _KineticPDU
}

// Kinetic Operation
typedef struct _KineticOperation
{
typedef struct _KineticOperation {
    KineticConnection* connection;
    KineticPDU* request;
    KineticPDU* response;
@@ -318,8 +340,7 @@ typedef struct _KineticOperation
}

// Kinetic Key Range request structure
typedef struct _KineticKeyRange
{
typedef struct _KineticKeyRange {
    ByteBuffer startKey;
    ByteBuffer endKey;
    bool startKeyInclusive;
+4 −1
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@
  :callback_include_count: true

:tools:

  :test_includes_preprocessor:
    :executable: gcc
    :arguments:
@@ -109,6 +110,7 @@
      - -D_POSIX_C_SOURCE=1
      - -D_C99_SOURCE=1
      - ${1}

  :test_compiler:
    :executable: gcc
    :arguments:
@@ -144,6 +146,7 @@
      - "-c \"${1}\""
      - "-o \"${2}\""


  :test_linker:
    :executable: gcc
    :name: test_linker
+32 −45
Original line number Diff line number Diff line
@@ -34,14 +34,12 @@ KineticStatus KineticClient_ExecuteOperation(KineticOperation* operation)
    KineticStatus status = KINETIC_STATUS_INVALID;

    // Send the request
    if (KineticPDU_Send(operation->request))
    {
    if (KineticPDU_Send(operation->request)) {
        // Associate response with same exchange as request
        operation->response->connection = operation->request->connection;

        // Receive the response
        if (KineticPDU_Receive(operation->response))
        {
        if (KineticPDU_Receive(operation->response)) {
            status = KineticOperation_GetStatus(operation);
        }
    }
@@ -64,33 +62,28 @@ bool KineticClient_Connect(KineticConnection* connection,
                           int64_t identity,
                           ByteArray hmacKey)
{
    if (connection == NULL)
    {
    if (connection == NULL) {
        LOG("Specified KineticConnection is NULL!");
        return false;
    }

    if (host == NULL)
    {
    if (host == NULL) {
        LOG("Specified host is NULL!");
        return false;
    }

    if (hmacKey.len < 1)
    {
    if (hmacKey.len < 1) {
        LOG("Specified HMAC key is empty!");
        return false;
    }

    if (hmacKey.data == NULL)
    {
    if (hmacKey.data == NULL) {
        LOG("Specified HMAC key is NULL!");
        return false;
    }

    if (!KineticConnection_Connect(connection, host, port, nonBlocking,
        clusterVersion, identity, hmacKey))
    {
                                   clusterVersion, identity, hmacKey)) {
        connection->connected = false;
        connection->socketDescriptor = -1;
        char message[64];
@@ -115,20 +108,17 @@ KineticOperation KineticClient_CreateOperation(KineticConnection* connection,
{
    KineticOperation op;

    if (connection == NULL)
    {
    if (connection == NULL) {
        LOG("Specified KineticConnection is NULL!");
        assert(connection != NULL);
    }

    if (request == NULL)
    {
    if (request == NULL) {
        LOG("Specified KineticPDU request is NULL!");
        assert(request != NULL);
    }

    if (response == NULL)
    {
    if (response == NULL) {
        LOG("Specified KineticPDU response is NULL!");
        assert(response != NULL);
    }
@@ -185,13 +175,12 @@ KineticStatus KineticClient_Get(KineticOperation* operation,
    assert(metadata->key.data != NULL);
    assert(metadata->key.len <= KINETIC_MAX_KEY_LEN);

    if (!metadata->metadataOnly)
    {
        if (metadata->value.data == NULL)
        {
    if (!metadata->metadataOnly) {
        if (metadata->value.data == NULL) {
            metadata->value = (ByteArray) {
                .data = operation->response->valueBuffer,
                .len = PDU_VALUE_MAX_LEN};
                 .len = PDU_VALUE_MAX_LEN
            };
        }
    }

@@ -202,12 +191,10 @@ KineticStatus KineticClient_Get(KineticOperation* operation,
    KineticStatus status = KineticClient_ExecuteOperation(operation);

    // Update the metadata with the received value length upon success
    if (status == KINETIC_STATUS_SUCCESS)
    {
    if (status == KINETIC_STATUS_SUCCESS) {
        metadata->value.len = operation->response->value.len;
    }
    else
    {
    else {
        metadata->value.len = 0;
    }

Loading