kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
kinetic_types_internal.h
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 
21 #ifndef _KINETIC_TYPES_INTERNAL_H
22 #define _KINETIC_TYPES_INTERNAL_H
23 
24 #include "kinetic_types.h"
25 #include "kinetic.pb-c.h"
28 #include "kinetic_resourcewaiter.h"
29 #include "kinetic_acl.h"
30 #include <netinet/in.h>
31 #include <ifaddrs.h>
32 #include <openssl/sha.h>
33 #include <time.h>
34 #include <pthread.h>
35 
36 #define KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION (10)
37 #define KINETIC_SOCKET_DESCRIPTOR_INVALID (-1)
38 #define KINETIC_CONNECTION_TIMEOUT_SECS (30) /* Java simulator may take longer than 10 seconds to respond */
39 #define KINETIC_OPERATION_TIMEOUT_SECS (20)
40 
41 
42 // Expose normally private data for test builds to allow inspection
43 #ifdef TEST
44 #define STATIC
45 #else
46 #define STATIC static
47 #endif
48 
49 
50 #define NUM_ELEMENTS(ARRAY) (sizeof(ARRAY)/sizeof((ARRAY)[0]))
51 
53  struct bus *bus;
54 };
55 
61 };
62 
63 // #TODO remove packed attribute and replace uses of sizeof(KineticPDUHeader)
64 // with a constant
65 typedef struct __attribute__((__packed__)) _KineticPDUHeader {
66  uint8_t versionPrefix;
67  uint32_t protobufLength;
68  uint32_t valueLength;
70 
75 };
76 
77 #define KINETIC_SEQUENCE_NOT_YET_BOUND ((int64_t)-2)
78 
79 typedef struct {
80  enum socket_state state;
81  KineticPDUHeader header;
82  enum unpack_error unpack_status;
83  size_t accumulated;
84  uint8_t buf[];
85 } socket_info;
86 
92  bool connected;
94  int socket;
95  int64_t connectionID;
96  int64_t sequence;
97  struct bus * messageBus;
98  socket_info * si;
99  pthread_mutex_t sendMutex;
100  KineticResourceWaiter connectionReady;
101  KineticCountingSemaphore * outstandingOperations;
102  uint16_t timeoutSeconds;
103 };
104 
105 // Kinetic Message HMAC
106 typedef struct _KineticHMAC {
108  uint32_t len;
109  uint8_t data[KINETIC_HMAC_MAX_LEN];
110 } KineticHMAC;
111 
112 
113 // Kinetic Device Message Request
114 typedef struct _KineticMessage {
115  // Kinetic Protocol Buffer Elements
116 
117  // Base Message
118  Com__Seagate__Kinetic__Proto__Message message;
119  Com__Seagate__Kinetic__Proto__Message__HMACauth hmacAuth;
120  Com__Seagate__Kinetic__Proto__Message__PINauth pinAuth;
121  uint8_t hmacData[KINETIC_HMAC_MAX_LEN];
122 
123  // Internal Command
124  Com__Seagate__Kinetic__Proto__Command command;
125  Com__Seagate__Kinetic__Proto__Command__Header header;
126  Com__Seagate__Kinetic__Proto__Command__Body body;
127  Com__Seagate__Kinetic__Proto__Command__Status status;
128  Com__Seagate__Kinetic__Proto__Command__Security security;
129  Com__Seagate__Kinetic__Proto__Command__Security__ACL acl;
130  Com__Seagate__Kinetic__Proto__Command__KeyValue keyValue;
131  Com__Seagate__Kinetic__Proto__Command__Range keyRange;
132  Com__Seagate__Kinetic__Proto__Command__Setup setup;
133  Com__Seagate__Kinetic__Proto__Command__GetLog getLog;
135  Com__Seagate__Kinetic__Proto__Command__GetLog__Device getLogDevice;
136  Com__Seagate__Kinetic__Proto__Command__PinOperation pinOp;
138 
139 // Kinetic PDU Header
140 #define PDU_HEADER_LEN (1 + (2 * sizeof(int32_t)))
141 #define PDU_PROTO_MAX_LEN (1024 * 1024)
142 #define PDU_PROTO_MAX_UNPACKED_LEN (PDU_PROTO_MAX_LEN * 2)
143 #define PDU_MAX_LEN (PDU_HEADER_LEN + \
144  PDU_PROTO_MAX_LEN + KINETIC_OBJ_SIZE)
145 
146 typedef enum {
152 
153 
156  Com__Seagate__Kinetic__Proto__Command* command;
157  bool pinAuth;
158 };
159 
160 typedef struct _KineticResponse
161 {
163  Com__Seagate__Kinetic__Proto__Message* proto;
164  Com__Seagate__Kinetic__Proto__Command* command;
165  uint8_t value[];
167 
168 typedef struct _KineticRequest KineticRequest;
169 typedef struct _KineticOperation KineticOperation;
170 
171 typedef KineticStatus (*KineticOperationCallback)(KineticOperation* const operation, KineticStatus const status);
172 
173 // Kinetic Operation
175  KineticSession* session;
176  KineticRequest* request;
178  uint16_t timeoutSeconds;
184  KineticP2P_Operation* p2pOp;
188 };
189 
190 
192  KineticAlgorithm kinteicAlgorithm);
195 
197  KineticSynchronization sync_mode);
200 
204  ProtobufCBinaryData protoData);
206  ByteBuffer dest, ProtobufCBinaryData src);
208  Com__Seagate__Kinetic__Proto__Command__KeyValue* keyValue, KineticEntry* entry);
210  Com__Seagate__Kinetic__Proto__Command__Range* keyRange, ByteBufferArray* keys);
211 int Kinetic_GetErrnoDescription(int err_num, char *buf, size_t len);
212 struct timeval Kinetic_TimevalZero(void);
213 bool Kinetic_TimevalIsZero(struct timeval const tv);
214 struct timeval Kinetic_TimevalAdd(struct timeval const a, struct timeval const b);
215 int Kinetic_TimevalCmp(struct timeval const a, struct timeval const b);
216 
218 
220 
221 void KineticMessage_Init(KineticMessage* const message);
222 void KineticRequest_Init(KineticRequest* reqeust, KineticSession const * const session);
223 
224 #endif // _KINETIC_TYPES_INTERNAL_H
Handle to the kinetic client, which is shared by all connections.
Com__Seagate__Kinetic__Proto__Command__GetLog__Type KineticLogInfo_Type_to_Com__Seagate__Kinetic__Proto__Command__GetLog__Type(KineticLogInfo_Type type)
Structure for handling generic arrays of bytes.
Definition: byte_array.h:34
KineticSynchronization
Enumeration of synchronization types for an operation on a KineticEntry.
Definition: kinetic_types.h:86
KineticOperationCallback opCallback
Com__Seagate__Kinetic__Proto__Command__MessageType
Definition: kinetic.pb-c.h:304
Structure for an embedded ByteArray as a buffer.
Definition: byte_array.h:53
KineticSessionConfig config
session configuration which is a deep copy of client configuration supplied to KienticClient_CreateSe...
KineticSession * session
Com__Seagate__Kinetic__Proto__Command__PinOperation pinOp
uint16_t timeoutSeconds
Default response timeout.
bool Copy_Com__Seagate__Kinetic__Proto__Command__Range_to_ByteBufferArray(Com__Seagate__Kinetic__Proto__Command__Range *keyRange, ByteBufferArray *keys)
Structure used to specify the configuration for a session.
Com__Seagate__Kinetic__Proto__Command__Range keyRange
#define KINETIC_HMAC_MAX_LEN
HMAC max length.
Definition: kinetic_types.h:43
socket_info * si
pointer to socket information
Com__Seagate__Kinetic__Proto__Command__Algorithm
Definition: kinetic.pb-c.h:274
KineticResponse * response
Com__Seagate__Kinetic__Proto__Command__Synchronization
Definition: kinetic.pb-c.h:253
Com__Seagate__Kinetic__Proto__Message * proto
bool Kinetic_TimevalIsZero(struct timeval const tv)
KineticLogInfo ** deviceInfo
bool connected
state of connection
Com__Seagate__Kinetic__Proto__Command__GetLog__Device getLogDevice
Com__Seagate__Kinetic__Proto__Command__Status status
ByteBufferArray * buffers
Message bus.
int Kinetic_TimevalCmp(struct timeval const a, struct timeval const b)
KineticAlgorithm
Enumeration of encryption/checksum key algorithms.
Definition: kinetic_types.h:73
Com__Seagate__Kinetic__Proto__Message message
socket_state
Definition: bus_example.c:52
struct timeval Kinetic_TimevalAdd(struct timeval const a, struct timeval const b)
void KineticRequest_Init(KineticRequest *reqeust, KineticSession const *const session)
ByteArray ProtobufCBinaryData_to_ByteArray(ProtobufCBinaryData protoData)
int socket
socket file descriptor
void KineticMessage_Init(KineticMessage *const message)
Com__Seagate__Kinetic__Proto__Command__GetLog__Type
Definition: kinetic.pb-c.h:161
Closure which can be specified for operations which support asynchronous mode.
Kinetic object instance.
struct __attribute__((__packed__)) _KineticPDUHeader
KineticLogInfo_Type
Log info type.
Base log info structure which is allocated by client and passed to KineticAdminClient_GetLog.
KineticStatus(* KineticOperationCallback)(KineticOperation *const operation, KineticStatus const status)
Com__Seagate__Kinetic__Proto__Command__Header header
Com__Seagate__Kinetic__Proto__Message__PINauth pinAuth
KineticMessageType Com__Seagate__Kinetic__Proto__Command__MessageType_to_KineticMessageType(Com__Seagate__Kinetic__Proto__Command__MessageType type)
Com__Seagate__Kinetic__Proto__Command__Algorithm Com__Seagate__Kinetic__Proto__Command__Algorithm_from_KineticAlgorithm(KineticAlgorithm kinteicAlgorithm)
bool Copy_ProtobufCBinaryData_to_ByteBuffer(ByteBuffer dest, ProtobufCBinaryData src)
bool Copy_Com__Seagate__Kinetic__Proto__Command__KeyValue_to_KineticEntry(Com__Seagate__Kinetic__Proto__Command__KeyValue *keyValue, KineticEntry *entry)
An instance of a session with a Kinetic device.
struct timeval Kinetic_TimevalZero(void)
Com__Seagate__Kinetic__Proto__Command * command
Com__Seagate__Kinetic__Proto__Command__Body body
KineticSynchronization KineticSynchronization_from_Com__Seagate__Kinetic__Proto__Command__Synchronization(Com__Seagate__Kinetic__Proto__Command__Synchronization sync_mode)
KineticStatus terminationStatus
reported status upon device termination (SUCCESS if not terminated)
KineticRequest * request
KineticPDUHeader header
Com__Seagate__Kinetic__Proto__Command__Security__ACL__HMACAlgorithm
Definition: kinetic.pb-c.h:176
Com__Seagate__Kinetic__Proto__Command__Security__ACL__HMACAlgorithm algorithm
Com__Seagate__Kinetic__Proto__Command__KeyValue keyValue
Com__Seagate__Kinetic__Proto__Command__Security security
int64_t connectionID
initialized to seconds since epoch
Com__Seagate__Kinetic__Proto__Command__GetLog getLog
Com__Seagate__Kinetic__Proto__Command__Security__ACL acl
KineticResourceWaiter connectionReady
connection ready status (set to true once connectionID recieved)
Com__Seagate__Kinetic__Proto__Command__Setup setup
KineticStatus
Kinetic status codes.
KineticMessageType
Log info message types.
Com__Seagate__Kinetic__Proto__Command command
KineticCompletionClosure closure
Com__Seagate__Kinetic__Proto__Command__GetLog__Type getLogType
int64_t sequence
increments for each request in a session
Com__Seagate__Kinetic__Proto__Command__Synchronization Com__Seagate__Kinetic__Proto__Command__Synchronization_from_KineticSynchronization(KineticSynchronization sync_mode)
Com__Seagate__Kinetic__Proto__Command * command
KineticStatus KineticProtoStatusCode_to_KineticStatus(Com__Seagate__Kinetic__Proto__Command__Status__StatusCode protoStatus)
Com__Seagate__Kinetic__Proto__Message__HMACauth hmacAuth
Com__Seagate__Kinetic__Proto__Command__Status__StatusCode
Definition: kinetic.pb-c.h:78
KineticAlgorithm KineticAlgorithm_from_Com__Seagate__Kinetic__Proto__Command__Algorithm(Com__Seagate__Kinetic__Proto__Command__Algorithm protoAlgorithm)
KineticP2P_Operation * p2pOp
KineticCountingSemaphore * outstandingOperations
counting semaphore to only allows the configured number of outstanding operation at a given time ...
example_state state
Definition: bus_example.c:83
int Kinetic_GetErrnoDescription(int err_num, char *buf, size_t len)
struct bus * messageBus
pointer to message bus instance
pthread_mutex_t sendMutex
mutex for locking around seq count acquisision, PDU packing, and transfer to threadpool ...