Loading src/lib/kinetic_api.c +48 −9 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ void KineticApi_Init(const char* log_file) KineticLogger_Init(log_file); } void KineticApi_Connect( bool KineticApi_Connect( KineticConnection* connection, const char* host, int port, Loading @@ -44,11 +44,12 @@ void KineticApi_Connect( char message[64]; sprintf(message, "Failed creating connection to %s:%d", host, port); LOG(message); return false; } else { connection->connected = true; } return true; } bool KineticApi_ConfigureExchange( Loading Loading @@ -91,13 +92,53 @@ bool KineticApi_ConfigureExchange( KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticPDU* response) KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg) { KineticOperation op; if (exchange == NULL) { LOG("Specified KineticExchange is NULL!"); assert(exchange != NULL); } if (request == NULL) { LOG("Specified request KineticPDU is NULL!"); assert(request != NULL); } if (requestMsg == NULL) { LOG("Specified request KineticMessage is NULL!"); assert(requestMsg != NULL); } if (response == NULL) { LOG("Specified response KineticPDU is NULL!"); assert(response != NULL); } if (responseMsg == NULL) { LOG("Specified response KineticMessage is NULL!"); assert(responseMsg != NULL); } KineticMessage_Init(requestMsg); KineticPDU_Init(request, exchange, requestMsg, NULL, 0); KineticMessage_Init(responseMsg); KineticPDU_Init(response, exchange, responseMsg, NULL, 0); op.exchange = exchange; op.request = request; op.request->protobuf = requestMsg; op.response = response; op.response->protobuf = responseMsg; return op; } Loading @@ -116,15 +157,13 @@ KineticProto_Status_StatusCode KineticApi_NoOp(KineticOperation* operation) // Initialize request KineticExchange_IncrementSequence(operation->exchange); KineticMessage_Init(operation->request->protobuf); KineticPDU_Init(operation->request, operation->request->exchange, operation->request->protobuf, NULL, 0); KineticOperation_BuildNoop(operation); // Send the request KineticPDU_Send(operation->request); // Associate response with same exchange as request KineticPDU_Init(operation->response, operation->response->exchange, operation->response->protobuf, NULL, 0); operation->response->exchange = operation->request->exchange; // Receive the response if (KineticPDU_Receive(operation->response)) Loading src/lib/kinetic_api.h +4 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ void KineticApi_Init( const char* log_file); void KineticApi_Connect( bool KineticApi_Connect( KineticConnection* connection, const char* host, int port, Loading @@ -46,7 +46,9 @@ bool KineticApi_ConfigureExchange( KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticPDU* response); KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg); KineticProto_Status_StatusCode KineticApi_NoOp( KineticOperation* operation Loading src/lib/kinetic_operation.c +2 −2 Original line number Diff line number Diff line Loading @@ -36,8 +36,8 @@ void KineticOperation_BuildNoop(KineticOperation* operation) assert(operation->request != NULL); assert(operation->response != NULL); KineticMessage_Init(operation->request->protobuf); KineticMessage_Init(operation->response->protobuf); // KineticMessage_Init(operation->request->protobuf); // KineticMessage_Init(operation->response->protobuf); KineticExchange_ConfigureHeader(operation->exchange, &operation->request->protobuf->header); operation->request->protobuf->header.messagetype = KINETIC_PROTO_MESSAGE_TYPE_NOOP; operation->request->protobuf->header.has_messagetype = true; Loading src/lib/kinetic_pdu.c +15 −22 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include "kinetic_socket.h" #include "kinetic_hmac.h" #include "kinetic_logger.h" #include <string.h> static void KineticPDU_PackInt32(uint8_t* const buffer, int32_t value); static int32_t KineticPDU_UnpackInt32(const uint8_t* const buffer); Loading @@ -34,35 +33,29 @@ void KineticPDU_Init( uint8_t* const value, int32_t valueLength) { size_t protoPackedSize; assert(pdu != NULL); assert(message != NULL); assert(exchange != NULL); // Initialize the instance struct memset(pdu, 0, sizeof(KineticPDU)); // Create properly initialized PDU and populate passed instance const KineticPDU tmpPDU = { .exchange = exchange, .protobuf = message, .protobufLength = KineticProto_get_packed_size(&message->proto), .value = value, .valueLength = valueLength, .header.versionPrefix = (uint8_t)'F' // Set header version prefix appropriately }; *pdu = tmpPDU; // Copy initial value into target PDU // Associate with the specified exchange pdu->exchange = exchange; // Pack protobuf length field KineticPDU_PackInt32((uint8_t*)&pdu->header.protobufLength, pdu->protobufLength); // Associate with the specified message pdu->protobuf = message; // Pack value length field KineticPDU_PackInt32((uint8_t*)&pdu->header.valueLength, pdu->valueLength); // Configure the protobuf header with exchange info KineticExchange_ConfigureHeader(exchange, &pdu->protobuf->header); // Setup the PDU header fields pdu->header.versionPrefix = (uint8_t)'F'; // Associate with protobuf pdu->protobufLength = KineticProto_get_packed_size(&pdu->protobuf->proto); KineticPDU_PackInt32((uint8_t*)&pdu->header.protobufLength, pdu->protobufLength); // Pack protobuf length field // Associate with payload (if present) pdu->valueLength = valueLength; KineticPDU_PackInt32((uint8_t*)&pdu->header.valueLength, pdu->valueLength); // Pack value length field pdu->value = value; KineticExchange_ConfigureHeader(exchange, &message->header); } bool KineticPDU_Send(KineticPDU* const request) Loading test/integration/test_kinetic_api_integration.c +30 −11 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ void setUp(void) { KineticApi_Init(TEST_LOG_FILE); KineticApi_Init(NULL); } void tearDown(void) Loading @@ -44,25 +44,44 @@ void tearDown(void) void test_NoOp_should_succeed(void) { KineticConnection connection; KineticExchange exchange; KineticOperation operation; KineticPDU request, response; int64_t identity = 1234; uint8_t key[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; int64_t connectionID = 5678; // ????? // KineticMessage requestMsg, responseMsg; const int64_t identity = 1234; uint8_t key[] = {1,2,3}; const int64_t connectionID = 5678; const int socketDesc = 783; KineticConnection connection = { .socketDescriptor = socketDesc // Fill in, since KineticConnection is mocked }; KineticMessage requestMsg, responseMsg; KineticProto_Status_StatusCode status; KineticHMAC respTempHMAC; KineticApi_Connect(&connection, "localhost", 8999, true); KineticConnection_Init_Expect(&connection); KineticConnection_Connect_ExpectAndReturn(&connection, "localhost", 8999, true, true); TEST_ASSERT_TRUE(KineticApi_Connect(&connection, "localhost", 8999, true)); TEST_ASSERT_EQUAL_INT(socketDesc, connection.socketDescriptor); // Ensure socket descriptor still intact! TEST_ASSERT_TRUE_MESSAGE( KineticApi_ConfigureExchange(&exchange, &connection, identity, key, sizeof(key), connectionID), "Failed configuring exchange!"); operation = KineticApi_CreateOperation(&exchange, &request, &response); operation = KineticApi_CreateOperation(&exchange, &request, &requestMsg, &response, &responseMsg); // Initialize response message status and HMAC, since receipt of packed protobuf is mocked out responseMsg.command.status->code = KINETIC_PROTO_STATUS_STATUS_CODE_SUCCESS; KineticHMAC_Populate(&respTempHMAC, &responseMsg, key, sizeof(key)); KineticSocket_Write_ExpectAndReturn(socketDesc, &request.header, sizeof(KineticPDUHeader), true); KineticSocket_WriteProtobuf_ExpectAndReturn(socketDesc, &requestMsg, true); KineticSocket_Read_ExpectAndReturn(socketDesc, &response.header, sizeof(KineticPDUHeader), true); KineticSocket_ReadProtobuf_ExpectAndReturn(socketDesc, &responseMsg.proto, response.protobufScratch, 0x08000000, true); status = KineticApi_NoOp(&operation); TEST_ASSERT_EQUAL_KINETIC_STATUS( KINETIC_PROTO_STATUS_STATUS_CODE_SUCCESS, KineticApi_NoOp(&operation)); TEST_ASSERT_EQUAL_KINETIC_STATUS(KINETIC_PROTO_STATUS_STATUS_CODE_SUCCESS, status); } Loading
src/lib/kinetic_api.c +48 −9 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ void KineticApi_Init(const char* log_file) KineticLogger_Init(log_file); } void KineticApi_Connect( bool KineticApi_Connect( KineticConnection* connection, const char* host, int port, Loading @@ -44,11 +44,12 @@ void KineticApi_Connect( char message[64]; sprintf(message, "Failed creating connection to %s:%d", host, port); LOG(message); return false; } else { connection->connected = true; } return true; } bool KineticApi_ConfigureExchange( Loading Loading @@ -91,13 +92,53 @@ bool KineticApi_ConfigureExchange( KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticPDU* response) KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg) { KineticOperation op; if (exchange == NULL) { LOG("Specified KineticExchange is NULL!"); assert(exchange != NULL); } if (request == NULL) { LOG("Specified request KineticPDU is NULL!"); assert(request != NULL); } if (requestMsg == NULL) { LOG("Specified request KineticMessage is NULL!"); assert(requestMsg != NULL); } if (response == NULL) { LOG("Specified response KineticPDU is NULL!"); assert(response != NULL); } if (responseMsg == NULL) { LOG("Specified response KineticMessage is NULL!"); assert(responseMsg != NULL); } KineticMessage_Init(requestMsg); KineticPDU_Init(request, exchange, requestMsg, NULL, 0); KineticMessage_Init(responseMsg); KineticPDU_Init(response, exchange, responseMsg, NULL, 0); op.exchange = exchange; op.request = request; op.request->protobuf = requestMsg; op.response = response; op.response->protobuf = responseMsg; return op; } Loading @@ -116,15 +157,13 @@ KineticProto_Status_StatusCode KineticApi_NoOp(KineticOperation* operation) // Initialize request KineticExchange_IncrementSequence(operation->exchange); KineticMessage_Init(operation->request->protobuf); KineticPDU_Init(operation->request, operation->request->exchange, operation->request->protobuf, NULL, 0); KineticOperation_BuildNoop(operation); // Send the request KineticPDU_Send(operation->request); // Associate response with same exchange as request KineticPDU_Init(operation->response, operation->response->exchange, operation->response->protobuf, NULL, 0); operation->response->exchange = operation->request->exchange; // Receive the response if (KineticPDU_Receive(operation->response)) Loading
src/lib/kinetic_api.h +4 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ void KineticApi_Init( const char* log_file); void KineticApi_Connect( bool KineticApi_Connect( KineticConnection* connection, const char* host, int port, Loading @@ -46,7 +46,9 @@ bool KineticApi_ConfigureExchange( KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticPDU* response); KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg); KineticProto_Status_StatusCode KineticApi_NoOp( KineticOperation* operation Loading
src/lib/kinetic_operation.c +2 −2 Original line number Diff line number Diff line Loading @@ -36,8 +36,8 @@ void KineticOperation_BuildNoop(KineticOperation* operation) assert(operation->request != NULL); assert(operation->response != NULL); KineticMessage_Init(operation->request->protobuf); KineticMessage_Init(operation->response->protobuf); // KineticMessage_Init(operation->request->protobuf); // KineticMessage_Init(operation->response->protobuf); KineticExchange_ConfigureHeader(operation->exchange, &operation->request->protobuf->header); operation->request->protobuf->header.messagetype = KINETIC_PROTO_MESSAGE_TYPE_NOOP; operation->request->protobuf->header.has_messagetype = true; Loading
src/lib/kinetic_pdu.c +15 −22 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include "kinetic_socket.h" #include "kinetic_hmac.h" #include "kinetic_logger.h" #include <string.h> static void KineticPDU_PackInt32(uint8_t* const buffer, int32_t value); static int32_t KineticPDU_UnpackInt32(const uint8_t* const buffer); Loading @@ -34,35 +33,29 @@ void KineticPDU_Init( uint8_t* const value, int32_t valueLength) { size_t protoPackedSize; assert(pdu != NULL); assert(message != NULL); assert(exchange != NULL); // Initialize the instance struct memset(pdu, 0, sizeof(KineticPDU)); // Create properly initialized PDU and populate passed instance const KineticPDU tmpPDU = { .exchange = exchange, .protobuf = message, .protobufLength = KineticProto_get_packed_size(&message->proto), .value = value, .valueLength = valueLength, .header.versionPrefix = (uint8_t)'F' // Set header version prefix appropriately }; *pdu = tmpPDU; // Copy initial value into target PDU // Associate with the specified exchange pdu->exchange = exchange; // Pack protobuf length field KineticPDU_PackInt32((uint8_t*)&pdu->header.protobufLength, pdu->protobufLength); // Associate with the specified message pdu->protobuf = message; // Pack value length field KineticPDU_PackInt32((uint8_t*)&pdu->header.valueLength, pdu->valueLength); // Configure the protobuf header with exchange info KineticExchange_ConfigureHeader(exchange, &pdu->protobuf->header); // Setup the PDU header fields pdu->header.versionPrefix = (uint8_t)'F'; // Associate with protobuf pdu->protobufLength = KineticProto_get_packed_size(&pdu->protobuf->proto); KineticPDU_PackInt32((uint8_t*)&pdu->header.protobufLength, pdu->protobufLength); // Pack protobuf length field // Associate with payload (if present) pdu->valueLength = valueLength; KineticPDU_PackInt32((uint8_t*)&pdu->header.valueLength, pdu->valueLength); // Pack value length field pdu->value = value; KineticExchange_ConfigureHeader(exchange, &message->header); } bool KineticPDU_Send(KineticPDU* const request) Loading
test/integration/test_kinetic_api_integration.c +30 −11 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ void setUp(void) { KineticApi_Init(TEST_LOG_FILE); KineticApi_Init(NULL); } void tearDown(void) Loading @@ -44,25 +44,44 @@ void tearDown(void) void test_NoOp_should_succeed(void) { KineticConnection connection; KineticExchange exchange; KineticOperation operation; KineticPDU request, response; int64_t identity = 1234; uint8_t key[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; int64_t connectionID = 5678; // ????? // KineticMessage requestMsg, responseMsg; const int64_t identity = 1234; uint8_t key[] = {1,2,3}; const int64_t connectionID = 5678; const int socketDesc = 783; KineticConnection connection = { .socketDescriptor = socketDesc // Fill in, since KineticConnection is mocked }; KineticMessage requestMsg, responseMsg; KineticProto_Status_StatusCode status; KineticHMAC respTempHMAC; KineticApi_Connect(&connection, "localhost", 8999, true); KineticConnection_Init_Expect(&connection); KineticConnection_Connect_ExpectAndReturn(&connection, "localhost", 8999, true, true); TEST_ASSERT_TRUE(KineticApi_Connect(&connection, "localhost", 8999, true)); TEST_ASSERT_EQUAL_INT(socketDesc, connection.socketDescriptor); // Ensure socket descriptor still intact! TEST_ASSERT_TRUE_MESSAGE( KineticApi_ConfigureExchange(&exchange, &connection, identity, key, sizeof(key), connectionID), "Failed configuring exchange!"); operation = KineticApi_CreateOperation(&exchange, &request, &response); operation = KineticApi_CreateOperation(&exchange, &request, &requestMsg, &response, &responseMsg); // Initialize response message status and HMAC, since receipt of packed protobuf is mocked out responseMsg.command.status->code = KINETIC_PROTO_STATUS_STATUS_CODE_SUCCESS; KineticHMAC_Populate(&respTempHMAC, &responseMsg, key, sizeof(key)); KineticSocket_Write_ExpectAndReturn(socketDesc, &request.header, sizeof(KineticPDUHeader), true); KineticSocket_WriteProtobuf_ExpectAndReturn(socketDesc, &requestMsg, true); KineticSocket_Read_ExpectAndReturn(socketDesc, &response.header, sizeof(KineticPDUHeader), true); KineticSocket_ReadProtobuf_ExpectAndReturn(socketDesc, &responseMsg.proto, response.protobufScratch, 0x08000000, true); status = KineticApi_NoOp(&operation); TEST_ASSERT_EQUAL_KINETIC_STATUS( KINETIC_PROTO_STATUS_STATUS_CODE_SUCCESS, KineticApi_NoOp(&operation)); TEST_ASSERT_EQUAL_KINETIC_STATUS(KINETIC_PROTO_STATUS_STATUS_CODE_SUCCESS, status); }